From f1eefd6cf99b2784b10390b7accf6bbe49245906 Mon Sep 17 00:00:00 2001 From: parihaaraka Date: Fri, 14 Jun 2013 22:38:43 +0400 Subject: Fix PSQL column's metadata Fixed libpq's PQfmod() interpretation inside QPSQLResult::record() Task-number: QTBUG-12477 Change-Id: I0e4c94ca1b06fd6a8e5b5702235cdd6d9736f8bf Reviewed-by: Andy Shaw Reviewed-by: Mark Brand --- src/sql/drivers/psql/qsql_psql.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index c052e4c2e7..722595ad52 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -104,6 +104,11 @@ #define QXIDOID 28 #define QCIDOID 29 +#define QBITOID 1560 +#define QVARBITOID 1562 + +#define VARHDRSZ 4 + /* This is a compile time switch - if PQfreemem is declared, the compiler will use that one, otherwise it'll run in this template */ template @@ -533,17 +538,33 @@ QSqlRecord QPSQLResult::record() const f.setName(QString::fromUtf8(PQfname(d->result, i))); else f.setName(QString::fromLocal8Bit(PQfname(d->result, i))); - f.setType(qDecodePSQLType(PQftype(d->result, i))); + int ptype = PQftype(d->result, i); + f.setType(qDecodePSQLType(ptype)); int len = PQfsize(d->result, i); int precision = PQfmod(d->result, i); - // swap length and precision if length == -1 - if (len == -1 && precision > -1) { - len = precision - 4; + + switch (ptype) { + case QNUMERICOID: + if (precision != -1) { + len = (precision >> 16); + precision = ((precision - VARHDRSZ) & 0xffff); + } + break; + case QBITOID: + case QVARBITOID: + len = precision; precision = -1; + break; + default: + if (len == -1 && precision >= VARHDRSZ) { + len = precision - VARHDRSZ; + precision = -1; + } } + f.setLength(len); f.setPrecision(precision); - f.setSqlType(PQftype(d->result, i)); + f.setSqlType(ptype); info.append(f); } return info; -- cgit v1.2.3