Skip to content

Commit

Permalink
fix SQL_DESC_OCTET_LENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Sep 1, 2017
1 parent 295f92d commit d0fdb8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions driver/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};


Expand Down
7 changes: 5 additions & 2 deletions driver/odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
10 changes: 10 additions & 0 deletions driver/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d0fdb8a

Please sign in to comment.