Results 1 to 5 of 5

Thread: Postgresql delete record error

  1. #1
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Postgresql delete record error

    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.
    Qt Code:
    1. QSqlQuery query ;
    2. query.prepare("DELETE FROM purchasing.invoice WHERE OID=:Oid AND invoice_id=:invoice_id ") ;
    3.  
    4. query.bindValue(":Oid" , Oid);
    5. query.bindValue(":invoice_id" , ui->invoice_id->text() );
    6.  
    7. query.exec();
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance for your help.
    Last edited by amr2027; 29th November 2013 at 21:52.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Postgresql delete record error

    What is the type of column invoice_id in database ?

  3. The following user says thank you to Lesiok for this useful post:

    amr2027 (30th November 2013)

  4. #3
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Postgresql delete record error

    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
    Last edited by amr2027; 30th November 2013 at 11:48.

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Postgresql delete record error

    Take a look into PostgreSQL log.

  6. The following user says thank you to Lesiok for this useful post:

    amr2027 (30th November 2013)

  7. #5
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Postgresql delete record error

    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.
    Last edited by amr2027; 30th November 2013 at 20:32.

Similar Threads

  1. Error Modifiying a record of a QSqlTableModel
    By qlands in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2011, 10:41
  2. delete record from qsqltable
    By robotics in forum Qt Programming
    Replies: 2
    Last Post: 7th June 2011, 11:21
  3. Replies: 4
    Last Post: 10th May 2011, 12:19
  4. Replies: 2
    Last Post: 11th February 2011, 17:53
  5. Replies: 3
    Last Post: 26th March 2010, 04:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.