Page 1 of 1

How to store data in BINARY field

Posted: Wed 06 Feb 2008 12:47
by avor_il
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

Posted: Thu 07 Feb 2008 12:21
by Dimon
Try setting param DataType to ftString, using this code:

Code: Select all

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

Posted: Thu 07 Feb 2008 13:34
by avor_il
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.

Posted: Wed 13 Feb 2008 09:12
by Dimon
We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.

Posted: Tue 19 Feb 2008 13:07
by Dimon
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.

Posted: Thu 21 Feb 2008 13:41
by avor_il
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

Posted: Fri 22 Feb 2008 14:32
by Dimon
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.