Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

[Solved] Drop Table problem with SQLite

$
0
0
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(sqlStatement))             {                 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.

Viewing all articles
Browse latest Browse all 18427

Trending Articles