未验证 提交 ae766df8 编写于 作者: 梦醒贰零壹柒's avatar 梦醒贰零壹柒 提交者: GitHub

Merge pull request #26 from mengxing2017/25-bug-clean-debug-code

25 bug clean debug code
文件已删除
......@@ -13,7 +13,7 @@
class ExcuteSqlFile {
public:
ExcuteSqlFile();
int excute(QFile *file, QSqlDatabase db);
bool excute(QFile *file, QSqlDatabase db);
};
#endif // EXCUTE_SQL_FILE_H
#include "db/create_table.h"
#include "db/excute_sql_file.h"
#include "log.h"
#include "log4qt/logger.h"
CreateTable::CreateTable() {}
bool CreateTable::CreateAccount(QSqlDatabase db) {
// QFile file(":/res/db/create_table/create_account_table.sql");
Log4Qt::Logger *log = Log::createLog()->getLogger();
QFile *file = new QFile(":/res/db/create_table/create_account_table.sql");
if (!file->exists()) {
qDebug() << "sql file not exists";
log->error("sql file not exists");
file->~QFile();
return false;
}
ExcuteSqlFile *excute = new ExcuteSqlFile();
if (0 == excute->excute(file, db)) {
qDebug() << "excute sql faild";
if (excute->excute(file, db)) {
file->~QFile();
log->error("create account table success!");
excute->~ExcuteSqlFile();
return true;
};
excute->~ExcuteSqlFile();
file->~QFile();
qDebug() << "create account table faild";
log->error("create account table failed!");
return false;
}
......@@ -5,38 +5,36 @@
ExcuteSqlFile::ExcuteSqlFile() {}
int ExcuteSqlFile::excute(QFile *file, QSqlDatabase db) {
bool ExcuteSqlFile::excute(QFile *file, QSqlDatabase db) {
Log4Qt::Logger *log = Log::createLog()->getLogger();
int iRet = 0;
if (!file->exists()) {
return -1;
log->error("sql file not exist!");
return false;
}
if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
return -1;
log->error("sql file open failed!");
return false;
}
if (db.isOpen()) {
qDebug() << "excuteSqlFile: open database....";
db.open();
}
QTextStream in(file);
in.setCodec("UTF-8");
QString sqlData = in.readAll();
QSqlQuery query(db);
QStringList qstrlist_sql = sqlData.split(";");
log->debug(QString::number(qstrlist_sql.size()));
for (int i = 0; i < qstrlist_sql.size() - 1; i++) {
QString qstr_sql_part = qstrlist_sql.at(i).toUtf8();
log->debug(qstr_sql_part);
bool success = query.exec(qstr_sql_part);
if (!success) {
QSqlError lastError = query.lastError();
QString err = lastError.driverText();
log->error(err);
iRet = -1;
break;
}
log->debug("创建数据库表成功!");
QString qstr_sql_part = qstrlist_sql.at(0).toUtf8();
log->debug(qstr_sql_part);
bool success = query.exec(qstr_sql_part);
if (!success) {
QSqlError lastError = query.lastError();
QString err = lastError.driverText();
log->error(err);
return false;
}
return iRet;
return true;
}
......@@ -6,7 +6,7 @@ ManageDatabase::ManageDatabase() {}
QSqlDatabase ManageDatabase::connect() {
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":rms:");
db.setDatabaseName(QCoreApplication::applicationDirPath() + "/../db/data.db");
db.setDatabaseName(QCoreApplication::applicationDirPath() + "/../db/rms.db");
return db;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册