UnixODBC Unicode support (!not tested!)

This commit is contained in:
Aleksandar Fabijanic
2008-01-02 00:20:06 +00:00
parent ad61968449
commit 6adc6346e6
6 changed files with 53 additions and 44 deletions

View File

@@ -10,8 +10,10 @@ include $(POCO_BASE)/build/rules/global
ifeq (0, $(shell test -e /usr/lib/libodbc.so; echo $$?)) ifeq (0, $(shell test -e /usr/lib/libodbc.so; echo $$?))
SYSLIBS += -lodbc -lodbcinst SYSLIBS += -lodbc -lodbcinst
COMMONFLAGS += -DPOCO_UNIXODBC
else ifeq (0, $(shell test -e /usr/lib/libiodbc.so; echo $$?)) else ifeq (0, $(shell test -e /usr/lib/libiodbc.so; echo $$?))
SYSLIBS += -liodbc -liodbcinst SYSLIBS += -liodbc -liodbcinst
COMMONFLAGS += -DPOCO_IODBC
else else
$(error No ODBC library found. Please install unixODBC or iODBC and try again) $(error No ODBC library found. Please install unixODBC or iODBC and try again)
endif endif

View File

@@ -278,7 +278,7 @@
> >
</File> </File>
<File <File
RelativePath=".\include\Poco\Data\ODBC\Unicode_UNIX.h" RelativePath=".\include\Poco\Data\ODBC\Unicode_UNIXODBC.h"
> >
</File> </File>
<File <File
@@ -346,7 +346,7 @@
> >
</File> </File>
<File <File
RelativePath=".\src\Unicode_UNIX.cpp" RelativePath=".\src\Unicode_UNIXODBC.cpp"
> >
<FileConfiguration <FileConfiguration
Name="debug_shared|Win32" Name="debug_shared|Win32"

View File

@@ -57,7 +57,11 @@
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8) #if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
#define POCO_ODBC_UNICODE_WINDOWS #define POCO_ODBC_UNICODE_WINDOWS
#elif defined(POCO_OS_FAMILY_UNIX) && defined(UNICODE) #elif defined(POCO_OS_FAMILY_UNIX) && defined(UNICODE)
#define POCO_ODBC_UNICODE_UNIX #ifdef POCO_UNIXODBC
#define POCO_ODBC_UNICODE_UNIXODBC
#elif defined(POCO_IODBC)
#error "iODBC Unicode not supported"
#endif
#endif #endif
@@ -374,7 +378,7 @@ inline SQLINTEGER stringLength(SQLPOINTER pValue, SQLINTEGER length)
} }
#if !defined(POCO_ODBC_UNICODE_WINDOWS) && !defined(POCO_ODBC_UNICODE_UNIX) #if !defined(POCO_ODBC_UNICODE_WINDOWS) && !defined(POCO_ODBC_UNICODE_UNIXODBC)
/// ///

View File

