Results 1 to 2 of 2

Thread: [Solved] QSqlQuery ATTACH Error (sqlite)

  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default [Solved] QSqlQuery ATTACH Error (sqlite)

    Hi all,
    i'm trying to merge two sqlite Databases via SQL statement ATTACH DATABASE pathToSecondDatabase AS toMerge.
    When i try to execute i get the QSqlError "No query Unable to fetch row" . I'm coding with QtCreator with QT 4.8.1.
    Probably it's a syntax error in the statement but i'm not sure whats wrong.

    Qt Code:
    1. db.setDatabaseName(dir->filePath("data.sqlite")); //declarated in the header
    2. db.open();
    3.  
    4. q = QSqlQuery(db); //declarated in the header
    5.  
    6. q.prepare("ATTACH DATABASE " + path + " AS toMerge"); //here is the problem
    7.  
    8. if(!q.exec())
    9. {
    10. QSqlError error = q.lastError(); //throws "No query Unable to fetch row"
    11. qDebug() << error.text();
    12. }
    13.  
    14. q.finish();
    15.  
    16. q.prepare("INSERT INTO Table SELECT * FROM toMerge.Table");
    17. q.exec();
    18. q.finish();
    19.  
    20. q.prepare("DETACH toMerge");
    21. q.exec();
    22. q.finish();
    23.  
    24. db.close();
    To copy to clipboard, switch view to plain text mode 
    Annotation:
    database is open and valid
    db and q are declarated in the header (other operations work fine)
    path is a QString caontaining the path to the second data.sqlite file.

    hope you can help me with the problem.
    Thanks.
    niebsi
    Last edited by niebsi; 7th June 2012 at 22:29.

  2. #2
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQuery ATTACH Error (sqlite)

    problem solved just forgot about the ' before and after the filepath.
    furthermore i changed the filepath toNativeSeperators.

    Qt Code:
    1. q.prepare("ATTACH DATABASE '" + path + "' AS toMerge"); //no error
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. qsqlquery insert error
    By fantom in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2011, 17:15
  2. error with QSqlQuery
    By mmm286 in forum Newbie
    Replies: 5
    Last Post: 26th May 2010, 00:27
  3. SQLITE ATTACH database
    By drescherjm in forum Qt Programming
    Replies: 8
    Last Post: 9th December 2009, 07:25
  4. QSqlQuery, bindValue and Sqlite
    By cydside in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2009, 16:53
  5. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43

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.