From 7828f16623b0f3a89992ef1b7ba1adfee9c3a37d Mon Sep 17 00:00:00 2001 From: Dave Page Date: Thu, 11 Aug 2005 14:08:28 +0000 Subject: [PATCH] Improve field length setup. Use the correct values for varchar and char, and SQL_NO_TOTAL for bytea and text. --- connection.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/connection.c b/connection.c index 2cb06b0..574a0ad 100644 --- a/connection.c +++ b/connection.c @@ -3239,14 +3239,8 @@ CC_mapping(PGresult *pgres,QResultClass *qres) { typid = PQftype(pgres,i); atttypmod = PQfmod(pgres,i); - - if (PG_TYPE_NUMERIC == typid) - typlen = ((atttypmod - 4) >> 16) & 0xffff; - else - typlen = PQfsize(pgres,i); - - if(typlen == -1 || PG_TYPE_VARCHAR == typid) - typlen = MAX_VARCHAR_SIZE; + + /* Setup the typmod */ switch (typid) { case PG_TYPE_DATETIME: @@ -3258,7 +3252,34 @@ CC_mapping(PGresult *pgres,QResultClass *qres) atttypmod -= 4; } if (atttypmod < 0) - atttypmod = -1; + atttypmod = -1; + + /* Setup the typlen */ + switch (typid) + { + case PG_TYPE_NUMERIC: + typlen = (atttypmod >> 16) & 0xffff; + break; + + case PG_TYPE_BPCHAR: + case PG_TYPE_VARCHAR: + typlen = atttypmod; + break; + + /* bytea and text have no defined maximum size, so we use SQL_NO_TOTAL per the docs */ + /* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbccolumn_size.asp */ + case PG_TYPE_BYTEA: + case PG_TYPE_TEXT: + typlen = SQL_NO_TOTAL; + break; + + default: + typlen = PQfsize(pgres,i); + } + + if(typlen == -1) + typlen = MAX_VARCHAR_SIZE; + CI_set_field_info(qres->fields, i, PQfname(pgres,i), typid, (Int2)typlen, atttypmod); } -- 2.39.5