Results 1 to 8 of 8

Thread: QSqlQuery does not execute

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default QSqlQuery does not execute

    I want to insert many records into MySQL,so I do as followings:

    Qt Code:
    1. ...
    2. QSqlQuery mQuery;
    3. if(!mQuery.exec("LOAD DATA INFILE '"+fileName+"' INTO TABLE table1 FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\r\n'"))
    4. {
    5. QMessageBox::warning(0,"",mQuery.lastError().text());
    6. return false;
    7. }
    8. ...
    To copy to clipboard, switch view to plain text mode 

    and there is no respones,that is, table1 has no recorders and there is no error.

    But when I execute " LOAD DATA INFILE '"+fileName+"' INTO TABLE table1 FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\r\n'" " in cmd window,it is ok,why?

  2. #2
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery does not execute

    You could look at mQuery.executedQuery() to see if the the query executed by QSqlQuery really matches the one you enter in the command window.

    It could also be a transaction problem, maybe there is a COMMIT missing in your Qt code?

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery does not execute

    Quote Originally Posted by chenz View Post
    You could look at mQuery.executedQuery() to see if the the query executed by QSqlQuery really matches the one you enter in the command window.
    I print the 'executedQuery()',and find that it execute ""LOAD DATA INFILE '"+fileName+"' INTO TABLE table1 FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\r\n'"))" ,that is, it exectue the query as I type.

    Quote Originally Posted by chenz View Post
    It could also be a transaction problem, maybe there is a COMMIT missing in your Qt code?
    I have no transaction ,so there is no COMMIT.

    By the way, if I exectue 'Insert' or 'update',it is ok.

  4. #4
    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: QSqlQuery does not execute

    Does exec() return true or false? What does QSqlQuery::lastError() return?
    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.


  5. #5
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery does not execute

    return true;

  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: QSqlQuery does not execute

    Then the query was executed successfully and there is nothing more you can do from within your application.
    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
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery does not execute

    Problem with incorrect file path ?

  8. #8
    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: QSqlQuery does not execute

    ...beside escaping your string proper. I bet it must be
    Qt Code:
    1. mQuery.exec("LOAD DATA INFILE '"+fileName+"' INTO TABLE table1 FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\\r\\n'")
    To copy to clipboard, switch view to plain text mode 
    Also have a look at bindValue or QString::arg() which makes your code better readable.

Similar Threads

  1. QT + Problem + execute
    By anouar2002 in forum Newbie
    Replies: 21
    Last Post: 20th January 2012, 18:56
  2. How to execute my .css file in Qt?
    By harish in forum Qt Programming
    Replies: 5
    Last Post: 2nd December 2011, 11:12
  3. Replies: 1
    Last Post: 18th July 2011, 12:12
  4. How to execute a QProgressDialog once
    By franco.amato in forum Newbie
    Replies: 4
    Last Post: 16th March 2010, 16:36
  5. How to Execute Qt script from Qt
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2007, 09:12

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.