You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
2 days ago
|
/*
|
||
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||
|
*
|
||
|
* SPDX-License-Identifier: Apache-2.0
|
||
|
*
|
||
|
* Change Logs:
|
||
|
* Date Author Notes
|
||
|
* 2025-10-20 Administrator the first version
|
||
|
*/
|
||
|
#include <rtthread.h>
|
||
|
#include <rtdevice.h>
|
||
|
#include <board.h>
|
||
|
#include "DB_SQLite.h"
|
||
|
|
||
|
#include <dbhelper.h>
|
||
|
#define DB_NAME "/rt.db"
|
||
|
|
||
|
void db_sqlite(void *parameter)
|
||
|
{
|
||
|
int db_HelperInit;
|
||
|
int db_;
|
||
|
|
||
|
db_HelperInit = db_helper_init();
|
||
|
|
||
|
if(db_HelperInit =RT_EOK){
|
||
|
rt_kprintf("HelperInit database\n");
|
||
|
}else {
|
||
|
// db_ = db_create_database("CREATE TABLE student(id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(32) NOT NULL,score INT NOT NULL);");
|
||
|
// if(db_=0){rt_kprintf("database ok\n");}else{rt_kprintf("database no\n");}
|
||
|
}
|
||
|
|
||
|
/* int fd = 0;
|
||
|
const char *dbname = db_get_name();
|
||
|
fd = open(dbname, O_RDONLY);
|
||
|
if (fd > 0)
|
||
|
rt_kprintf("%s exist\r\n", dbname);
|
||
|
else
|
||
|
rt_kprintf("%s not exist\r\n");
|
||
|
|
||
|
|
||
|
const char *sql = "CREATE TABLE IF NOT EXISTS student(id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(32) NOT NULL,score INT NOT NULL);";
|
||
|
rt_kprintf("sql cmd: %s\r\n\r\n", sql);
|
||
|
int ret = db_create_database(sql);
|
||
|
rt_kprintf("sql ret: %d\r\n", ret);*/
|
||
|
|
||
|
// sqlite3_os_init();
|
||
|
|
||
|
/* int rc = db_connect("/rt.db");
|
||
|
if (rc <0) {
|
||
|
const char *sql = "CREATE TABLE student(id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(32) NOT NULL,score INT NOT NULL);";
|
||
|
int db_create_database(sql);
|
||
|
}*/
|
||
|
}
|
||
|
|
||
|
/* 线程 */
|
||
|
void thread_DB_SQLite(void)
|
||
|
{
|
||
|
/* 初始化线程 1,名称是 thread1,入口是 thread1_entry*/
|
||
|
rt_thread_t tid;
|
||
|
tid = rt_thread_create("db_sqlite", db_sqlite, RT_NULL, 1024*32, 3, 10);
|
||
|
|
||
|
if (tid != RT_NULL)
|
||
|
{
|
||
|
rt_thread_startup(tid);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
rt_kprintf("Failed to create sqlite_sys thread!\n");
|
||
|
}
|
||
|
// return 0;
|
||
|
}
|