• 如何使用模板生成 sqlite3 sql 创建语句?


    template<typename T,typename... Args>
    std::string createTable(T tableName,Args&&... args)
    {
        std::string sql = "CREATE TABLE IF NOT EXISTS";
        sql += " ";
        sql += tableName;
        sql += "(";
        for(const auto &arg:{args...}){
            sql += arg;
            sql += ",";
        }
        if(!sql.empty()){
            char& back = sql.back();
            back = ')';
        }
        sql += ";";
        return sql;
    }
    
        QString sql = QString::fromStdString(createTable(std::string("blog"),
                    "id TEXT PRIMARY KEY NOT NULL",
                    "title TEXT NOT NULL",
                    "content TEXT NOT NULL",
                    "push_time TEXT NOT NULL",
                    "tag TEXT"));
        qDebug() << sql;
    
    SELECT,INSERT,UPDATE,DELETE,ALTER TABLE.
    
    Sqlite3 data type   SQL type description                                        Recommended input(C++ or Qt data type)
    NULL                NULL value                                                  NULL
    INTEGER             Signed integer,stored in 8,16,24,32,48,                     typedef qint8/16/32/64
                        or 64-bits depending on the magnitude of the value
    REAL                64-bit floating point value                                 By default mapping to QString
    TEXT                Character string(UTF-8,UTF-16BE or UTF-16-LE)               Mapped to QString
    CLOB                Charater large string object                                Mapped to QString
    BLOB                The value is a BLOB of data,stored exactly as it was input  Mapped to QByteArray
    
  • 相关阅读:
    websocket
    关于Java中的常量优化机制
    关于使用键盘录入Scanner录入不对应类型的错误
    哈希表
    集合-----双列
    树形结构
    leetcode_14: 最长公共前缀
    leetcode_283_移动零
    leetcode_4_ 寻找两个正序数组的中位数
    leetcode_402_ 移掉K位数字
  • 原文地址:https://www.cnblogs.com/cheungxiongwei/p/9262322.html
Copyright © 2020-2023  润新知