Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Drop Table problem with SQLite

    General and Desktop
    2
    2
    3559
    Loading More Posts
    • 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
      Sam last edited by

      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 Reply Quote 0
      • S
        SabinF last edited by SabinF

        Hi Sam,

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

        Thanks.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post