QtSql: cleanup QSqlDriverPrivate and QSqlResultPrivate
Cleanup QSqlDriverPrivate/QSqlResultPrivate and their derived classes in ODBC, MySql, PostgreSQL and SQLite. Change-Id: I52e69c00cf981b81dde7c3a0370f86f06ef756bb Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
parent
fd49b4a2b9
commit
3dd5caaaec
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
QPSQLDriverPrivate() : QSqlDriverPrivate(QSqlDriver::PostgreSQL) {}
|
||||
|
||||
PGconn *connection;
|
||||
bool isUtf8;
|
||||
QPSQLDriver::Protocol pro;
|
||||
QSocketNotifier *sn;
|
||||
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();
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -63,19 +63,16 @@ class QSqlDriverPrivate : public QObjectPrivate
|
||||
Q_DECLARE_PUBLIC(QSqlDriver)
|
||||
|
||||
public:
|
||||
QSqlDriverPrivate()
|
||||
QSqlDriverPrivate(QSqlDriver::DbmsType type = QSqlDriver::UnknownDbms)
|
||||
: QObjectPrivate(),
|
||||
isOpen(false),
|
||||
isOpenError(false),
|
||||
precisionPolicy(QSql::LowPrecisionDouble),
|
||||
dbmsType(QSqlDriver::UnknownDbms)
|
||||
dbmsType(type)
|
||||
{ }
|
||||
|
||||
uint isOpen;
|
||||
uint isOpenError;
|
||||
QSqlError error;
|
||||
QSql::NumericalPrecisionPolicy precisionPolicy;
|
||||
QSql::NumericalPrecisionPolicy precisionPolicy = QSql::LowPrecisionDouble;
|
||||
QSqlDriver::DbmsType dbmsType;
|
||||
bool isOpen = false;
|
||||
bool isOpenError = false;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -79,14 +79,7 @@ class Q_SQL_EXPORT QSqlResultPrivate
|
||||
public:
|
||||
QSqlResultPrivate(QSqlResult *q, const QSqlDriver *drv)
|
||||
: q_ptr(q),
|
||||
sqldriver(const_cast<QSqlDriver*>(drv)),
|
||||
idx(QSql::BeforeFirstRow),
|
||||
active(false),
|
||||
isSel(false),
|
||||
forwardOnly(false),
|
||||
precisionPolicy(QSql::LowPrecisionDouble),
|
||||
bindCount(0),
|
||||
binds(QSqlResult::PositionalBinding)
|
||||
sqldriver(const_cast<QSqlDriver*>(drv))
|
||||
{ }
|
||||
virtual ~QSqlResultPrivate() { }
|
||||
|
||||
@ -119,18 +112,17 @@ public:
|
||||
QString namedToPositionalBinding(const QString &query);
|
||||
QString holderAt(int index) const;
|
||||
|
||||
QSqlResult *q_ptr;
|
||||
QSqlResult *q_ptr = nullptr;
|
||||
QPointer<QSqlDriver> sqldriver;
|
||||
int idx;
|
||||
QString sql;
|
||||
bool active;
|
||||
bool isSel;
|
||||
QSqlError error;
|
||||
bool forwardOnly;
|
||||
QSql::NumericalPrecisionPolicy precisionPolicy;
|
||||
|
||||
int bindCount;
|
||||
QSqlResult::BindingSyntax binds;
|
||||
QSql::NumericalPrecisionPolicy precisionPolicy = QSql::LowPrecisionDouble;
|
||||
QSqlResult::BindingSyntax binds = QSqlResult::PositionalBinding;
|
||||
int idx = QSql::BeforeFirstRow;
|
||||
int bindCount = 0;
|
||||
bool active = false;
|
||||
bool isSel = false;
|
||||
bool forwardOnly = false;
|
||||
|
||||
QString executedQuery;
|
||||
QHash<int, QSql::ParamType> types;
|
||||
|
Loading…
Reference in New Issue
Block a user