How to store data in BINARY field

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
avor_il
Posts: 3
Joined: Wed 06 Feb 2008 12:31

How to store data in BINARY field

Post by avor_il » Wed 06 Feb 2008 12:47

I have BINARY field in the table.

`TAG` binary(12) NOT NULL

How I can store bytes from array of bytes in this field?
Followed code work but on `TAG` field data not stored.
tag contain right data.

Code: Select all

Variant tag = VarArrayCreate(Bounds, 1, varByte);
for(int i=0;iSQL->Add("INSERT INTO `alnetdb`.`pc_product_log` ( \                    `TAG`, `DT`, `STATION_ID`, `ENTRY_FLAG`) VALUES (:tag, :dt, :station_id, :entry_flag);");
                pQuery->Params->ParamByName("tag")->DataType = ftBytes;
                pQuery->Params->ParamByName("tag")->Size = RFID_TAG_LEN;
                pQuery->Params->ParamByName("tag")->Value = tag;
                pQuery->Params->ParamByName("dt")->AsDateTime = dtDate;
                pQuery->Params->ParamByName("station_id")->AsInteger = station->StationID;
                pQuery->Params->ParamByName("entry_flag")->AsBoolean = GetControlPointDirection(station->StationID);
                pQuery->Execute();
                pQuery->Close();
Help me please!
Alex

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 07 Feb 2008 12:21

Try setting param DataType to ftString, using this code:

Code: Select all

  pQuery->Params->ParamByName("tag")->DataType = ftString;

avor_il
Posts: 3
Joined: Wed 06 Feb 2008 12:31

Post by avor_il » Thu 07 Feb 2008 13:34

Dimon wrote:Try setting param DataType to ftString, using this code:

Code: Select all

  pQuery->Params->ParamByName("tag")->DataType = ftString;
Note: if in array of data some byte contain 0x00, after this byte other bytes not stored in the field. If array not contain such zero byte all data stored in the field correctly.

Any idea?

p.s. I did not changed DataType to ftString.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 13 Feb 2008 09:12

We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 19 Feb 2008 13:07

avor_il wrote:Note: if in array of data some byte contain 0x00, after this byte other bytes not stored in the field. If array not contain such zero byte all data stored in the field correctly.
Data is stored correctly if in array of data some byte contains 0x00.
However, on data opening Binary fields are mapped to string fields and therefore all data after 0x00 byte is cut off.

In order to solve this problem you should set the TMyQyery.Options.BinaryAsString property to false to create TBytesField for Binary fields.

avor_il
Posts: 3
Joined: Wed 06 Feb 2008 12:31

Post by avor_il » Thu 21 Feb 2008 13:41

Dimon wrote: Data is stored correctly if in array of data some byte contains 0x00.
However, on data opening Binary fields are mapped to string fields and therefore all data after 0x00 byte is cut off.
But with MySQL Query Browser I see that data NOT stored correctly. If first byte in my sequense id 0x00 I can't see anything in the field.
Dimon wrote: In order to solve this problem you should set the TMyQyery.Options.BinaryAsString property to false to create TBytesField for Binary fields.
Can you post simple sample here?

Thank you!
Alex

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 22 Feb 2008 14:32

You should use MyDAC version 5.20.1.14. There was TMyDataSetOptions.BinaryAsString property added for processing Binary fields. Set this property to false and try working with Binary fields.

Post Reply