我正在使用Blackberry Cascades。
我正在尝试访问我的数据库以插入/编辑我的数据库,但是当我尝试调用查询函数 favorite()时应用程序崩溃。
应用程序崩溃,控制台中没有记录任何内容,因此我不确定究竟是什么导致它。
我也在标题中声明: SqlDataAccess * sda
#include "dbHelper.h"
#include <bb/data/SqlDataAccess>
#include <bb/data/DataAccessError>
#include <QtSql/QtSql>
#include <QDebug>
dbHelper::dbHelper()
{
initDatabase();
SqlDataAccess sda (mdbFilewithPath);
// or should I use: this-> sda = new SqlDataAccess();
}
void dbHelper::initDatabase(){
//Copy database to Data folder ... pretty sure this part of the code works.
mdbFilewithPath = QDir::homePath() + "/data.db";
}
void dbHelper::executeQuery (const QString query){
this->sda->execute(query);
if (this->sda->hasError()){
DataAccessError err = this->sda->error();
qWarning() << "SQL Error: " << err.errorType() <<err.errorMessage();
}
}
void dbHelper::favourite(const QString &rule_id)
{
QVariantMap rule;
rule["id"] = rule_id;
QString query ="INSERT INTO user (rule_id, isFavourite) VALUES (" + rule_id + ", 1)";
executeQuery(query);
}
我不确定是什么原因造成的?非常感谢任何帮助谢谢!