RT-Thread-packages / SQLite

SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine.
16 stars 17 forks source link

how to use sqlite on sdcard? #9

Open lincoln310 opened 4 years ago

lincoln310 commented 4 years ago

i mounted sdcard to /, and i want to use sqlite3. I just did this in main, but it doesn't work:

    int fd = 0;
    const char *dbname = db_get_name();
    fd = open(dbname, O_RDONLY);
    if ((fd < 0) || (db_table_is_exist("student") <= 0))
    {
        rt_kprintf("%s not exist", dbname);
        /* there is not the .db file.create db and table */
        const char *sql = "CREATE TABLE student(id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(32) NOT NULL,score INT NOT NULL);";
        db_create_database(sql);
    }
    else
    {
        /* there is the table int db.close the db. */
        rt_kprintf("The table has already existed!\n");
    }
    close(fd);

here is the result:

 \ | /
- RT -     Thread Operating System
 / | \     4.0.3 build Jun 26 2020
 2006 - 2020 Copyright by rt-thread team
lwIP-2.0.2 initialized!
ÿ[32m[I/drv.rtc] RTC hasn't been configured, please use <date> command to config.ÿ[0m
ÿ[32m[I/sal.skt] Socket Abstraction Layer initialize success.ÿ[0m
ÿ[31m[E/wiz.dev] You should attach [spi10] into SPI bus firstly.ÿ[0m
ÿ[31m[E/wiz.dev] WIZnet SPI device initialize failed.ÿ[0m
ÿ[31m[E/wiz] RT-Thread WIZnet package (V2.0.0) initialize failed(-6).ÿ[0m
msh />ÿ[32m[I/SDIO] SD card capacity 7716864 KB.ÿ[0m
ÿ[32m[I/app.card] sd card mount to '/'ÿ[0m
(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread) assertion failed at function:rt_thread_control, line numbepsr: 0x60000000
r00: 0x00000000
r01: 0x00000001
r02: 0x2000160e
r03: 0x00000002
r04: 0x200015f0
r05: 0x200015f0
r06: 0x00000001
r07: 0x20013b18
r08: 0x0803939b
r09: 0x200174e8
r10: 0x00000000
r11: 0x20015bf4
r12: 0x08061669
 lr: 0x08062495
 pc: 0x20015e08
hard fault on thread: ÿÿ

thread   pri  status      sp     stack size max used left tick  error
-------- ---  ------- ---------- ----------  ------  ---------- ---
tshell    20  suspend 0x0000010c 0x00001000    06%   0x0000000a 000
sys_work  23  suspend 0x00000068 0x00000800    05%   0x0000000a 000
tcpip     10  suspend 0x000000e8 0x00000400    22%   0x00000014 000
etx       12  suspend 0x000000a4 0x00000400    16%   0x00000010 000
erx       12  suspend 0x000000a8 0x00000400    16%   0x00000010 000
mmcsd_de  22  suspend 0x000000a8 0x00000400    67%   0x0000000f 000
tidle0    31  ready   0x00000068 0x00000400    10%   0x0000000b 000
timer      4  suspend 0x00000068 0x00000200    20%   0x00000009 000
FPU active!
usage fault:
SCB_CFSR_UFSR:0x02 INVSTATE 
lincoln310 commented 4 years ago

i changed to this:

    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);

and result is :

 \ | /
- RT -     Thread Operating System
 / | \     4.0.3 build Jun 26 2020
 2006 - 2020 Copyright by rt-thread team
lwIP-2.0.2 initialized!
ÿ[32m[I/drv.rtc] RTC hasn't been configured, please use <date> command to config.ÿ[0m
ÿ[32m[I/sal.skt] Socket Abstraction Layer initialize success.ÿ[0m
ÿ[31m[E/wiz.dev] You should attach [spi10] into SPI bus firstly.ÿ[0m
ÿ[31m[E/wiz.dev] WIZnet SPI device initialize failed.ÿ[0m
ÿ[31m[E/wiz] RT-Thread WIZnet package (V2.0.0) initialize failed(-6).ÿ[0m
msh />ÿ[32m[I/SDIO] SD card capacity 7716864 KB.ÿ[0m
ÿ[32m[I/app.card] sd card mount to '/'ÿ[0m
/rt.db exist
sql cmd: CREATE TABLE IF NOT EXISTS student(id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(32) NOT NULL,score INT NOT NULL)
msh />ls
(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread) assertion failed at function:rt_thread_control, line numbeNo such directory
msh />

the line: "sql ret:" is not printed.