feniksa
10th August 2010, 15:22
My application use different database drivers, to connect. And i want to use one code for different database (now i am testing Oracel OCI and PSQL). And i have troubles with psql driver:
After insert query, i use QSqlQuery::lastInsertId() method to get id of inserted row. LastInsertId return oid value, not id, that i am waiting. I use additional query (something like sequence::cur_val) or make query like "SELECT id FROM table_name WHERE oid= lastInsertId". But, this is crutches around psql driver lastInsertId. How i can get actually id of row? It is not good, when in code i use
if (psql_driver) { get_real_id_from_oid(table_name, oid) }.
I found in qt4.6.3 psql driver sources such code for lastInsertId:
QVariant QPSQLResult::lastInsertId() const
{
if (isActive()) {
Oid id = PQoidValue(d->result);
if (id != InvalidOid)
return QVariant(id);
}
return QVariant();
}
Maybe it is usefull to make additional query in psql driver and return realyId or make additional method?!?
for testing i use such table:
CREATE TABLE test (
id oid NOT NULL DEFAULT nextval('test_autoin_sequence'::regclass),
"name" text
)
WITH (
OIDS=TRUE
);
sequence create:
CREATE SEQUENCE test_autoin_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 31
CACHE 1;
thanks
After insert query, i use QSqlQuery::lastInsertId() method to get id of inserted row. LastInsertId return oid value, not id, that i am waiting. I use additional query (something like sequence::cur_val) or make query like "SELECT id FROM table_name WHERE oid= lastInsertId". But, this is crutches around psql driver lastInsertId. How i can get actually id of row? It is not good, when in code i use
if (psql_driver) { get_real_id_from_oid(table_name, oid) }.
I found in qt4.6.3 psql driver sources such code for lastInsertId:
QVariant QPSQLResult::lastInsertId() const
{
if (isActive()) {
Oid id = PQoidValue(d->result);
if (id != InvalidOid)
return QVariant(id);
}
return QVariant();
}
Maybe it is usefull to make additional query in psql driver and return realyId or make additional method?!?
for testing i use such table:
CREATE TABLE test (
id oid NOT NULL DEFAULT nextval('test_autoin_sequence'::regclass),
"name" text
)
WITH (
OIDS=TRUE
);
sequence create:
CREATE SEQUENCE test_autoin_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 31
CACHE 1;
thanks