Skip to content

Commit

Permalink
Get rid of QStringLiteral
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed May 15, 2024
1 parent e4c0a77 commit 7d50e8b
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 111 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
70 changes: 33 additions & 37 deletions demos/async1/async1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
#include <QUuid>

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 {
Expand All @@ -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) {
Expand All @@ -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");

{
Expand All @@ -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");

Expand All @@ -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);

{
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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()) {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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() <<
Expand All @@ -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!');
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions demos/async1/dbscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions demos/async1/deleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include <QUuid>

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) {
Expand All @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions demos/async1/migrations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
#include <QUuid>

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) {
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion demos/async1/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#include <QUuid>

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);

{
Expand Down
Loading

0 comments on commit 7d50e8b

Please sign in to comment.