Hello everyone,
Could you m’adader, I can not open my base to give to write in, Is it necessary access rights to open it knowing that I added the access rights in the file. adef
void databaseSQL::connectDb()
{
std::string initQuery = “CREATE TABLE IF NOT EXISTS LOG_APP_TABLE (EVENT_NO INTEGER PRIMARY KEY AUTOINCREMENT,TIME TEXT, LOG TEXT);”;
std::string journalMode = “PRAGMA journal_mode=PERSIST;”;
std::string resultSet;
int rc;
//acces to database
rc = sqlite3_open_v2(NEW_DATABASE, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if(rc)
{
cout<<"[INFO/APPLICATION/STM] Can't open database:"<<sqlite3_errmsg(db)<<""<<strerror(errno)<<endl;
}
else
{
cout<<"[INFO/APPLICATION/STM] Opened database successfully"<<endl;
return;
}
if(this->doQuery(journalMode, &resultSet)!= SQLITE_ROW)
{
cout<<"[INFO/APPLICATION/STM] Error for stopping journal"<<endl;;
return;
}
int result = this->doQuery(initQuery,&resultSet);
if((result == SQLITE_OK) || (result == SQLITE_DONE))
{
cout<<"[INFO/APPLICATION/STM] ===== Created the table LOG_APP_TABLE"<<endl;;
}
else
{
cout<<"[INFO/APPLICATION/STM] ===== ERROR: Impossible create or access to table ====="<<endl;;
}
this->close();
}
int databaseSQL::doQuery(std::string query, std::string* resultSet){
sqlite3_stmt* statement;
if(this->db==NULL)
{
std::cout<<“[INFO/APPLICATION/STM]===== Connect to db =====”<<std::endl;
this->connectDb();
}
if(sqlite3_prepare_v2(db, query.c_str(), -1, &statement, NULL)==SQLITE_OK)
{
int result = sqlite3_step(statement);
switch(result)
{
case SQLITE_ROW:
{
cout<<“[INFO/APPLICATION/STM]===== Reading Params =====”<<endl;
resultSet->assign((char*)sqlite3_column_text(statement, 0));
break;
}
case SQLITE_DONE:
{
cout<<“[INFO/APPLICATION/STM]===== Query completed with success =====”<<endl;;
break;
}
default:
cout<<“[INFO/APPLICATION/STM] !!SQLITE error code[”<<endl;
}
return result;
}
else
{
std::cout<<“[INFO/APPLICATION/STM] [doQuery]”<<endl;
return -1;
}
}