当前位置:网站首页>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
边栏推荐
- Analysis on the current situation and optimization strategy of customer experience management in banking industry
- Convert Excel to csv/csv UTF-8
- What is OKR and what is the difference between OKR and KPI
- Ci framework learning of PHP
- [Vani有约会]雨天的尾巴
- 李沐动手学深度学习V2-transformer和代码实现
- The vscode run command reported an error: the mark "&" is not a valid statement separator in this version.
- Datascience: data generation adds a small amount of noise (customizable noise) to the original data to realize the construction of new data (dataframe format data storage case)
- Interpretation of deepsort source code (IV)
- Book borrowing management system based on SSM
猜你喜欢

(posted) comparison of Eureka, consumer and Nacos 1

String类的用法

内部类--看这篇就懂啦~

Esp8266 (esp-12f) third party library use -- sparkfun_ Apds9960 (gesture recognition)

MySQL2
![Jest single test style problem [identity obj proxy] NPM package](/img/1d/7845a6da9c09bfdde7676a37579225.png)
Jest single test style problem [identity obj proxy] NPM package

泛型 -- 学会它,好处多多

李沐动手学深度学习V2-transformer和代码实现

Watermelon book learning Chapter 5 --- neural network

Basic statement of MySQL (1) - add, delete, modify and query
随机推荐
Student status management system based on SSM
ESP8266(ESP-12F) 第三方库使用 -- SparkFun_APDS9960 (手势识别)
Codeforces Round #809 (Div. 2)(6/6)(Kruskal重构树)
How does golang assign values to empty structures
py2exe qt界面风格变成了win98解决方案
想sink 到 redis-hash 里面 把 对象的属性和值都写进去 ,大佬们有Demo 吗?
Pytorch notes: td3
A Competitive Swarm Optimizer for Large Scale Optimization
Word wrap: break word line feed is compatible with browsers
Gbase 8C - SQL reference 6 SQL syntax (11)
Internal class -- just read this article~
Campus news release management system based on SSM
LogCat工具
Leetcode series (I): buying and selling stocks
Jest single test style problem [identity obj proxy] NPM package
Shell programming specifications and variables
Netease Yunxin appeared at the giac global Internet architecture conference to decrypt the practice of the new generation of audio and video architecture in the meta universe scene
Pytorch model
Firefox browser, when accessing Tencent cloud server, failed to establish a secure connection.
Cass11.0.0.4 for autocad2010-2023 dog free usage