summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sqldrivers')
-rw-r--r--src/plugins/sqldrivers/mysql/qsql_mysql.cpp59
-rw-r--r--src/plugins/sqldrivers/odbc/qsql_odbc.cpp76
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp48
-rw-r--r--src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp25
4 files changed, 81 insertions, 127 deletions
diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
index 2930df7261..41141e1dd4 100644
--- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
+++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp
@@ -78,17 +78,14 @@ class QMYSQLDriverPrivate : public QSqlDriverPrivate
Q_DECLARE_PUBLIC(QMYSQLDriver)
public:
- QMYSQLDriverPrivate() : QSqlDriverPrivate(), mysql(0),
+ QMYSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::MySqlServer)
#if QT_CONFIG(textcodec)
- tc(QTextCodec::codecForLocale()),
-#else
- tc(0),
+ , tc(QTextCodec::codecForLocale())
#endif
- preparedQuerysEnabled(false) { dbmsType = QSqlDriver::MySqlServer; }
- MYSQL *mysql;
- QTextCodec *tc;
-
- bool preparedQuerysEnabled;
+ {}
+ MYSQL *mysql = nullptr;
+ QTextCodec *tc = nullptr;
+ bool preparedQuerysEnabled = false;
};
static inline QString toUnicode(QTextCodec *tc, const char *str)
@@ -201,46 +198,34 @@ class QMYSQLResultPrivate: public QSqlResultPrivate
public:
Q_DECLARE_SQLDRIVER_PRIVATE(QMYSQLDriver)
- QMYSQLResultPrivate(QMYSQLResult *q, const QMYSQLDriver *drv)
- : QSqlResultPrivate(q, drv),
- result(0),
- rowsAffected(0),
- hasBlobs(false)
- , stmt(0), meta(0), inBinds(0), outBinds(0)
- , preparedQuery(false)
- { }
-
- MYSQL_RES *result;
- MYSQL_ROW row;
-
- int rowsAffected;
+ using QSqlResultPrivate::QSqlResultPrivate;
bool bindInValues();
void bindBlobs();
- bool hasBlobs;
+ MYSQL_RES *result = nullptr;
+ MYSQL_ROW row;
+
struct QMyField
{
- QMyField()
- : outField(0), nullIndicator(false), bufLength(0ul),
- myField(0), type(QMetaType::UnknownType)
- {}
- char *outField;
- my_bool nullIndicator;
- ulong bufLength;
- MYSQL_FIELD *myField;
- QMetaType::Type type;
+ char *outField = nullptr;
+ MYSQL_FIELD *myField = nullptr;
+ QMetaType::Type type = QMetaType::UnknownType;
+ my_bool nullIndicator = false;
+ ulong bufLength = 0ul;
};
QVector<QMyField> fields;
- MYSQL_STMT* stmt;
- MYSQL_RES* meta;
+ MYSQL_STMT *stmt = nullptr;
+ MYSQL_RES *meta = nullptr;
- MYSQL_BIND *inBinds;
- MYSQL_BIND *outBinds;
+ MYSQL_BIND *inBinds = nullptr;
+ MYSQL_BIND *outBinds = nullptr;
- bool preparedQuery;
+ int rowsAffected = 0;
+ bool hasBlobs = false;
+ bool preparedQuery = false;
};
#if QT_CONFIG(textcodec)
diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp
index 72b2133327..63e8f9f9fe 100644
--- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp
+++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp
@@ -118,23 +118,19 @@ class QODBCDriverPrivate : public QSqlDriverPrivate
Q_DECLARE_PUBLIC(QODBCDriver)
public:
- enum DefaultCase{Lower, Mixed, Upper, Sensitive};
- QODBCDriverPrivate()
- : QSqlDriverPrivate(), hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), datetime_precision(19),
- isFreeTDSDriver(false), hasSQLFetchScroll(true), hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"'))
- {
- }
+ enum DefaultCase {Lower, Mixed, Upper, Sensitive};
+ using QSqlDriverPrivate::QSqlDriverPrivate;
- SQLHANDLE hEnv;
- SQLHANDLE hDbc;
+ SQLHANDLE hEnv = nullptr;
+ SQLHANDLE hDbc = nullptr;
- bool unicode;
- bool useSchema;
- int disconnectCount;
- int datetime_precision;
- bool isFreeTDSDriver;
- bool hasSQLFetchScroll;
- bool hasMultiResultSets;
+ int disconnectCount = 0;
+ int datetimePrecision = 19;
+ bool unicode = false;
+ bool useSchema = false;
+ bool isFreeTDSDriver = false;
+ bool hasSQLFetchScroll = true;
+ bool hasMultiResultSets = false;
bool checkDriver() const;
void checkUnicode();
@@ -150,8 +146,8 @@ public:
QString adjustCase(const QString&) const;
QChar quoteChar();
private:
- bool isQuoteInitialized;
- QChar quote;
+ bool isQuoteInitialized = false;
+ QChar quote = QLatin1Char('"');
};
class QODBCResultPrivate;
@@ -194,10 +190,7 @@ class QODBCResultPrivate: public QSqlResultPrivate
public:
Q_DECLARE_SQLDRIVER_PRIVATE(QODBCDriver)
QODBCResultPrivate(QODBCResult *q, const QODBCDriver *db)
- : QSqlResultPrivate(q, db),
- hStmt(0),
- useSchema(false),
- hasSQLFetchScroll(true)
+ : QSqlResultPrivate(q, db)
{
unicode = drv_d_func()->unicode;
useSchema = drv_d_func()->useSchema;
@@ -210,16 +203,15 @@ public:
SQLHANDLE dpEnv() const { return drv_d_func() ? drv_d_func()->hEnv : 0;}
SQLHANDLE dpDbc() const { return drv_d_func() ? drv_d_func()->hDbc : 0;}
- SQLHANDLE hStmt;
-
- bool unicode;
- bool useSchema;
+ SQLHANDLE hStmt = nullptr;
QSqlRecord rInf;
QVector<QVariant> fieldCache;
- int fieldCacheIdx;
- int disconnectCount;
- bool hasSQLFetchScroll;
+ int fieldCacheIdx = 0;
+ int disconnectCount = 0;
+ bool hasSQLFetchScroll = true;
+ bool unicode = false;
+ bool useSchema = false;
bool isStmtHandleValid() const;
void updateStmtHandleState();
@@ -1464,20 +1456,22 @@ bool QODBCResult::exec()
case QVariant::DateTime: {
QByteArray &ba = tmpStorage[i];
ba.resize(sizeof(TIMESTAMP_STRUCT));
- TIMESTAMP_STRUCT * dt = (TIMESTAMP_STRUCT *)const_cast<char *>(ba.constData());
- QDateTime qdt = val.toDateTime();
- dt->year = qdt.date().year();
- dt->month = qdt.date().month();
- dt->day = qdt.date().day();
- dt->hour = qdt.time().hour();
- dt->minute = qdt.time().minute();
- dt->second = qdt.time().second();
-
- int precision = d->drv_d_func()->datetime_precision - 20; // (20 includes a separating period)
+ TIMESTAMP_STRUCT *dt = reinterpret_cast<TIMESTAMP_STRUCT *>(const_cast<char *>(ba.constData()));
+ const QDateTime qdt = val.toDateTime();
+ const QDate qdate = qdt.date();
+ const QTime qtime = qdt.time();
+ dt->year = qdate.year();
+ dt->month = qdate.month();
+ dt->day = qdate.day();
+ dt->hour = qtime.hour();
+ dt->minute = qtime.minute();
+ dt->second = qtime.second();
+ // (20 includes a separating period)
+ const int precision = d->drv_d_func()->datetimePrecision - 20;
if (precision <= 0) {
dt->fraction = 0;
} else {
- dt->fraction = qdt.time().msec() * 1000000;
+ dt->fraction = qtime.msec() * 1000000;
// (How many leading digits do we want to keep? With SQL Server 2005, this should be 3: 123000000)
int keep = (int)qPow(10.0, 9 - qMin(9, precision));
@@ -1489,7 +1483,7 @@ bool QODBCResult::exec()
qParamType[bindValueType(i) & QSql::InOut],
SQL_C_TIMESTAMP,
SQL_TIMESTAMP,
- d->drv_d_func()->datetime_precision,
+ d->drv_d_func()->datetimePrecision,
precision,
(void *) dt,
0,
@@ -2245,7 +2239,7 @@ void QODBCDriverPrivate::checkDateTimePrecision()
if ( r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO )
{
if (SQLGetData(hStmt, 3, SQL_INTEGER, &columnSize, sizeof(columnSize), 0) == SQL_SUCCESS) {
- datetime_precision = (int)columnSize;
+ datetimePrecision = (int)columnSize;
}
}
}
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index 27841d9494..d2c57bcddc 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -149,26 +149,17 @@ class QPSQLDriverPrivate final : public QSqlDriverPrivate
{
Q_DECLARE_PUBLIC(QPSQLDriver)
public:
- QPSQLDriverPrivate() : QSqlDriverPrivate(),
- connection(nullptr),
- isUtf8(false),
- pro(QPSQLDriver::Version6),
- sn(nullptr),
- pendingNotifyCheck(false),
- hasBackslashEscape(false),
- stmtCount(0),
- currentStmtId(InvalidStatementId)
- { dbmsType = QSqlDriver::PostgreSQL; }
-
- PGconn *connection;
- bool isUtf8;
- QPSQLDriver::Protocol pro;
- QSocketNotifier *sn;
+ QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) {}
+
QStringList seid;
- mutable bool pendingNotifyCheck;
- bool hasBackslashEscape;
- int stmtCount;
- StatementId currentStmtId;
+ PGconn *connection = nullptr;
+ QSocketNotifier *sn = nullptr;
+ QPSQLDriver::Protocol pro = QPSQLDriver::Version6;
+ StatementId currentStmtId = InvalidStatementId;
+ int stmtCount = 0;
+ mutable bool pendingNotifyCheck = false;
+ bool hasBackslashEscape = false;
+ bool isUtf8 = false;
void appendTables(QStringList &tl, QSqlQuery &t, QChar type);
PGresult *exec(const char *stmt);
@@ -297,25 +288,18 @@ class QPSQLResultPrivate : public QSqlResultPrivate
Q_DECLARE_PUBLIC(QPSQLResult)
public:
Q_DECLARE_SQLDRIVER_PRIVATE(QPSQLDriver)
- QPSQLResultPrivate(QPSQLResult *q, const QPSQLDriver *drv)
- : QSqlResultPrivate(q, drv),
- result(nullptr),
- stmtId(InvalidStatementId),
- currentSize(-1),
- canFetchMoreRows(false),
- preparedQueriesEnabled(false)
- { }
+ using QSqlResultPrivate::QSqlResultPrivate;
QString fieldSerial(int i) const override { return QLatin1Char('$') + QString::number(i + 1); }
void deallocatePreparedStmt();
- PGresult *result;
std::queue<PGresult*> nextResultSets;
QString preparedStmtId;
- StatementId stmtId;
- int currentSize;
- bool canFetchMoreRows;
- bool preparedQueriesEnabled;
+ PGresult *result = nullptr;
+ StatementId stmtId = InvalidStatementId;
+ int currentSize = -1;
+ bool canFetchMoreRows = false;
+ bool preparedQueriesEnabled = false;
bool processResults();
};
diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
index 009e8a39ef..27e7d02472 100644
--- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
+++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
@@ -144,42 +144,33 @@ class QSQLiteDriverPrivate : public QSqlDriverPrivate
Q_DECLARE_PUBLIC(QSQLiteDriver)
public:
- inline QSQLiteDriverPrivate() : QSqlDriverPrivate(), access(0) { dbmsType = QSqlDriver::SQLite; }
- sqlite3 *access;
- QList <QSQLiteResult *> results;
+ inline QSQLiteDriverPrivate() : QSqlDriverPrivate(QSqlDriver::SQLite) {}
+ sqlite3 *access = nullptr;
+ QVector<QSQLiteResult *> results;
QStringList notificationid;
};
-class QSQLiteResultPrivate: public QSqlCachedResultPrivate
+class QSQLiteResultPrivate : public QSqlCachedResultPrivate
{
Q_DECLARE_PUBLIC(QSQLiteResult)
public:
Q_DECLARE_SQLDRIVER_PRIVATE(QSQLiteDriver)
- QSQLiteResultPrivate(QSQLiteResult *q, const QSQLiteDriver *drv);
+ using QSqlCachedResultPrivate::QSqlCachedResultPrivate;
void cleanup();
bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
// initializes the recordInfo and the cache
void initColumns(bool emptyResultset);
void finalize();
- sqlite3_stmt *stmt;
-
- bool skippedStatus; // the status of the fetchNext() that's skipped
- bool skipRow; // skip the next fetchNext()?
+ sqlite3_stmt *stmt = nullptr;
QSqlRecord rInf;
QVector<QVariant> firstRow;
+ bool skippedStatus = false; // the status of the fetchNext() that's skipped
+ bool skipRow = false; // skip the next fetchNext()?
};
-QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult *q, const QSQLiteDriver *drv)
- : QSqlCachedResultPrivate(q, drv),
- stmt(0),
- skippedStatus(false),
- skipRow(false)
-{
-}
-
void QSQLiteResultPrivate::cleanup()
{
Q_Q(QSQLiteResult);