Recent

Author Topic: [SOLVED] how to pass a TBytes value in TSQLQuery as parameter  (Read 2371 times)

eara

  • Jr. Member
  • **
  • Posts: 84
i want to run the following query

Code: [Select]
insert into texts(text_guid,text_data) values (:text_guid,:text_data);
where

  text_guid is declared as VARBINARY(16) in MySQL db 5.5
  text_data is declared as TEXT

i have created a TGuid, and converted it to a TBytes variable. And now i want now to pass the TBytes variable's value to the TSQLQuery with a ParamByName('text_guid') but ParamByName has no AsBytes property like TField. How should i handle this ?

I use VARBINARY(16) for economy and not VARCHAR(38) for guids so .AsString or AsGuid is not a option (i think).
« Last Edit: April 19, 2014, 09:14:38 pm by eara »

LacaK

  • Hero Member
  • *****
  • Posts: 577
Re: how to pass a TBytes value in TSQLQuery as parameter
« Reply #1 on: April 14, 2014, 02:39:40 pm »
You can set DataType = ftBytes, then create variant array of bytes (VarArrayCreate([0, 15], varByte) and fill it) and pass it as AsVariant.

eara

  • Jr. Member
  • **
  • Posts: 84
Re: how to pass a TBytes value in TSQLQuery as parameter
« Reply #2 on: April 14, 2014, 03:33:46 pm »
thanks, worked....

eara

  • Jr. Member
  • **
  • Posts: 84
Re: how to pass a TBytes value in TSQLQuery as parameter
« Reply #3 on: April 16, 2014, 12:52:57 am »
warning for other people that are reading this post and think "oh, i could also use binary fields as primary keys", please note my next problem...

http://forum.lazarus.freepascal.org/index.php/topic,24270.0.html

which states: yes you can, but don't use DataSet.Locate on this fields  :'( (till next version comes out)
« Last Edit: April 19, 2014, 09:15:20 pm by eara »