对应源码位置:cocos2d-x-3.3\cocos\storage\local-storage\localStorage
localStorage 的接口
cocos2d-x
提供了简单的本地数据存储的功能,其主要是由对sqlite
的封装来实现。
//初始化 数据库
void CC_DLL localStorageInit( const std::string& fullpath = "");
//释放数据库
void CC_DLL localStorageFree();
//存一个key-value
void CC_DLL localStorageSetItem( const std::string& key, const std::string& value);
//根据key获取value
std::string CC_DLL localStorageGetItem( const std::string& key );
//删除 key对应的 项
void CC_DLL localStorageRemoveItem( const std::string& key );
localStorage 的接口的实现
//是否初始化的标志
static int _initialized = 0;
static sqlite3 *_db;
//查询
static sqlite3_stmt *_stmt_select;
//删除
static sqlite3_stmt *_stmt_remove;
//更新
static sqlite3_stmt *_stmt_update;
//static表明 别处不能用
static void localStorageCreateTable()
{
//创建 data表 两个属性 key为主键
const char *sql_createtable = "CREATE TABLE IF NOT EXISTS data(key TEXT PRIMARY KEY,value TEXT);";
sqlite3_stmt *stmt;
int ok=sqlite3_prepare_v2(_db,