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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
procedure TParadoxToSQLForm.BtnExtractValuesClick(Sender: TObject);
var
LineValues: array of string;
Value, Line, Template: string;
I: Integer;
begin
Template := Trim(MemoSQLTemplate.Text);
if (Template = '') or (Pos(';', Template) > 0) then
begin
MessageDlg('Template SQL Incorrect', mtError, [mbAbort], 0);
Exit;
end;
MemoValues.Lines.Clear();
TableValues.First();
SetLength(LineValues, TableValues.Fields.Count);
while not TableValues.Eof do
begin
ZeroMemory(@LineValues[0], SizeOf(string) * Length(LineValues));
for I := 0 to TableValues.Fields.Count - 1 do
begin
if TableValues.Fields.Fields[I].IsNull then
begin
Value := 'NULL';
end
else
begin
try
case TableValues.Fields.Fields[I].DataType of
ftString : Value := QuotedStr(Format('%s', [TableValues.Fields.Fields[I].AsString]));
ftAutoInc : Value := TableValues.Fields.Fields[I].AsString;
ftInteger : Value := TableValues.Fields.Fields[I].AsString;
ftFloat : Value := ReplaceChar(TableValues.Fields.Fields[I].AsString, ',', '.');
ftDate : Value := Format(EdSQLDateFormat.Text, [FormatDateTime(EdDelphiDateFormat.Text, TableValues.Fields.Fields[I].AsDateTime)]);
ftDateTime : Value := Format(EdSQLDateTimeFormat.Text, [FormatDateTime(EdDelphiDateTimeFormat.Text, TableValues.Fields.Fields[I].AsDateTime)]);
ftBlob : Value := QuotedStr(Format('%s', [TableValues.Fields.Fields[I].AsString]));
ftMemo : Value := QuotedStr(Format('%s', [TableValues.Fields.Fields[I].AsString]));
ftFmtMemo : Value := QuotedStr(Format('%s', [TableValues.Fields.Fields[I].AsString]));
ftBoolean : Value := QuotedStr(Format('%s', [IfThen(TableValues.Fields.Fields[I].AsBoolean, 'T', 'F')]));
else
MessageDlg(Format('Type "%s" non géré', [GetEnumName(TypeInfo(TFieldType), Ord(TableValues.Fields.Fields[I].DataType))]), mtWarning, [mbAbort], 0);
Exit;
end;
except
on E: Exception do
begin
MessageDlg(Format('Valeur du Champ "%s" incorrect remplacé par NULL', [TableValues.Fields.Fields[I].FieldName]), mtInformation, [mbIgnore], 0);
Value := 'NULL';
end;
end;
end;
LineValues[I] := ReplaceChar(ReplaceChar(Value, #0, ' '), #$A0, ' '); // les Blobs contiennent un Zéro terminal ... le Blank est un séparateur interne, on le supprime des contenus
end;
Line := LineValues[Low(LineValues)];
for I := Succ(Low(LineValues)) to High(LineValues) do
Line := Line + ',' + LineValues[I];
MemoValues.Lines.Add(Format(Template, [Line]) + ';'#$A0);
TableValues.Next();
end;
end; |
Partager