@@ -1,7 +1,7 @@
// //
// Unicode.h // Unicode.h
// //
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Unicode_UNIX.h#4 $ // $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Unicode_UNIXODBC.h#4 $
// //
// Library: ODBC // Library: ODBC
// Package: ODBC // Package: ODBC
@@ -45,45 +45,47 @@ namespace Data {
namespace ODBC { namespace ODBC {
inline void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, Poco::Buffer<SQLWCHAR>& target) inline void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::string& target)
/// Utility function for conversion from ASCII to UTF-16 /// Utility function for conversion from UTF-8 to UTF-16
{ {
/*TODO
int len = length; int len = length;
if (SQL_NTS == len) if (SQL_NTS == len)
len = (int) std::strlen((const char *) pSQLChar); len = (int) std::strlen((const char *) pSQLChar);
UnicodeConverter::toUTF16((const char *) pSQLChar, len, target); UTF8Encoding utf8Encoding;
*/ UTF16Encoding utf16Encoding;
TextConverter converter(utf8Encoding, utf16Encoding);
if (0 != converter.convert(pSQLChar, len, target))
throw SyntaxException("Error converting UTF-8 to UTF-16");
} }
inline void makeUTF16(SQLCHAR* pSQLChar, SQLSMALLINT length, Poco::Buffer<SQLWCHAR>& target) inline void makeUTF16(SQLCHAR* pSQLChar, SQLSMALLINT length, std::string& target)
/// Utility function for conversion from ASCII to UTF-16. /// Utility function for conversion from UTF-8 to UTF-16.
{ {
/*TODO
makeUTF16(pSQLChar, (SQLINTEGER) length, target); makeUTF16(pSQLChar, (SQLINTEGER) length, target);
*/
} }
inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLINTEGER targetLength) inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLINTEGER targetLength)
{ {
/*TODO UTF8Encoding utf8Encoding;
UTF16Encoding utf16Encoding;
TextConverter converter(utf16Encoding, utf8Encoding);
std::string result; std::string result;
UnicodeConverter::toUTF8(buffer.begin(), length, result); if (0 != converter.convert(buffer.begin(), length, result))
throw SyntaxException("Error converting UTF-16 to UTF-8");
std::memset(pTarget, 0, targetLength); std::memset(pTarget, 0, targetLength);
std::strncpy((char*) pTarget, result.c_str(), result.size() < targetLength ? result.size() : targetLength); std::strncpy((char*) pTarget, result.c_str(), result.size() < targetLength ? result.size() : targetLength);
*/
} }
inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLSMALLINT targetLength) inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLSMALLINT targetLength)
{ {
/*TODO
makeUTF8(buffer, length, pTarget, (SQLINTEGER) targetLength); makeUTF8(buffer, length, pTarget, (SQLINTEGER) targetLength);
*/
} }

View File

@@ -39,6 +39,6 @@
#if defined(POCO_ODBC_UNICODE_WINDOWS) #if defined(POCO_ODBC_UNICODE_WINDOWS)
#include "Unicode_WIN32.cpp" #include "Unicode_WIN32.cpp"
#elif defined(POCO_ODBC_UNICODE_UNIX) #elif defined(POCO_ODBC_UNICODE_UNIXODBC)
#include "Unicode_UNIX.cpp" #include "Unicode_UNIXODBC.cpp"
#endif #endif

View File

