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

相关文章:

  • 2021-06-28
  • 2023-03-07
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
猜你喜欢
  • 2021-11-21
  • 2021-10-01
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2022-12-23
相关资源
相似解决方案