Skip to content

Commit

Permalink
UNICODE fixes (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
proller authored Feb 1, 2019
1 parent 097a7af commit dbf1ac1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions driver/config_cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#cmakedefine01 ODBC_IODBC
#cmakedefine01 ODBC_UNIXODBC
#cmakedefine01 SQL_WCHART_CONVERT
#if !SQL_WCHART_CONVERT
# undef SQL_WCHART_CONVERT
#endif

#cmakedefine ODBC_LIBRARIES "@ODBC_LIBRARIES@"
#cmakedefine ODBC_INCLUDE_DIRECTORIES "@ODBC_INCLUDE_DIRECTORIES@"
Expand Down
2 changes: 1 addition & 1 deletion driver/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Environment::Environment() {
# endif
report += " sizeof(SQLTCHAR)=" + std::to_string(sizeof(SQLTCHAR)) + " sizeof(wchar_t)=" + std::to_string(sizeof(wchar_t));
#endif
#if SQL_WCHART_CONVERT
#if defined(SQL_WCHART_CONVERT)
report += " SQL_WCHART_CONVERT";
#endif
#if ODBCVER
Expand Down
2 changes: 1 addition & 1 deletion driver/odbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ RETCODE SQL_API SQLBindCol(HSTMT statement_handle,

return doWith<Statement>(statement_handle, [&](Statement & statement) {
if (column_number < 1 || column_number > statement.result.getNumColumns())
throw SqlException("Column number is out of range", "07009");
throw SqlException("Column number " + std::to_string(column_number) + " is out of range: " + std::to_string(statement.result.getNumColumns()), "07009");
if (out_value_max_size < 0)
throw SqlException("Invalid string or buffer length", "HY090");

Expand Down
10 changes: 8 additions & 2 deletions driver/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,25 @@ void stringToTCHAR(const std::string & data, STRING (&result)[Len])
#if defined(UNICODE)
# if ODBC_WCHAR
using CharType = wchar_t;
using StringType = std::wstring;
# else
using CharType = char16_t;
using StringType = std::u16string;
# endif

std::wstring tmp = std::wstring_convert<std::codecvt_utf8<CharType>, CharType>().from_bytes(data);
StringType tmp = std::wstring_convert<std::codecvt_utf8<CharType>, CharType>().from_bytes(data);
//using type_to = wchar_t*;
#else
const auto & tmp = data;
//using type_to = char*;
#endif
const size_t len = std::min<size_t>(Len - 1, data.size());
#if defined(UNICODE)
wcsncpy(reinterpret_cast<wchar_t*>(result), tmp.c_str(), len);
# if ODBC_WCHAR
wcsncpy(reinterpret_cast<CharType*>(result), tmp.c_str(), len);
#else
strncpy(reinterpret_cast<char*>(result), reinterpret_cast<const char*>(tmp.c_str()), len * sizeof(CharType)); // WRONG TODO
#endif
#else
strncpy(reinterpret_cast<char*>(result), tmp.c_str(), len);
#endif
Expand Down

0 comments on commit dbf1ac1

Please sign in to comment.