feat support SQLite function, need follow README.md, RAM > 512KB, shell task stack > 32KB, TF card mount FATFS

This commit is contained in:
Liu_Weichao 2023-11-01 16:09:52 +08:00
parent dfa6b664ac
commit 4b579d1c8f
7 changed files with 48 additions and 14 deletions

View File

@ -14,12 +14,15 @@ SQLite 是一个小型,快速,独立的高可靠性全功能 SQL 数据库
| rtthread_io_methods.c | rt-thread为sqlite提供的底层文件IO接口 |
| rtthread_mutex.c | rt-thread为sqlite提供的互斥量操作接口 |
| rtthread_vfs.c | rt-thread为sqlite提供的VFS(虚拟文件系统)接口 |
| xizi_io_methods.c | xizi为sqlite提供的底层文件IO接口 |
| xizi_mutex.c | xizi为sqlite提供的互斥量操作接口 |
| xizi_vfs.c | xizi为sqlite提供的VFS(虚拟文件系统)接口 |
| dbhelper.c | sqlite3操作接口封装简化应用 |
| dbhelper.h | dbhelper头文件向外部声明封装后的接口供用户调用 |
| student_dao.c | 简单的DAO层例程简单展示了对dbhelper的使用方法 |
| student_dao.h | 数据访问对象对外接口声明,线程可通过调用这些接口完成对该表的操作 |
## 获取
## RT-Thread获取
在ENV中配置如下
@ -41,14 +44,39 @@ RT-Thread online packages --->
## 依赖
- RT-Thread 3.X+
- DFS组件
## XiZi获取
在menuconfig中配置如下
```c
LIB_USING_SQLITE --->
[*] Enable SQLite example
(1024) Set SQL statements max length
(64) Set SQL database filename fullpath max length
```
配置项说明:
| 名称 | 说明 |
| -----------------------------| --------------------------------------------------- |
| Enable example | 选择是否使能DAO层例程例程是模拟了学生成绩录入查询 |
| SQL statements max length | SQL语句最大长度请根据实际业务需求设置。 |
| filename fullpath max length | SQL数据库文件名最大长度请根据实际业务需求设置。 |
## 依赖
- XiZi_IIoT
- shell线程栈不少于32KB
- TF卡驱动支持并挂载FATFS文件系统
## dbhelp接口说明
dbhelp是对sqlite3操作接口的封装目的是使用户更加简单地操作sqlite。
### 数据库文件完整路径
数据库文件的默认存放完整路径是"/rt.db"用户可根据实际需求在dbhelper.h中修改。
数据库文件的默认存放完整路径是"/rt.db"或"xiuos.db"用户可根据实际需求在dbhelper.h中修改。
```c
#define DB_NAME "/rt.db"
#define DB_NAME "/rt.db" 、"xiuos.db"
```
### 初始化
dbhelp初始化其中包含了sqlite的初始化及互斥量创建。用户无需再对数据库及锁初始化。

View File

@ -56,7 +56,7 @@ Modification:
#endif
#ifdef ADD_XIZI_FEATURES
#define DEFAULT_DB_NAME "/xiuos.db"
#define DEFAULT_DB_NAME "xiuos.db"
#endif
#ifdef ADD_RTTHREAD_FEATURES
@ -98,7 +98,7 @@ int db_helper_init(void)
ret = PrivMutexCreate(&db_mutex_lock, 0);
if (ret < 0)
{
printf("rt_mutex_create dbmtx failed!\n");
printf("mutex_create dbmtx failed!\n");
return -1;
}
return 0;

View File

@ -570,12 +570,11 @@ static void list_by_score(int ls, int hs, enum order_type order)
return;
}
static void stu(uint8_t argc, char **argv)
static int stu(int argc, char *argv[])
{
if (argc < 2)
{
list_all();
return;
}
else
{
@ -706,15 +705,22 @@ static void stu(uint8_t argc, char **argv)
PrivFree(s);
}
}
return 0;
}
PRIV_SHELL_CMD_FUNCTION(stu, student add del update query, PRIV_SHELL_CMD_FUNC_ATTR);
PRIV_SHELL_CMD_FUNCTION(stu, student add del update query, PRIV_SHELL_CMD_MAIN_ATTR);
static int create_student_tbl(void)
{
int fd = 0;
int fd = -1;
//init sqlite3
db_helper_init();
db_set_name("/stu_info.db");
fd = PrivOpen(db_get_name(), O_RDONLY);
fd = PrivOpen("/stu_info.db", O_RDONLY);
printf(db_get_name());
printf(" fd %d\n", fd);
if (fd < 0)
{
/* there is not the .db file.create db and table */

View File

@ -408,7 +408,7 @@ static int _xizi_io_sector_size(sqlite3_file *file_id)
static int _xizi_io_device_characteristics(sqlite3_file *file_id)
{
return 0;
return SQLITE_IOCAP_SAFE_APPEND;
}
/*

View File

@ -122,7 +122,7 @@ static sqlite3_mutex * _xizi_mtx_alloc(int id)
{
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE:
p = PrivMalloc(sizeof(sqlite3_mutex));
p = sqlite3_malloc(sizeof(sqlite3_mutex));
if (p != NULL) {
PrivMutexCreate(&p->mutex, 0);

View File

@ -101,7 +101,7 @@ int _gettimeofday(struct timeval *tp, void *ignore)
static int _Access(const char *pathname, int mode)
{
int fd;
int fd = -1;
fd = PrivOpen(pathname, O_RDONLY);

View File

@ -449,7 +449,7 @@ int open(const char *path, int flags, ...)
abspath = GetAbsolutePath(path);
mp = GetMountPoint(abspath);
if (mp == NULL) {
SYS_ERR("%s: mount point not found\n", __func__);
SYS_ERR("%s: mount point not found path %s abspath %s\n", __func__, path, abspath);
ret = -EINVAL;
goto err;
}