C++ C++;,Qt 4 Sqlite:can';不创建表

C++ C++;,Qt 4 Sqlite:can';不创建表,c++,database,sqlite,qt4,C++,Database,Sqlite,Qt4,我试图使用sqlite作为symbian应用程序的数据库,但无法创建表。代码如下: bool DatabaseManager::createExpenseTable(){ if(QFile::exists(dbName)){ this->showDebugMsg("Database file exist"); }else{ this->showDebugMsg("Database file exist DOES NOT exist")

我试图使用sqlite作为symbian应用程序的数据库,但无法创建表。代码如下:

bool DatabaseManager::createExpenseTable(){

    if(QFile::exists(dbName)){
        this->showDebugMsg("Database file exist");
    }else{
        this->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;
    }
从调试消息“databasefileexist”和“databaseopen”中可以看出,数据库存在并且是打开的


但我总是收到“未创建表”的消息。有人看到问题出在哪里了吗?

您的查询中缺少一个右括号(您已将其注释掉)。

等等,我找到了问题。使用此代码:

this->showDebugMsg(query.lastError().text());

我看到“表费用已经存在”,因此,它不会创建一个新的表。抱歉打扰大家。

关门了。在评论部分之前查看。顺便说一句,如果它们没有关闭,代码就不会编译。括号在引用的SQL中丢失了@塞戈拉斯:它还没关。hmn是对的。您已注释掉包含结束参数的代码。删除引号并合并字符串表明您发布的代码执行此查询:
createtableexpense(id int主键,item varchar(100)
缺少最后一个参数。即使您将查询替换为
kjrfhiherfghdfgvjhfgvjh
,代码也会编译,因为编译器无法猜测您传递给SQL驱动程序的内容是否是有效的SQL,或者,就这一点而言,它甚至不知道它是SQL。它只是将您告诉它的任何字节传递给SQL驱动器r、 哦,是的,现在我明白了。谢谢。