summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/doc/snippets/code/doc_src_sql-driver.qdoc2
-rw-r--r--src/sql/doc/src/sql-driver.qdoc32
-rw-r--r--src/sql/kernel/qsqldatabase.cpp6
-rw-r--r--src/sql/kernel/qsqldriver.cpp27
-rw-r--r--src/sql/kernel/qsqldriver.h3
-rw-r--r--src/sql/kernel/qsqlfield.cpp11
-rw-r--r--src/sql/kernel/qsqlfield.h2
-rw-r--r--src/sql/kernel/qsqlresult.cpp4
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.cpp14
-rw-r--r--src/sql/models/qsqltablemodel.cpp4
10 files changed, 62 insertions, 43 deletions
diff --git a/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc b/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc
index 12a39d80b2..b869b309b7 100644
--- a/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc
+++ b/src/sql/doc/snippets/code/doc_src_sql-driver.qdoc
@@ -235,7 +235,7 @@ make sub-oci
//! [35]
QSqlDatabase: QPSQL driver not loaded
-QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
+QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QMARIADB QODBC QODBC3 QPSQL QPSQL7
Could not create database object
//! [35]
diff --git a/src/sql/doc/src/sql-driver.qdoc b/src/sql/doc/src/sql-driver.qdoc
index f6fc90a7e9..e77cc772e6 100644
--- a/src/sql/doc/src/sql-driver.qdoc
+++ b/src/sql/doc/src/sql-driver.qdoc
@@ -48,7 +48,7 @@
\header \li Driver name \li DBMS
\row \li \l{#QDB2}{QDB2} \li IBM DB2 (version 7.1 and above)
\row \li \l{#QIBASE}{QIBASE} \li Borland InterBase
- \row \li \l{#QMYSQL}{QMYSQL} \li MySQL (version 5.0 and above)
+ \row \li \l{#QMYSQL}{QMYSQL / MARIADB} \li MySQL or MariaDB (version 5.0 and above)
\row \li \l{#QOCI}{QOCI} \li Oracle Call Interface Driver
\row \li \l{#QODBC}{QODBC}
\li Open Database Connectivity (ODBC) - Microsoft SQL Server and other
@@ -123,7 +123,13 @@
\section1 Driver Specifics
\target QMYSQL
- \section2 QMYSQL for MySQL 5 and higher
+ \section2 QMYSQL for MySQL or MariaDB 5 and higher
+
+ MariaDB is a fork of MySQL intended to remain free and open-source software
+ under the GNU General Public License. MariaDB intended to maintain high
+ compatibility with MySQL, ensuring a drop-in replacement capability with
+ library binary parity and exact matching with MySQL APIs and commands.
+ Therefore the plugin for MySQL and MariaDB are combined into one Qt plugin.
\section3 QMYSQL Stored Procedure Support
@@ -158,12 +164,13 @@
\section3 How to Build the QMYSQL Plugin on Unix and \macos
- You need the MySQL header files, as well as the shared library
- \c{libmysqlclient.so}. Depending on your Linux distribution, you may
- need to install a package which is usually called "mysql-devel".
+ You need the MySQL / MariaDB header files, as well as the shared library
+ \c{libmysqlclient.so} / \c{libmariadb.so}. Depending on your Linux distribution,
+ you may need to install a package which is usually called "mysql-devel"
+ or "mariadb-devel".
- Tell \l qmake where to find the MySQL header files and shared
- libraries (here it is assumed that MySQL is installed in
+ Tell \l qmake where to find the MySQL / MariaDB header files and shared
+ libraries (here it is assumed that MySQL / MariaDB is installed in
\c{/usr/local}) and run \c{make}:
\snippet code/doc_src_sql-driver.qdoc 3
@@ -171,7 +178,8 @@
\section3 How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files (e.g.
- \l {https://dev.mysql.com/downloads/installer/}{mysql-installer-web-community-8.0.18.0.msi}).
+ \l {https://dev.mysql.com/downloads/installer/}{mysql-installer-web-community-8.0.18.0.msi}) or
+ \l {https://downloads.mariadb.org/connector-c/3.1.5/}{mariadb-connector-c-3.1.5-win64.msi}.
Run the installer,
select custom installation and install the MySQL C Connector
which matches your Qt installation (x86 or x64).
@@ -181,6 +189,12 @@
\li \c {<MySQL dir>/lib/libmysql.dll}
\li \c {<MySQL dir>/include/mysql.h}
\endlist
+ and for MariaDB
+ \list
+ \li \c {<MariaDB dir>/lib/libmariadb.lib}
+ \li \c {<MariaDB dir>/lib/libmariadb.dll}
+ \li \c {<MariaDB dir>/include/mysql.h}
+ \endlist
Build the plugin as follows (here it is assumed that the MySQL
C Connector is installed in
@@ -191,7 +205,7 @@
If you are not using a Microsoft compiler, replace \c nmake with \c
mingw32-make in the line above.
- When you distribute your application, remember to include libmysql.dll
+ When you distribute your application, remember to include libmysql.dll / libmariadb.dll
in your installation package. It must be placed in the same folder
as the application executable. \e libmysql.dll additionally needs the
MSVC runtime libraries which can be installed with
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp
index 01726d79ef..32338c1fe2 100644
--- a/src/sql/kernel/qsqldatabase.cpp
+++ b/src/sql/kernel/qsqldatabase.cpp
@@ -84,7 +84,7 @@ Q_GLOBAL_STATIC(QConnectionDict, dbDict)
class QSqlDatabasePrivate
{
public:
- QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = 0):
+ QSqlDatabasePrivate(QSqlDatabase *d, QSqlDriver *dr = nullptr):
ref(1),
q(d),
driver(dr),
@@ -178,7 +178,7 @@ DriverDict &QSqlDatabasePrivate::driverDict()
QSqlDatabasePrivate *QSqlDatabasePrivate::shared_null()
{
static QSqlNullDriver dr;
- static QSqlDatabasePrivate n(NULL, &dr);
+ static QSqlDatabasePrivate n(nullptr, &dr);
return &n;
}
@@ -702,7 +702,7 @@ void QSqlDatabasePrivate::init(const QString &type)
qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data());
qWarning("QSqlDatabase: available drivers: %s",
QSqlDatabase::drivers().join(QLatin1Char(' ')).toLatin1().data());
- if (QCoreApplication::instance() == 0)
+ if (QCoreApplication::instance() == nullptr)
qWarning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
driver = shared_null()->driver;
}
diff --git a/src/sql/kernel/qsqldriver.cpp b/src/sql/kernel/qsqldriver.cpp
index 7f7b81b05b..d1c9057aac 100644
--- a/src/sql/kernel/qsqldriver.cpp
+++ b/src/sql/kernel/qsqldriver.cpp
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
static QString prepareIdentifier(const QString &identifier,
QSqlDriver::IdentifierType type, const QSqlDriver *driver)
{
- Q_ASSERT( driver != NULL );
+ Q_ASSERT( driver != nullptr );
QString ret = identifier;
if (!driver->isIdentifierEscaped(identifier, type)) {
ret = driver->escapeIdentifier(identifier, type);
@@ -110,6 +110,9 @@ QSqlDriver::~QSqlDriver()
that the driver subscribes to. \a name identifies the event notification.
\sa subscribeToNotification()
+
+ \obsolete use QSqlDriver::notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload)
+ instead
*/
/*!
@@ -609,30 +612,30 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const
if (field.isNull())
r = nullTxt;
else {
- switch (field.type()) {
- case QVariant::Int:
- case QVariant::UInt:
- if (field.value().type() == QVariant::Bool)
+ switch (+field.type()) {
+ case QMetaType::Int:
+ case QMetaType::UInt:
+ if (field.value().userType() == QMetaType::Bool)
r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0");
else
r = field.value().toString();
break;
#if QT_CONFIG(datestring)
- case QVariant::Date:
+ case QMetaType::QDate:
if (field.value().toDate().isValid())
r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate)
+ QLatin1Char('\'');
else
r = nullTxt;
break;
- case QVariant::Time:
+ case QMetaType::QTime:
if (field.value().toTime().isValid())
r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate)
+ QLatin1Char('\'');
else
r = nullTxt;
break;
- case QVariant::DateTime:
+ case QMetaType::QDateTime:
if (field.value().toDateTime().isValid())
r = QLatin1Char('\'') +
field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\'');
@@ -640,8 +643,8 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const
r = nullTxt;
break;
#endif
- case QVariant::String:
- case QVariant::Char:
+ case QMetaType::QString:
+ case QMetaType::QChar:
{
QString result = field.value().toString();
if (trimStrings) {
@@ -655,10 +658,10 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const
r = QLatin1Char('\'') + result + QLatin1Char('\'');
break;
}
- case QVariant::Bool:
+ case QMetaType::Bool:
r = QString::number(field.value().toBool());
break;
- case QVariant::ByteArray : {
+ case QMetaType::QByteArray : {
if (hasFeature(BLOB)) {
QByteArray ba = field.value().toByteArray();
QString res;
diff --git a/src/sql/kernel/qsqldriver.h b/src/sql/kernel/qsqldriver.h
index 1e03be48d3..ca9f7dc51e 100644
--- a/src/sql/kernel/qsqldriver.h
+++ b/src/sql/kernel/qsqldriver.h
@@ -135,7 +135,10 @@ public Q_SLOTS:
virtual bool cancelQuery();
Q_SIGNALS:
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use the 3-args version of notification() instead.")
void notification(const QString &name);
+#endif
void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload);
protected:
diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp
index 5a6d173b3b..86a22bae10 100644
--- a/src/sql/kernel/qsqlfield.cpp
+++ b/src/sql/kernel/qsqlfield.cpp
@@ -48,7 +48,7 @@ class QSqlFieldPrivate
public:
QSqlFieldPrivate(const QString &name,
QVariant::Type type, const QString &tableName) :
- ref(1), nm(name), table(tableName), def(QVariant()), type(type),
+ ref(1), nm(name), table(tableName), def(QVariant()), type(QMetaType::Type(type)),
req(QSqlField::Unknown), len(-1), prec(-1), tp(-1),
ro(false), gen(true), autoval(false)
{}
@@ -86,7 +86,7 @@ public:
QString nm;
QString table;
QVariant def;
- QVariant::Type type;
+ QMetaType::Type type;
QSqlField::RequiredStatus req;
int len;
int prec;
@@ -399,7 +399,7 @@ QString QSqlField::name() const
*/
QVariant::Type QSqlField::type() const
{
- return d->type;
+ return QVariant::Type(d->type);
}
/*!
@@ -411,12 +411,11 @@ QVariant::Type QSqlField::type() const
void QSqlField::setType(QVariant::Type type)
{
detach();
- d->type = type;
+ d->type = QMetaType::Type(type);
if (!val.isValid())
val = QVariant(type);
}
-
/*!
Returns \c true if the field's value is read-only; otherwise returns
false.
@@ -526,7 +525,7 @@ bool QSqlField::isGenerated() const
*/
bool QSqlField::isValid() const
{
- return d->type != QVariant::Invalid;
+ return d->type != QMetaType::UnknownType;
}
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h
index 8650ba8715..892420d26e 100644
--- a/src/sql/kernel/qsqlfield.h
+++ b/src/sql/kernel/qsqlfield.h
@@ -55,7 +55,7 @@ public:
enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
explicit QSqlField(const QString& fieldName = QString(),
- QVariant::Type type = QVariant::Invalid);
+ QVariant::Type type = {});
QSqlField(const QString &fieldName, QVariant::Type type,
const QString &tableName);
diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp
index cc91c6d0ed..a41b3d8424 100644
--- a/src/sql/kernel/qsqlresult.cpp
+++ b/src/sql/kernel/qsqlresult.cpp
@@ -645,7 +645,7 @@ bool QSqlResult::exec()
for (i = d->holders.count() - 1; i >= 0; --i) {
holder = d->holders.at(i).holderName;
val = d->values.value(d->indexes.value(holder).value(0,-1));
- QSqlField f(QLatin1String(""), val.type());
+ QSqlField f(QLatin1String(""), QVariant::Type(val.userType()));
f.setValue(val);
query = query.replace(d->holders.at(i).holderPos,
holder.length(), driver()->formatValue(f));
@@ -659,7 +659,7 @@ bool QSqlResult::exec()
if (i == -1)
continue;
QVariant var = d->values.value(idx);
- QSqlField f(QLatin1String(""), var.type());
+ QSqlField f(QLatin1String(""), QVariant::Type(var.userType()));
if (var.isNull())
f.clear();
else
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp
index 34be010474..20adec6a3b 100644
--- a/src/sql/models/qsqlrelationaltablemodel.cpp
+++ b/src/sql/models/qsqlrelationaltablemodel.cpp
@@ -137,7 +137,7 @@ class QRelatedTableModel;
struct QRelation
{
public:
- QRelation(): model(0), m_parent(0), m_dictInitialized(false) {}
+ QRelation(): model(nullptr), m_parent(nullptr), m_dictInitialized(false) {}
void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation);
void populateModel();
@@ -161,7 +161,7 @@ struct QRelation
class QRelatedTableModel : public QSqlTableModel
{
public:
- QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase());
+ QRelatedTableModel(QRelation *rel, QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
bool select() override;
private:
bool firstSelect;
@@ -174,7 +174,7 @@ private:
*/
void QRelation::init(QSqlRelationalTableModel *parent, const QSqlRelation &relation)
{
- Q_ASSERT(parent != NULL);
+ Q_ASSERT(parent != nullptr);
m_parent = parent;
rel = relation;
}
@@ -183,7 +183,7 @@ void QRelation::populateModel()
{
if (!isValid())
return;
- Q_ASSERT(m_parent != NULL);
+ Q_ASSERT(m_parent != nullptr);
if (!model) {
model = new QRelatedTableModel(this, m_parent, m_parent->database());
@@ -202,7 +202,7 @@ void QRelation::populateDictionary()
if (!isValid())
return;
- if (model == NULL)
+ if (model == nullptr)
populateModel();
QSqlRecord record;
@@ -234,13 +234,13 @@ void QRelation::clearDictionary()
void QRelation::clear()
{
delete model;
- model = 0;
+ model = nullptr;
clearDictionary();
}
bool QRelation::isValid()
{
- return (rel.isValid() && m_parent != NULL);
+ return (rel.isValid() && m_parent != nullptr);
}
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 969194983e..7d2421d34e 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -1305,7 +1305,7 @@ Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const
Q_D(const QSqlTableModel);
if (index.internalPointer() || index.column() < 0 || index.column() >= d->rec.count()
|| index.row() < 0)
- return 0;
+ return { };
bool editable = true;
@@ -1369,7 +1369,7 @@ QSqlRecord QSqlTableModel::record(int row) const
// get generated flags from the cache
const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(row);
if (mrow.op() != QSqlTableModelPrivate::None) {
- const QSqlRecord crec = mrow.rec();
+ const QSqlRecord &crec = mrow.rec();
for (int i = 0, cnt = rec.count(); i < cnt; ++i)
rec.setGenerated(i, crec.isGenerated(i));
}