SQLSMALLINT ansi_to_wtype(const ConnectionClass *self, SQLSMALLINT ansitype) { #ifndef UNICODE_SUPPORT return ansitype; #else if (!ALLOW_WCHAR(self)) return ansitype; switch (ansitype) { case SQL_CHAR: return SQL_WCHAR; case SQL_VARCHAR: return SQL_WVARCHAR; case SQL_LONGVARCHAR: return SQL_WLONGVARCHAR; } return ansitype; #endif /* UNICODE_SUPPORT */ }
SQLSMALLINT pgtype_to_ctype(StatementClass *stmt, OID type) { ConnectionClass *conn = SC_get_conn(stmt); ConnInfo *ci = &(conn->connInfo); #if (ODBCVER >= 0x0300) EnvironmentClass *env = (EnvironmentClass *) CC_get_env(conn); #endif /* ODBCVER */ switch (type) { case PG_TYPE_INT8: #if (ODBCVER >= 0x0300) if (!conn->ms_jet) return ALLOWED_C_BIGINT; #endif /* ODBCVER */ return SQL_C_CHAR; case PG_TYPE_NUMERIC: return SQL_C_CHAR; case PG_TYPE_INT2: return SQL_C_SSHORT; case PG_TYPE_OID: case PG_TYPE_XID: return SQL_C_ULONG; case PG_TYPE_INT4: return SQL_C_SLONG; case PG_TYPE_FLOAT4: return SQL_C_FLOAT; case PG_TYPE_FLOAT8: return SQL_C_DOUBLE; case PG_TYPE_DATE: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_C_TYPE_DATE; #endif /* ODBCVER */ return SQL_C_DATE; case PG_TYPE_TIME: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_C_TYPE_TIME; #endif /* ODBCVER */ return SQL_C_TIME; case PG_TYPE_ABSTIME: case PG_TYPE_DATETIME: case PG_TYPE_TIMESTAMP_NO_TMZONE: case PG_TYPE_TIMESTAMP: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_C_TYPE_TIMESTAMP; #endif /* ODBCVER */ return SQL_C_TIMESTAMP; case PG_TYPE_MONEY: return SQL_C_FLOAT; case PG_TYPE_BOOL: return ci->drivers.bools_as_char ? SQL_C_CHAR : SQL_C_BIT; case PG_TYPE_BYTEA: return SQL_C_BINARY; case PG_TYPE_LO_UNDEFINED: return SQL_C_BINARY; #ifdef UNICODE_SUPPORT case PG_TYPE_BPCHAR: case PG_TYPE_VARCHAR: case PG_TYPE_TEXT: if (CC_is_in_unicode_driver(conn) #ifdef NOT_USED && ! stmt->catalog_result #endif /* NOT USED */ ) return SQL_C_WCHAR; return SQL_C_CHAR; #endif /* UNICODE_SUPPORT */ case PG_TYPE_UUID: #if (ODBCVER >= 0x0350) if (!conn->ms_jet) return SQL_C_GUID; #endif /* ODBCVER */ return SQL_C_CHAR; default: /* hack until permanent type is available */ if (type == stmt->hdbc->lobj_type) return SQL_C_BINARY; /* Experimental, Does this work ? */ #ifdef EXPERIMENTAL_CURRENTLY if (ALLOW_WCHAR(conn)) return SQL_C_WCHAR; #endif /* EXPERIMENTAL_CURRENTLY */ return SQL_C_CHAR; } }
/* * There are two ways of calling this function: * * 1. When going through the supported PG types (SQLGetTypeInfo) * * 2. When taking any type id (SQLColumns, SQLGetData) * * The first type will always work because all the types defined are returned here. * The second type will return a default based on global parameter when it does not * know. This allows for supporting * types that are unknown. All other pg routines in here return a suitable default. */ SQLSMALLINT pgtype_to_concise_type(StatementClass *stmt, OID type, int col) { ConnectionClass *conn = SC_get_conn(stmt); ConnInfo *ci = &(conn->connInfo); #if (ODBCVER >= 0x0300) EnvironmentClass *env = (EnvironmentClass *) CC_get_env(conn); #endif /* ODBCVER */ switch (type) { case PG_TYPE_CHAR: case PG_TYPE_CHAR2: case PG_TYPE_CHAR4: case PG_TYPE_CHAR8: return ALLOW_WCHAR(conn) ? SQL_WCHAR : SQL_CHAR; case PG_TYPE_NAME: return ALLOW_WCHAR(conn) ? SQL_WVARCHAR : SQL_VARCHAR; #ifdef UNICODE_SUPPORT case PG_TYPE_BPCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) return ALLOW_WCHAR(conn) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; return ALLOW_WCHAR(conn) ? SQL_WCHAR : SQL_CHAR; case PG_TYPE_VARCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) return ALLOW_WCHAR(conn) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; return ALLOW_WCHAR(conn) ? SQL_WVARCHAR : SQL_VARCHAR; case PG_TYPE_TEXT: return ci->drivers.text_as_longvarchar ? (ALLOW_WCHAR(conn) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR) : (ALLOW_WCHAR(conn) ? SQL_WVARCHAR : SQL_VARCHAR); #else case PG_TYPE_BPCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) return SQL_LONGVARCHAR; return SQL_CHAR; case PG_TYPE_VARCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) return SQL_LONGVARCHAR; return SQL_VARCHAR; case PG_TYPE_TEXT: return ci->drivers.text_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR; #endif /* UNICODE_SUPPORT */ case PG_TYPE_BYTEA: if (ci->bytea_as_longvarbinary) return SQL_LONGVARBINARY; else return SQL_VARBINARY; case PG_TYPE_LO_UNDEFINED: return SQL_LONGVARBINARY; case PG_TYPE_INT2: return SQL_SMALLINT; case PG_TYPE_OID: case PG_TYPE_XID: case PG_TYPE_INT4: return SQL_INTEGER; /* Change this to SQL_BIGINT for ODBC v3 bjm 2001-01-23 */ case PG_TYPE_INT8: if (ci->int8_as != 0) return ci->int8_as; if (conn->ms_jet) return SQL_NUMERIC; /* maybe a little better than SQL_VARCHAR */ #if (ODBCVER >= 0x0300) return SQL_BIGINT; #else return SQL_VARCHAR; #endif /* ODBCVER */ case PG_TYPE_NUMERIC: return SQL_NUMERIC; case PG_TYPE_FLOAT4: return SQL_REAL; case PG_TYPE_FLOAT8: return SQL_FLOAT; case PG_TYPE_DATE: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_TYPE_DATE; #endif /* ODBCVER */ return SQL_DATE; case PG_TYPE_TIME: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_TYPE_TIME; #endif /* ODBCVER */ return SQL_TIME; case PG_TYPE_ABSTIME: case PG_TYPE_DATETIME: case PG_TYPE_TIMESTAMP_NO_TMZONE: case PG_TYPE_TIMESTAMP: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_TYPE_TIMESTAMP; #endif /* ODBCVER */ return SQL_TIMESTAMP; case PG_TYPE_MONEY: return SQL_FLOAT; case PG_TYPE_BOOL: return ci->drivers.bools_as_char ? SQL_CHAR : SQL_BIT; case PG_TYPE_XML: return CC_is_in_unicode_driver(conn) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; case PG_TYPE_INET: case PG_TYPE_CIDR: case PG_TYPE_MACADDR: return CC_is_in_unicode_driver(conn) ? SQL_WVARCHAR : SQL_VARCHAR; case PG_TYPE_UUID: #if (ODBCVER >= 0x0350) return SQL_GUID; #endif /* ODBCVER */ return CC_is_in_unicode_driver(conn) ? SQL_WVARCHAR : SQL_VARCHAR; default: /* * first, check to see if 'type' is in list. If not, look up * with query. Add oid, name to list. If it's already in * list, just return. */ /* hack until permanent type is available */ if (type == stmt->hdbc->lobj_type) return SQL_LONGVARBINARY; #ifdef EXPERIMENTAL_CURRENTLY if (ALLOW_WCHAR(conn)) return ci->drivers.unknowns_as_longvarchar ? SQL_WLONGVARCHAR : SQL_WVARCHAR; #endif /* EXPERIMENTAL_CURRENTLY */ return ci->drivers.unknowns_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR; } }
SQLSMALLINT sqltype_to_default_ctype(const ConnectionClass *conn, SQLSMALLINT sqltype) { /* * from the table on page 623 of ODBC 2.0 Programmer's Reference * (Appendix D) */ switch (sqltype) { case SQL_CHAR: case SQL_VARCHAR: case SQL_LONGVARCHAR: case SQL_DECIMAL: case SQL_NUMERIC: #if (ODBCVER < 0x0300) case SQL_BIGINT: return SQL_C_CHAR; #else return SQL_C_CHAR; case SQL_BIGINT: return ALLOWED_C_BIGINT; #endif #ifdef UNICODE_SUPPORT case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR: if (!ALLOW_WCHAR(conn)) return SQL_C_CHAR; return SQL_C_WCHAR; #endif /* UNICODE_SUPPORT */ case SQL_BIT: return SQL_C_BIT; case SQL_TINYINT: return SQL_C_STINYINT; case SQL_SMALLINT: return SQL_C_SSHORT; case SQL_INTEGER: return SQL_C_SLONG; case SQL_REAL: return SQL_C_FLOAT; case SQL_FLOAT: case SQL_DOUBLE: return SQL_C_DOUBLE; case SQL_BINARY: case SQL_VARBINARY: case SQL_LONGVARBINARY: return SQL_C_BINARY; case SQL_DATE: return SQL_C_DATE; case SQL_TIME: return SQL_C_TIME; case SQL_TIMESTAMP: return SQL_C_TIMESTAMP; #if (ODBCVER >= 0x0300) case SQL_TYPE_DATE: return SQL_C_TYPE_DATE; case SQL_TYPE_TIME: return SQL_C_TYPE_TIME; case SQL_TYPE_TIMESTAMP: return SQL_C_TYPE_TIMESTAMP; #endif /* ODBCVER */ #if (ODBCVER >= 0x0350) case SQL_GUID: if (conn->ms_jet) return SQL_C_CHAR; else return SQL_C_GUID; #endif /* ODBCVER */ default: /* should never happen */ return SQL_C_CHAR; } }