zoukankan      html  css  js  c++  java
  • cocos2d-x 3.0rc2中读取sqlite文件

    cocos2d-x 3.0rc2中读取sqlite文件的方式,在Android中直接读取软件内的会失败。须要复制到可写的路径下


    sqlite3* dbFile = NULL;
    
    std::string path;
    
        path = FileUtils::getInstance()->fullPathForFilename("db1.db");
        
    #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
        path  = FileUtils::getInstance()->getWritablePath();
        path  += "/db1.db";
        
        FILE* file = fopen(path.c_str(), "r");
        if (file == nullptr)
        {
            ssize_t size;
            const char* data = (char*) FileUtils::getInstance()->getFileData("db1.db", "rb", &size);
            file = fopen(path.c_str(), "wb");
            fwrite(data, size, 1, file);
            CC_SAFE_DELETE_ARRAY(data);
        }
        fclose(file);
        
    #endif
    
    CCLOG("数据库路径:%s", path.c_str());
    int resultOK = sqlite3_open(path.c_str(), &dbFile);
    
    if (resultOK != SQLITE_OK) {
        sqlite3_close(dbFile);
        CCLOG("数据库打开失败: %d", resultOK);
        return;
    }


  • 相关阅读:
    ES6(二)
    ES6
    bootstrap
    数组对象
    bootstrap
    html5(二)
    css3转换、动画、布局
    整理的一些兼容写法
    css渐变、背景、过渡、分页
    css3(一)
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5422419.html
Copyright © 2011-2022 走看看