From c9f87042513f92645d624692c1eb1540aff39dc4 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Fri, 28 Jun 2002 02:44:15 +0000 Subject: [PATCH] 1) prevent setting of KSQO on 7.3+ servers(Thanks to Dave Page). 2) Allow LF->CR/LF conversion under UNICODE driver. --- src/interfaces/odbc/connection.c | 13 +++++++++---- src/interfaces/odbc/convert.c | 4 ++-- src/interfaces/odbc/psqlodbc.h | 5 +++-- src/interfaces/odbc/win_unicode.c | 9 ++++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/interfaces/odbc/connection.c b/src/interfaces/odbc/connection.c index c9b0c01c30..04de1c8e25 100644 --- a/src/interfaces/odbc/connection.c +++ b/src/interfaces/odbc/connection.c @@ -952,6 +952,13 @@ another_version_retry: * Send any initial settings */ + /* + * Get the version number first so we can check it before sending options + * that are now obsolete. DJP 21/06/2002 + */ + + CC_lookup_pg_version(self); /* Get PostgreSQL version for + SQLGetInfo use */ /* * Since these functions allocate statements, and since the connection * is not established yet, it would violate odbc state transition @@ -961,8 +968,6 @@ another_version_retry: CC_send_settings(self); CC_lookup_lo(self); /* a hack to get the oid of our large object oid type */ - CC_lookup_pg_version(self); /* Get PostgreSQL version for - SQLGetInfo use */ /* * Multibyte handling is available ? @@ -1802,8 +1807,8 @@ CC_send_settings(ConnectionClass *self) } - /* KSQO */ - if (ci->drivers.ksqo) + /* KSQO (not applicable to 7.1+ - DJP 21/06/2002) */ + if (ci->drivers.ksqo && PG_VERSION_LT(self, 7.1)) { result = PGAPI_ExecDirect(hstmt, "set ksqo to 'ON'", SQL_NTS); if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) diff --git a/src/interfaces/odbc/convert.c b/src/interfaces/odbc/convert.c index 60fdc54f9c..15a1a23c73 100644 --- a/src/interfaces/odbc/convert.c +++ b/src/interfaces/odbc/convert.c @@ -702,7 +702,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 #ifdef UNICODE_SUPPORT if (fCType == SQL_C_WCHAR) { - len = utf8_to_ucs2(neut_str, -1, NULL, 0); + len = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0); len *= 2; wchanged = changed = TRUE; } @@ -728,7 +728,7 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 #ifdef UNICODE_SUPPORT if (fCType == SQL_C_WCHAR) { - utf8_to_ucs2(neut_str, -1, (SQLWCHAR *) pbic->ttlbuf, len / 2); + utf8_to_ucs2_lf(neut_str, -1, lf_conv, (SQLWCHAR *) pbic->ttlbuf, len / 2); } else #endif /* UNICODE_SUPPORT */ diff --git a/src/interfaces/odbc/psqlodbc.h b/src/interfaces/odbc/psqlodbc.h index 167a35fa2f..431f6a4922 100644 --- a/src/interfaces/odbc/psqlodbc.h +++ b/src/interfaces/odbc/psqlodbc.h @@ -5,7 +5,7 @@ * * Comments: See "notice.txt" for copyright and license information. * - * $Id: psqlodbc.h,v 1.67 2002/06/06 04:50:47 inoue Exp $ + * $Id: psqlodbc.h,v 1.68 2002/06/28 02:44:15 inoue Exp $ * */ @@ -255,7 +255,8 @@ void logs_on_off(int cnopen, int, int); #ifdef UNICODE_SUPPORT UInt4 ucs2strlen(const SQLWCHAR *ucs2str); char *ucs2_to_utf8(const SQLWCHAR *ucs2str, Int4 ilen, UInt4 *olen); -UInt4 utf8_to_ucs2(const char * utf8str, Int4 ilen, SQLWCHAR *ucs2str, UInt4 buflen); +UInt4 utf8_to_ucs2_lf(const char * utf8str, Int4 ilen, BOOL lfconv, SQLWCHAR *ucs2str, UInt4 buflen); +#define utf8_to_ucs2(utf8str, ilen, ucs2str, buflen) utf8_to_ucs2_lf(utf8str, ilen, FALSE, ucs2str, buflen) #endif /* UNICODE_SUPPORT */ /*#define _MEMORY_DEBUG_ */ #ifdef _MEMORY_DEBUG_ diff --git a/src/interfaces/odbc/win_unicode.c b/src/interfaces/odbc/win_unicode.c index 3dfc9ff43d..112ea18be1 100644 --- a/src/interfaces/odbc/win_unicode.c +++ b/src/interfaces/odbc/win_unicode.c @@ -82,7 +82,7 @@ char *ucs2_to_utf8(const SQLWCHAR *ucs2str, Int4 ilen, UInt4 *olen) #define byte3_m3 0x3f #define byte2_m1 0x1f #define byte2_m2 0x3f -UInt4 utf8_to_ucs2(const char *utf8str, Int4 ilen, SQLWCHAR *ucs2str, UInt4 bufcount) +UInt4 utf8_to_ucs2_lf(const char *utf8str, Int4 ilen, BOOL lfconv, SQLWCHAR *ucs2str, UInt4 bufcount) { int i; UInt4 ocount, wcode; @@ -102,6 +102,13 @@ UInt4 utf8_to_ucs2(const char *utf8str, Int4 ilen, SQLWCHAR *ucs2str, UInt4 bufc { if (iswascii(*str)) { + if (lfconv && *str == '\n' && + (i == 0 || str[-1] != '\r')) + { + if (ocount < bufcount) + ucs2str[ocount] = '\r'; + ocount++; + } if (ocount < bufcount) ucs2str[ocount] = *str; ocount++;