I'm trying to use sqlite as database for a symbian app but I can't create a table. Here's the code:
bool DatabaseManager::createExpenseTable(){
if(QFile::exists(dbName)){
this->showDebugMsg("Database file exist");
}else{
this-&g开发者_运维技巧t;showDebugMsg("Database file exist DOES NOT exist");
}
// Create table "person"
bool ret = false;
if (db.isOpen()){
this->showDebugMsg("Database open");
QSqlQuery query;
ret = query.exec("create table expense "
"(id int primary key, "
"item varchar(100)");
//"price double, "
//"date datetime)");
}else{
this->showDebugMsg("Database CLOSED");
}
if(ret){
this->showDebugMsg("Table created");
}else{
this->showDebugMsg("Table NOT created");
}
return ret;
}
As far as I can see from the debug messages "Database file exist" and "Database open" the database exists and is open.
But I always get the "table NOT created" message. Does any of you see where the problem is?
There is a closing parenthesis missing in your query (you commented it out).
Wait, I found the problem. with this code:
this->showDebugMsg(query.lastError().text());
I saw that "the table expense already exist" and so, it doesn't create a new one. sorry for bothering you all.
精彩评论