zoukankan      html  css  js  c++  java
  • Sqlite3插入大量数据性能优化

    近期做的一个项目数据量很大。文本数据有30多M。这样就遇到一个问题。插入数据库时很慢。

    这里记录下,优化方法很easy。

    原文地址:http://blog.csdn.net/qqmcy/article/details/32173681


    在数据库的sql语句前加:"begin; "  结束后加“commit; ”。


             string strSql;
            strSql += "begin;
    ";
            for (unsigned int i = 0 ; i < v.Size(); ++i)
            {
                //unsigned int i = 0;
                
                const rapidjson::Value &val = v[i];
                
                auto month = new MothData();
                month->initWithDictionary(val);
               
                strSql += StringUtils::format("INSERT INTO Car_mqpfl(father_code, organ_code, organ_name, report_name, stat_month,mqpfl_dn,mqpfl_qn,mqpfl_sn,xh) VALUES ('%s',    '%s',       '%s',       '%s',        '%s',       '%s', '%s', '%s' , '%d');
    ",month->father_code.c_str(),month->organ_code.c_str(),month->organ_name.c_str(),month->report_name.c_str(),month->stat_month.c_str(),month->mqpfl_dn.c_str(),month->mqpfl_qn.c_str(),month->mqpfl_sn.c_str(),month->xh);
            }
             strSql+= "commit;
    ";
            SqlDB::insertData(strSql);

    void SqlDB::insertData(std::string sql)
    {
        result = sqlite3_exec(_db, sql.c_str(), nullptr, nullptr, &errMsg);
        
        
        if (result != SQLITE_OK) {
            log("insert error , code = %d, message = %s
    ",result,errMsg);
        }
    }
    


  • 相关阅读:
    uva 10900
    uva 11181
    Codeforces Round #256 (Div. 2) Multiplication Table
    UVALive 3977
    LA 4384
    Linear Regression
    Hadoop InputFormat浅析
    codeforces 432D Prefixes and Suffixes
    php学习小记2 类与对象
    php学习小记1
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6869034.html
Copyright © 2011-2022 走看看