Modified:
branches/guffert/driver/ansi.c
branches/guffert/driver/connect.c
branches/guffert/driver/myodbc3.def
branches/guffert/driver/myodbc3.h
branches/guffert/driver/unicode.c
branches/guffert/test/include/odbctap.h
branches/guffert/test/my_unicode.c
Log:
Implement SQLDriverConnectW
Modified: branches/guffert/driver/ansi.c
===================================================================
--- branches/guffert/driver/ansi.c 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/driver/ansi.c 2007-08-16 01:08:00 UTC (rev 651)
@@ -46,6 +46,16 @@
SQLRETURN SQL_API
+SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR *in, SQLSMALLINT in_len,
+ SQLCHAR *out, SQLSMALLINT out_max, SQLSMALLINT *out_len,
+ SQLUSMALLINT completion)
+{
+ return MySQLDriverConnect(hdbc, hwnd, in, in_len, out, out_max, out_len,
+ completion);
+}
+
+
+SQLRETURN SQL_API
SQLExecDirect(SQLHSTMT hstmt, SQLCHAR *str, SQLINTEGER str_len)
{
int error;
@@ -177,15 +187,6 @@
}
-SQLRETURN SQL_API
-SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd, SQLCHAR *in, SQLSMALLINT in_len,
- SQLCHAR *out, SQLSMALLINT out_max, SQLSMALLINT *out_len,
- SQLUSMALLINT completion)
-{
- NOT_IMPLEMENTED;
-}
-
-
//SQLDrivers
Modified: branches/guffert/driver/connect.c
===================================================================
--- branches/guffert/driver/connect.c 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/driver/connect.c 2007-08-16 01:08:00 UTC (rev 651)
@@ -392,9 +392,9 @@
/**
- An alternative to SQLDriverConnect that allows specifying more of the
- connection parameters, and whether or not to prompt the user for more
- information using the setup library.
+ An alternative to SQLConnect that allows specifying more of the connection
+ parameters, and whether or not to prompt the user for more information
+ using the setup library.
@param[in] hdbc Handle of database connection
@param[in] hwnd Window handle. May be @c NULL if no prompting will be done.
@@ -414,14 +414,14 @@
@since ODBC 1.0
@since ISO SQL 92
*/
-SQLRETURN SQL_API SQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd,
- SQLCHAR *szConnStrIn,
- SQLSMALLINT cbConnStrIn
- __attribute__((unused)),
- SQLCHAR * szConnStrOut,
- SQLSMALLINT cbConnStrOutMax,
- SQLSMALLINT *pcbConnStrOut,
- SQLUSMALLINT fDriverCompletion)
+SQLRETURN SQL_API MySQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd,
+ SQLCHAR *szConnStrIn,
+ SQLSMALLINT cbConnStrIn
+ __attribute__((unused)),
+ SQLCHAR * szConnStrOut,
+ SQLSMALLINT cbConnStrOutMax,
+ SQLSMALLINT *pcbConnStrOut,
+ SQLUSMALLINT fDriverCompletion)
{
SQLRETURN rc= SQL_SUCCESS;
DBC *dbc= (DBC *)hdbc;
Modified: branches/guffert/driver/myodbc3.def
===================================================================
--- branches/guffert/driver/myodbc3.def 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/driver/myodbc3.def 2007-08-16 01:08:00 UTC (rev 651)
@@ -118,6 +118,10 @@
;SQLGetDescField
;SQLGetDescRec
SQLCloseCursor
+SQLConnectW
+SQLDriverConnectW
+SQLExecDirectW
+SQLPrepareW
;
DllMain
LoadByOrdinal
Modified: branches/guffert/driver/myodbc3.h
===================================================================
--- branches/guffert/driver/myodbc3.h 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/driver/myodbc3.h 2007-08-16 01:08:00 UTC (rev 651)
@@ -411,6 +411,11 @@
SQLRETURN SQL_API MySQLConnect(SQLHDBC hdbc, SQLCHAR *szDSN, SQLSMALLINT cbDSN,
SQLCHAR *szUID, SQLSMALLINT cbUID,
SQLCHAR *szAuth, SQLSMALLINT cbAuth);
+SQLRETURN SQL_API MySQLDriverConnect(SQLHDBC hdbc, SQLHWND hwnd,
+ SQLCHAR *in, SQLSMALLINT in_len,
+ SQLCHAR *out, SQLSMALLINT out_max,
+ SQLSMALLINT *out_len,
+ SQLUSMALLINT completion);
SQLRETURN SQL_API MySQLPrepare(SQLHSTMT hstmt, SQLCHAR *query, SQLINTEGER len,
my_bool dupe);
Modified: branches/guffert/driver/unicode.c
===================================================================
--- branches/guffert/driver/unicode.c 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/driver/unicode.c 2007-08-16 01:08:00 UTC (rev 651)
@@ -36,6 +36,8 @@
/* Forward declarations. */
SQLCHAR *sqlwchar_as_utf8(SQLWCHAR *str, SQLINTEGER *len);
+SQLINTEGER utf8_as_sqlwchar(SQLWCHAR *out, SQLINTEGER out_max, SQLCHAR *in,
+ SQLINTEGER in_len);
SQLRETURN SQL_API
SQLPrepareWImpl(SQLHSTMT hstmt, SQLWCHAR *str, SQLINTEGER str_len);
@@ -98,7 +100,7 @@
}
i+= copy_and_convert((char *)out + i, out_bytes - i, charset_info,
- u8, u8_len, utf8_charset_info, &used_bytes,
+ (char *)u8, u8_len, utf8_charset_info, &used_bytes,
&used_chars, errors);
}
@@ -161,6 +163,39 @@
}
+/**
+ Convert a SQLCHAR encoded as UTF-8 into a SQLWCHAR.
+
+ @param[out] out Pointer to SQLWCHAR buffer
+ @param[in] out_max Length of @c out buffer
+ @param[in] in Pointer to SQLCHAR string (utf-8 encoded)
+ @param[in] in_len Length of @c in (in bytes)
+
+ @return Number of characters stored in the @c out buffer
+*/
+SQLINTEGER utf8_as_sqlwchar(SQLWCHAR *out, SQLINTEGER out_max, SQLCHAR *in,
+ SQLINTEGER in_len)
+{
+ SQLINTEGER i;
+ SQLWCHAR *pos, *out_end;
+
+ for (i= 0, pos= out, out_end= out + out_max; i < in_len && pos < out_end;
)
+ {
+ if (sizeof(SQLWCHAR) == 4)
+ i+= utf8toutf32(in + i, (UTF32 *)pos++);
+ else
+ {
+ UTF32 u32;
+ i+= utf8toutf32(in + i, &u32);
+ pos+= utf32toutf16(u32, (UTF16 *)pos);
+ }
+ }
+
+ *out= 0;
+ return pos - out;
+}
+
+
SQLRETURN SQL_API
SQLConnectW(SQLHDBC hdbc, SQLWCHAR *dsn, SQLSMALLINT dsn_len_in,
SQLWCHAR *user, SQLSMALLINT user_len_in,
@@ -185,6 +220,44 @@
SQLRETURN SQL_API
+SQLDriverConnectW(SQLHDBC hdbc, SQLHWND hwnd,
+ SQLWCHAR *in, SQLSMALLINT in_len_in,
+ SQLWCHAR *out, SQLSMALLINT out_max, SQLSMALLINT *out_len,
+ SQLUSMALLINT completion)
+{
+ SQLRETURN rc;
+ SQLINTEGER in_len= in_len_in;
+ SQLSMALLINT out8_max;
+ SQLCHAR *out8, *in8= sqlwchar_as_utf8(in, &in_len);
+
+ if (in_len == SQL_NTS)
+ in_len= sqlwchar_strlen(in);
+
+ out8_max= sizeof(SQLCHAR) * 4 * out_max;
+ out8= (SQLCHAR *)my_malloc(out8_max + 1, MYF(0));
+ if (!out8)
+ {
+ rc= set_dbc_error((DBC *)hdbc, "HY001", NULL, 0);
+ goto error;
+ }
+
+ ((DBC *)hdbc)->unicode= TRUE; /* Hooray, a Unicode connection! */
+
+ rc= MySQLDriverConnect(hdbc, hwnd, in8, in_len, out8, out8_max, out_len,
+ completion);
+
+ /* Now we have to convert out8 back into a SQLWCHAR. */
+ *out_len= utf8_as_sqlwchar(out, out_max, out8, *out_len);
+
+error:
+ x_free(out8);
+ x_free(in8);
+
+ return rc;
+}
+
+
+SQLRETURN SQL_API
SQLExecDirectW(SQLHSTMT hstmt, SQLWCHAR *str, SQLINTEGER str_len)
{
int error;
@@ -285,15 +358,6 @@
}
-SQLRETURN SQL_API
-SQLDriverConnectW(SQLHDBC hdbc, SQLHWND hwnd, SQLWCHAR *in, SQLSMALLINT in_len,
- SQLWCHAR *out, SQLSMALLINT out_max, SQLSMALLINT *out_len,
- SQLUSMALLINT completion)
-{
- NOT_IMPLEMENTED;
-}
-
-
//SQLDriversW
Modified: branches/guffert/test/include/odbctap.h
===================================================================
--- branches/guffert/test/include/odbctap.h 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/test/include/odbctap.h 2007-08-16 01:08:00 UTC (rev 651)
@@ -487,6 +487,7 @@
Helper for possibly converting a (wchar_t *) to a (SQLWCHAR *)
*/
#define W(string) dup_wchar_t_as_sqlwchar((string), sizeof(string))
+#define WL(string, len) dup_wchar_t_as_sqlwchar((string), (len))
/**
Modified: branches/guffert/test/my_unicode.c
===================================================================
--- branches/guffert/test/my_unicode.c 2007-08-15 22:44:20 UTC (rev 650)
+++ branches/guffert/test/my_unicode.c 2007-08-16 01:08:00 UTC (rev 651)
@@ -172,10 +172,52 @@
}
+DECLARE_TEST(sqldriverconnect)
+{
+ HDBC hdbc1;
+ HSTMT hstmt1;
+ wchar_t conn_in[512];
+ wchar_t dummy[80];
+ SQLWCHAR conn_out[512];
+ SQLSMALLINT conn_out_len;
+
+ ok_env(henv, SQLAllocConnect(henv, &hdbc1));
+
+ swprintf(conn_in,
+ L"DRIVER={MySQL ODBC 3.51 Driver};USER=%s;PASSWORD=%s;"
+ L"DATABASE=%s;SERVER=%s",
+ myuid, mypwd, mydb, myserver);
+ if (mysock != NULL)
+ {
+ wcscat(conn_in, L";SOCKET=");
+ mbstowcs(dummy, (char *)mysock, sizeof(dummy));
+ wcscat(conn_in, dummy);
+ }
+
+ ok_con(hdbc1, SQLDriverConnectW(hdbc1, NULL, WL(conn_in, wcslen(conn_in)),
+ wcslen(conn_in), conn_out, sizeof(conn_out),
+ &conn_out_len, SQL_DRIVER_NOPROMPT));
+
+ ok_con(hdbc, SQLAllocStmt(hdbc1, &hstmt1));
+
+ ok_stmt(hstmt1, SQLExecDirectW(hstmt1, W(L"SELECT 1234"), SQL_NTS));
+ ok_stmt(hstmt1, SQLFetch(hstmt1));
+ is_num(my_fetch_int(hstmt1, 1), 1234);
+
+ ok_stmt(hstmt, SQLFreeStmt(hstmt1, SQL_DROP));
+
+ ok_con(hdbc1, SQLDisconnect(hdbc1));
+ ok_con(hdbc1, SQLFreeConnect(hdbc1));
+
+ return OK;
+}
+
+
BEGIN_TESTS
ADD_TEST(sqlconnect)
ADD_TEST(sqlprepare)
ADD_TEST(sqlchar)
+ ADD_TEST(sqldriverconnect)
END_TESTS
| Thread |
|---|
| • Connector/ODBC 3.51 commit: r651 - in branches/guffert: driver test test/include | jwinstead | 16 Aug |