mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 19:25:53 +02:00
UnixODBC Unicode support (!not tested!)
This commit is contained in:
@@ -10,8 +10,10 @@ include $(POCO_BASE)/build/rules/global
|
||||
|
||||
ifeq (0, $(shell test -e /usr/lib/libodbc.so; echo $$?))
|
||||
SYSLIBS += -lodbc -lodbcinst
|
||||
COMMONFLAGS += -DPOCO_UNIXODBC
|
||||
else ifeq (0, $(shell test -e /usr/lib/libiodbc.so; echo $$?))
|
||||
SYSLIBS += -liodbc -liodbcinst
|
||||
COMMONFLAGS += -DPOCO_IODBC
|
||||
else
|
||||
$(error No ODBC library found. Please install unixODBC or iODBC and try again)
|
||||
endif
|
||||
|
@@ -278,7 +278,7 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Unicode_UNIX.h"
|
||||
RelativePath=".\include\Poco\Data\ODBC\Unicode_UNIXODBC.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -346,7 +346,7 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Unicode_UNIX.cpp"
|
||||
RelativePath=".\src\Unicode_UNIXODBC.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="debug_shared|Win32"
|
||||
|
@@ -57,7 +57,11 @@
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#define POCO_ODBC_UNICODE_WINDOWS
|
||||
#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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
///
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// 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
|
||||
// Package: ODBC
|
||||
@@ -45,45 +45,47 @@ namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
inline void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, Poco::Buffer<SQLWCHAR>& target)
|
||||
/// Utility function for conversion from ASCII to UTF-16
|
||||
inline void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::string& target)
|
||||
/// Utility function for conversion from UTF-8 to UTF-16
|
||||
{
|
||||
/*TODO
|
||||
int len = length;
|
||||
if (SQL_NTS == len)
|
||||
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)
|
||||
/// Utility function for conversion from ASCII to UTF-16.
|
||||
inline void makeUTF16(SQLCHAR* pSQLChar, SQLSMALLINT length, std::string& target)
|
||||
/// Utility function for conversion from UTF-8 to UTF-16.
|
||||
{
|
||||
/*TODO
|
||||
makeUTF16(pSQLChar, (SQLINTEGER) length, target);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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::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)
|
||||
{
|
||||
/*TODO
|
||||
makeUTF8(buffer, length, pTarget, (SQLINTEGER) targetLength);
|
||||
*/
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,6 @@
|
||||
|
||||
#if defined(POCO_ODBC_UNICODE_WINDOWS)
|
||||
#include "Unicode_WIN32.cpp"
|
||||
#elif defined(POCO_ODBC_UNICODE_UNIX)
|
||||
#include "Unicode_UNIX.cpp"
|
||||
#elif defined(POCO_ODBC_UNICODE_UNIXODBC)
|
||||
#include "Unicode_UNIXODBC.cpp"
|
||||
#endif
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Unicode.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/Unicode_UNIX.cpp#3 $
|
||||
// $Id: //poco/Main/Data/ODBC/src/Unicode_UNIXODBC.cpp#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Unicode_UNIX.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
@@ -109,19 +110,19 @@ SQLRETURN SQLConnect(SQLHDBC hdbc,
|
||||
SQLCHAR* szAuthStr,
|
||||
SQLSMALLINT cbAuthStr)
|
||||
{
|
||||
Buffer<SQLWCHAR> sqlDSN(cbDSN);
|
||||
std::string sqlDSN;
|
||||
makeUTF16(szDSN, cbDSN, sqlDSN);
|
||||
|
||||
Buffer<SQLWCHAR> sqlUID(cbUID);
|
||||
std::string sqlUID;
|
||||
makeUTF16(szUID, cbUID, sqlUID);
|
||||
|
||||
Buffer<SQLWCHAR> sqlPWD(cbAuthStr);
|
||||
std::string sqlPWD;
|
||||
makeUTF16(szAuthStr, cbAuthStr, sqlPWD);
|
||||
|
||||
return SQLConnectW(hdbc,
|
||||
sqlDSN.begin(), cbDSN,
|
||||
sqlUID.begin(), cbUID,
|
||||
sqlPWD.begin(), cbAuthStr);
|
||||
(SQLWCHAR*) sqlDSN.c_str(), cbDSN,
|
||||
(SQLWCHAR*) sqlUID.c_str(), cbUID,
|
||||
(SQLWCHAR*) sqlPWD.c_str(), cbAuthStr);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,10 +170,10 @@ SQLRETURN SQLExecDirect(SQLHSTMT hstmt,
|
||||
SQLCHAR* szSqlStr,
|
||||
SQLINTEGER cbSqlStr)
|
||||
{
|
||||
Buffer<SQLWCHAR> sqlStr(cbSqlStr);
|
||||
std::string 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))
|
||||
{
|
||||
Buffer<SQLWCHAR> str(cbValueMax);
|
||||
std::string str;
|
||||
makeUTF16((SQLCHAR*) rgbValue, cbValueMax, str);
|
||||
|
||||
return SQLSetDescFieldW(hdesc,
|
||||
iRecord,
|
||||
iField,
|
||||
(SQLPOINTER) str.begin(),
|
||||
(SQLPOINTER) str.c_str(),
|
||||
(SQLINTEGER) str.size() * sizeof(SQLWCHAR));
|
||||
}
|
||||
|
||||
@@ -356,10 +357,10 @@ SQLRETURN SQLPrepare(SQLHSTMT hstmt,
|
||||
SQLCHAR* szSqlStr,
|
||||
SQLINTEGER cbSqlStr)
|
||||
{
|
||||
Buffer<SQLWCHAR> sqlStr(cbSqlStr);
|
||||
std::string 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))
|
||||
{
|
||||
Buffer<SQLWCHAR> str(cbValue);
|
||||
std::string str;
|
||||
makeUTF16((SQLCHAR*) rgbValue, cbValue, str);
|
||||
|
||||
return SQLSetConnectAttrW(hdbc,
|
||||
fAttribute,
|
||||
str.begin(),
|
||||
(SQLWCHAR*) str.c_str(),
|
||||
(SQLINTEGER) str.size() * sizeof(SQLWCHAR));
|
||||
}
|
||||
|
||||
@@ -398,12 +399,12 @@ SQLRETURN SQLSetStmtAttr(SQLHSTMT hstmt,
|
||||
{
|
||||
if (isString(rgbValue, cbValueMax))
|
||||
{
|
||||
Buffer<SQLWCHAR> str(cbValueMax);
|
||||
std::string str;
|
||||
makeUTF16((SQLCHAR*) rgbValue, cbValueMax, str);
|
||||
|
||||
return SQLSetStmtAttrW(hstmt,
|
||||
fAttribute,
|
||||
str.begin(),
|
||||
(SQLWCHAR*) str.c_str(),
|
||||
(SQLINTEGER) str.size());
|
||||
}
|
||||
|
||||
@@ -577,13 +578,13 @@ SQLRETURN SQLDriverConnect(SQLHDBC hdbc,
|
||||
if (SQL_NTS == len)
|
||||
len = (SQLSMALLINT) std::strlen((const char*) szConnStrIn) + 1;
|
||||
|
||||
Buffer<SQLWCHAR> connStrIn(len);
|
||||
std::string connStrIn;
|
||||
makeUTF16(szConnStrIn, len, connStrIn);
|
||||
|
||||
Buffer<SQLWCHAR> out(cbConnStrOutMax);
|
||||
SQLRETURN rc = SQLDriverConnectW(hdbc,
|
||||
hwnd,
|
||||
connStrIn.begin(),
|
||||
(SQLWCHAR*) connStrIn.c_str(),
|
||||
(SQLSMALLINT) connStrIn.size(),
|
||||
out.begin(),
|
||||
cbConnStrOutMax,
|
||||
@@ -603,13 +604,13 @@ SQLRETURN SQLBrowseConnect(SQLHDBC hdbc,
|
||||
SQLSMALLINT cbConnStrOutMax,
|
||||
SQLSMALLINT* pcbConnStrOut)
|
||||
{
|
||||
Buffer<SQLWCHAR> str(cbConnStrIn);
|
||||
std::string str;
|
||||
makeUTF16(szConnStrIn, cbConnStrIn, str);
|
||||
|
||||
Buffer<SQLWCHAR> bufConnStrOut(cbConnStrOutMax);
|
||||
|
||||
SQLRETURN rc = SQLBrowseConnectW(hdbc,
|
||||
str.begin(),
|
||||
(SQLWCHAR*) str.c_str(),
|
||||
(SQLSMALLINT) str.size(),
|
||||
bufConnStrOut.begin(),
|
||||
(SQLSMALLINT) bufConnStrOut.size(),
|
||||
@@ -660,13 +661,13 @@ SQLRETURN SQLNativeSql(SQLHDBC hdbc,
|
||||
SQLINTEGER cbSqlStrMax,
|
||||
SQLINTEGER* pcbSqlStr)
|
||||
{
|
||||
Buffer<SQLWCHAR> str(cbSqlStrIn);
|
||||
std::string str;
|
||||
makeUTF16(szSqlStrIn, cbSqlStrIn, str);
|
||||
|
||||
Buffer<SQLWCHAR> bufSQLOut(cbSqlStrMax);
|
||||
|
||||
SQLRETURN rc = SQLNativeSqlW(hdbc,
|
||||
str.begin(),
|
||||
(SQLWCHAR*) str.c_str(),
|
||||
(SQLINTEGER) str.size(),
|
||||
bufSQLOut.begin(),
|
||||
(SQLINTEGER) bufSQLOut.size(),
|
Reference in New Issue
Block a user