示例#1
0
bool SQLite::insertIntoTable(const std::string &tableName, const cocos2d::ValueMap &keyValueMap)
{
    std::string sql = "INSERT INTO ";
    sql.append(tableName);
    std::string keyStr = "(";
    std::string valueStr = "(";
    
    int count = keyValueMap.size();
    
    int i = 0;
    for (auto iter = keyValueMap.cbegin(); iter != keyValueMap.cend(); ++iter)
    {
        std::string key = iter->first;
        std::string value = iter->second.asString();
        keyStr.append(key);
        valueStr.append("'");
        valueStr.append(value);
        valueStr.append("'");
        if (i != count-1) {
            keyStr.append(",");
            valueStr.append(",");
        }
        i++;
    }
    
    keyStr.append(")");
    valueStr.append(")");
    sql.append(keyStr);
    sql.append(" VALUES ");
    sql.append(valueStr);
    
    return this->executeUpdate(sql);
}
示例#2
0
// 以下为更新接口
bool SQLite::updateTable(const std::string &tableName, const cocos2d::ValueMap &keyValueMap, const cocos2d::ValueMap &conditionMap)
{
    std::string sql = "UPDATE ";
    sql.append(tableName);
    sql.append(" SET ");
    
    int count = keyValueMap.size();
    
    int i = 0;
    for (auto iter = keyValueMap.cbegin(); iter != keyValueMap.cend(); ++iter)
    {
        std::string key = iter->first;
        std::string value = iter->second.asString();
        
        sql.append(key);
        sql.append("='");
        sql.append(value);
        sql.append("'");
        if (i != count-1) {
            sql.append(",");
        }
        
        i++;
    }
    
    sql.append(this->convertConditionMap(conditionMap));
    
    return this->executeUpdate(sql);
}
示例#3
0
std::string SQLite::convertConditionMap(const cocos2d::ValueMap &conditionMap)
{
    std::string conditionStr;
    
    int count = conditionMap.size();
    
    if (count > 0) {
        
        conditionStr.append(" WHERE ");
        
        int i = 0;
        for (auto iter = conditionMap.cbegin(); iter != conditionMap.cend(); ++iter)
        {
            std::string columnName = iter->first;
            std::string columnValue = iter->second.asString();
            
            conditionStr.append(columnName);
            conditionStr.append("='");
            conditionStr.append(columnValue);
            conditionStr.append("'");
            
            if (i != count-1) {
                conditionStr.append(" AND ");
            }
            i++;
            
        }
        
    }
    return conditionStr;
}
示例#4
0
void Resource::addResourceReference(const cocos2d::ValueMap& files)
{
    if (files.size()<1)
        return;
    
    for (auto iter=files.begin(); iter!=files.end(); iter++) {
        auto fullpath=cocos2d::FileUtils::getInstance()->fullPathForFilename(iter->first);
        if (!fullpath.empty()) {
            auto find=_resourceReferences.find(fullpath);
            if (find!=_resourceReferences.end()) {
                find->second++;
            }
            else {
                _resourceReferences.insert(std::make_pair(fullpath, 1));
                _resourceNotLoadded.push_back(fullpath);
                _resourceTypes.insert(std::make_pair(fullpath, iter->second.asString()));
            }
        }
    }
}