Results 1 to 12 of 12

Thread: How to execute VACUUM command on SQLITE db

  1. #1
    Join Date
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to execute VACUUM command on SQLITE db

    Hello,

    I can't run VACUUM on my database file.

    I tried this:
    Qt Code:
    1. QSqlQuery query;
    2. query.exec("VACUUM");
    To copy to clipboard, switch view to plain text mode 
    But I get the following message:
    Qt Code:
    1. cannot VACUUM - SQL statements in progress Unable to fetch row
    To copy to clipboard, switch view to plain text mode 
    Do you have an idea to solve this problem?

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to execute VACUUM command on SQLITE db

    I assume your sqlite database is the default connection.

    You cannot vacuum an sqlite database if there are open transactions or active sql statements in the database. These transactions may be in your program or from another process.

    Look for other QSqlQuery or similar objects that are still open/active/in scope.
    Last edited by ChrisW67; 6th June 2015 at 23:28. Reason: updated contents

  3. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: How to execute VACUUM command on SQLITE db

    Quote Originally Posted by Marmelade View Post
    Do you have an idea to solve this problem?
    In addition to what ChrisW67 said, a QSqlQuery that you've prepared can cause this if it hasn't been finished.

  4. #4
    Join Date
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to execute VACUUM command on SQLITE db

    My program is really simple, a kind of address book.
    The VACUUM call is done in SLOT and I am certain at this point that there are no other running queries.

    For this to work I found this:
    Qt Code:
    1. QSqlDatabase db= QSqlDatabase::database();
    2. db.close();
    3. db.open();
    4. QSqlQuery query;
    5. query.exec("VACUUM");
    To copy to clipboard, switch view to plain text mode 
    Thank you for your advice

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to execute VACUUM command on SQLITE db

    How do you know the Vacuum command is not working?
    Is the Sqlite database in a writeable folder/file.?

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: How to execute VACUUM command on SQLITE db

    You should post your actual code, the example above is not useful.

  7. #7
    Join Date
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to execute VACUUM command on SQLITE db

    Quote Originally Posted by ChrisW67 View Post
    How do you know the Vacuum command is not working?
    Is the Sqlite database in a writeable folder/file.?
    File is in home directory.
    Quote Originally Posted by jefftee View Post
    You should post your actual code, the example above is not useful.
    Qt Code:
    1. void WidgetServeurs::CompactBD() {
    2. QSqlDatabase db= QSqlDatabase::database();
    3. db.close();
    4. db.open();
    5. QSqlQuery query;
    6. if(! query.exec("VACUUM"))
    7. QMessageBox::critical(this, "", query.lastError().text().toStdString().c_str());
    8. }
    To copy to clipboard, switch view to plain text mode 
    I tried to replace close() and open() by commit() but I got the same error message.

  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: How to execute VACUUM command on SQLITE db

    Do you have any QSqlQuery, QSqlQueryModel or QSqlTableModel objects elsewhere in your program?
    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
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to execute VACUUM command on SQLITE db

    Yes, I have two QTableView with its associated QSqlTableModel and ten QSqlQuery in different methods.

  10. #10
    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: How to execute VACUUM command on SQLITE db

    Quote Originally Posted by Marmelade View Post
    Yes, I have two QTableView with its associated QSqlTableModel and ten QSqlQuery in different methods.
    Are these models and objects destroyed before you try to vacuum the database?
    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.


  11. #11
    Join Date
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to execute VACUUM command on SQLITE db

    QSqlQuery are destroyed because their scope is still limited.
    But QTableView and QSqlTableModel are only destroyed at the exit in destructor.

  12. #12
    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: How to execute VACUUM command on SQLITE db

    So it seems you have open queries and vacuum doesn't work.
    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.


Similar Threads

  1. Need to Execute an system command, in QT
    By gunturrohith in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 27th November 2014, 09:28
  2. Execute system command from QProcess
    By graciano in forum General Programming
    Replies: 6
    Last Post: 20th February 2014, 11:05
  3. How to execute Powershell command from QT?
    By Gokulnathvc in forum Newbie
    Replies: 3
    Last Post: 22nd January 2014, 00:30
  4. How do I execute an .schema command using Qt's SQLITE driver?
    By danielperaza in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2010, 21:21
  5. Ho to use signals and slots to execute a command?
    By claudio-cit in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2008, 23:01

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.