summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp31
-rw-r--r--src/sql/kernel/qsqlquery.cpp25
2 files changed, 44 insertions, 12 deletions
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 <typename T>
@@ -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;
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index b08f6bc8ef..6b13eb02ed 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -511,12 +511,23 @@ const QSqlResult* QSqlQuery::result() const
\list
- \li If the result is currently positioned before the first record or
- on the first record, and \a index is negative, there is no change,
- and false is returned.
+ \li If the result is currently positioned before the first record and:
+ \list
+ \li \a index is negative or zero, there is no change, and false is
+ returned.
+ \li \a index is positive, an attempt is made to position the result
+ at absolute position \a index - 1, following the sames rule for non
+ relative seek, above.
+ \endlist
- \li If the result is currently located after the last record, and \a
- index is positive, there is no change, and false is returned.
+ \li If the result is currently positioned after the last record and:
+ \list
+ \li \a index is positive or zero, there is no change, and false is
+ returned.
+ \li \a index is negative, an attempt is made to position the result
+ at \a index + 1 relative position from last record, following the
+ rule below.
+ \endlist
\li If the result is currently located somewhere in the middle, and
the relative offset \a index moves the result below zero, the result
@@ -549,7 +560,7 @@ bool QSqlQuery::seek(int index, bool relative)
switch (at()) { // relative seek
case QSql::BeforeFirstRow:
if (index > 0)
- actualIdx = index;
+ actualIdx = index - 1;
else {
return false;
}
@@ -557,7 +568,7 @@ bool QSqlQuery::seek(int index, bool relative)
case QSql::AfterLastRow:
if (index < 0) {
d->sqlResult->fetchLast();
- actualIdx = at() + index;
+ actualIdx = at() + index + 1;
} else {
return false;
}