Results 1 to 3 of 3

Thread: QSqlQuery error

  1. #1
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QSqlQuery error

    Hello,
    i have a problem with QSqlQuery, i have a column "nombre" with an unique index (constraint), i am doing many inserts from PyQT (ODBC driver), i have the same problem from windows client and linux client, when any of the inserts of the prepared query have a duplicated unique column all the executed later gives me the same error but the insert works, i will explain here:

    i prepare the query:

    queryinsertmaxdb = QSqlQuery(maxdb)
    queryinsertmaxdb.prepare("INSERT INTO NAMESPACE.MODELO_FAMILIA (FAMILIA_ID, NOMBRE, SECCION) VALUES (?, ?, ?)")

    later inside a loop for every value in a list i do this:

    queryinsertmaxdb.addBindValue(QVariant(codigo_fami lia))
    queryinsertmaxdb.addBindValue(QVariant(nombre_fami lia))
    queryinsertmaxdb.addBindValue(QVariant(seccion_fam ilia))
    queryinsertmaxdb.exec_()

    all works fine but when it finds an integrity constraint violation:
    INSERT INTO NAMESPACE.MODELO_FAMILIA (FAMILIA_ID, NOMBRE, SECCION) VALUES (8325, TENIS MUJER, 2)
    Unable to execute statement: [SAP AG][LIBSQLOD SO][MaxDB] Integrity constraint violation;250 POS(1) Duplicate secondary key:UQ_NOMBRE [SAP AG][LIBSQLOD SO][MaxDB] Integrity constraint violation;250 POS(1) Duplicate secondary key:UQ_NOMBRE

    this insert does not works and it is correct (because it has the column name duplicated) but all the inserts after this gives me the same errors and all of them do correctly the insert because dont have a duplicate
    secondary key really, what can be the problem? I suppose with qsqlquery exec method reset the errors of last query but i thinks it is not working. Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery error

    Quote Originally Posted by skuda View Post
    I suppose with qsqlquery exec method reset the errors of last query but i thinks it is not working.
    QSqlQuery::lastError() returns the last error that has occured, even if there were some successful queries afterwards. You have to check what QSqlQuery::exec() returns to see whether the error has occurred or not.

  3. #3
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery error

    But in qt documentation says it is reseted in every exec method, here i paste the doc about ::exec.

    bool QSqlQuery::exec ( const QString & query )
    Executes the SQL in query. Returns true and sets the query state to active if the query was successful; otherwise returns false. The query string must use syntax appropriate for the SQL database being queried (for example, standard SQL).
    After the query is executed, the query is positioned on an invalid record and must be navigated to a valid record before data values can be retrieved (for example, using next()).
    Note that the last error for this query is reset when exec() is called.

    When i do the prepare inside the loop it works ok, i think it is a qt bug, i have posted to the tasktracker and i am awaiting reply.

Similar Threads

  1. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  2. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  3. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.