PDA

View Full Version : Postgresql delete record error



amr2027
29th November 2013, 21:11
Hello All.
I'm working on Qt 4.8-Postgresql application,I'm Using the following code to delete a database record the code works perfect, but if there is a data related to that table in another table an error 23503 raised till now everything is ok. Now if I delete the data related in the other table and execute the same code again to delete the same record an error 42601 raised indicating syntax error at or near "("
LINE 1: EXECUTE (77831, '30'). What could be the reason.


QSqlQuery query ;
query.prepare("DELETE FROM purchasing.invoice WHERE OID=:Oid AND invoice_id=:invoice_id ") ;

query.bindValue(":Oid" , Oid);
query.bindValue(":invoice_id" , ui->invoice_id->text() );

query.exec();


Thank you in advance for your help.

Lesiok
30th November 2013, 09:47
What is the type of column invoice_id in database ?

amr2027
30th November 2013, 11:48
Thank you for reply.
invoice_id type is serial (autoincrementing four-byte integer).
And ui->invoice_id->text() contains integer.

Added after 17 minutes:

I've changed the code to use an integer instead of Qstring -although I know that both are converted to QVariant - but I still have the same error except considering the invoice_id as an integer

Error num 42601
Error :ERROR: syntax error at or near "("
LINE 1: EXECUTE (77831, 30)
^
QPSQL: Unable to create query
LastQuery is: DELETE FROM purchasing.invoice WHERE OID=:Oid AND invoice_id=:invoice_id

Lesiok
30th November 2013, 14:34
Take a look into PostgreSQL log.

amr2027
30th November 2013, 20:32
PostgreSQL log doesn't contain any data about that.

Thank you very much for your interest.

Added after 20 minutes:

A new transaction solves the problem but I still don't find a convenient reason for that behaviour which I think that it's strange .
Thank you in advance all your efforts are appreciated.