mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-24 19:58:22 -05:00
used value<>() for QVariant everywhere
This commit is contained in:
@@ -134,7 +134,7 @@ namespace Orm
|
||||
|
||||
/*! Get the database connection name. */
|
||||
inline const QString getName() const override
|
||||
{ return getConfig("name").toString(); }
|
||||
{ return getConfig("name").value<QString>(); }
|
||||
/*! Get the name of the connected database. */
|
||||
inline const QString &getDatabaseName() const override
|
||||
{ return m_database; }
|
||||
|
||||
@@ -2809,7 +2809,6 @@ namespace Relations {
|
||||
throw InvalidFormatError(
|
||||
QStringLiteral("Could not parse the datetime '%1' using "
|
||||
"the given format '%2'.")
|
||||
// TODO next QVariant value<>() everywhere silverqx
|
||||
.arg(value.value<QString>(), format));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ ConnectionFactory::createConnector(const QVariantHash &config) const
|
||||
if (!config.contains("driver"))
|
||||
throw std::domain_error("A 'driver' configuration parameter must be specified.");
|
||||
|
||||
const auto driver = config["driver"].toString();
|
||||
const auto driver = config["driver"].value<QString>();
|
||||
|
||||
if (driver == "QMYSQL")
|
||||
return std::make_unique<MySqlConnector>();
|
||||
@@ -73,7 +73,7 @@ void ConnectionFactory::normalizeDriverName(QVariantHash &config) const
|
||||
else {
|
||||
auto &driver = config["driver"];
|
||||
|
||||
driver = driver.toString().toUpper();
|
||||
driver = driver.value<QString>().toUpper();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ std::unique_ptr<DatabaseConnection>
|
||||
ConnectionFactory::createSingleConnection(QVariantHash &config) const
|
||||
{
|
||||
return createConnection(
|
||||
config["driver"].toString(), createQSqlDatabaseResolver(config),
|
||||
config["database"].toString(), config["prefix"].toString(),
|
||||
config["driver"].value<QString>(), createQSqlDatabaseResolver(config),
|
||||
config["database"].value<QString>(), config["prefix"].value<QString>(),
|
||||
config);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ Connector::addQSqlDatabaseConnection(const QString &name, const QVariantHash &co
|
||||
{
|
||||
QSqlDatabase db;
|
||||
|
||||
// TODO now change all QVariant conversions to value<>() silverqx
|
||||
db = QSqlDatabase::addDatabase(config["driver"].value<QString>(), name);
|
||||
|
||||
db.setHostName(config["host"].value<QString>());
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Orm::Connectors
|
||||
ConnectionName
|
||||
MySqlConnector::connect(const QVariantHash &config) const
|
||||
{
|
||||
const auto name = config["name"].toString();
|
||||
const auto name = config["name"].value<QString>();
|
||||
|
||||
/* We need to grab the QSqlDatabse options that should be used while making
|
||||
the brand new connection instance. The QSqlDatabase options control various
|
||||
@@ -64,7 +64,7 @@ void MySqlConnector::parseConfigOptions(QVariantHash &options) const
|
||||
|
||||
if (options.contains(key) && options[key] == value)
|
||||
throw std::domain_error(
|
||||
"The connection option '" + value.toString().toStdString() +
|
||||
"The connection option '" + value.value<QString>().toStdString() +
|
||||
"' is not allowed in the TinyORM, TinyORM uses its own "
|
||||
"reconnector.");
|
||||
|
||||
@@ -129,7 +129,7 @@ void MySqlConnector::setModes(const QSqlDatabase &connection,
|
||||
|
||||
else if (config.contains("strict")) {
|
||||
|
||||
if (config["strict"].toBool()) {
|
||||
if (config["strict"].value<bool>()) {
|
||||
|
||||
const auto strictModeString = strictMode(connection, config);
|
||||
|
||||
@@ -171,8 +171,8 @@ QString MySqlConnector::getMySqlVersion(const QSqlDatabase &connection,
|
||||
QString version;
|
||||
|
||||
// Get the MySQL version from the configuration if it was defined
|
||||
if (config.contains("version") && !config["version"].toString().isEmpty())
|
||||
version = config["version"].toString();
|
||||
if (config.contains("version") && !config["version"].value<QString>().isEmpty())
|
||||
version = config["version"].value<QString>();
|
||||
|
||||
// Obtain the MySQL version from the database
|
||||
else {
|
||||
@@ -185,7 +185,7 @@ QString MySqlConnector::getMySqlVersion(const QSqlDatabase &connection,
|
||||
if (!query.first())
|
||||
return "";
|
||||
|
||||
version = query.value(0).toString();
|
||||
version = query.value(0).value<QString>();
|
||||
}
|
||||
|
||||
return version;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Orm::Connectors
|
||||
ConnectionName
|
||||
SQLiteConnector::connect(const QVariantHash &config) const
|
||||
{
|
||||
const auto name = config["name"].toString();
|
||||
const auto name = config["name"].value<QString>();
|
||||
|
||||
const auto options = getOptions(config);
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ QString parseExecutedQuery(const QSqlQuery &query)
|
||||
#else
|
||||
boundValue = (boundValueRaw.userType() == QMetaType::QString)
|
||||
#endif
|
||||
? QStringLiteral("\"%1\"").arg(boundValueRaw.toString())
|
||||
: boundValueRaw.toString();
|
||||
? QStringLiteral("\"%1\"").arg(boundValueRaw.value<QString>())
|
||||
: boundValueRaw.value<QString>();
|
||||
|
||||
executedQuery.replace(executedQuery.indexOf('?'), 1, boundValue);
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ QString Grammar::whereColumn(const WhereConditionItem &where) const
|
||||
second column. */
|
||||
return QStringLiteral("%1 %2 %3").arg(where.column,
|
||||
where.comparison,
|
||||
where.value.toString());
|
||||
where.value.value<QString>());
|
||||
}
|
||||
|
||||
QString Grammar::whereIn(const WhereConditionItem &where) const
|
||||
@@ -570,7 +570,7 @@ QString Grammar::parameter(const QVariant &value) const
|
||||
{
|
||||
// TODO rethink expressions, how to work with them and pass them to the query builder 🤔 silverqx
|
||||
return value.canConvert<Query::Expression>()
|
||||
? value.value<Query::Expression>().getValue().toString()
|
||||
? value.value<Query::Expression>().getValue().value<QString>()
|
||||
: QStringLiteral("?");
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ quint64 Builder::insertGetId(const QVariantMap &values)
|
||||
if (!ok)
|
||||
return 0;
|
||||
|
||||
return query.lastInsertId().toULongLong();
|
||||
return query.lastInsertId().value<quint64>();
|
||||
}
|
||||
|
||||
std::tuple<int, QSqlQuery>
|
||||
|
||||
@@ -63,8 +63,8 @@ ConfigurationOptionsParser::prepareConfigOptions(const QVariant &options) const
|
||||
return options.value<QVariantHash>();
|
||||
|
||||
// Convert to the QVariantHash
|
||||
const auto list = options.toString().split(QChar(';'),
|
||||
Qt::SkipEmptyParts);
|
||||
const auto list = options.value<QString>().split(QChar(';'),
|
||||
Qt::SkipEmptyParts);
|
||||
QVariantHash preparedOptions;
|
||||
|
||||
for (const auto &value : list) {
|
||||
@@ -112,7 +112,7 @@ QString ConfigurationOptionsParser::joinOptions(const QVariantHash &options) con
|
||||
const auto &value = itOption.value();
|
||||
|
||||
joined << QStringLiteral("%1=%2").arg(key,
|
||||
value.toString());
|
||||
value.value<QString>());
|
||||
++itOption;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ void tst_BaseModel::save_Insert() const
|
||||
|
||||
// Check attributes after save
|
||||
QVERIFY(torrent.getAttribute("id").isValid());
|
||||
QVERIFY(torrent.getAttribute("id").toULongLong() > 6);
|
||||
QVERIFY(torrent.getAttribute("id").value<quint64>() > 6);
|
||||
QCOMPARE(torrent.getAttribute("name"), QVariant("test50"));
|
||||
QCOMPARE(torrent.getAttribute("size"), QVariant(50));
|
||||
QCOMPARE(torrent.getAttribute("progress"), QVariant(50));
|
||||
@@ -160,7 +160,7 @@ void tst_BaseModel::save_Insert_WithDefaultValues() const
|
||||
|
||||
// Check attributes after save
|
||||
QVERIFY(torrent.getAttribute("id").isValid());
|
||||
QVERIFY(torrent.getAttribute("id").toULongLong() > 6);
|
||||
QVERIFY(torrent.getAttribute("id").value<quint64>() > 6);
|
||||
QCOMPARE(torrent.getAttribute("name"), QVariant("test51"));
|
||||
QCOMPARE(torrent.getAttribute("added_on"),
|
||||
QVariant(addedOn));
|
||||
@@ -176,7 +176,7 @@ void tst_BaseModel::save_Insert_WithDefaultValues() const
|
||||
|
||||
// And check attributes again
|
||||
QVERIFY(torrentToVerify->getAttribute("id").isValid());
|
||||
QVERIFY(torrentToVerify->getAttribute("id").toULongLong() > 6);
|
||||
QVERIFY(torrentToVerify->getAttribute("id").value<quint64>() > 6);
|
||||
QCOMPARE(torrentToVerify->getAttribute("name"), QVariant("test51"));
|
||||
QCOMPARE(torrentToVerify->getAttribute("size"), QVariant(0));
|
||||
QCOMPARE(torrentToVerify->getAttribute("progress"), QVariant(0));
|
||||
|
||||
Reference in New Issue
Block a user