SQL/PSQL: use a QByteArray for preparedStmtId
... instead a QString as it gets converted to an utf-8 string anyway to avoid this conversion. Task-number: QTBUG-132303 Change-Id: I3fcf721f9fd0d1dd181af262663fddd532262ee3 Reviewed-by: Thierry Bastian <thierryb@filewave.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 892a020cc3ad7e3d5cdcb38d26091343e78695da) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d5c5f9f352
commit
1a6b177ec7
@ -264,7 +264,7 @@ public:
|
|||||||
void deallocatePreparedStmt();
|
void deallocatePreparedStmt();
|
||||||
|
|
||||||
std::queue<PGresult*> nextResultSets;
|
std::queue<PGresult*> nextResultSets;
|
||||||
QString preparedStmtId;
|
QByteArray preparedStmtId;
|
||||||
PGresult *result = nullptr;
|
PGresult *result = nullptr;
|
||||||
StatementId stmtId = InvalidStatementId;
|
StatementId stmtId = InvalidStatementId;
|
||||||
int currentSize = -1;
|
int currentSize = -1;
|
||||||
@ -384,10 +384,10 @@ void QPSQLResultPrivate::deallocatePreparedStmt()
|
|||||||
{
|
{
|
||||||
if (drv_d_func() && !preparedStmtId.isEmpty()) {
|
if (drv_d_func() && !preparedStmtId.isEmpty()) {
|
||||||
#if defined(LIBPQ_HAS_CLOSE_PREPARED)
|
#if defined(LIBPQ_HAS_CLOSE_PREPARED)
|
||||||
PGresult *result = PQclosePrepared(drv_d_func()->connection, preparedStmtId.toUtf8());
|
PGresult *result = PQclosePrepared(drv_d_func()->connection, preparedStmtId.constData());
|
||||||
#else
|
#else
|
||||||
const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId;
|
const QByteArray stmt = QByteArrayView("DEALLOCATE ") + preparedStmtId;
|
||||||
PGresult *result = drv_d_func()->exec(stmt);
|
PGresult *result = drv_d_func()->exec(stmt.constData());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
||||||
@ -839,11 +839,10 @@ static auto qCreateParam(QSqlField &f, const QVariant &boundValue, const QPSQLDr
|
|||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString qMakePreparedStmtId()
|
static inline QByteArray qMakePreparedStmtId()
|
||||||
{
|
{
|
||||||
Q_CONSTINIT static QBasicAtomicInt qPreparedStmtCount = Q_BASIC_ATOMIC_INITIALIZER(0);
|
Q_CONSTINIT static QBasicAtomicInt qPreparedStmtCount = Q_BASIC_ATOMIC_INITIALIZER(0);
|
||||||
QString id = QStringLiteral("qpsqlpstmt_") + QString::number(qPreparedStmtCount.fetchAndAddRelaxed(1) + 1, 16);
|
return QByteArrayView("qpsqlpstmt_") + QByteArray::number(qPreparedStmtCount.fetchAndAddRelaxed(1) + 1, 16);
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QPSQLResult::prepare(const QString &query)
|
bool QPSQLResult::prepare(const QString &query)
|
||||||
@ -856,8 +855,8 @@ bool QPSQLResult::prepare(const QString &query)
|
|||||||
|
|
||||||
d->deallocatePreparedStmt();
|
d->deallocatePreparedStmt();
|
||||||
|
|
||||||
const QString stmtId = qMakePreparedStmtId();
|
const QByteArray stmtId = qMakePreparedStmtId();
|
||||||
PGresult *result = PQprepare(d->drv_d_func()->connection, stmtId.toUtf8(),
|
PGresult *result = PQprepare(d->drv_d_func()->connection, stmtId.constData(),
|
||||||
d->positionalToNamedBinding(query).toUtf8(), 0, nullptr);
|
d->positionalToNamedBinding(query).toUtf8(), 0, nullptr);
|
||||||
|
|
||||||
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
||||||
@ -898,7 +897,7 @@ bool QPSQLResult::exec()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->result = PQexecPrepared(d->drv_d_func()->connection, d->preparedStmtId.toUtf8(), pgParams.size(),
|
d->result = PQexecPrepared(d->drv_d_func()->connection, d->preparedStmtId.constData(), pgParams.size(),
|
||||||
pgParams.data(), pgParamLengths.data(), pgParamFormats.data(), 0);
|
pgParams.data(), pgParamLengths.data(), pgParamFormats.data(), 0);
|
||||||
|
|
||||||
const auto status = PQresultStatus(d->result);
|
const auto status = PQresultStatus(d->result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user