当前位置:网站首页>c sqlite...
c sqlite...
2022-08-04 19:33:00 【Hong Dayu】
#define DATABASE "drurmu.db"
#define READ 0x1
#define WRITE 0x2
#define EXEC 0x0
#define VALUE 0x6
#define INT32 0x10
#define STR 0x20
int32_t sqlite3_open_database(sqlite3 **sqlite) {
int32_t ret = sqlite3_open(DATABASE, sqlite);
if (ret != SQLITE_OK) {
printf("[USER DEBUG] sqlite3-> %s \n", sqlite3_errstr(ret));
return ret;
}
return SQLITE_OK;
}
int32_t sqlite3_exec_sql(sqlite3 *sqlite, int32_t mode, const char *sql,
void *value, int32_t _s) {
sqlite3_stmt *stmt = NULL;
int32_t ret = sqlite3_prepare_v2(sqlite, sql, strlen(sql), &stmt, NULL);
if (ret != SQLITE_OK) {
printf("[USER DEBUG] sqlite3-> %s \n", sqlite3_errstr(ret));
return ret;
}
switch (mode & 0xF) {
case EXEC:
if (sqlite3_step(stmt) == SQLITE_OK) {
return SQLITE_OK;
}
case READ:
if (sqlite3_step(stmt) == SQLITE_ROW) {
if ((mode & 0xF0) == INT32) {
*(int32_t *)value = sqlite3_column_int(stmt, VALUE);
} else if ((mode & 0xF0) == STR) {
int32_t size = strlen((const char *)sqlite3_column_text(stmt, VALUE));
if (value == NULL && _s < size) {
sqlite3_finalize(stmt);
return -3;
}
memcpy((char *)value, sqlite3_column_text(stmt, VALUE), size);
}
} else {
sqlite3_finalize(stmt);
return -5;
}
sqlite3_finalize(stmt);
return SQLITE_OK;
case WRITE:
if (sqlite3_step(stmt) == SQLITE_OK) {
return SQLITE_OK;
} else {
return -2;
}
default:
return -1;
}
return SQLITE_OK;
}
int32_t main(void) {
sqlite3 *sqlite;
int32_t ret = sqlite3_open_database(&sqlite);
if (ret != SQLITE_OK) {
printf("[USER DEBUG] sqlite3 open database error-> %s\n",
sqlite3_errstr(ret));
return -1;
}
char select[] = "select * from rmu where ID=\'0x0007\'";
char str[255];
bzero(str, 255);
sqlite3_exec_sql(sqlite, READ | STR, select, (void *)str, 255);
printf("%s\n", str);
int32_t INT;
bzero(select, strlen(select));
sprintf(select, "select * from rmu where ID=\'0x0002\'");
sqlite3_exec_sql(sqlite, READ | INT32, select, (void *)&INT, 0);
printf("%d\n", INT);
char add[] = "insert into rmu VALUES(\'0x1234\','hello "
"world','RW','uint1',1,20,0,0,0,0)";
sqlite3_exec_sql(sqlite, WRITE, add, NULL, 0);
return 0;
}
边栏推荐
- 手把手教你CSP系列之script-src
- T+Cloud: A "Smart Company" for Building New Business Social Networks and Marketing Relationships
- 元国度链游系统开发
- 如果是测试 axi dma抓数的话 看这里
- 备忘录模式
- Orthodontic MIA micro-implant anchorage technology China 10th anniversary exchange meeting was held in Shenyang
- 力扣题(5)—— 最长回文子串
- 量化交易机器人系统开发
- win10 uwp MetroLog 入门
- 【Attention演变史】翻译模型seq2seq (第二弹)
猜你喜欢
ELECTRA:Pre-training Text Encoders as Discriminators Rather Than Generators
查询APP Store已发布过的版本记录
MogDB学习笔记-环境准备及单实例安装
Infrared image filtering
元国度链游系统开发
VQ Realization of Wavelet Extraction Features
零基础做出高端堆叠极环图
Seata source code analysis: various message processing processes of seata server
运维就业现状怎么样?技能要求高吗?
基于YOLOV5行人跌倒检测实验
随机推荐
四维图新:子公司首款功能安全 MCU 芯片已陆续送样
WPF 元素裁剪 Clip 属性
[Latest Information] 2 new regions will announce the registration time for the soft exam in the second half of 2022
Ant Group's time series database CeresDB is officially open source
To -.-- -..- -
Finger Vein Recognition-matlab
如何让远在的老板看到你!----------来自财富中国网
WPF 多个 StylusPlugIn 的事件触发顺序
Video Object Detection
拥抱Cmake小朋友 简单又实用,但是不灵活
Yuanguo chain game system development
数据库治理的探索与实践
ERC20转账压缩
Highlights of some performance tests
入门:人脸专集1 | 级联卷积神经网络用于人脸检测(文末福利)
PG网络传输安全SSL介绍及使用示例
六月 致 -.-- -..- -
如何手动下载并安装 Visual Studio Code 的 SAP Fiori tools - Extension Pack
win10 uwp xaml 绑定接口
Chrome 开发者工具 performance 标签页的用法