Import BLOB, MEMO from Advantage Table

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
teunis
Posts: 48
Joined: Wed 01 Feb 2006 14:15
Location: Curacao

Import BLOB, MEMO from Advantage Table

Post by teunis » Fri 02 Feb 2007 15:45

With Delphi 6 i made a program to import tables in Advantage(extended systems) format
It works. If anybody is interested in the code let me know.
The only problem is to import values in the blob field
I am using INSERT INTO
If I use the Fields[i].Value as a string then it doesn't work.
Any suggestions how to do it.
Thanks for your help Teunis

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Fri 02 Feb 2007 16:31

Try to use parameters with the INSERT INTO statement.

Below is one more way to load a BLOB value:

Code: Select all

  if Query.Fields[i].IsBlob then
    TBlobField(Query.Fields[i]).Value := ;

teunis
Posts: 48
Joined: Wed 01 Feb 2006 14:15
Location: Curacao

Post by teunis » Mon 05 Feb 2007 13:59

Thanks for the answer.
a SQL parameter aproach is difficult to realise because I like to keep the conversion
general.
My working solution is the following for the interested reader:
This works if there is only 1 Blob field in the table.
The table is converted ADS -> MySQL In the INSERT statement the blob fileld is an empty string. The name of the field with ftBLOB is registered and has the name metblob
T1 is the TADSTable Q1 is a TMyQuery sleutel is a primary index field
So after creating the table with her records I fill in the BLOB values.

Code: Select all

IF metblob  '' THEN BEGIN
T1.Active:= TRUE;
T1.First;
WHILE NOT T1.Eof DO BEGIN
IF T1.FieldByName(metblob)  NIL THEN BEGIN
Q1.SQL.Clear;
Q1.SQL.Add('SELECT * FROM ' + AnsiUpperCase(tafelnaam));
Q1.SQL.Add('WHERE sleutel = ' + T1.FieldByname('sleutel').asString);
Q1.Active:= TRUE;
Q1.Edit;
BlobF:= Q1.FieldByName(metblob) as TBlobField;
BlobF.Assign(T1.FieldByName(metblob) as TBlobField);
Q1.Post;
END;
T1.Next END;
T1.Active:= FALSE;
END;
Teunis

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 06 Feb 2007 11:14

It is good to see that this problem has been solved
But I think that this way is not optimal. Usage of parameters is more correct and fast. Just assign UPDATE query like this before cycle:

Code: Select all

  Q1.SQL.Text := 'UPDATE ' + AnsiUpperCase(tafelnaam) + ' SET ' + metblob + '= :blob_param WHERE sleutel = :sleutel_param';
For each BLOB value assign the parameter value for the key field (sleutel_param) and the BLOB value itself (blob_param). Then call to the Q1.Execut method.

teunis
Posts: 48
Joined: Wed 01 Feb 2006 14:15
Location: Curacao

Post by teunis » Tue 06 Feb 2007 13:00

Yes Antaeius Thanks for your help.
The following code also works great:

Code: Select all

IF metblob  '' THEN BEGIN
Q1.SQL.Text:= 'UPDATE ' + AnsiUpperCase(tafelnaam) +
' SET ' + metblob + '= :blob_param WHERE sleutel = :sleutel_param';
T1.Active:= TRUE;
T1.First;
WHILE NOT T1.Eof DO BEGIN
IF T1.FieldByName(metblob)  NIL THEN BEGIN
Q1.params[1].asString:= T1.FieldByname('sleutel').asString;
Q1.Params[0].AsBlob:= T1.FieldByName(metblob).AsVariant;
Q1.Execute;
END;
T1.Next END;
T1.Active:= FALSE;
 END;
it is als quicker
Thanks Teunis

Post Reply