QPSQLResultPrivate: do not duplicate reference to private driver
The "private driver" is already known, so don't keep an extra reference to it. Change-Id: I34ec4108694bfbc3da3107f79598ae50a699911c Reviewed-by: Israel Lins Albuquerque <israelins85@yahoo.com.br> Reviewed-by: Mark Brand <mabrand@mabrand.nl>bb10
parent
6361227846
commit
7565f6fe0a
|
|
@ -194,12 +194,12 @@ PGresult * QPSQLDriverPrivate::exec(const QString & stmt) const
|
|||
class QPSQLResultPrivate
|
||||
{
|
||||
public:
|
||||
QPSQLResultPrivate(QPSQLResult *qq): q(qq), privDriver(0), result(0), currentSize(-1), preparedQueriesEnabled(false) {}
|
||||
QPSQLResultPrivate(QPSQLResult *qq): q(qq), result(0), currentSize(-1), preparedQueriesEnabled(false) {}
|
||||
static QString fieldSerial(int i) { return QLatin1Char('$') + QString::number(i + 1); }
|
||||
void deallocatePreparedStmt();
|
||||
const QPSQLDriverPrivate * privDriver() const { return reinterpret_cast<const QPSQLDriver *>(q->driver())->d; }
|
||||
|
||||
QPSQLResult *q;
|
||||
const QPSQLDriverPrivate *privDriver;
|
||||
PGresult *result;
|
||||
int currentSize;
|
||||
bool preparedQueriesEnabled;
|
||||
|
|
@ -238,7 +238,7 @@ bool QPSQLResultPrivate::processResults()
|
|||
return true;
|
||||
}
|
||||
q->setLastError(qMakeError(QCoreApplication::translate("QPSQLResult",
|
||||
"Unable to create query"), QSqlError::StatementError, privDriver, result));
|
||||
"Unable to create query"), QSqlError::StatementError, privDriver(), result));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -291,19 +291,18 @@ static QVariant::Type qDecodePSQLType(int t)
|
|||
void QPSQLResultPrivate::deallocatePreparedStmt()
|
||||
{
|
||||
const QString stmt = QLatin1String("DEALLOCATE ") + preparedStmtId;
|
||||
PGresult *result = privDriver->exec(stmt);
|
||||
PGresult *result = privDriver()->exec(stmt);
|
||||
|
||||
if (PQresultStatus(result) != PGRES_COMMAND_OK)
|
||||
qWarning("Unable to free statement: %s", PQerrorMessage(privDriver->connection));
|
||||
qWarning("Unable to free statement: %s", PQerrorMessage(privDriver()->connection));
|
||||
PQclear(result);
|
||||
preparedStmtId.clear();
|
||||
}
|
||||
|
||||
QPSQLResult::QPSQLResult(const QPSQLDriver* db, const QPSQLDriverPrivate* p)
|
||||
QPSQLResult::QPSQLResult(const QPSQLDriver* db)
|
||||
: QSqlResult(db)
|
||||
{
|
||||
d = new QPSQLResultPrivate(this);
|
||||
d->privDriver = p;
|
||||
d->preparedQueriesEnabled = db->hasFeature(QSqlDriver::PreparedQueries);
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +370,7 @@ QVariant QPSQLResult::data(int i)
|
|||
case QVariant::Bool:
|
||||
return QVariant((bool)(val[0] == 't'));
|
||||
case QVariant::String:
|
||||
return d->privDriver->isUtf8 ? QString::fromUtf8(val) : QString::fromLatin1(val);
|
||||
return d->privDriver()->isUtf8 ? QString::fromUtf8(val) : QString::fromLatin1(val);
|
||||
case QVariant::LongLong:
|
||||
if (val[0] == '-')
|
||||
return QString::fromLatin1(val).toLongLong();
|
||||
|
|
@ -469,7 +468,7 @@ bool QPSQLResult::reset (const QString& query)
|
|||
return false;
|
||||
if (!driver()->isOpen() || driver()->isOpenError())
|
||||
return false;
|
||||
d->result = d->privDriver->exec(query);
|
||||
d->result = d->privDriver()->exec(query);
|
||||
return d->processResults();
|
||||
}
|
||||
|
||||
|
|
@ -485,7 +484,7 @@ int QPSQLResult::numRowsAffected()
|
|||
|
||||
QVariant QPSQLResult::lastInsertId() const
|
||||
{
|
||||
if (d->privDriver->pro >= QPSQLDriver::Version81) {
|
||||
if (d->privDriver()->pro >= QPSQLDriver::Version81) {
|
||||
QSqlQuery qry(driver()->createResult());
|
||||
// Most recent sequence value obtained from nextval
|
||||
if (qry.exec(QLatin1String("SELECT lastval();")) && qry.next())
|
||||
|
|
@ -507,7 +506,7 @@ QSqlRecord QPSQLResult::record() const
|
|||
int count = PQnfields(d->result);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QSqlField f;
|
||||
if (d->privDriver->isUtf8)
|
||||
if (d->privDriver()->isUtf8)
|
||||
f.setName(QString::fromUtf8(PQfname(d->result, i)));
|
||||
else
|
||||
f.setName(QString::fromLocal8Bit(PQfname(d->result, i)));
|
||||
|
|
@ -579,11 +578,11 @@ bool QPSQLResult::prepare(const QString &query)
|
|||
const QString stmtId = qMakePreparedStmtId();
|
||||
const QString stmt = QString::fromLatin1("PREPARE %1 AS ").arg(stmtId).append(QSqlResultPrivate::positionalToNamedBinding(query, QPSQLResultPrivate::fieldSerial));
|
||||
|
||||
PGresult *result = d->privDriver->exec(stmt);
|
||||
PGresult *result = d->privDriver()->exec(stmt);
|
||||
|
||||
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
||||
setLastError(qMakeError(QCoreApplication::translate("QPSQLResult",
|
||||
"Unable to prepare statement"), QSqlError::StatementError, d->privDriver, result));
|
||||
"Unable to prepare statement"), QSqlError::StatementError, d->privDriver(), result));
|
||||
PQclear(result);
|
||||
d->preparedStmtId.clear();
|
||||
return false;
|
||||
|
|
@ -608,7 +607,7 @@ bool QPSQLResult::exec()
|
|||
else
|
||||
stmt = QString::fromLatin1("EXECUTE %1 (%2)").arg(d->preparedStmtId).arg(params);
|
||||
|
||||
d->result = d->privDriver->exec(stmt);
|
||||
d->result = d->privDriver()->exec(stmt);
|
||||
|
||||
return d->processResults();
|
||||
}
|
||||
|
|
@ -892,7 +891,7 @@ void QPSQLDriver::close()
|
|||
|
||||
QSqlResult *QPSQLDriver::createResult() const
|
||||
{
|
||||
return new QPSQLResult(this, d);
|
||||
return new QPSQLResult(this);
|
||||
}
|
||||
|
||||
bool QPSQLDriver::beginTransaction()
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ typedef struct pg_result PGresult;
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QPSQLResultPrivate;
|
||||
class QPSQLDriverPrivate;
|
||||
class QPSQLDriver;
|
||||
class QSqlRecordInfo;
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ class QPSQLResult : public QSqlResult
|
|||
{
|
||||
friend class QPSQLResultPrivate;
|
||||
public:
|
||||
QPSQLResult(const QPSQLDriver* db, const QPSQLDriverPrivate* p);
|
||||
QPSQLResult(const QPSQLDriver* db);
|
||||
~QPSQLResult();
|
||||
|
||||
QVariant handle() const;
|
||||
|
|
@ -101,8 +100,12 @@ private:
|
|||
QPSQLResultPrivate *d;
|
||||
};
|
||||
|
||||
class QPSQLDriverPrivate;
|
||||
|
||||
class Q_EXPORT_SQLDRIVER_PSQL QPSQLDriver : public QSqlDriver
|
||||
{
|
||||
friend class QPSQLResultPrivate;
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Protocol {
|
||||
|
|
|
|||
Loading…
Reference in New Issue