Results 1 to 8 of 8

Thread: QSQLITE problem with DROP

  1. #1
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4

    Default QSQLITE problem with DROP

    Hi to all,

    I have a problem with a db software that I create for my friend. The problem is the following:

    When I do:

    Qt Code:
    1. QSqlQuery *qry = new QSqlQuery();
    2.  
    3. qry->prepare("DROP TABLE Month");
    4.  
    5. if(!qry->exec()){
    6.  
    7. qDebug() << qry->lastError().text();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    I get the following error during the application runtime:

    "database table is locked Unable to fetch row"

    How can I solve this problem? I try to Delete the table with sqlite_browser but after that I re-create the table Month with:

    Qt Code:
    1. QSqlQuery *qry1 = new QSqlQuery();
    2.  
    3. if(!qry1->exec("CREATE TABLE IF NOT EXISTS Month (Codice NUMERIC, Prodotto TEXT, Qta TEXT)"))
    4.  
    5. qDebug() << qry1->lastError().text();
    6.  
    7. delete qry1;
    To copy to clipboard, switch view to plain text mode 


    and try to DROP the table Month, I obtain the same error.

    My db is in qsqlite.


    Sorry for my bad english but I'm italian and I hope that we can understand my really bad english

    Thanks a lot in advance !!!!

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSQLITE problem with DROP

    Since SQLite databases are mere files... have you checked file permissions on it? (i.e. not read-only)

    Usually if a process has a lock on a sqlite database and crashes it locks it permanently. If that's the case I suggest dump and restore it to another file...

    Linux solution:
    Qt Code:
    1. echo ".dump" | sqlite old.db | sqlite new.db
    To copy to clipboard, switch view to plain text mode 

    HTH

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

    Default Re: QSQLITE problem with DROP

    If the directory containing the database cannot be written then Sqlite cannot create needed temporary files to track transactions and you get messages similar to this. On Windows writes will be blocked by default if you place the database in a subfolder of Program Files hierarchy.

  4. #4
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4

    Default Re: QSQLITE problem with DROP

    I'm under Windows. To see if the problem is the db, I create another program to do the Drop. The new software do it without problem with the same db. But when I try my software I obtain the error.

    My db is in C:\Users\Luigi\Documents\Qt_Code\Database\Prodotti .db

    It is possible that I forgot to delete an QSqlQuery's object?

    I check but I see that all my QSqlQuery's objects are deleted.


    Added after 5 minutes:


    And after this problem when I close the application I get the warning:

    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.

    But When I click the pushButton to Close the app I execute:

    Qt Code:
    1. db.close();
    2. this->close();
    To copy to clipboard, switch view to plain text mode 

    where db is a QSqlDatabase object.
    Last edited by protagonista3; 19th March 2012 at 11:48.

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

    Default Re: QSQLITE problem with DROP

    Are there multiple copies of your application running?
    Or are there multiple threads in your application holding connections to the database?
    Or is sql_browser still running and holding a lock?

  6. #6
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4

    Default Re: QSQLITE problem with DROP

    There aren't applications when I run my app and don't uses multiple thread.


    Added after 1 11 minutes:


    I solve the warning:

    QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.

    To solve this I delete the QSqlTableModel's Object.

    But I cannot solve

    "database table is locked Unable to fetch row"

    I try to create a new db but the problem still remains.
    Last edited by protagonista3; 22nd March 2012 at 21:27.

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

    Default Re: QSQLITE problem with DROP

    Is the file "C:\Users\Luigi\Documents\Qt_Code\Database\Prodott i.db" writeable?
    Can you drop tables using the sqlite shell command line tool?
    Do you execute any "pragma" commands on your connection?
    Does your database pass a "pragma integrity_check;" ?

    Provide a minimal, compilable example that fails on your machine on a file in that directory.

  8. #8
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4

    Default Re: QSQLITE problem with DROP

    Finally I solve the last warning.

    The problem is the QSqlTableModel that locks the functions DROP and ALTER. Infact when I do model->clear(); or delete model; before the query, I can do everything.

    Do you know the reasone?

Similar Threads

  1. problem with QSQLITE.
    By Con Nít in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2011, 08:20
  2. QSQLITE problem with FOREIGN KEY
    By kamilus in forum Qt Programming
    Replies: 6
    Last Post: 26th April 2011, 00:10
  3. Problem deploying qt application using qsqlite on Windows XP/7
    By anoraxis in forum Installation and Deployment
    Replies: 4
    Last Post: 8th April 2011, 13:18
  4. Replies: 1
    Last Post: 7th July 2008, 20:13
  5. QSqlite problem
    By dragon in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2007, 02:02

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.