New property 'NotModify'

sinys

Member²
I ask to add a new property for TField. It must show, if the field must be updated in database when I update it in my program.

Sample query:

SQL:
select t1.*, t1.rowid, t2.name as ABC_NAME
from table1 t1, table2 t2
where t1.id_abc = t2.id_abc(+)
table2 - table directory, from which the user can choose the value

My source code:

Code:
procedure TForm1.OracleDataSet1AfterOpen(DataSet: TDataSet);
begin
  // My new property
  OracleDataSet1.FieldByName('ABC_NAME').NotModify := True;
end;

procedure TForm2.DBGrid1DblClick(Sender: TObject);
begin
  OracleDataSet1.Edit;
  OracleDataSet1.FieldByName('id_abc').AsInteger := OracleDataSet2.FieldByName('id_abc').AsInteger;
  OracleDataSet1.FieldByName('ABC_NAME').AsString := OracleDataSet2.FieldByName('name').AsString;
  OracleDataSet1.Post;
end;
Must send the command to update to the database only for the field 'id_abc'!

I don't REFRESH OracleDataSet1 or only one record in it (RefreshRecord) because the query selects a lot rows and in practice very complex queries and large (long run). In addition it saves bandwidth and time.
Event 'AfterOpen' is used because prior to the opening OracleDataSet1 we don't know the exact type of data
some fields (example: NUMBER or NUMBER(5)), the disorder in the databases :). If fields can be determined in advance on some database to get an error OracleDataSet1: Type mismatch for field 'ID_ABC', expecting: Float actual: Integer.

For myself, I added a property "NotModify" (Boolean) for TOracleDataset. Please add this to the list of enhancement request.
 
For myself, I made:

unit OracleData;

...

// Determine if a field has been changed
function TOracleDataSet.FieldChanged(Field: TField): Boolean;
var OldValue, NewValue: Variant;
OldNull, NewNull: Boolean;
OldBlob, NewBlob: TOracleBlob;
Log: TChangeLogItem;
Rec: PRecordData;
begin
if Field.NotModify then
begin
Result := False;
Exit;
end;

...

procedure TOracleDataSet.CreateInsert(LOBList: TList; Blobs: TBLOBList);
var SQL1, SQL2, ReturningFrom, ReturningInto: string;
f: Integer;
AllNull: Boolean;
Col: TOracleFieldInfo;
begin
DMLQuery.Clear;
SQL1 := '';
SQL2 := '';
ReturningFrom := '';
ReturningInto := '';
AllNull := True;
for f := 0 to FieldInfoList.Count - 1 do
begin
Col := FieldInfoList[f];
if ((Col.InfoType = itField) and (Col.Field.FieldKind = fkData)) or
((Col.InfoType = itUnusedField) and (Col.DataType = otObject) and (not Col.IsCollection)) then
begin
if ((not Col.FieldIsNull) or Col.FieldHasDefault) and (not Col.Field.NotModify) then
begin
AllNull := False;
ColSQL(Col, True, SQL1, SQL2, ReturningFrom, ReturningInto, LOBList, Blobs);
end;

 
Back
Top