* * *

Author Topic: PostgreSQL 9.4.10, TSQLQuery, how to assign value to uuid column as parameter  (Read 522 times)

ertank

  • Jr. Member
  • **
  • Posts: 95
Hello,

Assuming we have following table:
Code: [Select]
create table foo(
autoinc serial not null primary key,
id uuid,
value integer
);

In my application my TSQLQuery.SQL is assigned below text at design time:
Code: [Select]
insert into foo(id, value) values(:id, :value)

If I write a code like:
Code: [Select]
var
  Guid: TGUID;
begin
  if CreateGUID(Guid) <> 0 then
  begin
    ShowMessage('Cannot create a GUID. Check hadware.');
    Exit;
  end;

  SQLQuery1.Params[0].AsString := GuidToString(Guid);
  SQLQuery1.Params[1].AsInteger := 1;
  SQLQuery1.ExecSQL();
end;

I get an error message saying that column is of type uuid and expression is of type text. I should cast or rewrite my sql.

- I checked, but I cannot seem to find a uuid field type to make my parameter assignment right.
- I checked TSQLScript and I could not use parameters in that component.

Is there any workaround I can do for this problem?

Thanks & regards,
-Ertan

sky_khan

  • Guest
try this,

Code: Pascal  [Select]
  1. SQLQuery1.Params[0].AsString := GuidToString(Guid);
  2. SQLQuery1.Params[0].DataType:=ftGUID;
  3.  


ertank

  • Jr. Member
  • **
  • Posts: 95
Hi SkyKhan,

Your suggestion worked. Thank you.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus