forked from xuos/xiuos
feat support SQLite function, need follow README.md, RAM > 512KB, shell task stack > 32KB, TF card mount FATFS
This commit is contained in:
parent
dfa6b664ac
commit
4b579d1c8f
|
@ -14,12 +14,15 @@ SQLite 是一个小型,快速,独立的高可靠性全功能 SQL 数据库
|
||||||
| rtthread_io_methods.c | rt-thread为sqlite提供的底层文件IO接口 |
|
| rtthread_io_methods.c | rt-thread为sqlite提供的底层文件IO接口 |
|
||||||
| rtthread_mutex.c | rt-thread为sqlite提供的互斥量操作接口 |
|
| rtthread_mutex.c | rt-thread为sqlite提供的互斥量操作接口 |
|
||||||
| rtthread_vfs.c | rt-thread为sqlite提供的VFS(虚拟文件系统)接口 |
|
| 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.c | sqlite3操作接口封装,简化应用 |
|
||||||
| dbhelper.h | dbhelper头文件,向外部声明封装后的接口,供用户调用 |
|
| dbhelper.h | dbhelper头文件,向外部声明封装后的接口,供用户调用 |
|
||||||
| student_dao.c | 简单的DAO层例程,简单展示了对dbhelper的使用方法 |
|
| student_dao.c | 简单的DAO层例程,简单展示了对dbhelper的使用方法 |
|
||||||
| student_dao.h | 数据访问对象对外接口声明,线程可通过调用这些接口完成对该表的操作 |
|
| student_dao.h | 数据访问对象对外接口声明,线程可通过调用这些接口完成对该表的操作 |
|
||||||
|
|
||||||
## 获取
|
## RT-Thread获取
|
||||||
|
|
||||||
在ENV中配置如下
|
在ENV中配置如下
|
||||||
|
|
||||||
|
@ -41,14 +44,39 @@ RT-Thread online packages --->
|
||||||
## 依赖
|
## 依赖
|
||||||
- RT-Thread 3.X+
|
- RT-Thread 3.X+
|
||||||
- DFS组件
|
- 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接口说明
|
||||||
|
|
||||||
dbhelp是对sqlite3操作接口的封装,目的是使用户更加简单地操作sqlite。
|
dbhelp是对sqlite3操作接口的封装,目的是使用户更加简单地操作sqlite。
|
||||||
|
|
||||||
### 数据库文件完整路径
|
### 数据库文件完整路径
|
||||||
数据库文件的默认存放完整路径是"/rt.db",用户可根据实际需求在dbhelper.h中修改。
|
数据库文件的默认存放完整路径是"/rt.db"或"xiuos.db",用户可根据实际需求在dbhelper.h中修改。
|
||||||
```c
|
```c
|
||||||
#define DB_NAME "/rt.db"
|
#define DB_NAME "/rt.db" 、"xiuos.db"
|
||||||
```
|
```
|
||||||
### 初始化
|
### 初始化
|
||||||
dbhelp初始化,其中包含了sqlite的初始化及互斥量创建。用户无需再对数据库及锁初始化。
|
dbhelp初始化,其中包含了sqlite的初始化及互斥量创建。用户无需再对数据库及锁初始化。
|
||||||
|
|
|
@ -56,7 +56,7 @@ Modification:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ADD_XIZI_FEATURES
|
#ifdef ADD_XIZI_FEATURES
|
||||||
#define DEFAULT_DB_NAME "/xiuos.db"
|
#define DEFAULT_DB_NAME "xiuos.db"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ADD_RTTHREAD_FEATURES
|
#ifdef ADD_RTTHREAD_FEATURES
|
||||||
|
@ -98,7 +98,7 @@ int db_helper_init(void)
|
||||||
ret = PrivMutexCreate(&db_mutex_lock, 0);
|
ret = PrivMutexCreate(&db_mutex_lock, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
printf("rt_mutex_create dbmtx failed!\n");
|
printf("mutex_create dbmtx failed!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -570,12 +570,11 @@ static void list_by_score(int ls, int hs, enum order_type order)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stu(uint8_t argc, char **argv)
|
static int stu(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
list_all();
|
list_all();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -706,15 +705,22 @@ static void stu(uint8_t argc, char **argv)
|
||||||
PrivFree(s);
|
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)
|
static int create_student_tbl(void)
|
||||||
{
|
{
|
||||||
int fd = 0;
|
int fd = -1;
|
||||||
|
|
||||||
|
//init sqlite3
|
||||||
|
db_helper_init();
|
||||||
|
|
||||||
db_set_name("/stu_info.db");
|
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(db_get_name());
|
||||||
|
printf(" fd %d\n", fd);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
/* there is not the .db file.create db and table */
|
/* there is not the .db file.create db and table */
|
||||||
|
|
|
@ -408,7 +408,7 @@ static int _xizi_io_sector_size(sqlite3_file *file_id)
|
||||||
|
|
||||||
static int _xizi_io_device_characteristics(sqlite3_file *file_id)
|
static int _xizi_io_device_characteristics(sqlite3_file *file_id)
|
||||||
{
|
{
|
||||||
return 0;
|
return SQLITE_IOCAP_SAFE_APPEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -122,7 +122,7 @@ static sqlite3_mutex * _xizi_mtx_alloc(int id)
|
||||||
{
|
{
|
||||||
case SQLITE_MUTEX_FAST:
|
case SQLITE_MUTEX_FAST:
|
||||||
case SQLITE_MUTEX_RECURSIVE:
|
case SQLITE_MUTEX_RECURSIVE:
|
||||||
p = PrivMalloc(sizeof(sqlite3_mutex));
|
p = sqlite3_malloc(sizeof(sqlite3_mutex));
|
||||||
|
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
PrivMutexCreate(&p->mutex, 0);
|
PrivMutexCreate(&p->mutex, 0);
|
||||||
|
|
|
@ -101,7 +101,7 @@ int _gettimeofday(struct timeval *tp, void *ignore)
|
||||||
|
|
||||||
static int _Access(const char *pathname, int mode)
|
static int _Access(const char *pathname, int mode)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
|
|
||||||
fd = PrivOpen(pathname, O_RDONLY);
|
fd = PrivOpen(pathname, O_RDONLY);
|
||||||
|
|
||||||
|
|
|
@ -449,7 +449,7 @@ int open(const char *path, int flags, ...)
|
||||||
abspath = GetAbsolutePath(path);
|
abspath = GetAbsolutePath(path);
|
||||||
mp = GetMountPoint(abspath);
|
mp = GetMountPoint(abspath);
|
||||||
if (mp == NULL) {
|
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;
|
ret = -EINVAL;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue