1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| interface
[...]
function GetFieldSQLValue( AField: TField ): String;
function GetSQLInsert( DataSetSource: TDataSet ): String;
implementation
function GetFieldSQLValue( AField: TField ): String;
begin
if AField.IsNull then
Result := 'NULL'
else if ( AField is TStringField ) then
Result := QuotedStr( AField.AsString )
else
Result := AField.AsString;
end;
function GetSQLInsert( DataSetSource: TDataSet ): String;
var
SQLChamps, SQLValeurs: String;
Cpt: Integer;
begin
for Cpt := 0 to DataSetSource.Fields.Count - 1 do
begin
SQLChamps := SQLChamps + ',' + DataSetSource.Fields[Cpt].FieldName;
SQLValeurs := SQLValeurs + ',' + GetFieldSQLValue( DataSetSource.Fields[Cpt] );
end;
Delete( SQLChamps, 1, 1 );
Delete( SQLValeurs , 1, 1 );
Result := 'INSERT INTO matable(' + SQLChamps + ')'
+ ' VALUES(' + SQLValeurs + ')';
end; |
Partager