@@ -1,7 +1,7 @@
// //
// Unicode.cpp // Unicode.cpp
// //
// $Id: //poco/Main/Data/ODBC/src/Unicode_UNIX.cpp#3 $ // $Id: //poco/Main/Data/ODBC/src/Unicode_UNIXODBC.cpp#3 $
// //
// Library: ODBC // Library: ODBC
// Package: ODBC // Package: ODBC
@@ -35,6 +35,7 @@
#include "Poco/Data/ODBC/ODBC.h" #include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Unicode_UNIX.h"
#include "Poco/Buffer.h" #include "Poco/Buffer.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
@@ -109,19 +110,19 @@ SQLRETURN SQLConnect(SQLHDBC hdbc,
SQLCHAR* szAuthStr, SQLCHAR* szAuthStr,
SQLSMALLINT cbAuthStr) SQLSMALLINT cbAuthStr)
{ {
Buffer<SQLWCHAR> sqlDSN(cbDSN); std::string sqlDSN;
makeUTF16(szDSN, cbDSN, sqlDSN); makeUTF16(szDSN, cbDSN, sqlDSN);
Buffer<SQLWCHAR> sqlUID(cbUID); std::string sqlUID;
makeUTF16(szUID, cbUID, sqlUID); makeUTF16(szUID, cbUID, sqlUID);
Buffer<SQLWCHAR> sqlPWD(cbAuthStr); std::string sqlPWD;
makeUTF16(szAuthStr, cbAuthStr, sqlPWD); makeUTF16(szAuthStr, cbAuthStr, sqlPWD);
return SQLConnectW(hdbc, return SQLConnectW(hdbc,
sqlDSN.begin(), cbDSN, (SQLWCHAR*) sqlDSN.c_str(), cbDSN,
sqlUID.begin(), cbUID, (SQLWCHAR*) sqlUID.c_str(), cbUID,
sqlPWD.begin(), cbAuthStr); (SQLWCHAR*) sqlPWD.c_str(), cbAuthStr);
} }
@@ -169,10 +170,10 @@ SQLRETURN SQLExecDirect(SQLHSTMT hstmt,
SQLCHAR* szSqlStr, SQLCHAR* szSqlStr,
SQLINTEGER cbSqlStr) SQLINTEGER cbSqlStr)
{ {
Buffer<SQLWCHAR> sqlStr(cbSqlStr); std::string sqlStr;
makeUTF16(szSqlStr, cbSqlStr, sqlStr); makeUTF16(szSqlStr, cbSqlStr, sqlStr);
return SQLExecDirectW(hstmt, sqlStr.begin(), cbSqlStr); return SQLExecDirectW(hstmt, (SQLWCHAR*) sqlStr.c_str(), cbSqlStr);
} }
@@ -222,13 +223,13 @@ SQLRETURN SQLSetDescField(SQLHDESC hdesc,
{ {
if (isString(rgbValue, cbValueMax)) if (isString(rgbValue, cbValueMax))
{ {
Buffer<SQLWCHAR> str(cbValueMax); std::string str;
makeUTF16((SQLCHAR*) rgbValue, cbValueMax, str); makeUTF16((SQLCHAR*) rgbValue, cbValueMax, str);
return SQLSetDescFieldW(hdesc, return SQLSetDescFieldW(hdesc,
iRecord, iRecord,
iField, iField,
(SQLPOINTER) str.begin(), (SQLPOINTER) str.c_str(),
(SQLINTEGER) str.size() * sizeof(SQLWCHAR)); (SQLINTEGER) str.size() * sizeof(SQLWCHAR));
} }
@@ -356,10 +357,10 @@ SQLRETURN SQLPrepare(SQLHSTMT hstmt,
SQLCHAR* szSqlStr, SQLCHAR* szSqlStr,
SQLINTEGER cbSqlStr) SQLINTEGER cbSqlStr)
{ {
Buffer<SQLWCHAR> sqlStr(cbSqlStr); std::string sqlStr;
makeUTF16(szSqlStr, cbSqlStr, sqlStr); makeUTF16(szSqlStr, cbSqlStr, sqlStr);
return SQLPrepareW(hstmt, sqlStr.begin(), (SQLINTEGER) sqlStr.size()); return SQLPrepareW(hstmt, (SQLWCHAR*) sqlStr.c_str(), (SQLINTEGER) sqlStr.size());
} }
@@ -370,12 +371,12 @@ SQLRETURN SQLSetConnectAttr(SQLHDBC hdbc,
{ {
if (isString(rgbValue, cbValue)) if (isString(rgbValue, cbValue))
{ {
Buffer<SQLWCHAR> str(cbValue); std::string str;
makeUTF16((SQLCHAR*) rgbValue, cbValue, str); makeUTF16((SQLCHAR*) rgbValue, cbValue, str);
return SQLSetConnectAttrW(hdbc, return SQLSetConnectAttrW(hdbc,
fAttribute, fAttribute,
str.begin(), (SQLWCHAR*) str.c_str(),
(SQLINTEGER) str.size() * sizeof(SQLWCHAR)); (SQLINTEGER) str.size() * sizeof(SQLWCHAR));
} }
@@ -398,12 +399,12 @@ SQLRETURN SQLSetStmtAttr(SQLHSTMT hstmt,
{ {
if (isString(rgbValue, cbValueMax)) if (isString(rgbValue, cbValueMax))
{ {
Buffer<SQLWCHAR> str(cbValueMax); std::string str;
makeUTF16((SQLCHAR*) rgbValue, cbValueMax, str); makeUTF16((SQLCHAR*) rgbValue, cbValueMax, str);
return SQLSetStmtAttrW(hstmt, return SQLSetStmtAttrW(hstmt,
fAttribute, fAttribute,
str.begin(), (SQLWCHAR*) str.c_str(),
(SQLINTEGER) str.size()); (SQLINTEGER) str.size());
} }
@@ -577,13 +578,13 @@ SQLRETURN SQLDriverConnect(SQLHDBC hdbc,
if (SQL_NTS == len) if (SQL_NTS == len)
len = (SQLSMALLINT) std::strlen((const char*) szConnStrIn) + 1; len = (SQLSMALLINT) std::strlen((const char*) szConnStrIn) + 1;
Buffer<SQLWCHAR> connStrIn(len); std::string connStrIn;
makeUTF16(szConnStrIn, len, connStrIn); makeUTF16(szConnStrIn, len, connStrIn);
Buffer<SQLWCHAR> out(cbConnStrOutMax); Buffer<SQLWCHAR> out(cbConnStrOutMax);
SQLRETURN rc = SQLDriverConnectW(hdbc, SQLRETURN rc = SQLDriverConnectW(hdbc,
hwnd, hwnd,
connStrIn.begin(), (SQLWCHAR*) connStrIn.c_str(),
(SQLSMALLINT) connStrIn.size(), (SQLSMALLINT) connStrIn.size(),
out.begin(), out.begin(),
cbConnStrOutMax, cbConnStrOutMax,
@@ -603,13 +604,13 @@ SQLRETURN SQLBrowseConnect(SQLHDBC hdbc,
SQLSMALLINT cbConnStrOutMax, SQLSMALLINT cbConnStrOutMax,
SQLSMALLINT* pcbConnStrOut) SQLSMALLINT* pcbConnStrOut)
{ {
Buffer<SQLWCHAR> str(cbConnStrIn); std::string str;
makeUTF16(szConnStrIn, cbConnStrIn, str); makeUTF16(szConnStrIn, cbConnStrIn, str);
Buffer<SQLWCHAR> bufConnStrOut(cbConnStrOutMax); Buffer<SQLWCHAR> bufConnStrOut(cbConnStrOutMax);
SQLRETURN rc = SQLBrowseConnectW(hdbc, SQLRETURN rc = SQLBrowseConnectW(hdbc,
str.begin(), (SQLWCHAR*) str.c_str(),
(SQLSMALLINT) str.size(), (SQLSMALLINT) str.size(),
bufConnStrOut.begin(), bufConnStrOut.begin(),
(SQLSMALLINT) bufConnStrOut.size(), (SQLSMALLINT) bufConnStrOut.size(),
@@ -660,13 +661,13 @@ SQLRETURN SQLNativeSql(SQLHDBC hdbc,
SQLINTEGER cbSqlStrMax, SQLINTEGER cbSqlStrMax,
SQLINTEGER* pcbSqlStr) SQLINTEGER* pcbSqlStr)
{ {
Buffer<SQLWCHAR> str(cbSqlStrIn); std::string str;
makeUTF16(szSqlStrIn, cbSqlStrIn, str); makeUTF16(szSqlStrIn, cbSqlStrIn, str);
Buffer<SQLWCHAR> bufSQLOut(cbSqlStrMax); Buffer<SQLWCHAR> bufSQLOut(cbSqlStrMax);
SQLRETURN rc = SQLNativeSqlW(hdbc, SQLRETURN rc = SQLNativeSqlW(hdbc,
str.begin(), (SQLWCHAR*) str.c_str(),
(SQLINTEGER) str.size(), (SQLINTEGER) str.size(),
bufSQLOut.begin(), bufSQLOut.begin(),
(SQLINTEGER) bufSQLOut.size(), (SQLINTEGER) bufSQLOut.size(),