Results 1 to 5 of 5

Thread: Update query

  1. #1
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Update query

    Cannot update a table with this code

    Qt Code:
    1. QString str;
    2. int ord = n_ord->text().toInt();
    3. query = QSqlQuery ("UPDATE leg SET dip = '"+ str +"' WHERE n_ord = "+ ord +" LIMIT 1");
    To copy to clipboard, switch view to plain text mode 

    "n_ord" is an integer primary key table field and "ord" its actual value

    Can someone helps ?
    Thanks in advance

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Update query

    What's the error you get?

  3. #3
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update query

    I suggest you use it this way

    Qt Code:
    1. query = QSqlQuery (QString("UPDATE leg SET dip = '%1' WHERE n_ord = %2 LIMIT 1").arg(str).arg(ord));
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  4. #4
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update query

    It works, thank you !
    Why does my previous code fail in QT ? In Java, for instance, it is correct ...

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Update query

    To avoid possible injections have a look at QSqlQuery::prepare().

Similar Threads

  1. Error executing SELECT query with QSQLITE
    By garfield85 in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2009, 19:05
  2. Problem in QProgressBar update
    By nikhilqt in forum Qt Programming
    Replies: 0
    Last Post: 10th March 2009, 11:20
  3. Qt Update project - Opinions wanted
    By pvdk in forum Qt Programming
    Replies: 0
    Last Post: 8th November 2008, 09:41
  4. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 10:42
  5. Problems with QSqlQuery update
    By whoops.slo in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2006, 08:17

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.