大佬教程收集整理的这篇文章主要介绍了转cocos2dx官网上的sqlite基础使用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在Cocos2d-x中,简单数据存储,可以使用UserDefault。那么如何存储大量,不规则的数据?我们可以使用SQLite数据库存储数据。sqlite是使用非常广泛的嵌入式数据库,它有小巧 、高效、跨平台、开源免费和易操作的特点。
sqlite数据库是使用C语言来编写的,那么在Cocos2d-x使用SQLite也是得心应手。
首先创建一个Cocos2d-x v3.x的Helloworld工程,我们将以该工程作为sqlite集成与用法的实战工程。
打开终端,使用如下命令新建工程:
按照上面的操作,我们新建了一个Cocos2d-x v3.x的HelloWorld工程。
iOS/Mac的系统库自带sqlite库,我们只需添加libsqlite3.0.dylib库即可。
Android系统没有自带sqlite库,我们需要手动添加。
1.下载sqlite包
下载地址:http://www.sqlite.org/download.html下载后,在项目中导入sqlite3.c和sqlite3.h两个文件即可。
2.导入到工程
3.修改Android.mk
打开HelloWorldScene.cpp文件,我们在里面加入sqlite的使用示例
引入头文件
result=sqlite3_exec(pdb,sql.c_str(),NULL,null);
//1
|
"insert into student values(1,'student1','male')"
@H_675_26@;
:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,null);
:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,null);
"insert into student values(3,'student3',monospace!important; font-size:1em!important; min-height:inherit!important">;
:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,null);
查询结果: 我们可以看到查询到结果和我们前面插入的数据一样。 删除
|