mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 22:31:23 +01:00
unixODBC Unicode support (compiles, not tested)
This commit is contained in:
parent
6adc6346e6
commit
76079f5baa
@ -5,6 +5,12 @@
|
||||
#
|
||||
# Makefile for Poco ODBC
|
||||
#
|
||||
# For Unicode support, add following to COMMONFLAGS:
|
||||
#
|
||||
# -DUNICODE
|
||||
#
|
||||
# Unicode is supported only for UnixODBC
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
|
@ -176,10 +176,10 @@
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBC.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBCMetaColumn.h">
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBCException.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBCException.h">
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBCMetaColumn.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBCStatementImpl.h">
|
||||
@ -200,10 +200,34 @@
|
||||
RelativePath=".\include\Poco\Data\ODBC\Unicode.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Unicode_UNIX.h">
|
||||
RelativePath=".\include\Poco\Data\ODBC\Unicode_UNIXODBC.h">
|
||||
<FileConfiguration
|
||||
Name="debug_shared|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="release_shared|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Unicode_WIN32.h">
|
||||
<FileConfiguration
|
||||
Name="debug_shared|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="release_shared|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Utility.h">
|
||||
@ -228,10 +252,10 @@
|
||||
RelativePath=".\src\Extractor.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCMetaColumn.cpp">
|
||||
RelativePath=".\src\ODBCException.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCException.cpp">
|
||||
RelativePath=".\src\ODBCMetaColumn.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCStatementImpl.cpp">
|
||||
@ -252,7 +276,7 @@
|
||||
RelativePath=".\src\Unicode.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Unicode_UNIX.cpp">
|
||||
RelativePath=".\src\Unicode_UNIXODBC.cpp">
|
||||
<FileConfiguration
|
||||
Name="debug_shared|Win32"
|
||||
ExcludedFromBuild="TRUE">
|
||||
|
@ -55,8 +55,10 @@
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#define POCO_ODBC_UNICODE
|
||||
#define POCO_ODBC_UNICODE_WINDOWS
|
||||
#elif defined(POCO_OS_FAMILY_UNIX) && defined(UNICODE)
|
||||
#define POCO_ODBC_UNICODE
|
||||
#ifdef POCO_UNIXODBC
|
||||
#define POCO_ODBC_UNICODE_UNIXODBC
|
||||
#elif defined(POCO_IODBC)
|
||||
@ -378,7 +380,7 @@ inline SQLINTEGER stringLength(SQLPOINTER pValue, SQLINTEGER length)
|
||||
}
|
||||
|
||||
|
||||
#if !defined(POCO_ODBC_UNICODE_WINDOWS) && !defined(POCO_ODBC_UNICODE_UNIXODBC)
|
||||
#if !defined(POCO_ODBC_UNICODE)
|
||||
|
||||
|
||||
///
|
||||
|
@ -45,53 +45,28 @@ namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
inline void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::string& target)
|
||||
/// Utility function for conversion from UTF-8 to UTF-16
|
||||
{
|
||||
int len = length;
|
||||
if (SQL_NTS == len)
|
||||
len = (int) std::strlen((const char *) pSQLChar);
|
||||
|
||||
UTF8Encoding utf8Encoding;
|
||||
UTF16Encoding utf16Encoding;
|
||||
TextConverter converter(utf8Encoding, utf16Encoding);
|
||||
|
||||
if (0 != converter.convert(pSQLChar, len, target))
|
||||
throw SyntaxException("Error converting UTF-8 to UTF-16");
|
||||
}
|
||||
void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::string& 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.
|
||||
/// Utility function for conversion from ASCII to UTF-16.
|
||||
{
|
||||
makeUTF16(pSQLChar, (SQLINTEGER) length, target);
|
||||
}
|
||||
|
||||
|
||||
inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLINTEGER targetLength)
|
||||
{
|
||||
UTF8Encoding utf8Encoding;
|
||||
UTF16Encoding utf16Encoding;
|
||||
TextConverter converter(utf16Encoding, utf8Encoding);
|
||||
|
||||
std::string 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, SQLINTEGER targetLength);
|
||||
/// Utility function for conversion from UTF-16 to ASCII.
|
||||
|
||||
|
||||
inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLSMALLINT targetLength)
|
||||
/// Utility function for conversion from UTF-16 to ASCII.
|
||||
{
|
||||
makeUTF8(buffer, length, pTarget, (SQLINTEGER) targetLength);
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_ODBC_UNICODE
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
|
@ -35,12 +35,19 @@
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Unicode_UNIX.h"
|
||||
#include "Poco/Data/ODBC/Unicode_UNIXODBC.h"
|
||||
#include "Poco/TextConverter.h"
|
||||
#include "Poco/UTF8Encoding.h"
|
||||
#include "Poco/UTF16Encoding.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Buffer;
|
||||
using Poco::UTF8Encoding;
|
||||
using Poco::UTF16Encoding;
|
||||
using Poco::TextConverter;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::NotImplementedException;
|
||||
|
||||
@ -50,6 +57,36 @@ namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::string& target)
|
||||
{
|
||||
int len = length;
|
||||
if (SQL_NTS == len)
|
||||
len = (int) std::strlen((const char *) pSQLChar);
|
||||
|
||||
UTF8Encoding utf8Encoding;
|
||||
UTF16Encoding utf16Encoding;
|
||||
TextConverter converter(utf8Encoding, utf16Encoding);
|
||||
|
||||
if (0 != converter.convert(pSQLChar, len, target))
|
||||
throw SyntaxException("Error converting UTF-8 to UTF-16");
|
||||
}
|
||||
|
||||
|
||||
void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLINTEGER targetLength)
|
||||
{
|
||||
UTF8Encoding utf8Encoding;
|
||||
UTF16Encoding utf16Encoding;
|
||||
TextConverter converter(utf16Encoding, utf8Encoding);
|
||||
|
||||
std::string result;
|
||||
if (0 != converter.convert(buffer.begin(), length * sizeof(SQLWCHAR), 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);
|
||||
}
|
||||
|
||||
|
||||
SQLRETURN SQLColAttribute(SQLHSTMT hstmt,
|
||||
SQLUSMALLINT iCol,
|
||||
SQLUSMALLINT iField,
|
||||
|
@ -5,13 +5,21 @@
|
||||
#
|
||||
# Makefile for Poco SQLite testsuite
|
||||
#
|
||||
# For Unicode support, add following to COMMONFLAGS:
|
||||
#
|
||||
# -DUNICODE
|
||||
#
|
||||
# Unicode is supported only for UnixODBC
|
||||
#
|
||||
|
||||
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
|
||||
|
@ -65,7 +65,7 @@ using Poco::NotFoundException;
|
||||
|
||||
#define DB2_ODBC_DRIVER "IBM DB2 ODBC DRIVER - DB2COPY1"
|
||||
#define DB2_DSN "PocoDataDB2Test"
|
||||
#define DB2_SERVER "localhost"
|
||||
#define DB2_SERVER POCO_ODBC_TEST_DATABASE_SERVER
|
||||
#define DB2_PORT "50000"
|
||||
#define DB2_DB "POCOTEST"
|
||||
#define DB2_UID "db2admin"
|
||||
|
@ -65,7 +65,7 @@ using Poco::NotFoundException;
|
||||
#define MYSQL_ODBC_DRIVER "MySQL"
|
||||
#endif
|
||||
#define MYSQL_DSN "PocoDataMySQLTest"
|
||||
#define MYSQL_SERVER "localhost"
|
||||
#define MYSQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER
|
||||
#define MYSQL_DB "test"
|
||||
#define MYSQL_UID "root"
|
||||
#define MYSQL_PWD "mysql"
|
||||
|
@ -60,7 +60,7 @@ using Poco::DateTime;
|
||||
|
||||
#define ORACLE_ODBC_DRIVER "Oracle in XE"
|
||||
#define ORACLE_DSN "PocoDataOracleTest"
|
||||
#define ORACLE_SERVER "localhost"
|
||||
#define ORACLE_SERVER POCO_ODBC_TEST_DATABASE_SERVER
|
||||
#define ORACLE_PORT "1521"
|
||||
#define ORACLE_SID "XE"
|
||||
#define ORACLE_UID "scott"
|
||||
|
@ -56,13 +56,13 @@ using Poco::DateTime;
|
||||
|
||||
#ifdef POCO_ODBC_USE_MAMMOTH_NG
|
||||
#define POSTGRESQL_ODBC_DRIVER "Mammoth ODBCng Beta"
|
||||
#elif defined (POCO_OS_FAMILY_WINDOWS) && defined (POCO_WIN32_UTF8)
|
||||
#elif defined (POCO_ODBC_UNICODE)
|
||||
#define POSTGRESQL_ODBC_DRIVER "PostgreSQL Unicode"
|
||||
#else
|
||||
#define POSTGRESQL_ODBC_DRIVER "PostgreSQL ANSI"
|
||||
#endif
|
||||
#define POSTGRESQL_DSN "PocoDataPgSQLTest"
|
||||
#define POSTGRESQL_SERVER "localhost"
|
||||
#define POSTGRESQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER
|
||||
#define POSTGRESQL_PORT "5432"
|
||||
#define POSTGRESQL_DB "postgres"
|
||||
#define POSTGRESQL_UID "postgres"
|
||||
|
@ -69,7 +69,7 @@ using Poco::DateTime;
|
||||
#define MS_SQL_SERVER_ODBC_DRIVER "FreeTDS"
|
||||
#endif
|
||||
#define MS_SQL_SERVER_DSN "PocoDataSQLServerTest"
|
||||
#define MS_SQL_SERVER_SERVER "localhost"
|
||||
#define MS_SQL_SERVER_SERVER POCO_ODBC_TEST_DATABASE_SERVER
|
||||
#define MS_SQL_SERVER_PORT "1433"
|
||||
#define MS_SQL_SERVER_DB "test"
|
||||
#define MS_SQL_SERVER_UID "test"
|
||||
|
@ -66,8 +66,8 @@ using Poco::DateTime;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
ODBCTest::Drivers ODBCTest::_drivers;
|
||||
const bool ODBCTest::_bindValues[8] =
|
||||
ODBCTest::Drivers ODBCTest::_drivers;
|
||||
const bool ODBCTest::_bindValues[8] =
|
||||
{true, true, true, false, false, true, false, false};
|
||||
|
||||
|
||||
|
@ -44,11 +44,14 @@
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
#define POCO_ODBC_TEST_DATABASE_SERVER "localhost"
|
||||
|
||||
|
||||
class ODBCTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
typedef Poco::SharedPtr<Poco::Data::Session> SessionPtr;
|
||||
typedef Poco::SharedPtr<SQLExecutor> ExecPtr;
|
||||
typedef Poco::SharedPtr<Poco::Data::Session> SessionPtr;
|
||||
typedef Poco::SharedPtr<SQLExecutor> ExecPtr;
|
||||
|
||||
ODBCTest(const std::string& name,
|
||||
SessionPtr pSession,
|
||||
|
@ -2422,7 +2422,7 @@ void SQLExecutor::internalExtraction()
|
||||
i = rset.value("str0", 2);
|
||||
assert (5 == i);
|
||||
|
||||
const Column<std::deque<int> >& col = rset.column<std::deque<int>, InternalExtraction<std::deque<int> > >(0);
|
||||
const Column<std::deque<int> >& col = rset.column<std::deque<int> >(0);
|
||||
Column<std::deque<int> >::Iterator it = col.begin();
|
||||
Column<std::deque<int> >::Iterator end = col.end();
|
||||
for (int i = 1; it != end; ++it, ++i)
|
||||
@ -2456,7 +2456,7 @@ void SQLExecutor::internalExtraction()
|
||||
s = rset.value("cnt", 0).convert<std::string>();
|
||||
assert ("4" == s);
|
||||
|
||||
try { rset.column<std::deque<int>, InternalExtraction<std::deque<int> > >(100); fail ("must fail"); }
|
||||
try { rset.column<std::deque<int> >(100); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
|
||||
try { rset.value<std::string>(0,0); fail ("must fail"); }
|
||||
@ -2465,7 +2465,7 @@ void SQLExecutor::internalExtraction()
|
||||
stmt = (session() << "DELETE FROM Vectors", now);
|
||||
rset = stmt;
|
||||
|
||||
try { rset.column<std::deque<int>, InternalExtraction<std::deque<int> > >(0); fail ("must fail"); }
|
||||
try { rset.column<std::deque<int> >(0); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
}
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "Poco/Data/BulkBinding.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#define poco_odbc_check_env(r, h) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user