mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-04-30 13:44:57 -05:00
tests added binary (blob) tests
- added a new tst_Blobs functional test case that inserts binary()/text() and mediumBinary()/mediumText() - updated schema builder unit tests, added all supported binary types - updated migrations - added Lorem ipsum paragraphs generator
This commit is contained in:
@@ -77,6 +77,11 @@ namespace Orm::Utils
|
||||
QChar lastCharacter);
|
||||
#endif
|
||||
|
||||
#ifdef TINYORM_TESTS_CODE
|
||||
/*! Lorem ipsum paragraphs generator (511 characters in paragraph + newline). */
|
||||
static QString loremIpsum512Paragraph(std::size_t count);
|
||||
#endif
|
||||
|
||||
private:
|
||||
/*! Determine whether all characters in the given tag are allowed. */
|
||||
static bool allTagCharsAllowed(const QString &string, QString::size_type posStart,
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
#include "orm/constants.hpp"
|
||||
|
||||
/*! Alias for the QStringLiteral(). */
|
||||
#define sl(str) QStringLiteral(str)
|
||||
|
||||
TINYORM_BEGIN_COMMON_NAMESPACE
|
||||
|
||||
using Orm::Constants::DASH;
|
||||
@@ -17,6 +20,7 @@ using Orm::Constants::EQ_C;
|
||||
using Orm::Constants::GT_C;
|
||||
using Orm::Constants::LT_C;
|
||||
using Orm::Constants::MINUS;
|
||||
using Orm::Constants::NEWLINE;
|
||||
using Orm::Constants::PLUS;
|
||||
using Orm::Constants::SPACE;
|
||||
using Orm::Constants::SQUOTE;
|
||||
@@ -418,6 +422,27 @@ QString String::wrapValue(const QString &string, const QChar firstCharacter,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TINYORM_TESTS_CODE
|
||||
QString String::loremIpsum512Paragraph(const std::size_t count)
|
||||
{
|
||||
Q_ASSERT(count != 0);
|
||||
|
||||
static const auto lorem511 =
|
||||
sl("Lorem ipsum dolor sit amet consectetuer cursus euismod eget Vestibulum sodales. "
|
||||
"Pellentesque neque Phasellus id id Pellentesque Integer mauris nibh nibh. "
|
||||
"Non Morbi pharetra cursus in interdum fringilla Donec quam nunc vitae. "
|
||||
"Nulla purus eget et Quisque congue Maecenas Phasellus at Curabitur. "
|
||||
"Tellus vel Sed ac nulla dis Vestibulum tellus turpis. "
|
||||
"Convallis elit Vestibulum turpis metus Integer nunc quis Sed Integer. "
|
||||
"Semper a rutrum at In nibh cursus Nam libero tempus. "
|
||||
"Risus nibh semper quis volutpat facilisi.");
|
||||
|
||||
return QStringList(count, lorem511).join(NEWLINE);
|
||||
// Insert the s character before the last . to make it 512, 1024, ...
|
||||
// .insert(-1, QLatin1Char('s'));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* private */
|
||||
|
||||
bool String::allTagCharsAllowed(const QString &string, const QString::size_type posStart,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
project(blobs
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(blobs
|
||||
tst_blobs.cpp
|
||||
)
|
||||
|
||||
add_test(NAME blobs COMMAND blobs)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(blobs)
|
||||
@@ -0,0 +1,4 @@
|
||||
include($$TINYORM_SOURCE_TREE/tests/qmake/common.pri)
|
||||
include($$TINYORM_SOURCE_TREE/tests/qmake/TinyUtils.pri)
|
||||
|
||||
SOURCES = tst_blobs.cpp
|
||||
@@ -0,0 +1,467 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest>
|
||||
|
||||
#include "orm/db.hpp"
|
||||
#include "orm/utils/query.hpp"
|
||||
#include "orm/utils/string.hpp"
|
||||
#include "orm/utils/type.hpp"
|
||||
|
||||
#include "databases.hpp"
|
||||
|
||||
/*! Alias for the QStringLiteral(). */
|
||||
#define sl(str) QStringLiteral(str)
|
||||
|
||||
using Orm::Constants::QMYSQL;
|
||||
using Orm::Constants::text_;
|
||||
|
||||
using Orm::DB;
|
||||
using Orm::Query::Builder;
|
||||
|
||||
using QueryBuilder = Orm::Query::Builder;
|
||||
using QueryUtils = Orm::Utils::Query;
|
||||
using StringUtils = Orm::Utils::String;
|
||||
using TypeUtils = Orm::Utils::Type;
|
||||
|
||||
using TestUtils::Databases;
|
||||
|
||||
class tst_Blobs : public QObject // clazy:exclude=ctor-missing-parent-argument
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase_data() const;
|
||||
void cleanup() const;
|
||||
|
||||
void text() const;
|
||||
void mediumText() const;
|
||||
|
||||
void binary() const;
|
||||
void mediumBinary() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Create QueryBuilder instance for the given connection. */
|
||||
[[nodiscard]] static std::shared_ptr<QueryBuilder>
|
||||
createQuery(const QString &connection);
|
||||
|
||||
/* MySQL max_allowed_packet */
|
||||
/*! Check and set the max_allowed_packet GLOBAL variable to the given value. */
|
||||
void prepareMaxAllowedPacketForMySql(std::size_t minimumValue,
|
||||
const QString &connection) const;
|
||||
/*! Restore the max_allowed_packet GLOBAL variable to the initial value. */
|
||||
void restoreMaxAllowedPacketForMySql(const QString &connection) const;
|
||||
/*! Obtain the max_allowed_packet SESSION variable value in bytes. */
|
||||
static std::size_t getMaxAllowedPacketForMySql(const QString &connection);
|
||||
|
||||
/*! Lorem ipsum paragraph size (number of characters including a newline). */
|
||||
constexpr static auto m_paragraphSize = 512;
|
||||
/*! An initial max_allowed_packet value cache (to be able to restore it). */
|
||||
mutable std::optional<std::size_t> m_initialMaxAllowedPacket = std::nullopt;
|
||||
};
|
||||
|
||||
/*! QString constant for the "types" table. */
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TypesTable, ("types"))
|
||||
/*! QString constant for the "medium_text" column name. */
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, medium_text, ("medium_text"))
|
||||
/*! QString constant for the "binary" column name. */
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, medium_binary, ("medium_binary"))
|
||||
|
||||
/* private slots */
|
||||
|
||||
// NOLINTBEGIN(readability-convert-member-functions-to-static)
|
||||
void tst_Blobs::initTestCase_data() const
|
||||
{
|
||||
const auto connections = Databases::createConnections();
|
||||
|
||||
if (connections.isEmpty())
|
||||
QSKIP(TestUtils::AutoTestSkippedAny.arg(TypeUtils::classPureBasename(*this))
|
||||
.toUtf8().constData(), );
|
||||
|
||||
QTest::addColumn<QString>("connection");
|
||||
|
||||
// Run all tests for all supported database connections
|
||||
for (const auto &connection : connections)
|
||||
QTest::newRow(connection.toUtf8().constData()) << connection;
|
||||
}
|
||||
|
||||
void tst_Blobs::cleanup() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
restoreMaxAllowedPacketForMySql(connection);
|
||||
}
|
||||
|
||||
void tst_Blobs::text() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// Prepare the max_allowed_packet MySQL variable (requires 16MB)
|
||||
prepareMaxAllowedPacketForMySql(16'777'216, connection);
|
||||
|
||||
constexpr static auto paragraphsCount = 128;
|
||||
/* 65'535 bytes (65kB without 1 byte).
|
||||
It's the max. size of the MySQL TEXT column type. */
|
||||
constexpr auto expectedLoremIpsumSize = m_paragraphSize * paragraphsCount - 1;
|
||||
|
||||
static const auto loremIpsum = StringUtils::loremIpsum512Paragraph(paragraphsCount);
|
||||
/* 128 paragraphs each has 511 characters + a newline;
|
||||
The last paragraph has 511 characters without a newline. */
|
||||
QCOMPARE(loremIpsum.size(), expectedLoremIpsumSize);
|
||||
|
||||
QVariant lastId;
|
||||
quint64 lastIdInt = 0;
|
||||
|
||||
// Insert to the TEXT column
|
||||
{
|
||||
auto query = createQuery(connection)
|
||||
->from(*TypesTable).insert({text_}, {{loremIpsum}});
|
||||
QVERIFY(query->isActive());
|
||||
QVERIFY(!query->isSelect());
|
||||
QVERIFY(!query->isValid());
|
||||
|
||||
lastId = query->lastInsertId();
|
||||
lastIdInt = lastId.value<quint64>();
|
||||
|
||||
QVERIFY(lastId.isValid() && !lastId.isNull());
|
||||
QVERIFY(lastIdInt > 3);
|
||||
}
|
||||
|
||||
// Verify an insert
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 1);
|
||||
|
||||
QVERIFY(query.first());
|
||||
QVERIFY(query.isValid());
|
||||
|
||||
QCOMPARE(query.value(text_), QVariant(loremIpsum));
|
||||
}
|
||||
|
||||
// Restore
|
||||
{
|
||||
auto &&[affected, query] = createQuery(connection)
|
||||
->from(*TypesTable).deleteRow(lastIdInt);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(!query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(affected, 1);
|
||||
}
|
||||
|
||||
// Verify Restore
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Blobs::mediumText() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// Prepare the max_allowed_packet MySQL variable (requires 64MB)
|
||||
prepareMaxAllowedPacketForMySql(67'108'864, connection);
|
||||
|
||||
constexpr static auto paragraphsCount = 32'768;
|
||||
/* 16'777'215 bytes (16MB without 1 byte).
|
||||
It's the max. size of the MySQL MEDIUMTEXT column type. */
|
||||
constexpr auto expectedLoremIpsumSize = m_paragraphSize * paragraphsCount - 1;
|
||||
|
||||
static const auto loremIpsum = StringUtils::loremIpsum512Paragraph(paragraphsCount);
|
||||
/* 32768 paragraphs each has 511 characters + a newline;
|
||||
The last paragraph has 511 characters without a newline. */
|
||||
QCOMPARE(loremIpsum.size(), expectedLoremIpsumSize);
|
||||
|
||||
QVariant lastId;
|
||||
quint64 lastIdInt = 0;
|
||||
|
||||
// Insert to the TEXT column
|
||||
{
|
||||
auto query = createQuery(connection)
|
||||
->from(*TypesTable).insert({*medium_text}, {{loremIpsum}});
|
||||
QVERIFY(query->isActive());
|
||||
QVERIFY(!query->isSelect());
|
||||
QVERIFY(!query->isValid());
|
||||
|
||||
lastId = query->lastInsertId();
|
||||
lastIdInt = lastId.value<quint64>();
|
||||
|
||||
QVERIFY(lastId.isValid() && !lastId.isNull());
|
||||
QVERIFY(lastIdInt > 3);
|
||||
}
|
||||
|
||||
// Verify an insert
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 1);
|
||||
|
||||
QVERIFY(query.first());
|
||||
QVERIFY(query.isValid());
|
||||
|
||||
QCOMPARE(query.value(*medium_text), QVariant(loremIpsum));
|
||||
}
|
||||
|
||||
// Restore the types table
|
||||
{
|
||||
auto &&[affected, query] = createQuery(connection)
|
||||
->from(*TypesTable).deleteRow(lastIdInt);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(!query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(affected, 1);
|
||||
}
|
||||
|
||||
// Verify Restore the types table
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Blobs::binary() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// Prepare the max_allowed_packet MySQL variable (requires 16MB)
|
||||
prepareMaxAllowedPacketForMySql(16'777'216, connection);
|
||||
|
||||
constexpr static auto paragraphsCount = 128;
|
||||
/* 65'535 bytes (65kB without 1 byte).
|
||||
It's the max. size of the MySQL BLOB column type. */
|
||||
constexpr auto expectedLoremIpsumSize = m_paragraphSize * paragraphsCount - 1;
|
||||
|
||||
static const auto loremIpsumString = StringUtils::loremIpsum512Paragraph(
|
||||
paragraphsCount);
|
||||
static const auto loremIpsum = QByteArray(loremIpsumString.toUtf8().constData());
|
||||
|
||||
/* 128 paragraphs each has 511 characters + a newline;
|
||||
The last paragraph has 511 characters without a newline. */
|
||||
QCOMPARE(loremIpsum.size(), expectedLoremIpsumSize);
|
||||
|
||||
QVariant lastId;
|
||||
quint64 lastIdInt = 0;
|
||||
|
||||
// Insert to the BLOB column
|
||||
{
|
||||
auto query = createQuery(connection)
|
||||
->from(*TypesTable).insert({*medium_binary}, {{loremIpsum}});
|
||||
QVERIFY(query->isActive());
|
||||
QVERIFY(!query->isSelect());
|
||||
QVERIFY(!query->isValid());
|
||||
|
||||
lastId = query->lastInsertId();
|
||||
lastIdInt = lastId.value<quint64>();
|
||||
|
||||
QVERIFY(lastId.isValid() && !lastId.isNull());
|
||||
QVERIFY(lastIdInt > 3);
|
||||
}
|
||||
|
||||
// Verify an insert
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 1);
|
||||
|
||||
QVERIFY(query.first());
|
||||
QVERIFY(query.isValid());
|
||||
|
||||
auto val = query.value(*medium_binary);
|
||||
QCOMPARE(val, QVariant(loremIpsum));
|
||||
}
|
||||
|
||||
// Restore the types table
|
||||
{
|
||||
auto &&[affected, query] = createQuery(connection)
|
||||
->from(*TypesTable).deleteRow(lastIdInt);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(!query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(affected, 1);
|
||||
}
|
||||
|
||||
// Verify Restore the types table
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Blobs::mediumBinary() const
|
||||
{
|
||||
QFETCH_GLOBAL(QString, connection);
|
||||
|
||||
// Prepare the max_allowed_packet MySQL variable (requires 64MB)
|
||||
prepareMaxAllowedPacketForMySql(67'108'864, connection);
|
||||
|
||||
constexpr static auto paragraphsCount = 32'768;
|
||||
/* 16'777'215 bytes (16MB without 1 byte).
|
||||
It's the max. size of the MySQL MEDIUMBLOB column type. */
|
||||
constexpr auto expectedLoremIpsumSize = m_paragraphSize * paragraphsCount - 1;
|
||||
|
||||
static const auto loremIpsumString = StringUtils::loremIpsum512Paragraph(
|
||||
paragraphsCount);
|
||||
static const auto loremIpsum = QByteArray(loremIpsumString.toUtf8().constData());
|
||||
|
||||
/* 32768 paragraphs each has 511 characters + a newline;
|
||||
The last paragraph has 511 characters without a newline. */
|
||||
QCOMPARE(loremIpsum.size(), expectedLoremIpsumSize);
|
||||
|
||||
QVariant lastId;
|
||||
quint64 lastIdInt = 0;
|
||||
|
||||
// Insert to the BLOB column
|
||||
{
|
||||
auto query = createQuery(connection)
|
||||
->from(*TypesTable).insert({*medium_binary}, {{loremIpsum}});
|
||||
QVERIFY(query->isActive());
|
||||
QVERIFY(!query->isSelect());
|
||||
QVERIFY(!query->isValid());
|
||||
|
||||
lastId = query->lastInsertId();
|
||||
lastIdInt = lastId.value<quint64>();
|
||||
|
||||
QVERIFY(lastId.isValid() && !lastId.isNull());
|
||||
QVERIFY(lastIdInt > 3);
|
||||
}
|
||||
|
||||
// Verify an insert
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 1);
|
||||
|
||||
QVERIFY(query.first());
|
||||
QVERIFY(query.isValid());
|
||||
|
||||
auto val = query.value(*medium_binary);
|
||||
QCOMPARE(val, QVariant(loremIpsum));
|
||||
}
|
||||
|
||||
// Restore the types table
|
||||
{
|
||||
auto &&[affected, query] = createQuery(connection)
|
||||
->from(*TypesTable).deleteRow(lastIdInt);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(!query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(affected, 1);
|
||||
}
|
||||
|
||||
// Verify Restore the types table
|
||||
{
|
||||
auto query = createQuery(connection)->from(*TypesTable).find(lastId);
|
||||
QVERIFY(query.isActive());
|
||||
QVERIFY(query.isSelect());
|
||||
QVERIFY(!query.isValid());
|
||||
QCOMPARE(QueryUtils::queryResultSize(query), 0);
|
||||
}
|
||||
}
|
||||
// NOLINTEND(readability-convert-member-functions-to-static)
|
||||
|
||||
/* private */
|
||||
|
||||
std::shared_ptr<QueryBuilder>
|
||||
tst_Blobs::createQuery(const QString &connection)
|
||||
{
|
||||
return DB::query(connection);
|
||||
}
|
||||
|
||||
/* MySQL max_allowed_packet */
|
||||
|
||||
void tst_Blobs::prepareMaxAllowedPacketForMySql(const std::size_t minimumValue,
|
||||
const QString &connection) const
|
||||
{
|
||||
// Nothing to do, this is only needed for MySQL/MariaDB databases
|
||||
if (DB::driverName(connection) != QMYSQL)
|
||||
return;
|
||||
|
||||
// Obtain the max_allowed_packet SESSION variable value in bytes
|
||||
const auto initialMaxAllowedPacket = getMaxAllowedPacketForMySql(connection);
|
||||
|
||||
// Nothing to do, the max_allowed_packet value is OK
|
||||
if (initialMaxAllowedPacket >= minimumValue)
|
||||
return;
|
||||
|
||||
// Set the max_allowed_packet GLOBAL variable
|
||||
DB::unprepared(sl("set global `max_allowed_packet` = %1").arg(minimumValue),
|
||||
connection);
|
||||
|
||||
// Re-connect is needed so a newly set max_allowed_packet can be applied
|
||||
DB::disconnect(connection);
|
||||
|
||||
// Verify the max_allowed_packet SESSION variable value
|
||||
if (getMaxAllowedPacketForMySql(connection) == minimumValue) {
|
||||
// Cache the current/initial value
|
||||
m_initialMaxAllowedPacket = initialMaxAllowedPacket;
|
||||
return;
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
sl("Setting the max_allowed_packet to '%1' value for '%2' connection "
|
||||
"failed in %3().")
|
||||
.arg(minimumValue)
|
||||
.arg(connection, __tiny_func__).toUtf8().constData());
|
||||
}
|
||||
|
||||
void tst_Blobs::restoreMaxAllowedPacketForMySql(const QString &connection) const
|
||||
{
|
||||
/* Nothing to do, this is only needed for MySQL/MariaDB databases or
|
||||
the max_allowed_packet GLOBAL variable wasn't set/changed. */
|
||||
if (DB::driverName(connection) != QMYSQL || !m_initialMaxAllowedPacket)
|
||||
return;
|
||||
|
||||
// Restore the max_allowed_packet GLOBAL variable to the initial value
|
||||
auto query = DB::unprepared(sl("set global `max_allowed_packet` = %1")
|
||||
.arg(*m_initialMaxAllowedPacket),
|
||||
connection);
|
||||
|
||||
// Re-connect is needed so a newly set max_allowed_packet can be applied
|
||||
DB::disconnect(connection);
|
||||
|
||||
// Verify the max_allowed_packet SESSION variable value
|
||||
if (getMaxAllowedPacketForMySql(connection) == m_initialMaxAllowedPacket)
|
||||
return m_initialMaxAllowedPacket.reset(); // clazy:exclude=returning-void-expression
|
||||
|
||||
throw std::runtime_error(
|
||||
sl("Restoring the max_allowed_packet to '%1' value for '%2' connection "
|
||||
"failed in %3().")
|
||||
.arg(*m_initialMaxAllowedPacket)
|
||||
.arg(connection, __tiny_func__).toUtf8().constData());
|
||||
}
|
||||
|
||||
std::size_t tst_Blobs::getMaxAllowedPacketForMySql(const QString &connection)
|
||||
{
|
||||
// Obtain the max_allowed_packet SESSION variable value in bytes
|
||||
auto query = DB::unprepared(sl("select @@session.`max_allowed_packet` as `value`"),
|
||||
connection);
|
||||
|
||||
if (query.first())
|
||||
return query.value(sl("value")).value<std::size_t>();
|
||||
|
||||
throw std::runtime_error(
|
||||
sl("Obtaining the @@session.max_allowed_packet variable "
|
||||
"for '%1' connection failed in %2().")
|
||||
.arg(connection, __tiny_func__).toUtf8().constData());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_Blobs)
|
||||
|
||||
#include "tst_blobs.moc"
|
||||
@@ -1,6 +1,7 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = \
|
||||
blobs \
|
||||
mysql_qdatetime \
|
||||
postgresql_qdatetime \
|
||||
querybuilder \
|
||||
|
||||
@@ -339,6 +339,11 @@ void tst_MySql_SchemaBuilder::createTable() const
|
||||
table.uuid();
|
||||
table.ipAddress();
|
||||
table.macAddress();
|
||||
|
||||
table.tinyBinary("tiny_binary");
|
||||
table.binary("binary");
|
||||
table.mediumBinary("medium_binary");
|
||||
table.longBinary("long_binary");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -370,7 +375,11 @@ void tst_MySql_SchemaBuilder::createTable() const
|
||||
"`unsignedBigInteger` bigint unsigned not null, "
|
||||
"`uuid` char(36) not null, "
|
||||
"`ip_address` varchar(45) not null, "
|
||||
"`mac_address` varchar(17) not null) "
|
||||
"`mac_address` varchar(17) not null, "
|
||||
"`tiny_binary` tinyblob not null, "
|
||||
"`binary` blob not null, "
|
||||
"`medium_binary` mediumblob not null, "
|
||||
"`long_binary` longblob not null) "
|
||||
"default character set %1 collate '%2' "
|
||||
"engine = InnoDB")
|
||||
.arg(m_charset, m_collation));
|
||||
@@ -644,6 +653,11 @@ void tst_MySql_SchemaBuilder::modifyTable() const
|
||||
table.smallInteger("smallInteger");
|
||||
table.mediumInteger("mediumInteger");
|
||||
|
||||
table.tinyBinary("tiny_binary");
|
||||
table.binary("binary");
|
||||
table.mediumBinary("medium_binary");
|
||||
table.longBinary("long_binary");
|
||||
|
||||
table.dropColumn("long_text");
|
||||
table.dropColumns({"medium_text", "text"});
|
||||
table.dropColumns("smallInteger", "mediumInteger");
|
||||
@@ -669,7 +683,11 @@ void tst_MySql_SchemaBuilder::modifyTable() const
|
||||
"add column `integer` int null, "
|
||||
"add column `tinyInteger` tinyint not null, "
|
||||
"add column `smallInteger` smallint not null, "
|
||||
"add column `mediumInteger` mediumint not null");
|
||||
"add column `mediumInteger` mediumint not null, "
|
||||
"add column `tiny_binary` tinyblob not null, "
|
||||
"add column `binary` blob not null, "
|
||||
"add column `medium_binary` mediumblob not null, "
|
||||
"add column `long_binary` longblob not null");
|
||||
QVERIFY(log0.boundValues.isEmpty());
|
||||
|
||||
const auto &log1 = log.at(1);
|
||||
|
||||
+20
-2
@@ -302,6 +302,11 @@ void tst_PostgreSQL_SchemaBuilder::createTable() const
|
||||
table.uuid();
|
||||
table.ipAddress();
|
||||
table.macAddress();
|
||||
|
||||
table.tinyBinary("tiny_binary");
|
||||
table.binary("binary");
|
||||
table.mediumBinary("medium_binary");
|
||||
table.longBinary("long_binary");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -332,7 +337,11 @@ void tst_PostgreSQL_SchemaBuilder::createTable() const
|
||||
"\"unsignedBigInteger\" bigint not null, "
|
||||
"\"uuid\" uuid not null, "
|
||||
"\"ip_address\" inet not null, "
|
||||
"\"mac_address\" macaddr not null)");
|
||||
"\"mac_address\" macaddr not null, "
|
||||
"\"tiny_binary\" bytea not null, "
|
||||
"\"binary\" bytea not null, "
|
||||
"\"medium_binary\" bytea not null, "
|
||||
"\"long_binary\" bytea not null)");
|
||||
QVERIFY(firstLog.boundValues.isEmpty());
|
||||
}
|
||||
|
||||
@@ -568,6 +577,11 @@ void tst_PostgreSQL_SchemaBuilder::modifyTable() const
|
||||
table.smallInteger("smallInteger");
|
||||
table.mediumInteger("mediumInteger");
|
||||
|
||||
table.tinyBinary("tiny_binary");
|
||||
table.binary("binary");
|
||||
table.mediumBinary("medium_binary");
|
||||
table.longBinary("long_binary");
|
||||
|
||||
table.dropColumn("long_text");
|
||||
table.dropColumns({"medium_text", "text"});
|
||||
table.dropColumns("smallInteger", "mediumInteger");
|
||||
@@ -593,7 +607,11 @@ void tst_PostgreSQL_SchemaBuilder::modifyTable() const
|
||||
"add column \"integer\" integer null, "
|
||||
"add column \"tinyInteger\" smallint not null, "
|
||||
"add column \"smallInteger\" smallint not null, "
|
||||
"add column \"mediumInteger\" integer not null");
|
||||
"add column \"mediumInteger\" integer not null, "
|
||||
"add column \"tiny_binary\" bytea not null, "
|
||||
"add column \"binary\" bytea not null, "
|
||||
"add column \"medium_binary\" bytea not null, "
|
||||
"add column \"long_binary\" bytea not null");
|
||||
QVERIFY(log0.boundValues.isEmpty());
|
||||
|
||||
const auto &log1 = log.at(1);
|
||||
|
||||
@@ -221,6 +221,11 @@ void tst_SQLite_SchemaBuilder::createTable() const
|
||||
table.uuid();
|
||||
table.ipAddress();
|
||||
table.macAddress();
|
||||
|
||||
table.tinyBinary("tiny_binary");
|
||||
table.binary("binary");
|
||||
table.mediumBinary("medium_binary");
|
||||
table.longBinary("long_binary");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -251,7 +256,11 @@ void tst_SQLite_SchemaBuilder::createTable() const
|
||||
"\"unsignedBigInteger\" integer not null, "
|
||||
"\"uuid\" varchar not null, "
|
||||
"\"ip_address\" varchar not null, "
|
||||
"\"mac_address\" varchar not null)");
|
||||
"\"mac_address\" varchar not null, "
|
||||
"\"tiny_binary\" blob not null, "
|
||||
"\"binary\" blob not null, "
|
||||
"\"medium_binary\" blob not null, "
|
||||
"\"long_binary\" blob not null)");
|
||||
QVERIFY(firstLog.boundValues.isEmpty());
|
||||
}
|
||||
|
||||
@@ -467,6 +476,11 @@ void tst_SQLite_SchemaBuilder::modifyTable() const
|
||||
table.smallInteger("smallInteger");
|
||||
table.mediumInteger("mediumInteger");
|
||||
|
||||
table.tinyBinary("tiny_binary");
|
||||
table.binary("binary");
|
||||
table.mediumBinary("medium_binary");
|
||||
table.longBinary("long_binary");
|
||||
|
||||
table.dropColumn("long_text");
|
||||
table.dropColumns({"medium_text", "text"});
|
||||
table.dropColumns("smallInteger", "mediumInteger");
|
||||
@@ -476,7 +490,7 @@ void tst_SQLite_SchemaBuilder::modifyTable() const
|
||||
});
|
||||
});
|
||||
|
||||
QCOMPARE(log.size(), 19);
|
||||
QCOMPARE(log.size(), 23);
|
||||
|
||||
const auto &log0 = log.at(0);
|
||||
QCOMPARE(log0.query,
|
||||
@@ -540,40 +554,60 @@ void tst_SQLite_SchemaBuilder::modifyTable() const
|
||||
|
||||
const auto &log12 = log.at(12);
|
||||
QCOMPARE(log12.query,
|
||||
R"(alter table "firewalls" drop column "long_text")");
|
||||
R"(alter table "firewalls" add column "tiny_binary" blob not null)");
|
||||
QVERIFY(log12.boundValues.isEmpty());
|
||||
|
||||
const auto &log13 = log.at(13);
|
||||
QCOMPARE(log13.query,
|
||||
R"(alter table "firewalls" drop column "medium_text")");
|
||||
R"(alter table "firewalls" add column "binary" blob not null)");
|
||||
QVERIFY(log13.boundValues.isEmpty());
|
||||
|
||||
const auto &log14 = log.at(14);
|
||||
QCOMPARE(log14.query,
|
||||
R"(alter table "firewalls" drop column "text")");
|
||||
R"(alter table "firewalls" add column "medium_binary" blob not null)");
|
||||
QVERIFY(log14.boundValues.isEmpty());
|
||||
|
||||
const auto &log15 = log.at(15);
|
||||
QCOMPARE(log15.query,
|
||||
R"(alter table "firewalls" drop column "smallInteger")");
|
||||
R"(alter table "firewalls" add column "long_binary" blob not null)");
|
||||
QVERIFY(log15.boundValues.isEmpty());
|
||||
|
||||
const auto &log16 = log.at(16);
|
||||
QCOMPARE(log16.query,
|
||||
R"(alter table "firewalls" drop column "mediumInteger")");
|
||||
R"(alter table "firewalls" drop column "long_text")");
|
||||
QVERIFY(log16.boundValues.isEmpty());
|
||||
|
||||
const auto &log17 = log.at(17);
|
||||
QCOMPARE(log17.query,
|
||||
"alter table \"firewalls\" "
|
||||
"rename column \"integer\" to \"integer_renamed\"");
|
||||
R"(alter table "firewalls" drop column "medium_text")");
|
||||
QVERIFY(log17.boundValues.isEmpty());
|
||||
|
||||
const auto &log18 = log.at(18);
|
||||
QCOMPARE(log18.query,
|
||||
R"(alter table "firewalls" drop column "text")");
|
||||
QVERIFY(log18.boundValues.isEmpty());
|
||||
|
||||
const auto &log19 = log.at(19);
|
||||
QCOMPARE(log19.query,
|
||||
R"(alter table "firewalls" drop column "smallInteger")");
|
||||
QVERIFY(log19.boundValues.isEmpty());
|
||||
|
||||
const auto &log20 = log.at(20);
|
||||
QCOMPARE(log20.query,
|
||||
R"(alter table "firewalls" drop column "mediumInteger")");
|
||||
QVERIFY(log20.boundValues.isEmpty());
|
||||
|
||||
const auto &log21 = log.at(21);
|
||||
QCOMPARE(log21.query,
|
||||
"alter table \"firewalls\" "
|
||||
"rename column \"integer\" to \"integer_renamed\"");
|
||||
QVERIFY(log21.boundValues.isEmpty());
|
||||
|
||||
const auto &log22 = log.at(22);
|
||||
QCOMPARE(log22.query,
|
||||
"alter table \"firewalls\" "
|
||||
"rename column \"string_22\" to \"string_22_renamed\"");
|
||||
QVERIFY(log18.boundValues.isEmpty());
|
||||
QVERIFY(log22.boundValues.isEmpty());
|
||||
}
|
||||
|
||||
void tst_SQLite_SchemaBuilder::modifyTable_WithComment() const
|
||||
|
||||
+2
@@ -315,6 +315,7 @@ function createTables(string $connection): void
|
||||
|
||||
$table->string('string')->nullable();
|
||||
$table->text('text')->nullable();
|
||||
$table->mediumText('medium_text')->nullable();
|
||||
|
||||
$table->timestamp('timestamp')->nullable();
|
||||
|
||||
@@ -322,6 +323,7 @@ function createTables(string $connection): void
|
||||
$table->date('date')->nullable();
|
||||
|
||||
$table->binary('binary')->nullable();
|
||||
$table->mediumBinary('medium_binary')->nullable();
|
||||
});
|
||||
|
||||
$schema->create('albums', function (Blueprint $table) {
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Migrations
|
||||
|
||||
table.string("string").nullable();
|
||||
table.text("text").nullable();
|
||||
table.mediumText("medium_text").nullable();
|
||||
|
||||
table.timestamp("timestamp").nullable();
|
||||
|
||||
@@ -45,6 +46,7 @@ namespace Migrations
|
||||
table.date("date").nullable();
|
||||
|
||||
table.binary("binary").nullable();
|
||||
table.mediumBinary("medium_binary").nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user