Results 1 to 4 of 4

Thread: QSqlQuery and prepare/bindValue problem!

  1. #1
    Join Date
    Jun 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Angry QSqlQuery and prepare/bindValue problem!

    Hey all, I'm having a problem, using this:
    Qt Code:
    1. QSqlQuery peticion(enlace);
    2. QString SQL("UPDATE mercaderias SET :1 = :4 WHERE Nombre=:3 AND Proveedor=:4");
    3. QString columna;
    4. switch(uno.column()) {
    5. case 0:
    6. columna="Nombre";
    7. break;
    8. case 1:
    9. columna="Proveedor";
    10. break;
    11. case 2:
    12. columna="Cantidad";
    13. break;
    14. case 3:
    15. columna="Precio";
    16. break;
    17. }
    18. peticion.prepare(SQL);
    19. peticion.bindValue(":1",columna);
    20. peticion.bindValue(":2",uno.data().toString());
    21. peticion.bindValue(":3",ui->Tabla->model()->index(uno.row(),0).data().toString());
    22. peticion.bindValue(":4",ui->Tabla->model()->index(uno.row(),2).data().toString());
    23.  
    24. if ( !peticion.exec() ) {
    25. qDebug() << "Error al actualizar";
    26. qDebug() << peticion.executedQuery();
    27. qDebug() << peticion.lastError().text();
    28. }
    To copy to clipboard, switch view to plain text mode 

    peticion.executedQuery() returns the values inside quotes (like 'value') instead of them being raw. What can I do to fix this?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSqlQuery and prepare/bindValue problem!

    Don't convert them to strings with QVariant::toString(). All you are doing is converting the original QVariant returned by the data() method (with whatever type it contains) to a QString and then back to a QVariant with a string type.

  3. #3
    Join Date
    Jun 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSqlQuery and prepare/bindValue problem!

    Line 19, using the QString directly, does not work not even if converted to a c_str()
    Further ideas? Since the information is good, but does not solve the actual problem.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSqlQuery and prepare/bindValue problem!

    Line 19, using the QString directly, does not work not even if converted to a c_str()
    And "does not work" means what, exactly? Won't compile? Creates malformed SQL? Doesn't return results when the query is executed?

    Sort of hard to know what's going on when we aren't looking over your shoulder at your PC and you give vague replies.

    There is no QString::c_str() method, so I don't know what you mean by this.

Similar Threads

  1. Compilation problem with QSqlQuery::bindValue()
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 18th November 2013, 22:30
  2. Problem with qsqlquery's prepare and bindvalue
    By yuzhouzhiwai in forum Qt Programming
    Replies: 4
    Last Post: 5th November 2013, 13:32
  3. QSqlQuery::bindValue problem
    By segfault in forum Qt Programming
    Replies: 6
    Last Post: 11th March 2009, 07:27
  4. QSqlQuery prepare() bindValue() broken badly
    By RolandHughes in forum Qt Programming
    Replies: 4
    Last Post: 14th November 2008, 18:25
  5. Database and QSqlQuery::prepare problem
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 23:17

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.