bugfix: bit/varbit type support

Quan Zongliang <[email protected]> Mon, 19 Nov 2018 19:37:16 +0800
Newsgroups gmane.comp.db.postgresql.odbc
Message-ID <[email protected]>
hi, all

patch attached,please review.

support the type BIT/BIT VARYING
1. calculate column length correctly.
2. reverse type name correctly

it cause SQLColAttribute can not get
SQL_DESC_BASE_COLUMN_NAME/SQL_DESC_TYPE_NAME.

--
Quan Zongliang
bittype.patch (text/plain, 1.8 KB)
diff --git a/columninfo.c b/columninfo.c
index 60bd89c..c0d67ab 100644
--- a/columninfo.c
+++ b/columninfo.c
@@ -95,6 +95,8 @@ CI_read_fields_from_pgres(ColumnInfoClass *self, PGresult *pgres)
 			case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			case PG_TYPE_TIME:
 			case PG_TYPE_TIME_WITH_TMZONE:
+			case PG_TYPE_BIT:
+			case PG_TYPE_VARBIT:
 				break;
 			default:
 				new_atttypmod -= 4;
diff --git a/info.c b/info.c
index 052f0ae..bdaa575 100644
--- a/info.c
+++ b/info.c
@@ -2705,6 +2705,7 @@ MYLOG(0, " and the data=%s\n", attdef);
 			case PG_TYPE_TIME:
 			case PG_TYPE_TIME_WITH_TMZONE:
 			case PG_TYPE_BIT:
+			case PG_TYPE_VARBIT:
 				break;
 			default:
 				if (mod_length >= 4)
diff --git a/pgtypes.c b/pgtypes.c
index 5f49137..1bf7d8a 100644
--- a/pgtypes.c
+++ b/pgtypes.c
@@ -840,6 +840,10 @@ MYLOG(DETAIL_LOG_LEVEL, "pgtype_to_name int4\n");
 			return "cidr";
 		case PG_TYPE_UUID:
 			return "uuid";
+		case PG_TYPE_BIT:
+			return "bit";
+		case PG_TYPE_VARBIT:
+			return "varbit";
 		case PG_TYPE_INTERVAL:
 			get_interval_type(atttypmod, &tname);
 			return tname;
diff --git a/pgtypes.h b/pgtypes.h
index 2b120bd..9703dee 100644
--- a/pgtypes.h
+++ b/pgtypes.h
@@ -58,6 +58,7 @@
 #define PG_TYPE_TIME_WITH_TMZONE	1266		/* since 7.1 */
 #define PG_TYPE_TIMESTAMP		1296	/* deprecated since 7.0 */
 #define PG_TYPE_BIT			1560
+#define PG_TYPE_VARBIT			1562
 #define PG_TYPE_NUMERIC			1700
 #define PG_TYPE_REFCURSOR		1790
 #define PG_TYPE_RECORD			2249
diff --git a/qresult.c b/qresult.c
index c89a3ea..ab899ef 100644
--- a/qresult.c
+++ b/qresult.c
@@ -625,6 +625,8 @@ QR_from_PGresult(QResultClass *self, StatementClass *stmt, ConnectionClass *conn
 			case PG_TYPE_TIMESTAMP_NO_TMZONE:
 			case PG_TYPE_TIME:
 			case PG_TYPE_TIME_WITH_TMZONE:
+			case PG_TYPE_BIT:
+			case PG_TYPE_VARBIT:
 				break;
 			default:
 				new_atttypmod -= 4;