SQL/PSQL: remove non utf-8 support
PostgreSQL supports the utf-8 encoding ('UNICODE') since at least version 7.3 which is the oldest version we support. Therefore remove the non utf-8 codepath completely. Change-Id: I64b1a4e7b0b85141fe13f5f57e6f35f9eb7d542e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
dbcad6392b
commit
a74059f2bd
@ -125,7 +125,6 @@ public:
|
|||||||
int stmtCount = 0;
|
int stmtCount = 0;
|
||||||
mutable bool pendingNotifyCheck = false;
|
mutable bool pendingNotifyCheck = false;
|
||||||
bool hasBackslashEscape = false;
|
bool hasBackslashEscape = false;
|
||||||
bool isUtf8 = false;
|
|
||||||
|
|
||||||
void appendTables(QStringList &tl, QSqlQuery &t, QChar type);
|
void appendTables(QStringList &tl, QSqlQuery &t, QChar type);
|
||||||
PGresult *exec(const char *stmt);
|
PGresult *exec(const char *stmt);
|
||||||
@ -175,7 +174,7 @@ PGresult *QPSQLDriverPrivate::exec(const char *stmt)
|
|||||||
|
|
||||||
PGresult *QPSQLDriverPrivate::exec(const QString &stmt)
|
PGresult *QPSQLDriverPrivate::exec(const QString &stmt)
|
||||||
{
|
{
|
||||||
return exec((isUtf8 ? stmt.toUtf8() : stmt.toLocal8Bit()).constData());
|
return exec(stmt.toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementId QPSQLDriverPrivate::sendQuery(const QString &stmt)
|
StatementId QPSQLDriverPrivate::sendQuery(const QString &stmt)
|
||||||
@ -183,8 +182,7 @@ StatementId QPSQLDriverPrivate::sendQuery(const QString &stmt)
|
|||||||
// Discard any prior query results that the application didn't eat.
|
// Discard any prior query results that the application didn't eat.
|
||||||
// This is required for PQsendQuery()
|
// This is required for PQsendQuery()
|
||||||
discardResults();
|
discardResults();
|
||||||
const int result = PQsendQuery(connection,
|
const int result = PQsendQuery(connection, stmt.toUtf8().constData());
|
||||||
(isUtf8 ? stmt.toUtf8() : stmt.toLocal8Bit()).constData());
|
|
||||||
currentStmtId = result ? generateStatementId() : InvalidStatementId;
|
currentStmtId = result ? generateStatementId() : InvalidStatementId;
|
||||||
return currentStmtId;
|
return currentStmtId;
|
||||||
}
|
}
|
||||||
@ -274,7 +272,7 @@ static QSqlError qMakeError(const QString &err, QSqlError::ErrorType type,
|
|||||||
const QPSQLDriverPrivate *p, PGresult *result = nullptr)
|
const QPSQLDriverPrivate *p, PGresult *result = nullptr)
|
||||||
{
|
{
|
||||||
const char *s = PQerrorMessage(p->connection);
|
const char *s = PQerrorMessage(p->connection);
|
||||||
QString msg = p->isUtf8 ? QString::fromUtf8(s) : QString::fromLocal8Bit(s);
|
QString msg = QString::fromUtf8(s);
|
||||||
QString errorCode;
|
QString errorCode;
|
||||||
if (result) {
|
if (result) {
|
||||||
errorCode = QString::fromLatin1(PQresultErrorField(result, PG_DIAG_SQLSTATE));
|
errorCode = QString::fromLatin1(PQresultErrorField(result, PG_DIAG_SQLSTATE));
|
||||||
@ -606,7 +604,7 @@ QVariant QPSQLResult::data(int i)
|
|||||||
case QMetaType::Bool:
|
case QMetaType::Bool:
|
||||||
return QVariant((bool)(val[0] == 't'));
|
return QVariant((bool)(val[0] == 't'));
|
||||||
case QMetaType::QString:
|
case QMetaType::QString:
|
||||||
return d->drv_d_func()->isUtf8 ? QString::fromUtf8(val) : QString::fromLatin1(val);
|
return QString::fromUtf8(val);
|
||||||
case QMetaType::LongLong:
|
case QMetaType::LongLong:
|
||||||
if (val[0] == '-')
|
if (val[0] == '-')
|
||||||
return QByteArray::fromRawData(val, qstrlen(val)).toLongLong();
|
return QByteArray::fromRawData(val, qstrlen(val)).toLongLong();
|
||||||
@ -747,10 +745,7 @@ QSqlRecord QPSQLResult::record() const
|
|||||||
int count = PQnfields(d->result);
|
int count = PQnfields(d->result);
|
||||||
QSqlField f;
|
QSqlField f;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
if (d->drv_d_func()->isUtf8)
|
|
||||||
f.setName(QString::fromUtf8(PQfname(d->result, i)));
|
f.setName(QString::fromUtf8(PQfname(d->result, i)));
|
||||||
else
|
|
||||||
f.setName(QString::fromLocal8Bit(PQfname(d->result, i)));
|
|
||||||
const int tableOid = PQftable(d->result, i);
|
const int tableOid = PQftable(d->result, i);
|
||||||
// WARNING: We cannot execute any other SQL queries on
|
// WARNING: We cannot execute any other SQL queries on
|
||||||
// the same db connection while forward-only mode is active
|
// the same db connection while forward-only mode is active
|
||||||
@ -1125,6 +1120,7 @@ bool QPSQLDriver::hasFeature(DriverFeature f) const
|
|||||||
case EventNotifications:
|
case EventNotifications:
|
||||||
case MultipleResultSets:
|
case MultipleResultSets:
|
||||||
case BLOB:
|
case BLOB:
|
||||||
|
case Unicode:
|
||||||
return true;
|
return true;
|
||||||
case PreparedQueries:
|
case PreparedQueries:
|
||||||
case PositionalPlaceholders:
|
case PositionalPlaceholders:
|
||||||
@ -1135,8 +1131,6 @@ bool QPSQLDriver::hasFeature(DriverFeature f) const
|
|||||||
case FinishQuery:
|
case FinishQuery:
|
||||||
case CancelQuery:
|
case CancelQuery:
|
||||||
return false;
|
return false;
|
||||||
case Unicode:
|
|
||||||
return d->isUtf8;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1194,7 +1188,13 @@ bool QPSQLDriver::open(const QString &db,
|
|||||||
|
|
||||||
d->pro = d->getPSQLVersion();
|
d->pro = d->getPSQLVersion();
|
||||||
d->detectBackslashEscape();
|
d->detectBackslashEscape();
|
||||||
d->isUtf8 = d->setEncodingUtf8();
|
if (!d->setEncodingUtf8()) {
|
||||||
|
setLastError(qMakeError(tr("Unable to set client encoding to 'UNICODE'"), QSqlError::ConnectionError, d));
|
||||||
|
setOpenError(true);
|
||||||
|
PQfinish(d->connection);
|
||||||
|
d->connection = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
d->setDatestyle();
|
d->setDatestyle();
|
||||||
d->setByteaOutput();
|
d->setByteaOutput();
|
||||||
|
|
||||||
@ -1627,7 +1627,7 @@ void QPSQLDriver::_q_handleNotification()
|
|||||||
QString payload;
|
QString payload;
|
||||||
#if defined PG_VERSION_NUM && PG_VERSION_NUM-0 >= 70400
|
#if defined PG_VERSION_NUM && PG_VERSION_NUM-0 >= 70400
|
||||||
if (notify->extra)
|
if (notify->extra)
|
||||||
payload = d->isUtf8 ? QString::fromUtf8(notify->extra) : QString::fromLatin1(notify->extra);
|
payload = QString::fromUtf8(notify->extra);
|
||||||
#endif
|
#endif
|
||||||
QSqlDriver::NotificationSource source = (notify->be_pid == PQbackendPID(d->connection)) ? QSqlDriver::SelfSource : QSqlDriver::OtherSource;
|
QSqlDriver::NotificationSource source = (notify->be_pid == PQbackendPID(d->connection)) ? QSqlDriver::SelfSource : QSqlDriver::OtherSource;
|
||||||
emit notification(name, source, payload);
|
emit notification(name, source, payload);
|
||||||
|
Loading…
Reference in New Issue
Block a user