rt_thread v1.2.2 版本使用sqlite-3.8问题请教

29 views
Skip to first unread message

jason shi

unread,
Aug 25, 2014, 5:31:03 AM8/25/14
to rt-threa...@googlegroups.com, newl...@126.com
各位大侠,
       我在M3上使用的是rtt v1.2.2稳定版本,并且启用了里面的sqlite-3.8的数据库,
       具体就是将 rt-thread-1.2.2\components\external\SQLite-3.8.1\SQLiteLib\ 目录下的sqlite3.c文件添加到工程,
       然后去 rtconfig.h中定义了 #define     RT_USING_SQLITE 这个宏,然后根据test10.c文件里面的程序写了自己的demo:
void test_db(void)
{
    sqlite3 *db;
    int result = -1;
    char *errmsg = NULL;
    

    result = sqlite3_open(db_name, &db);
    MY_DEBUG("%s, %d:  ret = %d\n\r",__func__,__LINE__,result);
    if(result != SQLITE_OK) {
      MY_DEBUG("%s, %d: open db file %s faild : %s ...\n\r",__func__,__LINE__, db_name,sqlite3_errmsg(db));
      return ;
    }else {
      MY_DEBUG("%s, %d: open db file %s success ...\n\r",__func__,__LINE__, db_name);
    }

    result = sqlite3_exec(db, "create table tb(ID integer primary key autoincrement, name nvarchar(32))", NULL, NULL, NULL);
    if(result != SQLITE_OK) {
      MY_DEBUG("%s, %d: create table faild: %d, %s\n\r",__func__,__LINE__, result,sqlite3_errmsg(db));
      sqlite3_close( db );
      return ;
    }else {
      MY_DEBUG("%s, %d: create success !\n\r",__func__,__LINE__);
    }
    sqlite3_close( db );
    return ;
}

上面创建数据库的时候,返回值为0,显示创建成功,然后我试着用 sqlite3_exec()向数据库文件里添加一个表的时候,就出现了这个错误:  

unable to open database file

我以为是自己的程序的问题,于是又将这部分代码在 ubuntu 下进行了测试,完整通过,一切都OK。

在google上看了一下sqlite3的资料,据说是权限问题,但是依然不明白该怎么解决,我的文件系统是 ELMFAT ,希望有弄过的大侠给与指点下,谢谢!

Grissiom

unread,
Aug 25, 2014, 5:37:48 AM8/25/14
to rt-threa...@googlegroups.com, newl...@126.com
这个内存是不是够用呢?失败了之后 list_mem 一下看看?

--
Cheers,
Grissiom

jason shi

unread,
Aug 25, 2014, 5:57:05 AM8/25/14
to rt-threa...@googlegroups.com, newl...@126.com
我的finsh shell关闭了,我在检测到 sqlite3_exec()的返回值不为0的情况下,调用了  void list_mem(voi)这个API。下面是我修改后的代码及调试信息:
void test_db(void)
{
    sqlite3 *db;
    int result = -1;
    char *errmsg = NULL;
    

    result = sqlite3_open(db_name, &db);
    MY_DEBUG("%s, %d:  ret = %d\n\r",__func__,__LINE__,result);
    if(result != SQLITE_OK) {
      MY_DEBUG("%s, %d: open db file %s faild : %s ...\n\r",__func__,__LINE__, db_name,sqlite3_errmsg(db));
      return ;
    }else {
      MY_DEBUG("%s, %d: open db file %s success ...\n\r",__func__,__LINE__, db_name);
    }

    result = sqlite3_exec(db, "create table tb(ID integer primary key autoincrement, name nvarchar(32))", NULL, NULL, NULL);
    if(result != SQLITE_OK) {
      MY_DEBUG("%s, %d: create table faild: %d, %s\n\r",__func__,__LINE__, result,sqlite3_errmsg(db));
      MY_DEBUG("flow memory use : \n\r");
      list_mem();
      sqlite3_close( db );
      return ;
    }else {
      MY_DEBUG("%s, %d: create success !\n\r",__func__,__LINE__);
    }
    sqlite3_close( db );
    return ;
}

-------------------调试打印----------------------------
File System initialized!
test_db, 31:  result = 0
test_db, 36: open db file /test.db success ...
test_db, 41: create table faild: 14, unable to open database file
flow memory use :
total memory: 49016
used memory : 22768
maximum allocated memory: 36416


现在其他的任务都关闭了,就只是测试数据库的了,还是不能读取,看这个情况,应该不是内存不够吧?

在 2014年8月25日星期一UTC+8下午5时37分48秒,grissiom写道:

Romeo

unread,
Aug 25, 2014, 8:14:27 AM8/25/14
to rt-thread-cnusers, newleaves
显然内存小了,有一次性声请90K+的内存,分配失败肯定打开错误!


------------------ 原始邮件 ------------------
发件人: "jason shi";<boyis...@gmail.com>;
发送时间: 2014年8月25日(星期一) 下午5:57
收件人: "rt-thread-cnusers"<rt-threa...@googlegroups.com>;
抄送: "newleaves"<newl...@126.com>;
主题: Re: rt_thread v1.2.2 版本使用sqlite-3.8问题请教
--
You received this message because you are subscribed to the Google Groups "rt-thread用户组" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rt-thread-cnus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jason shi

unread,
Aug 25, 2014, 9:01:21 PM8/25/14
to rt-threa...@googlegroups.com, newl...@126.com
那如果要使用sqlite的话,对于这种情况比较好的方式是什么呢?  有人说可以把M3的代码,放到flash中运行,这可行吗? 谢谢!

在 2014年8月25日星期一UTC+8下午5时31分03秒,jason shi写道:

Grissiom

unread,
Aug 25, 2014, 9:44:20 PM8/25/14
to rt-threa...@googlegroups.com, newl...@126.com
2014-08-26 9:01 GMT+08:00 jason shi <boyis...@gmail.com>:
那如果要使用sqlite的话,对于这种情况比较好的方式是什么呢?  有人说可以把M3的代码,放到flash中运行,这可行吗? 谢谢!


貌似一般情况本来就是代码在 Flash 中运行的……

sqlite 应该需要比较大的内存吧!不过既然会一次申请 90K+ 的内存,那么系统内存至少要 100K 应该算是硬性指标。

--
Cheers,
Grissiom

jason shi

unread,
Aug 25, 2014, 10:31:54 PM8/25/14
to rt-threa...@googlegroups.com, newl...@126.com
那我就买一个外扩的 sram吧,不纠结了。

在 2014年8月25日星期一UTC+8下午5时31分03秒,jason shi写道:

bernard

unread,
Aug 25, 2014, 10:44:19 PM8/25/14
to rt-thread用户组, newl...@126.com
运行sqlite的MCU有些麻烦的,很多都不能够满足,资源消耗高啊
目前在MCU上试过的是LPC4088开发板


--
Reply all
Reply to author
Forward
0 new messages