Skip to content

Commit

Permalink
Add missing 0.82 code and use migration file name as fallback to migr…
Browse files Browse the repository at this point in the history
…ation name
  • Loading branch information
dantti committed Oct 23, 2023
1 parent d82bedb commit e9d4b2b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 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.81.0 LANGUAGES CXX)
project(libasql VERSION 0.83.0 LANGUAGES CXX)

include(GNUInstallDirs)

Expand Down
1 change: 1 addition & 0 deletions src/adriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AResultInvalid : public AResultPrivate
QString errorString() const { return {}; }

QByteArray query() const { return {}; }
QVariantList queryArgs() const { return {}; }

int size() const final { return 0; }
int fields() const final { return 0; }
Expand Down
5 changes: 5 additions & 0 deletions src/adriverpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@ QByteArray AResultPg::query() const
return m_query;
}

QVariantList AResultPg::queryArgs() const
{
return m_queryArgs;
}

int AResultPg::size() const
{
return PQntuples(m_result);
Expand Down
6 changes: 5 additions & 1 deletion src/adriverpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AResultPg final : public AResultPrivate
QString errorString() const override;

QByteArray query() const override;
QVariantList queryArgs() const override;

int size() const override;
int fields() const override;
Expand Down Expand Up @@ -59,6 +60,7 @@ class AResultPg final : public AResultPrivate
inline void processResult();

QByteArray m_query;
QVariantList m_queryArgs;
QString m_errorString;
PGresult *m_result = nullptr;
bool m_error = false;
Expand All @@ -82,7 +84,8 @@ class APGQuery
inline void done()
{
if (cb && (!checkReceiver || !receiver.isNull())) {
result->m_query = query;
result->m_query = query;
result->m_queryArgs = params;
AResult r(std::move(result));
cb(r);
}
Expand All @@ -93,6 +96,7 @@ class APGQuery
if (cb && (!checkReceiver || !receiver.isNull())) {
result = std::make_shared<AResultPg>(nullptr);
result->m_query = query;
result->m_queryArgs = params;
result->m_errorString = error;
result->m_error = true;
AResult r(std::move(result));
Expand Down
5 changes: 5 additions & 0 deletions src/aresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ QByteArray AResult::query() const
return d->query();
}

QVariantList AResult::queryArgs() const
{
return d->queryArgs();
}

int AResult::size() const
{
return d->size();
Expand Down
7 changes: 7 additions & 0 deletions src/aresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ASQL_EXPORT AResultPrivate
virtual QString errorString() const = 0;

virtual QByteArray query() const = 0;
virtual QVariantList queryArgs() const = 0;

virtual int size() const = 0;
virtual int fields() const = 0;
Expand Down Expand Up @@ -67,6 +68,12 @@ class ASQL_EXPORT AResult
*/
[[nodiscard]] QByteArray query() const;

/*!
* \brief returns the query arguments sent to the database
* \return
*/
[[nodiscard]] QVariantList queryArgs() const;

[[nodiscard]] int size() const;
[[nodiscard]] int fields() const;
[[nodiscard]] int numRowsAffected() const;
Expand Down
21 changes: 13 additions & 8 deletions src/asql_migration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QCoreApplication>
#include <QElapsedTimer>
#include <QFile>
#include <QFileInfo>
#include <QLoggingCategory>

using namespace ASql;
Expand Down Expand Up @@ -85,10 +86,14 @@ int main(int argc, char *argv[])
return 3;
}

const QString name = parser.value(nameOption);
QString name = parser.value(nameOption);
if (name.isEmpty()) {
std::cerr << qPrintable(QCoreApplication::translate("main", "Migration name not set.")) << std::endl;
return 4;
// Use the first filename as the migration name
name = QFileInfo(args.value(0)).baseName();
if (name.isEmpty()) {
std::cerr << qPrintable(QCoreApplication::translate("main", "Migration name not set.")) << std::endl;
return 4;
}
}

const QString conn = parser.value(connOption);
Expand Down Expand Up @@ -124,7 +129,7 @@ int main(int argc, char *argv[])

auto mig = new AMigrations;
mig->fromString(sql);
mig->connect(mig, &AMigrations::ready, [targetVersion, mig, confirm, dryRun, showSql](bool error, const QString &errorString) {
mig->connect(mig, &AMigrations::ready, [=](bool error, const QString &errorString) {
if (error) {
std::cerr << qPrintable(QCoreApplication::translate("main", "Failed to initialize migrations: %1.").arg(errorString)) << std::endl;
qApp->exit(7);
Expand All @@ -146,11 +151,11 @@ int main(int argc, char *argv[])

if (!confirm || newVersion < mig->active()) {
if (newVersion < mig->active()) {
std::cout << qPrintable(QCoreApplication::translate("main", "Do you wanto to migrate the database from %1 to %2? [yes/no] ")
.arg(QString::number(mig->active()), QString::number(newVersion)));
std::cout << qPrintable(QCoreApplication::translate("main", "Do you want to migrate '%1' from %2 to %3? [yes/no] ")
.arg(name).arg(QString::number(mig->active())).arg(QString::number(newVersion)));
} else {
std::cout << qPrintable(QCoreApplication::translate("main", "Do you wanto to migrate the database from %1 to %2? [y/n] ")
.arg(QString::number(mig->active()), QString::number(newVersion)));
std::cout << qPrintable(QCoreApplication::translate("main", "Do you wanto to migrate '%1' from %2 to %3? [y/n] ")
.arg(name).arg(QString::number(mig->active())).arg(QString::number(newVersion)));
}

std::string value;
Expand Down

0 comments on commit e9d4b2b

Please sign in to comment.