派生自 development/c++

pansen
2019-02-28 080c7f97bdb3e6dde95ef2a34f7b5184fbe169bd
QiaoJiaSystem/LocalDBTool/SqliteToolkit.hpp
@@ -28,6 +28,7 @@
    std::string uuid;
    FaceFeature feature;
    std::string faceUrl;
    std::string feature_base64;
};
struct FaceInfo {
@@ -37,6 +38,8 @@
    std::string sex;
    std::string idCard;
    std::string phoneNum;
    std::string enable;
    std::string monLevel;
};
typedef std::vector<FaceInfo> FaceInfos;
typedef std::map<std::string, FaceInfo> FaceInfosCache;
@@ -49,6 +52,10 @@
    std::string startTime;
    std::string endTime;
    std::string createBy;
    std::string uploadFlag;
    std::string cmpThreshold;
    std::string enabled;
};
typedef std::vector<TableInfo> TableInfos;
typedef std::map<std::string, TableInfo> TableInfosCache;
@@ -61,6 +68,8 @@
    std::string uuid;
    std::string faceurl;
    FaceFeature faceFeature;
    std::string enable;
    std::string monLevel;
};
typedef std::map<std::string, FaceFeatureWithUrl> FeatureDBWithUrlCache;
@@ -81,14 +90,15 @@
    //
    std::string getFacesFromTableSql(std::string tableName) {
//        #todo get monLevel 联合查询
        std::string sql =
            "select uuid,feature,create_time,faceUrl,del_flag from " + tableName +
            "_fea where feature is not null ";
            "select uuid,feature,create_time,faceUrl,del_flag from '" + tableName +
            "_fea' where feature is not null ";
        return sql;
    }
    std::string getTableListSqlWithType(std::string type) {
        std::string sql = "select tableName,del_flag from " + g_tableName + " where del_flag = 0";
        std::string sql = "select tableName,del_flag from '" + g_tableName + "' where del_flag = 0";
        if (type.size() > 0) {
            sql.append(" and tableType = '" + type + "'");
        }
@@ -96,15 +106,16 @@
    }
    std::string getTableInfosSql(std::string tableName) {
        std::string sql = "select * from " + tableName;// + " where del_flag = 0";
        std::string sql = "select * from '" + tableName + "';";// + " where del_flag = 0";
        return sql;
    }
    std::string getTableInfosSql() {
        //uuid,tableName,tableDesc,tableType,bwType,startTime,endTime
        std::string sql = "select uuid,tableName,tableType,bwType,startTime,endTime from " + g_tableName +
                          " where del_flag = 0";
        std::string sql =
            "select uuid,tableName,tableType,bwType,startTime,endTime,uploadFlag,cmpThreshold,enabled,create_by from " +
            g_tableName + " where del_flag = 0";
        return sql;
    }
