Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Drop Table problem with SQLite

[Solved] Drop Table problem with SQLite

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    I have written a small function that parse a script file and executes the query. The parser works fine and the basic sql statements works as expected. The problem here is with the DROP TABLE statement , it throws following error/warning and the query is not executed.

    "database table is locked Unable to fetch row"

    Funcition :

    @bool MySQLiteDatabase::readSqlFile(const QString &filename)
    {
    QFile file(filename);
    QFileInfo f(filename);

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        LOG_ERROR_EXT(1249, "Could not open script file.", "File name: " + filename);
        return false;
    }
    
    QTextStream stream(&file);
    QString line;
    QString sqlStatement = "";
    while (!stream.atEnd())
    {
        line = stream.readLine();
        if (line.startsWith('#') || line.startsWith('\\') || line.isEmpty())
            continue;
        sqlStatement += line;
        if (sqlStatement.trimmed().endsWith(";"))
        {
            qDebug() << "Statement: " <<sqlStatement;
            MySQLiteQuery query(m_db);
            if (!query.exec&#40;sqlStatement&#41;)
            {
                LOG_ERROR_EXT(1250, "Update query failed.", "File name: " + f.absoluteFilePath() + "\nStatement: " + sqlStatement);
                return false;
            }
            sqlStatement = "";
        }
    }
    
    return true;
    

    }@

    and

    @m_db = QSqlDatabase::addDatabase("QSQLITE",m_instanceName);@

    Test Script 1 :-

    @CREATE TABLE IF NOT EXISTS employee
    ( emp_id INTEGER NOT NULL ,
    emp_name TEXT ,
    emp_add TEXT );@

    Test Script 2 :-

    @DROP TABLE employee; //fails @

    P.S
    Soved I figured out where my database was locked.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SabinF
      wrote on last edited by SabinF
      #2

      Hi Sam,

      could you please share the solution for solving the error? I'm facing the same issue.

      Thanks.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved