SQLite

SQLite

基本流程

1
2
3
4
5
6
7
8
9
//打开数据库
sqlite3 *sqldb = NULL;
int res = sqlite3_open(db_file_name.c_str(), &sqldb);
if (res != SQLITE_OK) {
    fprintf(stderr, "Can not open database: %s\n", sqlite3_errmsg(sqldb));
    return false;
}
// 关闭数据库
sqlite3_close(sqldb);

常用语句

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT column1, column2, columnN FROM table_name; --从表 table_name 中选择column1, column2, columnN列
SELECT * FROM table_name; --选择所有列


SELECT * FROM COMPANY WHERE AGE IN ( 25, 27 );  --列出了 AGE 的值为 25 或 27 的所有记录
ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
2           Allen       25          Texas       15000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
--直接看菜鸟教程吧,很详细

常用函数

sqlite3_exec(),称为便捷函数,封装了好多任务。

正则表达式

正则表达式

正则表达式语法

元字符

元字符描述
.句号匹配任意单个字符除了换行符。
".ar" => The car parked in the garage.
[ ]匹配方括号内的任意字符
"[Tt]he" => The car parked in the garage.
[^ ]否定的字符种类。匹配除了方括号里的任意字符
"[^c]ar=> The car parked in the garage.
*匹配>=0个重复的在*号之前的字符。
"[a-z]*" => The car parked in the garage #21.
+匹配>=1个重复的+号前的字符。
"c.+t" => The fat cat sat on the mat.
?标记?之前的字符为可选.
"[T]?he" => The car is parked in the garage.
{n,m}匹配num个大括号之前的字符或字符集 (n <= num <= m).
0~9之间匹配最少2位,最多3位的数字:"[0-9]{2,3}" => The number was 9.9997 but we rounded it off to 10.0.
0~9之间匹配只是2位的数字:"[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0.
0~9之间匹配3位数字:"[0-9]{3}" => The number was 9.9997 but we rounded it off to 10.0.
(xyz)字符集,匹配与 xyz 完全相等的字符串.
"`(c
|或运算符,匹配符号前或后的字符.
“`(T
\转义字符,用于匹配一些保留的字符 [ ] ( ) { } . * + ? ^ $ \ |
"`(f
^从开始行开始匹配
`[T
$从末端开始匹配
"(at\.)” =>The fat cat. sat. on the mat.
"(at\.$)"=>The fat cat. sat. on the mat.

简写字符集

简写描述
.除换行符外的所有字符
\w匹配所有字母数字,等同于 [a-zA-Z0-9_]
\W匹配所有非字母数字,即符号,等同于: [^\w]
\d匹配数字: [0-9]
\D匹配非数字: [^\d]
\s匹配所有空格字符,等同于: [\t\n\f\r\p{Z}]
\S匹配所有非空格字符: [^\s]
\f匹配一个换页符
\n匹配一个换行符
\r匹配一个回车符
\t匹配一个制表符
\v匹配一个垂直制表符
\p匹配 CR/LF(等同于 \r\n),用来匹配 DOS 行终止符

零宽度断言

符号描述
?=正先行断言-存在
“`(T
?!负先行断言-排除
“`(T
?<=正后发断言-存在
“`(?<=(T
?<!负后发断言-排除
“`(?<!(T

标志(可选项)

标志描述
i忽略大小写。
"The/gi" => The fat cat sat on the mat.
g全局搜索。
".(at)/gi" => The fat cat sat on the mat.
m多行修饰符:锚点元字符 ^ $ 工作范围在每行的起始。

贪婪与惰性匹配

默认贪婪匹配,意味着会匹配尽可能长的子串

0%