mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Completed new field options (foDoNot*)
This commit is contained in:
parent
ab92225d12
commit
17747dcf19
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 = (
|
||||
/// <summary>
|
||||
/// It's the primary key of the mapped table }
|
||||
/// </summary>
|
||||
foPrimaryKey,
|
||||
/// <summary>
|
||||
/// Not written, read - similar to readonly - is updated after insert and update
|
||||
/// </summary>
|
||||
foAutoGenerated,
|
||||
/// <summary>
|
||||
/// shortcut for --> Insertable := False; Updatable := False; Selectable := True;
|
||||
/// </summary>
|
||||
foReadOnly,
|
||||
/// <summary>
|
||||
/// used for versioning, only one field with foVersion is allowed in class
|
||||
/// </summary>
|
||||
foVersion,
|
||||
/// <summary>
|
||||
/// not included in SQL SELECT commands
|
||||
/// </summary>
|
||||
foDoNotSelect,
|
||||
/// <summary>
|
||||
/// not included in SQL INSERT commands
|
||||
/// </summary>
|
||||
foDoNotInsert,
|
||||
/// <summary>
|
||||
/// not included in SQL UPDATE commands
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user