sqlite语句

  1. 查找语句
select id,strCN,strEN from String2 where strCN == '' 

从表String2中查找三列数据:id、strCN、strEN其中条件是strCN这一列为空。

查找语句还可以嵌套使用例如:

select id,strCN,strEN from String2 where strCN != '' and id not in (select id from String2 where strEN != '')

从表String2中查找三列数据:id、strCN、strEN。其中,条件是strCN不为空,并且id不在strEN为空的范围内。概括起来就讲,这个条件就是strCN不为空,strEN为空。

模糊查找语句

select id,strCN,strEN from String2 where strCN like ‘%\n%

从表String2中查找三列数据:id、strCN、strEN。其中,条件是词条中包含有’\n’。

  1. 删除语句
delete from String2 where id == 100

从表String2中删除id为100的项。

  1. 增加一个项语句
insert into String2 (id,strEN) values ('1044055','camshaft position actuator circuit')

向String2中添加一条,该条数据是:id是1044055,strEN为camshaft position actuator circuit。

  1. 更新一条数据
update String set strFR = '' where id = 1080692

更新表String中的strFR列。其中,条件是id等于1080692。

  1. 列出一个表的信息
pragma table_info([StringAttrib_Brand])

列出表StringAttrib_Brand的信息

  1. 给某张表增加一列
alter table StringAttrib_Brand add column strD

在表StringAttrib_Brand中新增一列名字为strD

  1. 获得某张表中主键的最大值
Select max(id) from String

说明:从表String中获得主键id的最大值
备注:屏蔽一个语句用“–”

  1. 将某一列的数据复制到一个新的列中去
update String set strDU=strNE where id = 100

说明:将String表中id=100的strEN列数据复制到strDU列中去

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt 中可以使用 QSqlQuery 类来执行 SQLite 数据库的 SQL 语句。下面是一些常用的 SQLite 语句及其 Qt 实现: 1. 创建表 ```sql CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, ..... ); ``` ```c++ QSqlQuery query; query.exec("CREATE TABLE table_name (" "column1 datatype," "column2 datatype," "column3 datatype," "....." ")"); ``` 2. 插入数据 ```sql INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); ``` ```c++ QSqlQuery query; query.prepare("INSERT INTO table_name (column1, column2, column3, ...) VALUES (?, ?, ?, ...)"); query.addBindValue(value1); query.addBindValue(value2); query.addBindValue(value3); // ... query.exec(); ``` 3. 查询数据 ```sql SELECT column1, column2, column3, ... FROM table_name WHERE condition; ``` ```c++ QSqlQuery query; query.exec("SELECT column1, column2, column3, ... FROM table_name WHERE condition"); while(query.next()) { QString column1 = query.value(0).toString(); QString column2 = query.value(1).toString(); QString column3 = query.value(2).toString(); // ... } ``` 4. 更新数据 ```sql UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; ``` ```c++ QSqlQuery query; query.prepare("UPDATE table_name SET column1 = ?, column2 = ?, ... WHERE condition"); query.addBindValue(value1); query.addBindValue(value2); // ... query.exec(); ``` 5. 删除数据 ```sql DELETE FROM table_name WHERE condition; ``` ```c++ QSqlQuery query; query.exec("DELETE FROM table_name WHERE condition"); ``` 以上就是一些常用的 SQLite 语句及其在 Qt 中的实现方式。需要注意的是,在执行 SQL 语句时,应该使用 prepare 和 addBindValue 函数来避免 SQL 注入攻击。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值