QT中Sqlite的使用

环境:

静态编译过sqlite

步骤:

1.C++链接器中加入Sqlite.lib,然后在测试一下是否能正常加载Sqlite驱动

#include<QtPlugin>

Q_IMPORT_PLUGIN(sqlite)

测试打印:

QStringList dirvers = QSqlDatabase:drivers();

qDebug() << drivers;

2.能正常加载的情况下,继续如下,不能的话检查库路径知否加载正确。

下一个sqlite.exe,其中命令为:

sqlite SQL语句


>dos下启动sqlite
sqlite3.ext test.db
#查看数据库
.databases
>dos下执行sql命令
sqlite3.exe test.db < test.sql
>dos下dump命令
sqlite3.exe test.db .dump > test.sql
>加载数据库
attach database 'test.db' as test;
>卸载数据库
detach database test;
>创建表
create table test(id integer primary key, name text);
>创建视图
create view testview as select * from test;
>创建索引
create index idx_name on test(name);
>重建索引
reindex test;
或者
reindex idx_name;
>添加数据
insert into test(name) values('123');
select last_insert_rowid();
>查询数据
select * from test;
>系统表
select * from sqlite_master;
>sqlite支持ANSI SQL中除right outer join和full outer join之外的所有操作
>sqlite支持limit子句
>sqlite的表默认生成自增长的64位整型字段rowid,别名oid

下面为测试用例:

SQLIte中,主键Integer PRIMARY KEY是默认自增的。

OK,后面自己去写代码实现数据库连接把

原文地址:https://www.cnblogs.com/hermit/p/3552311.html