2013-06-04 27 views
0

我正在使用QT和Sqlite3。 當我做從sqlite_master鎖數據庫中選擇

Select name from database.sqlite_master WHERE type = "table" 

我的數據庫鎖。如果運行任何其他查詢,數據庫的工作沒有問題。 看來問題是當我專門運行命令來獲取數據庫中的所有表。

這裏是我的sqlite3的方法以檢索數據

bool SqliteManager::executeSQL(QString query, bool onlyExecute, bool pagination, bool initialize){ 
    this->query=query; 
    sqlite3_stmt *st; 
    if(results->size()>0)results->clear(); 
    if(sqlite3_prepare_v2(connection, this->query.toStdString().c_str(), -1, &st, 0)==SQLITE_OK){ 
     if(!onlyExecute){ 
      this->columnCount=sqlite3_column_count(st); 
      //Get Row Count With Original Query 
      this->rowCount=this->getRowCount(this->originalQuery, helper::haveLimit(this->originalQuery)); 
      this->queryRowCount=this->getRowCount(this->query, helper::haveLimit(this->originalQuery)); 
      cout << "Query count " << this->queryRowCount << " query executed " << this->query.toStdString() << endl; 
      //Get Column names and store the data inside the QString vector 
      for(int col=0;col<this->columnCount;col++) 
       columnNames->push_back(QString((char*)sqlite3_column_name(st, col))); 

      //Store the values inside the vector, if you want to get only one row (columnNumber*row) is your index 
      while(sqlite3_step(st)==SQLITE_ROW) 
       for(int col=0;col<this->columnCount;col++) 
        results->push_back(QString((char*)sqlite3_column_text(st, col)).remove('\r').remove('\n')); 
     } 
     else{ 
      bool executed=false; 
      int status; 
      while((status=sqlite3_step(st))==SQLITE_OK)executed=true; 
      cout << "Command executed: " << this->query.toStdString() << endl; 
      sqlite3_finalize(st); 
      return executed || status == SQLITE_DONE; 

     } 
     cout << "finalize true" << endl; 
     sqlite3_finalize(st); 
     return true; 

    } 
    cout << "prepare error=> " << this->query.toStdString() << endl; 
    sqlite3_finalize(st); 
    return false; 

} 

的!onlyExecute將數據存儲到一個載體,所以我可以在以後得到的字段。 這是我做表格列表時調用的代碼的一部分。 對於插入(我運行後)else是插入運行的地方。

問候。

回答

0

看來,如果你打開你的連接沒有任何文件名,只需稍後連接它,你的sqlite_master不會被鎖定寫入。