赞
踩
https://www.w3cschool.cn/sqlite
下载地址:https://www.sqlite.org/download.html : Precompiled Binaries for Windows
https://blog.csdn.net/u011555996/article/details/108065572
QT += sql
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
if (QSqlDatabase::contains(db_name)){
QSqlDatabase::database()
}
QSqlDatabase::addDatabase("QSQLITE", db_name)
database.open()
database.lastError()
QSqlQuery sql_query;
QString create_sql = "create table <table_name> (f1 type1, f2 type2,…)";
sql_query.prepare(create_sql); \\ sql_query.exec()
insert into <table_name> values (value1, value2,…);
update <table_name> set <f1=value1>, <f2=value2>… where <expression>;
sql_query.bindValue(":name", "Qt"); // 把语句中的待定变量换成确定值
select <f1>, <f2>, ... from <table_name>;
select * from <table_name>;
select max(id) from <table_name>; // 查询最大id
// sql_query.value(int) 获得数据, 返回值类型是QVariant,因此要用toInt()等函数转换成特定的类型。
while(sql_query.next())
{
int id = sql_query.value(0).toInt();
QString name = sql_query.value(1).toString();
}
delete from <table_name> where <f1> = <value>
sqlite3_open(const char *filename, sqlite3 **ppDb)
sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void *data, char **errmsg)
sqlite3_close(sqlite3*)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。