2 Star 0 Fork 1

王海亮/kylin-update-desktop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
db_installed_imformation.cpp 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
王海亮 提交于 2021-07-16 14:33 . init
#include "db_installed_imformation.h"
Installed_imformation::Installed_imformation()
{
QString db_path = "/usr/share/kylin-update-manager/original/kylin-update-manager_1.db";
QFile file;
if(file.exists(db_path))
{
//设置数据库驱动名称
this->database=QSqlDatabase::addDatabase("QSQLITE");
//设置数据库名
this->database.setDatabaseName(db_path);
//看是否能正确打开
if(!this->database.open())
{
// qDebug()<<database.lastError().text();
qDebug()<<"打开失败";
}
else
{
qDebug()<<"数据库打开成功!";
}
}
}
void Installed_imformation::select()
{
QSqlQuery sql_select;
QString select_sql = "select * from installed order by time desc";
sql_select.prepare(select_sql);
if(!sql_select.exec())
{
qDebug()<<"select error";
}
else
{
while(sql_select.next())
{
appname = sql_select.value(0).toString();
version = sql_select.value(1).toString();
now_time = sql_select.value(2).toString();
description = sql_select.value(3).toString();
icon = sql_select.value(4).toString();
statue = sql_select.value(5).toString();
}
}
}
bool Installed_imformation::insert(QString appname, QString version,QString description, QString icon,QString statue)
{
QSqlQuery sql_insert;
time_t time1 = time(NULL);
tm *time2;
time2 = localtime(&time1);
time2->tm_year = time2->tm_year;
char tmp[512] = {};
strftime(tmp,sizeof(tmp),"%Y-%m-%d %H:%M:%S",time2);
QString time3 = tmp;
qDebug()<<appname<<version<<description<<icon<<statue;
QString insert_msg = "insert into installed values(?,?,?,?,?,?)";
sql_insert.prepare(insert_msg);
sql_insert.addBindValue(appname);
sql_insert.addBindValue(version);
sql_insert.addBindValue(tmp);
sql_insert.addBindValue(description);
sql_insert.addBindValue(icon);
sql_insert.addBindValue(statue);
//bool re = sql_insert.exec(insert_msg)
if(!sql_insert.exec())
{
qDebug() << "insert error";
}
else
{
qDebug() << "inserted seccuss!";
}
sql_insert.finish();
database.close();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/wanghailiang1996/kylin-update-desktop.git
git@gitee.com:wanghailiang1996/kylin-update-desktop.git
wanghailiang1996
kylin-update-desktop
kylin-update-desktop
master

搜索帮助