InsertId is not supported
InsertId is not supported
Hello all,
I need the property TuniQuery->InsertId which was possible for TMyQuery.
Thanks
Thomas
I need the property TuniQuery->InsertId which was possible for TMyQuery.
Thanks
Thomas
We'll add the discription of LastInsertId to the documentation.
LastInsertId is filled only if server returns this value for a SQL statement. PostgreSQL returns only value of OID for a table with OIDs. If you have such table, you can read last inserted OID in the property.
To get the value of SERIAL, use SQL statement with RETURNING:
LastInsertId is filled only if server returns this value for a SQL statement. PostgreSQL returns only value of OID for a table with OIDs. If you have such table, you can read last inserted OID in the property.
To get the value of SERIAL, use SQL statement with RETURNING:
Code: Select all
INSERT INTO table1(f) VALUES ('hello')
RETURNING id
Sorry but I get for each new record 0.
DROP TABLE p_cratemaker.t_test;
CREATE TABLE p_cratemaker.t_test
(
n_firmakey serial NOT NULL,
c_name character varying(40),
CONSTRAINT t_test_pkey PRIMARY KEY (n_firmakey)
);
ALTER TABLE p_cratemaker.t_test OWNER TO cratemaker;
insert into p_cratemaker.t_test (c_name) VALUES ('Paul') returning n_firmaKey;
I can alos create the table with OID this doens't matter.
This returns outside 1.
If I run my app and execute these lines.
UniQuery1->LastInsertId is 0.
Thanks for you help
DROP TABLE p_cratemaker.t_test;
CREATE TABLE p_cratemaker.t_test
(
n_firmakey serial NOT NULL,
c_name character varying(40),
CONSTRAINT t_test_pkey PRIMARY KEY (n_firmakey)
);
ALTER TABLE p_cratemaker.t_test OWNER TO cratemaker;
insert into p_cratemaker.t_test (c_name) VALUES ('Paul') returning n_firmaKey;
I can alos create the table with OID this doens't matter.
This returns outside 1.
If I run my app and execute these lines.
Code: Select all
UniQuery1->Active = true;
UniQuery1->Insert();
UniQuery1->FieldByName("c_name")->AsString = "Problem";
UniQuery1->Post();
EdInsertedId->Text = IntToStr(UniQuery1->LastInsertId);
Thanks for you help
LastInsertId cannot be used to get the value of SERIAL field.
Assign a SQL statement like the following to the SQLInsert property of TUniQuery:
Set the ReturnParams option of TUniQuery to True.
After you call Post the value of the field will be in the corresponding TField object:
Assign a SQL statement like the following to the SQLInsert property of TUniQuery:
Code: Select all
INSERT INTO table1(f) VALUES (:f)
RETURNING id
Set the ReturnParams option of TUniQuery to True.
After you call Post the value of the field will be in the corresponding TField object:
Code: Select all
EdInsertedId->Text = IntToStr(UniQuery1->FieldByName("id")->AsInteger);