Hello.
I want to generate SQL insert for a mariadb table using zeos component.
Table contains Numbers, Dates, DateTimes, Booleans ( tinyint), Memo's & Blob for images.
I have a Form with SynEdit to display SQL insert for Every record returned with query
here is the code:
procedure TForm1.Button3Click(Sender: TObject);
var
I, j, fCount: Integer;
LsValue: String;
begin
with ZQ_nrec do
begin
Close;
SQL.Text := SysUtils.Format(C_Nsql, ['uc_ptnts_test']);
Open;
if RecordCount = 0 then // Not records
begin
Exit;
end;
fCount := FieldCount - 1;
First ; // First
while not Eof do // loop until the end
begin
LsValue := '';
for j := 0 to fCount do
begin
Application.ProcessMessages;
if j<>fCount then
begin
if Fields[j].DataType = ftBlob then
begin
if not Fields[j].IsNull then
LsValue := LsValue + QuotedStr(( Fields[j].AsString )) + ' ,'
else LsValue := LsValue + ' NULL ,' ;
end
else
if Fields[j].DataType in [ftInteger, ftLargeint, ftBoolean] then
begin
if not Fields[j].IsNull then
LsValue := LsValue + IntToStr( Fields[j].AsLargeInt ) + ' ,'
else LsValue := LsValue + ' NULL ,';
end
else
if Fields[j].DataType in [ftDate, ftTime, ftDateTime] then
begin
if not Fields[j].IsNull then
LsValue := LsValue + QuotedStr( FormatDateTime( 'yyyy-mm-dd hh:nn:ss', Fields[j].AsDateTime ) )+ ' ,'
else LsValue := LsValue + ' NULL ,';
end
else
begin
if not Fields[j].IsNull then
LsValue := LsValue + QuotedStr( Fields[j].AsString ) + ' ,'
else LsValue := LsValue + ' NULL ,';
end;
end
else
begin
if not Fields[j].IsNull then
LsValue := LsValue + QuotedStr( Fields[j].AsString )
else LsValue := LsValue + ' NULL ';
end;
end;
LsValue := SysUtils.Format( C_Isql, ['uc_ptnts_test']) + LsValue + ');';
SynEdit1.Append(LsValue);
Application.ProcessMessages;
Next;
end;
end;
SynEdit1.Append('');
end;
The problem is with Blobs ( graphics ).
I tried using this , to encode bytes as string ( IdEncoderMIME1 from Indy package)
LsValue := LsValue + QuotedStr( IdEncoderMIME1.EncodeBytes( Fields[j].AsString ))) + ' ,'
It do the job but, when I try to execute one row from SQL result, the image effectivelly do not inserts as stream of bytes but encoded in MIME64.
So,
Is there any solution to do not use the Encoders, and to get it work .
Thanks.