2013-06-04 1 views
0

저는 Sqlite3에서 QT를 사용하고 있습니다. 내가 할 때sqlite_master에서 선택하십시오. 데이터베이스를 잠급니다.

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

데이터베이스가 잠 깁니다. 다른 쿼리를 실행하면 데이터베이스가 문제없이 작동합니다. 문제는 데이터베이스의 모든 테이블을 가져 오는 명령을 구체적으로 실행할 때입니다.

다음은 데이터

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; 

} 

을 PIN이 내 sqlite3를 방법입니다! onlyExecute 저장은 벡터에 데이터가 그래서 난 필드를 나중에 얻을 수 있습니다. 이것은 테이블 목록을 작성할 때 호출되는 코드의 일부입니다. 삽입 (i 실행 후)은 삽입이 실행되는 곳입니다.

감사합니다.

답변

0

파일 이름없이 연결을 열고 나중에 첨부하기 만하면 sqlite_master가 쓰기 위해 잠기지 않은 것처럼 보입니다.

관련 문제