psqlodbc.git / summary / log / commit / refs

commit    0c81a67ce2830dbc1ceb97616040004d8baebd22
Author:   Dave Page <dpage@pgadmin.org>
Date:     Wed Feb 04 08:55:28 2004 +0000

    [Jon Willeke] I'm attaching a few tweaks to build psqlodbc with Unicode support on Unix.  I changed some code that assumes two-byte SQLWCHAR and I changed configure.ac and Makefile.am, as necessary.
    
    I tested this with unixODBC 2.2.7 on SuSE Linux 8.2.  I built unixODBC --with-iconv-ucode-enc=UCS-4LE and with SQL_WCHART_CONVERT defined, so that SQLWCHAR is wchar_t.  I have not tested it with UCS-2 / unsigned short.
    
    I also tested this with iODBC 3.51.1, which always uses wchar_t on Unix.
    
    One caveat, if anyone actually plays with this: sqlext.h should include sqlucode.h, so I haven't patched psqlodbc to do so.  The next release of unixODBC will contain this fix, and I've mentioned it to the iODBC maintainer.


Makefile.am | 9 +++++++-- configure.ac | 15 ++++++++++++++- convert.c | 18 +++++++++--------- execute.c | 2 +- info.c | 2 +- info30.c | 2 +- psqlodbc.h | 3 ++- win_unicode.c | 17 +++++++++++++++-- 8 files changed, 50 insertions(+), 18 deletions(-) diff --git a/Makefile.am b/Makefile.am index 28fc87b..0728ab0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ # # Makefile.am for psqlodbc (PostgreSQL ODBC driver) # -# $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/Makefile.am,v 1.9 2003/12/09 10:01:37 hinoue Exp $ +# $Header: /home/heikki/psqlodbc-cvs-copy/psqlodbc/Makefile.am,v 1.10 2004/02/04 08:55:28 dpage Exp $ # #------------------------------------------------------------------------- @@ -27,6 +27,11 @@ psqlodbc_la_SOURCES += \ psqlodbc.h qresult.h resource.h socket.h statement.h tuple.h \ tuplelist.h version.h +if enable_unicode +psqlodbc_la_SOURCES += \ + odbcapi30w.c odbcapiw.c win_unicode.c +endif + EXTRA_psqlodbc_la_SOURCES = md5.c if with_unixodbc @@ -45,7 +50,7 @@ BUILT_SOURCES = odbc-drop.sql EXTRA_DIST = README.unix license.txt notice.txt readme.txt odbcinst.ini \ libtool.m4 psqlodbc_win32.def psqlodbc_apiw.def psqlodbc_api30w.def \ psqlodbc_api25.def win32.mak win32_30w.mak win32_25.mak \ - dlg_wingui.c win_unicode.c win_setup.h win_md5.c setup.c \ + dlg_wingui.c win_setup.h win_md5.c setup.c \ psqlodbc.reg psqlodbc25.reg psqlodbc30w.reg MAINTAINERCLEANFILES = odbc-drop.sql \ Makefile.in config.guess config.h.in config.sub configure \ diff --git a/configure.ac b/configure.ac index 4ef4253..e273020 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,8 @@ AC_DEFINE(DRIVER_CURSOR_IMPLEMENT, 1, PGAC_ARG_BOOL(with, unixodbc, no, [ --with-unixodbc build ODBC driver for unixODBC], [AC_DEFINE(WITH_UNIXODBC, 1, - [Define to 1 to build with unixODBC support (--with-unixodbc)])]) + [Define to 1 to build with unixODBC support (--with-unixodbc)]) + AC_DEFINE(SQL_WCHART_CONVERT, [], [Define to use wchar_t as SQLWCHAR in unixODBC])]) PGAC_ARG_BOOL(with, iodbc, no, [ --with-iodbc build ODBC driver for iODBC], @@ -34,8 +35,20 @@ PGAC_ARG_REQ(with, odbcver, [ --with-odbcver=VERSION change default ODBC versi [Define to ODBC version (--with-odbcver)])]) AC_MSG_RESULT([$with_odbcver]) +# to implement the Unicode driver +AC_ARG_ENABLE(unicode, + [ --enable-unicode build ODBC driver for Unicode], + [AC_DEFINE(UNICODE_SUPPORT, 1, + [Define to 1 to build with Unicode support (--enable-unicode)]) + AC_DEFINE(UNICODE, [], + [Define to use wide APIs]) + AC_DEFINE(SQL_NOUNICODEMAP, [], + [Define to disable mapping SQL* to SQL*W]) + AC_CHECK_FUNCS(iswascii)]) + AM_CONDITIONAL(with_unixodbc, [test $with_unixodbc = yes]) AM_CONDITIONAL(with_iodbc, [test $with_iodbc = yes]) +AM_CONDITIONAL(enable_unicode, [test x"$enable_unicode" = xyes]) AC_CHECK_FUNCS(strtoul strtoll) AC_CHECK_LIB(socket, socket) diff --git a/convert.c b/convert.c index 5332be1..106b0af 100644 --- a/convert.c +++ b/convert.c @@ -763,7 +763,7 @@ inolog("2stime fr=%d\n", std_time.fr); if (fCType == SQL_C_WCHAR) { len = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0); - len *= 2; + len *= WCLEN; wchanged = changed = TRUE; } else @@ -810,7 +810,7 @@ inolog("2stime fr=%d\n", std_time.fr); #ifdef UNICODE_SUPPORT if (fCType == SQL_C_WCHAR) { - utf8_to_ucs2_lf(neut_str, -1, lf_conv, (SQLWCHAR *) pgdc->ttlbuf, len / 2); + utf8_to_ucs2_lf(neut_str, -1, lf_conv, (SQLWCHAR *) pgdc->ttlbuf, len / WCLEN); } else #endif /* UNICODE_SUPPORT */ @@ -942,18 +942,18 @@ inolog("2stime fr=%d\n", std_time.fr); #ifdef UNICODE_SUPPORT if (SQL_C_WCHAR == fCType && ! wchanged) { - if (cbValueMax > 2 * len) + if (cbValueMax > WCLEN * len) { char *str = strdup(rgbValueBindRow); - UInt4 ucount = utf8_to_ucs2(str, len, (SQLWCHAR *) rgbValueBindRow, cbValueMax / 2); - if (cbValueMax < 2 * (SDWORD) ucount) + UInt4 ucount = utf8_to_ucs2(str, len, (SQLWCHAR *) rgbValueBindRow, cbValueMax / WCLEN); + if (cbValueMax < WCLEN * (SDWORD) ucount) result = COPY_RESULT_TRUNCATED; - len = ucount * 2; + len = ucount * WCLEN; free(str); } else { - len *= 2; + len *= WCLEN; result = COPY_RESULT_TRUNCATED; } } @@ -2647,8 +2647,8 @@ ResolveOneParam(QueryBuild *qb) #ifdef UNICODE_SUPPORT case SQL_C_WCHAR: - buf = allocbuf = ucs2_to_utf8((SQLWCHAR *) buffer, used / 2, &used, FALSE); - used *= 2; + buf = allocbuf = ucs2_to_utf8((SQLWCHAR *) buffer, used / WCLEN, &used, FALSE); + used *= WCLEN; break; #endif /* UNICODE_SUPPORT */ diff --git a/execute.c b/execute.c index 2e1933d..7b3c879 100644 --- a/execute.c +++ b/execute.c @@ -990,7 +990,7 @@ PGAPI_PutData( #ifdef UNICODE_SUPPORT if (SQL_C_WCHAR == ctype) { - putlen = 2 * ucs2strlen((SQLWCHAR *) rgbValue); + putlen = WCLEN * ucs2strlen((SQLWCHAR *) rgbValue); lenset = TRUE; } else diff --git a/info.c b/info.c index e0676d5..3917ce1 100644 --- a/info.c +++ b/info.c @@ -751,7 +751,7 @@ PGAPI_GetInfo( if (conn->unicode) { len = utf8_to_ucs2(p, len, (SQLWCHAR *) rgbInfoValue, cbInfoValueMax / 2); - len *= 2; + len *= WCLEN; } else #endif /* UNICODE_SUPPORT */ diff --git a/info30.c b/info30.c index 026fdde..bb784f0 100644 --- a/info30.c +++ b/info30.c @@ -369,7 +369,7 @@ PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue, if (conn->unicode) { len = utf8_to_ucs2(p, len, (SQLWCHAR *) rgbInfoValue, cbInfoValueMax / 2); - len *= 2; + len *= WCLEN; } else #endif /* UNICODE_SUPPORT */ diff --git a/psqlodbc.h b/psqlodbc.h index 2448ef8..05d3011 100644 --- a/psqlodbc.h +++ b/psqlodbc.h @@ -5,7 +5,7 @@ * * Comments: See "notice.txt" for copyright and license information. * - * $Id: psqlodbc.h,v 1.81 2003/12/09 10:01:38 hinoue Exp $ + * $Id: psqlodbc.h,v 1.82 2004/02/04 08:55:28 dpage Exp $ * */ @@ -321,6 +321,7 @@ int initialize_global_cs(void); const pthread_mutexattr_t *getMutexAttr(void); #endif /* POSIX_THREADMUTEX_SUPPORT */ #ifdef UNICODE_SUPPORT +#define WCLEN sizeof(SQLWCHAR) UInt4 ucs2strlen(const SQLWCHAR *ucs2str); char *ucs2_to_utf8(const SQLWCHAR *ucs2str, Int4 ilen, UInt4 *olen, BOOL tolower); UInt4 utf8_to_ucs2_lf(const char * utf8str, Int4 ilen, BOOL lfconv, SQLWCHAR *ucs2str, UInt4 buflen); diff --git a/win_unicode.c b/win_unicode.c index e3ab7f8..68ac864 100644 --- a/win_unicode.c +++ b/win_unicode.c @@ -11,7 +11,7 @@ #include <stdio.h> #include <string.h> -#define byte3check 0xf800 +#define byte3check 0xfffff800 #define byte2_base 0x80c0 #define byte2_mask1 0x07c0 #define byte2_mask2 0x003f @@ -20,6 +20,19 @@ #define byte3_mask2 0x0fc0 #define byte3_mask3 0x003f +#ifndef WIN32 +#ifdef HAVE_ISWASCII +#include <wctype.h> +#else +#include <wchar.h> +#include <ctype.h> +int iswascii(wchar_t c) +{ + return isascii(wctob(c)); +} +#endif /* HAVE_ISWASCII */ +#endif /* WIN32 */ + UInt4 ucs2strlen(const SQLWCHAR *ucs2str) { UInt4 len; @@ -49,7 +62,7 @@ char *ucs2_to_utf8(const SQLWCHAR *ucs2str, Int4 ilen, UInt4 *olen, BOOL lower_i { if (!*wstr) break; - else if (0 == (*wstr & 0xff80)) /* ASCII */ + else if (0 == (*wstr & 0xffffff80)) /* ASCII */ { if (lower_identifier) utf8str[len++] = (char) tolower(*wstr); [parent: 01d10c233df6]