当前位置:网站首页>SQLite 常用功能整合
SQLite 常用功能整合
2022-07-27 06:08:00 【熊思宇】
目录
SQLite 提示错误:SQLite error near “@table“: syntax error
SQLite 日期、时间 比较方法
一、新建表
下面用的软件是 Navicat 15 for SQLite
新建一个测试用的表 test,添加两个字段,id,myTimer,myTimer 的格式用 datetimer

二、插入数据
查询当前时间
SELECT DATETIME('now','localtime')结果:

知道了如何获取当前的时间,我们向test表中插入数据
INSERT INTO test(myTimer) VALUES(DATETIME('now','localtime'))随便生成几条数据,为了后面的查询,如下:

三、 比较时间
1.查询大于 2022-02-22 16:45:59 的数据
SELECT * FROM test WHERE myTimer > '2022-02-22 16:45:59'运行:

可以看到,查询结果是对的。
有时候,需要注意的是,用 Where 后的查询条件用“2022-02-22 12:00:00”这种格式作为比较,也会出现异常,查出来的结果全是乱七八糟的,完全与 Where 中的条件不符合,可以查看我的帖子:点击跳转
在C#上显示时间时,可以用下面的格式:
DateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));显示就和上图一样
SQLite 提示错误:SQLite error near “@table“: syntax error
在之前写的C#操作SQLite帖子中,我发现有时候运行会出现下面的错误:
SQLite error near "@table": syntax error

出现错误的代码如下:
public static Tuple<bool, DataSet, string> GetBarcode(string barcode)
{
if (string.IsNullOrEmpty(barcode))
{
return new Tuple<bool, DataSet, string>(false, null, "传递的参数不能为空");
}
string sql = "SELECT * FROM @table WHERE Barcode = @barcode";
SQLiteParameter[] parameter = new SQLiteParameter[]
{
new SQLiteParameter("table", "数据库表名"),
new SQLiteParameter("barcode", barcode)
};
return SQLiteHelpers.ExecuteDataSet(sql, parameter);
}SQLiteHelpers 的脚本看我之前帖子:点击跳转
解决方法:
我发现,数据库表名不能加入到 SQLiteParameter 参数列表中,其他的列名是没问题的,SQL语句改用字符串连接方式就不会报错了,如下:
public static Tuple<bool, DataSet, string> GetBarcode(string barcode)
{
if (string.IsNullOrEmpty(barcode))
{
return new Tuple<bool, DataSet, string>(false, null, "传递的参数不能为空");
}
string sql = string.Format("SELECT * FROM {0} WHERE Barcode = @barcode", "数据库表名");
SQLiteParameter[] parameter = new SQLiteParameter[]
{
new SQLiteParameter("barcode", barcode)
};
return SQLiteHelpers.ExecuteDataSet(sql, parameter);
}SQL 创建表,ID设置key,并自增
sql 语句如下:
CREATE TABLE user
(
ID integer PRIMARY KEY AUTOINCREMENT,
UserName text NOT NULL,
Age int NOT NULL
)
SQLite 查询最大值,返回整行数据
查询最大值
SELECT MAX(列名) FROM 表名查询最大值,返回整行数据
SELECT * FROM 表名 WHERE 列名= (SELECT MAX(列名) FROM 表名) LIMIT 1;SQLite 添加索引
打开 SQLite Studio,新建一个表student,添加几个字段:id、name、age、address
点击 Create index

就会打开下面界面
Sort(排序)
ASC 表示升序
DESC 表示降序

在排序规则这里
Collation(排序规则)
RTRIM 清除字符串结尾空格符
NOCASE 禁用大小写区分
BINARY 二进制

SQL语句:
例1
CREATE INDEX findName ON student (
name COLLATE BINARY ASC
);
COLLATE 是排序规则
例2
CREATE INDEX findTestTime ON sampleRecord (
TestTime ASC
);
findTestTime 是索引名,
sampleRecord 是表名,
TestTime 是字段名,
ASC 代表升序
end
边栏推荐
- flink cdc 抽取oracle的数据,会不断的占用oracle的内存吗,最后引发ora-040
- The qualities that a technical manager should have (guess)
- How to learn C language? This article gives you the complete answer
- 内部类--看这篇就懂啦~
- How to implement Devops with automation tools | including low code and Devops application practice
- Interpretation of deepsort source code (II)
- 【QT】capture.obj:-1: error: LNK2019: 无法解析的外部符号 __imp_htons(解决方法)
- 二叉树--天然的查找语义(1)基础篇
- 一款开源 OA 办公自动化系统
- ESP8266(ESP-12F) 第三方库使用 -- SparkFun_APDS9960 (手势识别)
猜你喜欢

C4D云渲染平台选哪家合作?

Campus news release management system based on SSM

Leetcode series (I): buying and selling stocks

Relevant principles of MySQL index optimization

Working principle analysis of deepsort

VScode连接远程服务器开发

Internal class -- just read this article~

Analysis of strong tennis cup 2021 PWN competition -- babypwn

2022 0726 顾宇佳 学习笔记

C4D动画如何提交云渲染农场快速渲染?
随机推荐
Jmeter:接口自动化测试-BeanShell对数据库数据和返回数据比较
C4D动画如何提交云渲染农场快速渲染?
Vscode creates golang development environment and debug unit test of golang
如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
零号培训平台课程-2、SSRF基础
(posted) comparison of Eureka, consumer and Nacos 2
Jest single test style problem [identity obj proxy] NPM package
Relevant principles of MySQL index optimization
Interpretation of deepsort source code (II)
(转帖)eureka、consul、nacos的对比2
指令集董事长潘爱民出席2022 ECUG Con,为中国技术力量发声
2022-07-25 顾宇佳 学习笔记
一款开源 OA 办公自动化系统
Es compares the data difference between the two indexes
Codeforces Round #804 (Div. 2)(5/5)
Talk about multimodality of fire
2021 interview question of php+go for Zhongda factory (1)
Golang controls the number of goroutines and obtains processing results
sql-labs SQL注入平台-第1关Less-1 GET - Error based - Single quotes - String(基于错误的GET单引号字符型注入)
OpenGL development with QT (I) drawing plane graphics