Cocos2dx-sqlite3
发布时间:2020-12-14 16:43:04 所属栏目:百科 来源:网络整理
导读:本文出自 “老G的小屋” 博客,请务必保留此出处http://goldlion.blog.51cto.com/4127613/772518 一、安装与配置 SQLite是使用非常广泛的嵌入式数据库,它有着0配置,占用资源少等特点。从大型游戏《魔兽世界》到android上的很多游戏和软件(google提供了一
本文出自 “老G的小屋” 博客,请务必保留此出处http://goldlion.blog.51cto.com/4127613/772518
03 |
std::string sqlstr;//SQL指令 |
04
int
result;
//sqlite3_exec返回值
05
06
//打开一个数据库,如果该数据库不存在,则创建一个数据库文件
07
result = sqlite3_open(
"save.db"
,&pDB);
08
if
( result != SQLITE_OK )
09
CCLog(
"打开数据库失败,错误码:%d ,错误原因:%sn"
10
11
//创建表,设置ID为主键,且自动增加
12
result=sqlite3_exec( pDB,
( result != SQLITE_OK )
"create table MyTable_1( ID integer primary key autoincrement,name nvarchar(32) ) "
13
14
"创建表失败,错误码:%d ,错误原因:%sn"
16
//插入数据
15
17
sqlstr=
" insert into MyTable_1( name ) values ( '克塞' ) "
;
18
result = sqlite3_exec( pDB,sqlstr.c_str(),monospace!important; font-weight:normal!important; font-style:normal!important; font-size:10pt!important; min-height:auto!important; display:block!important; background:none!important">19
(result != SQLITE_OK )
20
"插入记录失败,错误码:%d ,错误原因:%sn"
22
23
" insert into MyTable_1( name ) values ( '葫芦娃' ) "
25
26
27
28
29
" insert into MyTable_1( name ) values ( '擎天柱' ) "
31
32
33
34
//关闭数据库
21
24
30
35
sqlite3_close(pDB);