@@ -124,7 +135,7 @@
        str_fea.assign(feature.begin(), feature.end());
        std::stringstream sql;//= ;
        sql << "INSERT INTO " << tableName << " (";
        sql << "INSERT INTO '" << tableName << "' (";
        //std::string sqlTemp = sql;
        std::string sql2 = ") VALUES(\"";
        if (id >= 0) {
@@ -149,7 +160,7 @@
            //#todo errInfo
            return "tableName or fieldValues is NULL";
        }
        std::string sql = "DELETE from " + tableName + " where 1 = 1 ";
        std::string sql = "DELETE from '" + tableName + "' where 1 = 1 ";
        for (auto item : fieldValues) {
            if (item.first.size() != 0) {
                sql.append("and " + item.first + " = '" + item.second + "' ");
@@ -169,11 +180,11 @@
            //#todo errInfo
            return "tableName or fieldValues is NULL";
        }
        std::string sql = "INSERT INTO " + tableName + " (";
        std::string sql = "INSERT INTO '" + tableName + "' (";
        std::string sqlTemp = sql;
        std::string sql2 = ") VALUES('";
        for (auto item : fieldValues) {
            if (item.first.size() != 0) {
            if (item.first.size() != 0 && item.second.size() != 0) {
                sql.append(item.first + ",");
                sql2.append(item.second + "','");
            }
@@ -182,7 +193,7 @@
        sql = sql.substr(0, sql.length() - 1);
        //sql2 delete 2 ,'  add )
        sql2 = sql2.substr(0, sql2.length() - 2);
        sql2.append(" )");
        sql2.append(" );");
        sql.append(sql2);
        return sql;
    }
@@ -193,6 +204,9 @@
     * @return sql
     */
    std::string getInitDBSql() {
//        %%      ALTER TABLE sys_o_tables ADD COLUMN uploadFlag varchar(255) DEFAULT 0;
//        %%      ALTER TABLE sys_o_tables ADD COLUMN cmpThreshold varchar(255) DEFAULT 60;
//        %%      ALTER TABLE sys_o_tables ADD COLUMN enabled varchar(255) DEFAULT 1;
        std::string sql = "CREATE TABLE \"main\".\"sys_o_tables\" (";
        sql.append(" uuid        varchar(255) PRIMARY KEY, ");
//        sql.append(" ClusterName varchar(255) DEFAULT NULL,");//本地库不需要
@@ -205,7 +219,10 @@
        sql.append(" create_time BLOB default (datetime('now', 'localtime')),");
        sql.append(" update_time varchar(255) DEFAULT NULL,");
        sql.append(" create_by   varchar(255) DEFAULT NULL,");
        sql.append(" del_flag    varchar(255) DEFAULT 0");
        sql.append(" del_flag    varchar(255) DEFAULT 0,");
        sql.append(" uploadFlag  varchar(255) DEFAULT 0,");
        sql.append(" cmpThreshold    varchar(255) DEFAULT 60,");
        sql.append(" enabled     varchar(255) DEFAULT 1");
        sql.append(");");
        return sql;
    }
@@ -222,9 +239,9 @@
            return "tableName is NULL";
        }
        // 人员信息表
        std::string sql = "CREATE TABLE " + g_dbName + ".";
        std::string sql = "CREATE TABLE " + g_dbName + ".'";
        sql.append(tableName);
        sql.append(" (  uuid        varchar(255) PRIMARY KEY,");
        sql.append("' (  uuid        varchar(255) PRIMARY KEY,");
        sql.append("personName  varchar(255) DEFAULT NULL,");
        sql.append("age         varchar(255) DEFAULT NULL,");
        sql.append("sex         varchar(255) DEFAULT NULL,");
@@ -233,11 +250,13 @@
        sql.append("create_time BLOB         DEFAULT (datetime('now', 'localtime')),");
        sql.append("update_time DATETIME     DEFAULT NULL,");
        sql.append("create_by   varchar(255) DEFAULT NULL,");
        sql.append("del_flag    INTEGER      DEFAULT 0");
        sql.append("del_flag    INTEGER      DEFAULT 0,");
        sql.append("monitorLevel    varchar(255)      DEFAULT 0,");
        sql.append("    enabled     varchar(255) DEFAULT 1");
        sql.append(");");
        // 人脸特征表
        sql.append("CREATE TABLE " + g_dbName + ".");
        sql.append(tableName + "_fea");
        sql.append("CREATE TABLE " + g_dbName + ".'");
        sql.append(tableName + "_fea'");
        sql.append(" (  uuid        varchar(255) PRIMARY KEY,");
        sql.append("    feature     BLOB NOT NULL,");
        sql.append("    faceUrl     BLOB NOT NULL,");
@@ -265,13 +284,16 @@
            SQLERR("fieldValues size is error");
            return "";
        }
        std::string sql = "update ";
        sql.append(tableName + " set ");
        std::string sql = "update '";
        sql.append(tableName + "' set ");
        for (auto &item :fieldValues) {
            if (item.second.size() == 0) {
                continue;
            }
            sql.append(item.first + " =  '" + item.second + "',");
        }
        sql.append(" update_time ='" + AppUtil::getTimeSecString() + "'");
        sql.append(" where uuid ='" + uuid + "'");
        sql.append(" where uuid ='" + uuid + "';");
        return sql;
    }
@@ -282,8 +304,8 @@
            //#todo errInfo
            return "tableName is NULL";
        }
        std::string sql = "DROP TABLE " + g_dbName + "." + tableName + ";";
        sql.append("DROP TABLE " + g_dbName + "." + tableName + "_fea;");
        std::string sql = "DROP TABLE " + g_dbName + ".'" + tableName + "';";
        sql.append("DROP TABLE " + g_dbName + ".'" + tableName + "_fea';");
        return sql;
    }