diff --git a/driver/environment.h b/driver/environment.h index 20ae74a6f..679d20d93 100644 --- a/driver/environment.h +++ b/driver/environment.h @@ -21,6 +21,11 @@ struct TypeInfo sql_type == SQL_TINYINT || sql_type == SQL_SMALLINT || sql_type == SQL_INTEGER || sql_type == SQL_BIGINT; } + + inline bool IsStringType() const + { + return sql_type == SQL_VARCHAR; + } }; diff --git a/driver/odbc.cpp b/driver/odbc.cpp index ed5448390..b1f7a6629 100644 --- a/driver/odbc.cpp +++ b/driver/odbc.cpp @@ -236,9 +236,12 @@ SQLColAttribute(HSTMT statement_handle, SQLUSMALLINT column_number, SQLUSMALLINT num_value = column_info.is_nullable; break; case SQL_DESC_OCTET_LENGTH: - if (column_info.fixed_size) + if (type_info.IsStringType()) { - num_value = column_info.fixed_size; + if (column_info.fixed_size) + num_value = column_info.fixed_size * SIZEOF_CHAR; + else + num_value = type_info.octet_length * SIZEOF_CHAR; } else { diff --git a/driver/platform.h b/driver/platform.h index ff938c970..eb7fd01a5 100644 --- a/driver/platform.h +++ b/driver/platform.h @@ -50,3 +50,13 @@ # define LPCTSTR const char* # define TEXT(value) value #endif + +#if defined (UNICODE) +# if defined (_win_) +# define SIZEOF_CHAR sizeof(uint_least16_t) +# else +# define SIZEOF_CHAR sizeof(char16_t) +# endif +#else +# define SIZEOF_CHAR sizeof(char) +#endif