From 7d50e8b58fbc26d1f35cb151af2446012d48a512 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Wed, 15 May 2024 18:00:03 -0300 Subject: [PATCH] Get rid of QStringLiteral --- CMakeLists.txt | 2 +- demos/async1/async1.cpp | 70 +++++++++++++++++------------------ demos/async1/dbscope.cpp | 4 +- demos/async1/deleter.cpp | 7 ++-- demos/async1/migrations.cpp | 37 +++++++++--------- demos/async1/pipeline.cpp | 3 +- demos/async1/prepared.cpp | 15 ++++---- demos/async1/transactions.cpp | 7 ++-- src/adriver.cpp | 3 +- src/adriverpg.cpp | 29 ++++++++------- src/amigrations.cpp | 23 ++++++------ src/aresult.cpp | 3 +- src/asql_migration.cpp | 24 ++++++------ 13 files changed, 116 insertions(+), 111 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb1aaf7..88c01e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: MIT cmake_minimum_required(VERSION 3.16) -project(libasql VERSION 0.85.0 LANGUAGES CXX) +project(libasql VERSION 0.86.0 LANGUAGES CXX) include(GNUInstallDirs) diff --git a/demos/async1/async1.cpp b/demos/async1/async1.cpp index 70c3345..6b4c4ef 100644 --- a/demos/async1/async1.cpp +++ b/demos/async1/async1.cpp @@ -22,14 +22,12 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; void recursiveLoop() { auto db = APool::database(u"memory_loop"); - db.exec(u"SELECT now()", - {QJsonObject{{QStringLiteral("foo"), true}}}, - nullptr, - [](AResult &result) { + db.exec(u"SELECT now()", {QJsonObject{{u"foo"_s, true}}}, nullptr, [](AResult &result) { if (result.error()) { qDebug() << "Error memory_loop" << result.errorString(); } else { @@ -43,7 +41,7 @@ int main(int argc, char *argv[]) QCoreApplication app(argc, argv); { - APool::create(APg::factory(QStringLiteral("postgres:///")), u"move_db_pool"); + APool::create(APg::factory(u"postgres:///")), u"move_db_pool"_s; APool::setMaxConnections(1, u"move_db_pool"); APool::database(nullptr, [](ADatabase db) { db.exec(u"SELECT 'I ♥ Cutelyst!' AS utf8", nullptr, [](AResult &result) { @@ -65,7 +63,7 @@ int main(int argc, char *argv[]) { // regresion test crash - where selfDriver gets released - APool::create(APg::factory(QStringLiteral("postgres:///")), u"delete_db_after_use"); + APool::create(APg::factory(u"postgres:///")), u"delete_db_after_use"_s; APool::setMaxIdleConnections(0, u"delete_db_after_use"); { @@ -81,7 +79,7 @@ int main(int argc, char *argv[]) { // memory loop - APool::create(APg::factory(QStringLiteral("postgres:///")), u"memory_loop"); + APool::create(APg::factory(u"postgres:///")), u"memory_loop"_s; APool::setMaxIdleConnections(5, u"memory_loop"); // APool::setMaxConnections(0, u"memory_loop"); @@ -92,7 +90,7 @@ int main(int argc, char *argv[]) } } - APool::create(APg::factory(QStringLiteral("postgres:///"))); + APool::create(APg::factory(u"postgres:///"_s)); APool::setMaxIdleConnections(10); { @@ -139,22 +137,21 @@ int main(int argc, char *argv[]) // For range for (const auto &row : result) { - qDebug() << "for loop row numbered" << row.value(0) - << row.value(QStringLiteral("number")); + qDebug() << "for loop row numbered" << row.value(0) << row.value(u"number"_s); series.append(row[0].value()); } // Iterators auto it = result.begin(); while (it != result.end()) { - qDebug() << "iterator" << it.at() << it.value(0) - << it[QStringLiteral("number")].value() << it[0].toInt(); + qDebug() << "iterator" << it.at() << it.value(0) << it[u"number"_s].value() + << it[0].toInt(); ++it; } }); db.setLastQuerySingleRowMode(); - db.exec(QStringLiteral("SELECT generate_series(1, 10) AS number"), + db.exec(u"SELECT generate_series(1, 10) AS number"_s, nullptr, [&series](AResult &result) mutable { qDebug() << "=====iterator" << result.errorString() << result.size() << "last" @@ -165,26 +162,26 @@ int main(int argc, char *argv[]) // For range for (const auto &row : result) { - qDebug() << "for loop row numbered" << row.value(0) - << row[QStringLiteral("number")].value() << row[0].toInt(); + qDebug() << "for loop row numbered" << row.value(0) << row[u"number"_s].value() + << row[0].toInt(); series.append(row[0].value()); } // Iterators auto it = result.begin(); while (it != result.end()) { - qDebug() << "iterator" << it.at() << it[0].value() - << it.value(QStringLiteral("number")) << it[0].toInt(); + qDebug() << "iterator" << it.at() << it[0].value() << it.value(u"number"_s) + << it[0].toInt(); ++it; } }); } - APool::database().exec(QStringLiteral("SELECT $1, $2, $3, $4, now()"), + APool::database().exec(u"SELECT $1, $2, $3, $4, now()"_s, { QJsonValue(true), QJsonValue(123.4567), - QJsonValue(QStringLiteral("fooo")), + QJsonValue(u"fooo"_s), QJsonValue(QJsonObject{}), }, nullptr, @@ -199,9 +196,8 @@ int main(int argc, char *argv[]) qDebug() << "JSON result" << result[0].toList(); }); - APool::database().exec(QStringLiteral("select jsonb_build_object('foo', now());"), - nullptr, - [](AResult &result) mutable { + APool::database().exec( + u"select jsonb_build_object('foo', now());"_s, nullptr, [](AResult &result) mutable { qDebug() << "=====iterator JSON" << result.errorString() << result.size() << "last" << result[0][0].toJsonValue(); if (result.error()) { @@ -214,7 +210,7 @@ int main(int argc, char *argv[]) auto cache = new ACache; cache->setDatabase(APool::database()); - cache->exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + cache->exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { qDebug() << "CACHED 1" << result.errorString() << result.size(); if (result.error()) { qDebug() << "Error" << result.errorString(); @@ -239,7 +235,7 @@ int main(int argc, char *argv[]) }); QTimer::singleShot(2000, cache, [=] { - cache->exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + cache->exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { qDebug() << "CACHED 2" << result.errorString() << result.size(); if (result.error()) { qDebug() << "Error" << result.errorString(); @@ -252,10 +248,10 @@ int main(int argc, char *argv[]) } }); - bool ret = cache->clear(QStringLiteral("SELECT now()")); + bool ret = cache->clear(u"SELECT now()"_s); qDebug() << "CACHED - CLEARED" << ret; - cache->exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + cache->exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { qDebug() << "CACHED 3" << result.errorString() << result.size(); if (result.error()) { qDebug() << "Error 3" << result.errorString(); @@ -271,7 +267,7 @@ int main(int argc, char *argv[]) // auto obj = new QObject; - // APool::database().exec(QStringLiteral("select 100, pg_sleep(1)"), [=] (AResult &result) { + // APool::database().exec(u"select 100, pg_sleep(1)"_s, [=] (AResult &result) { // qDebug() << "data" << result.size() << result.error() << result.errorString() << // "LAST" << result.lastResulSet(); delete obj; while (result.next()) { // for (int i = 0; i < result.fields(); ++i) { @@ -280,7 +276,7 @@ int main(int argc, char *argv[]) // } // }, obj); - // APool::database().exec(QStringLiteral("select 200, pg_sleep(5)"), [=] (AResult &result) { + // APool::database().exec(u"select 200, pg_sleep(5)"_s, [=] (AResult &result) { // qDebug() << "data" << result.size() << result.error() << result.errorString() << // "LAST" << result.lastResulSet(); delete obj; while (result.next()) { // for (int i = 0; i < result.fields(); ++i) { @@ -292,18 +288,18 @@ int main(int argc, char *argv[]) // db.open([=] (bool isOpen, const QString &error) { // qDebug() << "OPEN" << isOpen << error; - //// ADatabase(db).exec(QStringLiteral("select 1; select 2"), [=] (AResult &result) { + //// ADatabase(db).exec(u"select 1; select 2"_s, [=] (AResult &result) { //// qDebug() << "data" << result.size() << result.error() << result.errorString() << ///"LAST" << result.lastResulSet(); / while (result.next()) { / for ///(int i = 0; i < result.fields(); ++i) { / qDebug() << "data" << /// result.at() << i << result.value(i); / } / } / }); / - /// QJsonObject obj{ / {QStringLiteral("foo"), 234} / }; + /// QJsonObject obj{ / {u"foo"_s, 234} / }; // ADatabase db1 = APool::database(); // db1.begin(); // QUuid uuid = QUuid::createUuid(); // qDebug() << "uuid" << uuid.toString(); - // db1.exec(QStringLiteral("insert into temp4 values ($1, $2, $3, $4, $5, $6)"), - // {true, QStringLiteral("bla bla"), QVariant::Int, QDateTime::currentDateTime(), + // db1.exec(u"insert into temp4 values ($1, $2, $3, $4, $5, $6)"_s, + // {true, u"bla bla"_s, QVariant::Int, QDateTime::currentDateTime(), // 123456.78, uuid}, // [=] (AResult &result) { // qDebug() << "data" << result.size() << result.error() << result.errorString(); @@ -315,11 +311,11 @@ int main(int argc, char *argv[]) // }); // db1.commit(); - //// db1.subscribeToNotification(QStringLiteral("minha_notifyç_ã3"), [=] (const QString + //// db1.subscribeToNotification(u"minha_notifyç_ã3"_s, [=] (const QString ///&payload, bool self){ / qDebug() << "notificação" << payload << self; / }); // }); - // APool::database().exec(QStringLiteral("select * from aaa.users limit 3"), [=] (AResult + // APool::database().exec(u"select * from aaa.users limit 3"_s, [=] (AResult // &result) { // qDebug() << "data" << result.size() << result.error() << result.errorString() << // "LAST" << result.lastResulSet(); qDebug() << "data" << result.hash(); qDebug() << @@ -338,9 +334,9 @@ int main(int argc, char *argv[]) // qDebug() << "MIGRATED" << error << errorString; // }); // }); - // mig->load(APool::database(), QStringLiteral("foo")); + // mig->load(APool::database(), u"foo"_s); - // mig->fromString(QStringLiteral(R"V0G0N( + // mig->fromString(uR"V0G0N( // -- 1 up // create table messages (message text); // insert into messages values ('I ♥ Cutelyst!'); @@ -353,7 +349,7 @@ int main(int argc, char *argv[]) // drop table log; // -- 3 up // create tabsle log (message text); - // )V0G0N")); + // )V0G0N"_s); // qDebug() << "MIG" << mig.latest() << mig.active(); // qDebug() << "sqlFor" << mig.sqlFor(0, 2); diff --git a/demos/async1/dbscope.cpp b/demos/async1/dbscope.cpp index 7c1b1f8..5b00269 100644 --- a/demos/async1/dbscope.cpp +++ b/demos/async1/dbscope.cpp @@ -25,11 +25,11 @@ int main(int argc, char *argv[]) auto obj = new QObject; { - ADatabase db(QStringLiteral("postgres:///?target_session_attrs=read-write")); + ADatabase db(u"postgres:///?target_session_attrs=read-write"_s); db.open([db, obj](bool ok, const QString &status) { qDebug() << "OPEN value" << ok << status; - ADatabase(db).exec(QStringLiteral("SELECT now()"), [db](AResult &result) { + ADatabase(db).exec(u"SELECT now()"_s, [db](AResult &result) { if (result.error()) { qDebug() << "SELECT error" << result.errorString(); return; diff --git a/demos/async1/deleter.cpp b/demos/async1/deleter.cpp index 8ce92b9..dbd7e45 100644 --- a/demos/async1/deleter.cpp +++ b/demos/async1/deleter.cpp @@ -21,12 +21,13 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - APool::create(APg::factory(QStringLiteral("postgres:///?target_session_attrs=read-write"))); + APool::create(APg::factory(u"postgres:///?target_session_attrs=read-write"_s)); APool::setSetupCallback([](ADatabase db) { qDebug() << "setup db"; db.exec(u"SET TIME ZONE 'Europe/Rome';", nullptr, [](AResult &result) { @@ -43,10 +44,10 @@ int main(int argc, char *argv[]) auto obj = new QObject; { - ADatabase db(APg::factory(QStringLiteral("postgres:///?target_session_attrs=read-write"))); + ADatabase db(APg::factory(u"postgres:///?target_session_attrs=read-write"_s)); db.open(nullptr, [](bool ok, const QString &status) { qDebug() << "OPEN value" << ok << status; }); - db.exec(QStringLiteral("SELECT now()"), obj, [](AResult &result) { + db.exec(u"SELECT now()"_s, obj, [](AResult &result) { if (result.error()) { qDebug() << "SELECT error" << result.errorString(); return; diff --git a/demos/async1/migrations.cpp b/demos/async1/migrations.cpp index a35ff44..fa293be 100644 --- a/demos/async1/migrations.cpp +++ b/demos/async1/migrations.cpp @@ -22,13 +22,14 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - // APool::addDatabase(QStringLiteral("postgres://server.com,server2.com/mydb?target_session_attrs=read-write")); - APool::create(APg::factory(QStringLiteral("postgres:///"))); + // APool::addDatabase(u"postgres://server.com,server2.com/mydb?target_session_attrs=read-write"_s); + APool::create(APg::factory(u"postgres:///"_s)); auto mig = new AMigrations(); mig->connect(mig, &AMigrations::ready, [=](bool error, const QString &erroString) { @@ -37,22 +38,22 @@ int main(int argc, char *argv[]) qDebug() << "Migration Error" << error << errorString; }); }); - mig->load(APool::database(), QStringLiteral("foo")); - - mig->fromString(QStringLiteral(R"V0G0N( - -- 1 up - create table messages (message text); - insert into messages values ('I ♥ Cutelyst!'); - -- 1 down - drop table messages; - -- 2 up - create table log (message text); - insert into log values ('logged'); - -- 2 down - drop table log; - -- 3 up - create tabsle log (message text); - )V0G0N")); + mig->load(APool::database(), u"foo"_s); + + mig->fromString(uR"V0G0N( +-- 1 up +create table messages (message text); +insert into messages values ('I ♥ Cutelyst!'); +-- 1 down +drop table messages; +-- 2 up +create table log (message text); +insert into log values ('logged'); +-- 2 down +drop table log; +-- 3 up +create tabsle log (message text); +)V0G0N"_s); qDebug() << "MIG" << mig->latest() << mig->active(); // qDebug() << "sqlFor" << mig->sqlFor(0, 2); diff --git a/demos/async1/pipeline.cpp b/demos/async1/pipeline.cpp index bc985bb..7e4bbc8 100644 --- a/demos/async1/pipeline.cpp +++ b/demos/async1/pipeline.cpp @@ -22,12 +22,13 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - APool::create(APg::factory(QStringLiteral("postgres:///?target_session_attrs=read-write"))); + APool::create(APg::factory(u"postgres:///?target_session_attrs=read-write"_s)); APool::setMaxIdleConnections(10); { diff --git a/demos/async1/prepared.cpp b/demos/async1/prepared.cpp index 0e47031..5c4eeb2 100644 --- a/demos/async1/prepared.cpp +++ b/demos/async1/prepared.cpp @@ -23,13 +23,14 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - APool::create(APg::factory(QStringLiteral("postgres:///")), QStringLiteral("static")); - APool::create(APg::factory(QStringLiteral("postgres:///?target_session_attrs=read-write"))); + APool::create(APg::factory(u"postgres:///"_s), u"static"_s); + APool::create(APg::factory(u"postgres:///?target_session_attrs=read-write"_s)); APool::setMaxIdleConnections(2); APool::setMaxConnections(4); @@ -85,7 +86,7 @@ int main(int argc, char *argv[]) qDebug() << "db7 valid" << db7.isValid(); ATransaction t(db7); t.begin(); - db7.exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + db7.exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { if (result.error()) { qDebug() << "SELECT error db7" << result.errorString(); return; @@ -102,7 +103,7 @@ int main(int argc, char *argv[]) APool::database(nullptr, [=](ADatabase db) { qDebug() << "Got db" << db.isOpen() << db.state(); - db.exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + db.exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { if (result.error()) { qDebug() << "got db, SELECT error" << result.errorString(); return; @@ -118,7 +119,7 @@ int main(int argc, char *argv[]) } auto db = APool::database(); - static APreparedQuery query(QStringLiteral("SELECT now()")); + static APreparedQuery query(u"SELECT now()"_s); db.exec(query, nullptr, [=](AResult &result) { if (result.error()) { qDebug() << "SELECT 1 error" << result.errorString(); @@ -141,7 +142,7 @@ int main(int argc, char *argv[]) } }); - static APreparedQuery query2(QStringLiteral("SELECT now(), $1")); + static APreparedQuery query2(u"SELECT now(), $1"_s); db.exec(query2, {qint64(12345)}, nullptr, [=](AResult &result) { if (result.error()) { qDebug() << "SELECT error" << result.errorString(); @@ -166,7 +167,7 @@ int main(int argc, char *argv[]) } }); - auto dbStatic = APool::database(QStringLiteral("static")); + auto dbStatic = APool::database(u"static"_s); auto loopFn = [=](double sleep) { auto queryStatic = APreparedQueryLiteral(u"SELECT $1::text AS first, now() AS ts, pg_sleep($1::integer)"); diff --git a/demos/async1/transactions.cpp b/demos/async1/transactions.cpp index e7ce734..407ce0d 100644 --- a/demos/async1/transactions.cpp +++ b/demos/async1/transactions.cpp @@ -23,19 +23,20 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); - APool::create(APg::factory(QStringLiteral("postgres:///?target_session_attrs=read-write"))); + APool::create(APg::factory(u"postgres:///?target_session_attrs=read-write"_s)); APool::setMaxIdleConnections(10); { auto db = APool::database(); ATransaction t(db); t.begin(); - db.exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + db.exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { if (result.error()) { qDebug() << "SELECT error" << result.errorString(); return; @@ -56,7 +57,7 @@ int main(int argc, char *argv[]) return; } - t.database().exec(QStringLiteral("SELECT now()"), nullptr, [=](AResult &result) { + t.database().exec(u"SELECT now()"_s, nullptr, [=](AResult &result) { if (result.error()) { qDebug() << "SELECT error" << result.errorString(); return; diff --git a/src/adriver.cpp b/src/adriver.cpp index 6dbc4f8..73ca21f 100644 --- a/src/adriver.cpp +++ b/src/adriver.cpp @@ -11,6 +11,7 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; class AResultInvalid : public AResultPrivate { @@ -66,7 +67,7 @@ void ADriver::open(QObject *receiver, std::function { Q_UNUSED(receiver); if (cb) { - cb(false, QStringLiteral("INVALID DATABASE DRIVER")); + cb(false, u"INVALID DATABASE DRIVER"_s); } } diff --git a/src/adriverpg.cpp b/src/adriverpg.cpp index 807f6cf..1e9c195 100644 --- a/src/adriverpg.cpp +++ b/src/adriverpg.cpp @@ -52,6 +52,7 @@ Q_LOGGING_CATEGORY(ASQL_PG, "asql.pg", QtInfoMsg) #define VARHDRSZ 4 using namespace ASql; +using namespace Qt::StringLiterals; ADriverPg::ADriverPg(const QString &connInfo) : ADriver(connInfo) @@ -69,18 +70,18 @@ QString connectionStatus(ConnStatusType type) { switch (type) { case CONNECTION_OK: - return QStringLiteral("CONNECTION_OK"); + return u"CONNECTION_OK"_s; case CONNECTION_BAD: - return QStringLiteral("CONNECTION_BAD"); + return u"CONNECTION_BAD"_s; case CONNECTION_STARTED: - return QStringLiteral("CONNECTION_STARTED"); + return u"CONNECTION_STARTED"_s; case CONNECTION_AWAITING_RESPONSE: - return QStringLiteral("CONNECTION_AWAITING_RESPONSE"); + return u"CONNECTION_AWAITING_RESPONSE"_s; case CONNECTION_AUTH_OK: - return QStringLiteral("CONNECTION_AUTH_OK"); + return u"CONNECTION_AUTH_OK"_s; default: - return QStringLiteral("STATUS: ").arg(type); + return u"STATUS: "_s.arg(type); } } @@ -293,7 +294,7 @@ void ADriverPg::open(QObject *receiver, std::function &db, } m_subscribedNotifications.insert(name, cb); - exec(db, QString{QLatin1String("LISTEN ") + name}, {}, this, [this, name](AResult &result) { + exec(db, QString{u"LISTEN " + name}, {}, this, [this, name](AResult &result) { qDebug(ASQL_PG) << "subscribed" << !result.error() << result.errorString(); if (result.error()) { m_subscribedNotifications.remove(name); @@ -549,7 +550,7 @@ QStringList ADriverPg::subscribedToNotifications() const void ADriverPg::unsubscribeFromNotification(const std::shared_ptr &db, const QString &name) { if (m_subscribedNotifications.remove(name)) { - exec(db, QString{QStringLiteral("UNLISTEN ") + name}, {}, this, [=](AResult &result) { + exec(db, QString{u"UNLISTEN "_s + name}, {}, this, [=](AResult &result) { qDebug(ASQL_PG) << "unsubscribed" << !result.error() << result.errorString(); }); } @@ -1026,8 +1027,9 @@ QVariant AResultPg::value(int row, int column) const return QDateTime(); } else { QChar sign = dtval[dtval.size() - 3]; - if (sign == QLatin1Char('-') || sign == QLatin1Char('+')) - dtval += QLatin1String(":00"); + if (sign == u'-' || sign == u'+') { + dtval += u8":00"; + } return QDateTime::fromString(dtval, Qt::ISODate); } #else @@ -1156,8 +1158,9 @@ QDateTime AResultPg::toDateTime(int row, int column) const return {}; } else { QChar sign = dtval[dtval.size() - 3]; - if (sign == QLatin1Char('-') || sign == QLatin1Char('+')) - dtval += QLatin1String(":00"); + if (sign == u'-' || sign == u'+') { + dtval += u8":00"; + } return QDateTime::fromString(dtval, Qt::ISODate); } #else diff --git a/src/amigrations.cpp b/src/amigrations.cpp index ead9035..7207670 100644 --- a/src/amigrations.cpp +++ b/src/amigrations.cpp @@ -163,13 +163,13 @@ void AMigrations::fromString(const QString &text) qDebug(ASQL_MIG) << "UP" << version << line; auto &mig = up[version]; mig.version = version; - mig.query.append(line + QLatin1Char('\n')); + mig.query.append(line + u'\n'); mig.noTransaction = noTransaction; } else { qDebug(ASQL_MIG) << "DOWN" << version << line; auto &mig = down[version]; mig.version = version; - mig.query.append(line + QLatin1Char('\n')); + mig.query.append(line + u'\n'); mig.noTransaction = noTransaction; } } @@ -182,7 +182,7 @@ void AMigrations::fromString(const QString &text) QString AMigrations::sqlFor(int versionFrom, int versionTo) const { - return sqlListFor(versionFrom, versionTo).join(QLatin1Char('\n')); + return sqlListFor(versionFrom, versionTo).join(u'\n'); } QStringList AMigrations::sqlListFor(int versionFrom, int versionTo) const @@ -226,7 +226,7 @@ void AMigrations::migrate(int targetVersion, Q_D(AMigrations); if (targetVersion < 0) { if (cb) { - cb(true, QStringLiteral("Failed to migrate: invalid target version")); + cb(true, u"Failed to migrate: invalid target version"_s); } qWarning(ASQL_MIG) << "Failed to migrate: invalid target version" << targetVersion; return; @@ -255,16 +255,15 @@ void AMigrations::migrate(int targetVersion, if (active > latest()) { cb(true, - QStringLiteral("Current version %1 is greater than the latest version %2") - .arg(active) - .arg(latest())); + u"Current version %1 is greater than the latest version %2"_s.arg(active).arg( + latest())); return; } const auto migration = d->nextQuery(active, targetVersion); if (migration.query.isEmpty()) { if (cb) { - cb(false, QStringLiteral("Done.")); + cb(false, u"Done."_s); } return; } @@ -282,7 +281,7 @@ void AMigrations::migrate(int targetVersion, << "Cannot dry run a migration that requires no transaction: " << migration.version; if (cb) { - cb(true, QStringLiteral("Done.")); + cb(true, u"Done."_s); } return; } @@ -315,7 +314,7 @@ void AMigrations::migrate(int targetVersion, << "Migrated from" << active << "to" << migration.version; if (dryRun) { if (cb) { - cb(false, QStringLiteral("Done.")); + cb(false, u"Done."_s); } } else { migrate(targetVersion, cb, dryRun); @@ -339,12 +338,12 @@ AMigrationsPrivate::MigQuery AMigrationsPrivate::nextQuery(int versionFrom, int { AMigrationsPrivate::MigQuery ret; - static QString query = QStringLiteral(R"V0G0N( + static QString query = uR"V0G0N( INSERT INTO public.asql_migrations VALUES ('%1', %2) ON CONFLICT (name) DO UPDATE SET version=EXCLUDED.version RETURNING version; -)V0G0N"); +)V0G0N"_s; if (versionFrom < versionTo) { // up diff --git a/src/aresult.cpp b/src/aresult.cpp index 26ef6f0..4ebdfdf 100644 --- a/src/aresult.cpp +++ b/src/aresult.cpp @@ -12,6 +12,7 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; AResult::AResult() = default; @@ -34,7 +35,7 @@ bool AResult::error() const QString AResult::errorString() const { - return !d ? QStringLiteral("INVALID DRIVER") : d->errorString(); + return !d ? u"INVALID DRIVER"_s : d->errorString(); } QByteArray AResult::query() const diff --git a/src/asql_migration.cpp b/src/asql_migration.cpp index fa90852..2996b95 100644 --- a/src/asql_migration.cpp +++ b/src/asql_migration.cpp @@ -17,13 +17,14 @@ #include using namespace ASql; +using namespace Qt::StringLiterals; int main(int argc, char *argv[]) { - QCoreApplication::setOrganizationName(QStringLiteral("Cutelyst")); - QCoreApplication::setOrganizationDomain(QStringLiteral("org.cutelyst")); - QCoreApplication::setApplicationName(QStringLiteral("ASqlMigration")); - QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0")); + QCoreApplication::setOrganizationName(u"Cutelyst"_s); + QCoreApplication::setOrganizationDomain(u"org.cutelyst"_s); + QCoreApplication::setApplicationName(u"ASqlMigration"_s); + QCoreApplication::setApplicationVersion(u"0.2.0"_s); QCoreApplication app(argc, argv); @@ -32,36 +33,35 @@ int main(int argc, char *argv[]) QCoreApplication::translate("main", "ASql database migration tool.")); parser.addHelpOption(); parser.addVersionOption(); - parser.addPositionalArgument(QStringLiteral("source"), + parser.addPositionalArgument(u"source"_s, QCoreApplication::translate("main", "Migration file(s).")); QCommandLineOption confirmOption( - QStringLiteral("y"), - QCoreApplication::translate("main", "Automatically confirm migration")); + u"y"_s, QCoreApplication::translate("main", "Automatically confirm migration")); parser.addOption(confirmOption); QCommandLineOption dryRunOption( - {QStringLiteral("d"), QStringLiteral("dry-run")}, + {u"d"_s, u"dry-run"_s}, QCoreApplication::translate("main", "Do not actually commit changes to the database.")); parser.addOption(dryRunOption); - QCommandLineOption showSqlOption({QStringLiteral("s"), QStringLiteral("show-sql")}, + QCommandLineOption showSqlOption({u"s"_s, u"show-sql"_s}, QCoreApplication::translate("main", "Show migration SQL.")); parser.addOption(showSqlOption); QCommandLineOption connOption( - {QStringLiteral("c"), QStringLiteral("connection")}, + {u"c"_s, u"connection"_s}, QCoreApplication::translate("main", "Connection URL to the database."), QCoreApplication::translate("main", "url")); parser.addOption(connOption); - QCommandLineOption nameOption({QStringLiteral("n"), QStringLiteral("name")}, + QCommandLineOption nameOption({u"n"_s, u"name"_s}, QCoreApplication::translate("main", "Migration name."), QCoreApplication::translate("main", "name")); parser.addOption(nameOption); QCommandLineOption targetVersionOption( - QStringLiteral("target"), + u"target"_s, QCoreApplication::translate("main", "Migrate database to target ."), QCoreApplication::translate("main", "version")); parser.addOption(targetVersionOption);