Results 1 to 9 of 9

Thread: QPSQL + QT4 (Postgresql driver bug)

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QPSQL + QT4 (Postgresql driver bug)

    Hi everyone,
    So basically, I've been have some problems with QSQL code so i tested it with both the mysql driver and postgresql driver. It works perfectly with the mysql database however when i run the same thing with the postgresql driver i get the following error. And I have to use postgresql it's for my senior project

    Qt Code:
    1. QPSQL: Unable to create query"
    2. query failed: "ERROR: syntax error at or near "("
    3. LINE 1: EXECUTE ('Don''t Say No', '21:03', 'Twenty One O Three', '/..
    4. ^
    To copy to clipboard, switch view to plain text mode 

    I don't know where that EXECUTE command comes from, and i check the error log on the server and the same query shows when i'm doing an INSERT

    has an anyone seen this before ??
    thanks in advance

    Qt Code:
    1. QSqlQuery query("INSERT INTO tracks (title, artist, album, path, duration) VALUES ( ?, ?, ?, ?, ? )");
    2.  
    3. query.addBindValue(QString(f.tag()->title().toCString()));
    4. query.addBindValue(QString(f.tag()->artist().toCString()));
    5. query.addBindValue(QString(f.tag()->album().toCString()));
    6. query.addBindValue(it.filePath());
    7. query.addBindValue(QString(f.audioProperties()->length()));
    8. if(query.exec()) {
    9. qDebug() << query.lastQuery();
    10. } else {
    11. qDebug() << "query failed: " << query.lastError().text();
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    Doesn't the query execute right away if the string given as part of the constructor is not empty?
    I think you need to use the syntax as shown here:
    http://doc.qt.nokia.com/latest/qsqlquery.html#details

    look for the section on approach to binding values.

    A good example of binding can be seen in the querymodel example. Look at EditableSqlModel::setFirstName.
    Last edited by schnitzel; 21st February 2011 at 23:27. Reason: reworded

  3. #3
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    If you mean doing this

    Qt Code:
    1. SqlQuery query;
    2. query.prepare("INSERT INTO person (id, forename, surname) "
    3. "VALUES (:id, :forename, :surname)");
    4. query.bindValue(":id", 1001);
    5. query.bindValue(":forename", "Bart");
    6. query.bindValue(":surname", "Simpson");
    7. query.exec();
    To copy to clipboard, switch view to plain text mode 

    I've tried using both binding syntaxes, however I'm getting the same error when the query is actually executed

  4. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    Quote Originally Posted by l2succes View Post
    If you mean doing this

    Qt Code:
    1. SqlQuery query;
    2. query.prepare("INSERT INTO person (id, forename, surname) "
    3. "VALUES (:id, :forename, :surname)");
    4. query.bindValue(":id", 1001);
    5. query.bindValue(":forename", "Bart");
    6. query.bindValue(":surname", "Simpson");
    7. query.exec();
    To copy to clipboard, switch view to plain text mode 

    I've tried using both binding syntaxes, however I'm getting the same error when the query is actually executed
    Does a simple case work, i.e. without binding - just hard coding the values?
    Also try from psql command line client to take Qt out of the loop.

  5. #5
    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: QPSQL + QT4 (Postgresql driver bug)

    What is a version of PostgreSQL server and Qt ?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    So where is this "bug"? You have an unescaped appostrophe character so it doesn't work. Since psql uses apostrophes for string delimiters, the query syntax you use is irrelevant, you'll run into the same situation. EXECUTE is used by postgresql to well... execute prepared statements.

    By the way, you can see how the driver encodes your query using QSqlDriver::formatValue() for the right driver (psql in your case). The docs say a single quote should be escaped by surrounding them with single quotes. See if QSqlDriver returns escaped data. Note it might not work if your field is of a wrong type.
    Last edited by wysota; 27th February 2011 at 11:29.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    Quote Originally Posted by wysota View Post
    So where is this "bug"? You have an unescaped appostrophe character so it doesn't work. Since psql uses apostrophes for string delimiters, the query syntax you use is irrelevant, you'll run into the same situation. EXECUTE is used by postgresql to well... execute prepared statements.

    By the way, you can see how the driver encodes your query using QSqlDriver::formatValue() for the right driver (psql in your case). The docs say a single quote should be escaped by surrounding them with single quotes. See if QSqlDriver returns escaped data. Note it might not work if your field is of a wrong type.
    well apparantly, the second example (without any quotes) was giving him the same error.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    I still don't see a bug. We don't even know if query preparation was successful because the first two syntaxes used are incorrect (one needs to use prepare() to have a prepared query).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QPSQL + QT4 (Postgresql driver bug)

    Quote Originally Posted by wysota View Post
    I still don't see a bug. We don't even know if query preparation was successful because the first two syntaxes used are incorrect (one needs to use prepare() to have a prepared query).
    Sorry, for taking so long to respond, never got a notice of your reply also I ended up using mysql for testing purposes. So I just got back to postgresql and I admit I spoke too soon, get your point. Anyway thanks for the help

Similar Threads

  1. Replies: 2
    Last Post: 11th February 2011, 18:53
  2. QPSQL driver not loaded
    By drave in forum Newbie
    Replies: 4
    Last Post: 4th May 2010, 14:11
  3. QPSQL - Driver Not Loaded (WIN XP)
    By db in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2009, 02:48
  4. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 13:57
  5. Can't find QPSQL driver!!
    By brevleq in forum Qt Programming
    Replies: 9
    Last Post: 30th October 2007, 01:29

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.