diff --git a/samples/activerecord_restful_crud/activerecord_restful_crud.dpr b/samples/activerecord_restful_crud/activerecord_restful_crud.dpr index 56e0deb8..f0b0f136 100644 --- a/samples/activerecord_restful_crud/activerecord_restful_crud.dpr +++ b/samples/activerecord_restful_crud/activerecord_restful_crud.dpr @@ -40,7 +40,7 @@ begin if ParamCount >= 1 then lCmd := ParamStr(1) else - lCmd := '/firebird'; + lCmd := '/postgresql'; if (lCmd = '/firebird') then begin @@ -50,15 +50,14 @@ begin begin CreateMySQLPrivateConnDef(True); end - else if (lCmd = '/postgresql') then - begin - CreatePostgreSQLPrivateConnDef(True); - end else begin - CreateFirebirdPrivateConnDef(True); + lCmd := '/postgresql'; + CreatePostgreSQLPrivateConnDef(True); end; + WriteLn('Using ' + lCmd.Substring(1)); + lServer := TIdHTTPWebBrokerBridge.Create(nil); try lServer.KeepAlive := True; diff --git a/samples/activerecord_showcase/EntitiesU.pas b/samples/activerecord_showcase/EntitiesU.pas index 291dd561..a4d767dd 100644 --- a/samples/activerecord_showcase/EntitiesU.pas +++ b/samples/activerecord_showcase/EntitiesU.pas @@ -73,9 +73,9 @@ type 'SEQ_ARTICLES_ID' { required for interbase } )] {$ENDIF} fID: NullableInt32; - [MVCTableField('description', [foWriteOnly])] + [MVCTableField('description', [foDoNotSelect])] fDescrizione: string; - [MVCTableField('price', [foWriteOnly])] + [MVCTableField('price', [foDoNotSelect])] fPrice: Integer; public property ID: NullableInt32 read fID write fID; diff --git a/sources/MVCFramework.ActiveRecord.pas b/sources/MVCFramework.ActiveRecord.pas index 0947808f..58a89985 100644 --- a/sources/MVCFramework.ActiveRecord.pas +++ b/sources/MVCFramework.ActiveRecord.pas @@ -64,14 +64,42 @@ type TMVCActiveRecordClass = class of TMVCActiveRecord; TMVCActiveRecord = class; - TMVCActiveRecordFieldOption = (foPrimaryKey, { it's the primary key of the mapped table } - foAutoGenerated, { not written, read - similar to readonly } - foReadOnly, { not written, read - like foDoNotInsert+foDoNotUpdate } - foWriteOnly, { written, not read } - foVersion, {used for versioning, only one field with foVersion is allowed in class} - foDoNotInsert, { this field is not included in SQL INSERT commands } - foDoNotUpdate { this field is not included in SQL UPDATE commands } - ); + + + TMVCActiveRecordFieldOption = ( + /// + /// It's the primary key of the mapped table } + /// + foPrimaryKey, + /// + /// Not written, read - similar to readonly - is updated after insert and update + /// + foAutoGenerated, + /// + /// shortcut for --> Insertable := False; Updatable := False; Selectable := True; + /// + foReadOnly, + /// + /// used for versioning, only one field with foVersion is allowed in class + /// + foVersion, + /// + /// not included in SQL SELECT commands + /// + foDoNotSelect, + /// + /// not included in SQL INSERT commands + /// + foDoNotInsert, + /// + /// not included in SQL UPDATE commands + /// + foDoNotUpdate + ); + + + + TMVCActiveRecordFieldOptions = set of TMVCActiveRecordFieldOption; TMVCEntityAction = (eaCreate, eaRetrieve, eaUpdate, eaDelete); TMVCEntityActions = set of TMVCEntityAction; @@ -106,7 +134,7 @@ type FieldName: string; FieldOptions: TMVCActiveRecordFieldOptions; DataTypeName: string; - Writeable, Readable, Insertable, Updatable, IsVersion: Boolean; + Selectable, Insertable, Updatable, IsVersion: Boolean; procedure EndUpdates; end; @@ -1601,7 +1629,7 @@ begin if lTableMap.fIsVersioned then begin lFieldInfo := lTableMap.fMap.GetInfoByFieldName(lTableMap.fVersionFieldName); - if not (lFieldInfo.Writeable and lFieldInfo.Readable) then + if not (lFieldInfo.Insertable and lFieldInfo.Updatable) then begin raise EMVCActiveRecord .CreateFmt('Field [%s], is marked as foVersion so must be a Read/Write field - ' + @@ -2740,7 +2768,7 @@ begin begin for lItem in fTableMap.fMap do begin - if not lItem.Value.Readable then + if not lItem.Value.Selectable then begin Continue; end; @@ -4089,8 +4117,7 @@ var begin for lPair in Map do begin - // if not lPair.Value.FieldName.IsEmpty then - if lPair.Value.Readable then + if lPair.Value.Selectable then begin Result := Result + GetFieldNameForSQL(lPair.Value.FieldName) + Delimiter; end; @@ -4204,11 +4231,11 @@ begin for lPair in Self do begin lPair.Value.EndUpdates; - if lPair.Value.Writeable then + if lPair.Value.Insertable or lPair.Value.Updatable then begin Inc(fWritableFieldsCount); end; - if lPair.Value.Readable then + if lPair.Value.Selectable then begin Inc(fReadableFieldsCount); end; @@ -4236,17 +4263,23 @@ procedure TFieldInfo.EndUpdates; begin if FieldName.IsEmpty then begin - Writeable := false; - Readable := false; + //Writeable := false; + Selectable := false; Insertable := False; Updatable := False; end else begin - Writeable := ((FieldOptions * [foReadOnly, foAutoGenerated]) = []); - Readable := not (foWriteOnly in FieldOptions); + //Writeable := ((FieldOptions * [foReadOnly, foAutoGenerated]) = []); + Selectable := not (foDoNotSelect in FieldOptions); Insertable := not (foDoNotInsert in FieldOptions); Updatable := not (foDoNotUpdate in FieldOptions); + if foReadOnly in FieldOptions then + begin + Insertable := False; + Updatable := False; + Selectable := True; + end; end; IsVersion := foVersion in FieldOptions; diff --git a/sources/MVCFramework.SQLGenerators.Firebird.pas b/sources/MVCFramework.SQLGenerators.Firebird.pas index 561da67a..f8d1a12f 100644 --- a/sources/MVCFramework.SQLGenerators.Firebird.pas +++ b/sources/MVCFramework.SQLGenerators.Firebird.pas @@ -83,7 +83,7 @@ begin for lKeyValue in TableMap.fMap do begin // if not(foTransient in lKeyValue.Value.FieldOptions) then - if lKeyValue.Value.Writeable then + if lKeyValue.Value.Insertable then begin lSB.Append(GetFieldNameForSQL(lKeyValue.Value.FieldName) + ','); end; @@ -108,7 +108,7 @@ begin if lKeyValue.Value.IsVersion then begin lSB.Append(OBJECT_VERSION_STARTING_VALUE + ','); - end else if lKeyValue.Value.Writeable then + end else if lKeyValue.Value.Insertable then begin lSB.Append(':' + GetParamNameForSQL(lKeyValue.Value.FieldName) + ','); end; diff --git a/sources/MVCFramework.SQLGenerators.Interbase.pas b/sources/MVCFramework.SQLGenerators.Interbase.pas index 3bdbe08d..09235657 100644 --- a/sources/MVCFramework.SQLGenerators.Interbase.pas +++ b/sources/MVCFramework.SQLGenerators.Interbase.pas @@ -80,7 +80,7 @@ begin for lKeyValue in TableMap.fMap do begin - if lKeyValue.Value.Writeable then + if lKeyValue.Value.Insertable then begin lSB.Append(GetFieldNameForSQL(lKeyValue.Value.FieldName) + ','); end; @@ -105,7 +105,7 @@ begin if lKeyValue.Value.IsVersion then begin lSB.Append(OBJECT_VERSION_STARTING_VALUE + ','); - end else if lKeyValue.Value.Writeable then + end else if lKeyValue.Value.Insertable then begin lSB.Append(':' + GetParamNameForSQL(lKeyValue.Value.FieldName) + ','); end; diff --git a/sources/MVCFramework.SQLGenerators.MSSQL.pas b/sources/MVCFramework.SQLGenerators.MSSQL.pas index 35a496c0..6182ee5e 100644 --- a/sources/MVCFramework.SQLGenerators.MSSQL.pas +++ b/sources/MVCFramework.SQLGenerators.MSSQL.pas @@ -79,7 +79,7 @@ begin for lKeyValue in TableMap.fMap do begin - if lKeyValue.Value.Writeable then + if lKeyValue.Value.Insertable then begin lSB.Append(lKeyValue.Value.FieldName + ','); end; @@ -103,7 +103,7 @@ begin if lKeyValue.Value.IsVersion then begin lSB.Append(OBJECT_VERSION_STARTING_VALUE + ','); - end else if lKeyValue.Value.Writeable then + end else if lKeyValue.Value.Insertable then begin lSB.Append(':' + lKeyValue.Value.FieldName + ','); end; diff --git a/sources/MVCFramework.SQLGenerators.MySQL.pas b/sources/MVCFramework.SQLGenerators.MySQL.pas index efcfcb55..f8c08130 100644 --- a/sources/MVCFramework.SQLGenerators.MySQL.pas +++ b/sources/MVCFramework.SQLGenerators.MySQL.pas @@ -81,7 +81,7 @@ begin for lKeyValue in TableMap.fMap do begin - if lKeyValue.Value.Writeable then + if lKeyValue.Value.Insertable then begin lSB.Append(GetFieldNameForSQL(lKeyValue.Value.FieldName) + ','); end; @@ -106,7 +106,7 @@ begin if lKeyValue.Value.IsVersion then begin lSB.Append(OBJECT_VERSION_STARTING_VALUE + ','); - end else if lKeyValue.Value.Writeable then + end else if lKeyValue.Value.Insertable then begin lSB.Append(':' + GetParamNameForSQL(lKeyValue.Value.FieldName) + ','); end; diff --git a/sources/MVCFramework.SQLGenerators.Sqlite.pas b/sources/MVCFramework.SQLGenerators.Sqlite.pas index 2beaf1cd..91c2de1d 100644 --- a/sources/MVCFramework.SQLGenerators.Sqlite.pas +++ b/sources/MVCFramework.SQLGenerators.Sqlite.pas @@ -79,7 +79,7 @@ begin for lKeyValue in TableMap.fMap do begin - if lKeyValue.Value.Writeable then + if lKeyValue.Value.Insertable then begin lSB.Append(GetFieldNameForSQL(lKeyValue.Value.FieldName) + ','); end; @@ -103,7 +103,7 @@ begin if lKeyValue.Value.IsVersion then begin lSB.Append(OBJECT_VERSION_STARTING_VALUE + ','); - end else if lKeyValue.Value.Writeable then + end else if lKeyValue.Value.Insertable then begin lSB.Append(':' + GetParamNameForSQL(lKeyValue.Value.FieldName) + ','); end;