mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 00:05:53 +01:00
Merge pull request #187 from pedrooliveira01/master
Pedro <pedrooliveira__@hotmail.com>
This commit is contained in:
commit
425a7c5d26
@ -54,7 +54,7 @@ type
|
||||
end;
|
||||
|
||||
TMVCActiveRecordClass = class of TMVCActiveRecord;
|
||||
TMVCActiveRecordFieldOption = (foAutoGenerated);
|
||||
TMVCActiveRecordFieldOption = (foAutoGenerated,foNoUpdate);
|
||||
TMVCActiveRecordFieldOptions = set of TMVCActiveRecordFieldOption;
|
||||
TMVCEntityAction = (eaCreate, eaRetrieve, eaUpdate, eaDelete);
|
||||
TMVCEntityActions = set of TMVCEntityAction;
|
||||
@ -88,7 +88,9 @@ type
|
||||
MVCTableFieldAttribute = class(MVCActiveRecordCustomAttribute)
|
||||
public
|
||||
FieldName: string;
|
||||
constructor Create(aFieldName: string);
|
||||
FieldOptions: TMVCActiveRecordFieldOptions;
|
||||
constructor Create(const aFieldName: string; const aFieldOptions: TMVCActiveRecordFieldOptions); overload;
|
||||
constructor Create(aFieldName: string); overload;
|
||||
end;
|
||||
|
||||
MVCPrimaryKeyAttribute = class(MVCActiveRecordCustomAttribute)
|
||||
@ -133,6 +135,7 @@ type
|
||||
fPropsAttributes: TArray<TCustomAttribute>;
|
||||
fTableName: string;
|
||||
fMap: TDictionary<TRttiField, string>;
|
||||
fMapUpdate: TDictionary<TRttiField, string>;
|
||||
fPrimaryKey: TRttiField;
|
||||
fBackendDriver: string;
|
||||
fMapping: TMVCFieldsMapping;
|
||||
@ -606,8 +609,7 @@ end;
|
||||
|
||||
constructor MVCTableFieldAttribute.Create(aFieldName: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FieldName := aFieldName;
|
||||
Create(aFieldName, []);
|
||||
end;
|
||||
|
||||
{ TableAttribute }
|
||||
@ -623,6 +625,7 @@ end;
|
||||
destructor TMVCActiveRecord.Destroy;
|
||||
begin
|
||||
fMap.Free;
|
||||
fMapUpdate.Free;
|
||||
fSQLGenerator.Free;
|
||||
fRQL2SQL.Free;
|
||||
fConn := nil; // do not free it!!
|
||||
@ -781,6 +784,8 @@ begin
|
||||
if lAttribute is MVCTableFieldAttribute then
|
||||
begin
|
||||
fMap.Add(lRTTIField, { fTableName + '.' + } MVCTableFieldAttribute(lAttribute).FieldName);
|
||||
if not (foNoUpdate in MVCTableFieldAttribute(lAttribute).FieldOptions) then
|
||||
fMapUpdate.add(lRTTIField, MVCTableFieldAttribute(lAttribute).FieldName);
|
||||
end
|
||||
else if lAttribute is MVCPrimaryKeyAttribute then
|
||||
begin
|
||||
@ -800,7 +805,7 @@ begin
|
||||
OnValidation;
|
||||
OnBeforeInsert;
|
||||
OnBeforeInsertOrUpdate;
|
||||
SQL := SQLGenerator.CreateInsertSQL(fTableName, fMap, fPrimaryKeyFieldName, fPrimaryKeyOptions);
|
||||
SQL := SQLGenerator.CreateInsertSQL(fTableName, fMapUpdate, fPrimaryKeyFieldName, fPrimaryKeyOptions);
|
||||
ExecNonQuery(SQL, True);
|
||||
OnAfterInsert;
|
||||
OnAfterInsertOrUpdate;
|
||||
@ -817,6 +822,7 @@ begin
|
||||
SelfConnection;
|
||||
// end;
|
||||
fMap := TDictionary<TRttiField, string>.Create;
|
||||
fMapUpdate := TDictionary<TRttiField, string>.Create;
|
||||
InitTableInfo;
|
||||
end;
|
||||
|
||||
@ -1543,7 +1549,7 @@ begin
|
||||
OnBeforeUpdate;
|
||||
OnBeforeInsertOrUpdate;
|
||||
{ TODO -oDanieleT -cSQLGenerators : Add a parameter to update to allow to update only selected fields }
|
||||
SQL := SQLGenerator.CreateUpdateSQL(fTableName, fMap, fPrimaryKeyFieldName, fPrimaryKeyOptions);
|
||||
SQL := SQLGenerator.CreateUpdateSQL(fTableName, fMapUpdate, fPrimaryKeyFieldName, fPrimaryKeyOptions);
|
||||
ExecNonQuery(SQL, false);
|
||||
OnAfterUpdate;
|
||||
OnAfterInsertOrUpdate;
|
||||
@ -1809,6 +1815,14 @@ begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
constructor MVCTableFieldAttribute.Create(const aFieldName: string;
|
||||
const aFieldOptions: TMVCActiveRecordFieldOptions);
|
||||
begin
|
||||
inherited Create;
|
||||
FieldName := aFieldName;
|
||||
FieldOptions := aFieldOptions;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
gLock := TObject.Create;
|
||||
|
Loading…
Reference in New Issue
Block a user