当前位置:网站首页>SQLite common function integration
SQLite common function integration
2022-07-27 07:30:00 【Xiongsiyu】
Catalog
SQLite date 、 Time Comparison method
SQLite Prompt error :SQLite error near “@table“: syntax error
SQL Create table ,ID Set up key, And self increase
SQLite Query maximum , Returns the entire line of data
SQLite date 、 Time Comparison method
One 、 new table
The following software is Navicat 15 for SQLite
Create a new table for testing test, Add two fields ,id,myTimer,myTimer Format for datetimer

Two 、 insert data
Query the current time
SELECT DATETIME('now','localtime')result :

Know how to get the current time , We ask test Insert data into the table
INSERT INTO test(myTimer) VALUES(DATETIME('now','localtime'))Randomly generate a few pieces of data , For the following query , as follows :

3、 ... and 、 Compare time
1. The query is greater than 2022-02-22 16:45:59 The data of
SELECT * FROM test WHERE myTimer > '2022-02-22 16:45:59'function :

You can see , The query result is right .
occasionally , It should be noted that , use Where The following query conditions are used “2022-02-22 12:00:00” This format is used for comparison , There will be exceptions , The results are all messy , Completely with Where The condition in does not meet , You can check my post : Click the jump
stay C# When the time is displayed on the , You can use the following format :
DateTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));The display is the same as the above
SQLite Prompt error :SQLite error near “@table“: syntax error
I wrote it before C# operation SQLite In the post , I found that sometimes the following errors occur during operation :
SQLite error near "@table": syntax error

The error code is as follows :
public static Tuple<bool, DataSet, string> GetBarcode(string barcode)
{
if (string.IsNullOrEmpty(barcode))
{
return new Tuple<bool, DataSet, string>(false, null, " The passed parameter cannot be empty ");
}
string sql = "SELECT * FROM @table WHERE Barcode = @barcode";
SQLiteParameter[] parameter = new SQLiteParameter[]
{
new SQLiteParameter("table", " Database table name "),
new SQLiteParameter("barcode", barcode)
};
return SQLiteHelpers.ExecuteDataSet(sql, parameter);
}SQLiteHelpers See my previous post for my script : Click the jump
resolvent :
I find , Database table name cannot be added to SQLiteParameter In the parameter list , Other column names are OK ,SQL The statement will not report an error if it is connected by string , as follows :
public static Tuple<bool, DataSet, string> GetBarcode(string barcode)
{
if (string.IsNullOrEmpty(barcode))
{
return new Tuple<bool, DataSet, string>(false, null, " The passed parameter cannot be empty ");
}
string sql = string.Format("SELECT * FROM {0} WHERE Barcode = @barcode", " Database table name ");
SQLiteParameter[] parameter = new SQLiteParameter[]
{
new SQLiteParameter("barcode", barcode)
};
return SQLiteHelpers.ExecuteDataSet(sql, parameter);
}SQL Create table ,ID Set up key, And self increase
sql The statement is as follows :
CREATE TABLE user
(
ID integer PRIMARY KEY AUTOINCREMENT,
UserName text NOT NULL,
Age int NOT NULL
)
SQLite Query maximum , Returns the entire line of data
Query maximum
SELECT MAX( Name ) FROM Table name Query maximum , Returns the entire line of data
SELECT * FROM Table name WHERE Name = (SELECT MAX( Name ) FROM Table name ) LIMIT 1;SQLite Add index
open SQLite Studio, Create a new table student, Add a few fields :id、name、age、address
Click on Create index

The following interface will be opened
Sort( Sort )
ASC Expressing ascending order
DESC Representation of descending order

Here in the collation
Collation( Sort rule )
RTRIM Clear the space character at the end of the string
NOCASE Disable case sensitivity
BINARY Binary system

SQL sentence :
example 1
CREATE INDEX findName ON student (
name COLLATE BINARY ASC
);
COLLATE It's sort rules
example 2
CREATE INDEX findTestTime ON sampleRecord (
TestTime ASC
);
findTestTime Is the index name ,
sampleRecord Is the name of the table ,
TestTime Field name ,
ASC Represents ascending order
end
边栏推荐
- 临界区(critical section 每个线程中访问 临界资源 的那段代码)和互斥锁(mutex)的区别(进程间互斥量、共享内存、虚拟地址)
- Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
- 【QT】capture.obj:-1: error: LNK2019: 无法解析的外部符号 __imp_htons(解决方法)
- 用shell来计算文本中的数字之和
- 在kettle中快速更新一个字段中的信息
- MySQL: 提高最大连接数
- Use the PIP command to switch between different mirror sources
- 单臂路由(讲解+实验)
- Use of tigervnc
- 冰冰学习笔记:类与对象(中)
猜你喜欢

Overall dichotomy?

Perl: 将要执行的外部命令拆分为多行

Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk

C语言实现猜数字小游戏项目实战(基于srand函数、rand函数,Switch语句、while循环、if条件判据等)

Perl: split the external command to be executed into multiple lines

How to submit C4d animation to cloud rendering farm for fast rendering?

Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)

Array method and loop in JS

Bash: create a function that returns a Boolean value

IO中节点流和处理流的理解学习
随机推荐
闭散列和开散列解决哈希冲突
Actual combat of flutter - Request encapsulation (I)
12. Integer to Roman
一款开源 OA 办公自动化系统
vlan间路由(讲解+验证)
Synchronized锁
? Experiment 7 implementation of PHP management system based on MySQL
How to submit C4d animation to cloud rendering farm for fast rendering?
View the dmesg log before server restart
次轮Okaleido Tiger即将登录Binance NFT,引发社区热议
tigervnc的使用
C语言程序设计 | 程序编译与预处理
Turn off the auto start function of Oracle service in centos7
centos7中关闭oracle服务自动启动的功能
sql-labs SQL注入平台-第1关Less-1 GET - Error based - Single quotes - String(基于错误的GET单引号字符型注入)
36 - new promise method: allsettled & any & race
(2022牛客多校三)J-Journey(dijkstra)
(2022杭电多校三)1011.Taxi(曼哈顿最值+二分)
Demonstrate the use of foreign keys with Oracle
Oracle cleans up the Database disk space of tables with referenced partitions