正在做的项目需要sqlite数据库存储数据。小巧 、高效和易操作是sqlite的明显特点,无平台更是强大。开源且免费啊,亲。
好的,下面步入正题。看下xcode下的Cocos2d—X的数据存储如何使用。
看下sqlite表的数据返回,会带有字段的一行:
As an example of the result table format,suppose a query result is as follows:
- Name | Age
- -----------------------
- Alice | 43
- Bob | 28
- Cindy | 21
There are two column (M==2) and three rows (N==3). Thus the result table has 8 entries. Suppose the result table is stored in an array names azResult. Then azResult holds this content:
- azResult[0] = "Name";
- azResult[1] = "Age";
- azResult[2] = "Alice";
- azResult[3] = "43";
- azResult[4] = "Bob";
- azResult[5] = "28";
- azResult[6] = "Cindy";
- azResult[7] = "21";
在helloWorld的初始化直接写了。废话不说,直接代码贴出:
- stringpath=CCFileUtils::sharedFileUtils()->getWritablePath()+"MysqLite.db";
- remove(path.c_str());
- intflag=access(path.c_str(),0);
- if(flag!=0){
- userData.init();
- }
copy