Skip to content

Commit

Permalink
ODBC-193 Enabling connect and most of operations
Browse files Browse the repository at this point in the history
SQLWCHAR encoding is depending on DM or on the size of SQLWCHAR. It's either utf16(UnixODBC) or utf32(iODBC). Since iconv needs to know if utf32 le or be, defining charset info struct for le order of bytes. More like a hack to make mariadb_coonvert_string to give iconv correct encoding name.
Fixed failing testcase.
  • Loading branch information
lawrinn committed Nov 19, 2018
1 parent bb8c6b8 commit 12cec4b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 25 deletions.
15 changes: 14 additions & 1 deletion ma_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@

#include <ma_odbc.h>

MARIADB_CHARSET_INFO* utf16= NULL;
static unsigned int ValidChar(const char *start, const char *end)
{
return 4;
}


static unsigned CharOctetLen(unsigned int utf32)
{
return 4;
}

MARIADB_CHARSET_INFO dummyUtf32le= {0, 1, "utf32le", "utf32_general_ci", "", 0, "UTF-32LE", 4, 4, CharOctetLen, ValidChar};

MARIADB_CHARSET_INFO* DmUnicodeCs= NULL;
Client_Charset utf8= {CP_UTF8, NULL};

/* {{{ ltrim */
Expand Down
14 changes: 11 additions & 3 deletions ma_environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include <ma_odbc.h>

extern Client_Charset utf8;
extern MARIADB_CHARSET_INFO* utf16;
extern MARIADB_CHARSET_INFO* DmUnicodeCs;
extern MARIADB_CHARSET_INFO dummyUtf32le;
Client_Charset SourceAnsiCs= {0, 0}; /* Basically it should be initialized with 0 anyway */

MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name);
Expand Down Expand Up @@ -99,9 +100,16 @@ MADB_Env *MADB_EnvInit()
Env->OdbcVersion= SQL_OV_ODBC3;

/* This is probably is better todo with thread_once */
if (utf16 == NULL)
if (DmUnicodeCs == NULL)
{
utf16= mariadb_get_charset_by_name(little_endian() ? "utf16le" : "utf16");
if (sizeof(SQLWCHAR) == 2)
{
DmUnicodeCs= mariadb_get_charset_by_name(little_endian() ? "utf16le" : "utf16");
}
else
{
DmUnicodeCs= little_endian() ? &dummyUtf32le : mariadb_get_charset_by_name("utf32");
}
}
utf8.cs_info= mariadb_get_charset_by_name("utf8");
GetDefaultLogDir();
Expand Down
12 changes: 6 additions & 6 deletions ma_platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <ma_odbc.h>
#include <stdarg.h>

extern MARIADB_CHARSET_INFO *utf16;
extern MARIADB_CHARSET_INFO *DmUnicodeCs;
extern Client_Charset utf8;

char LogFile[256];
Expand Down Expand Up @@ -127,9 +127,9 @@ SQLINTEGER SqlwcsOctetLen(const SQLWCHAR *str, SQLINTEGER *CharLen)
{
while (inChars > 0 || inChars < 0 && *str)
{
result+= utf16->mb_charlen(*str);
result+= DmUnicodeCs->mb_charlen(*str);
--inChars;
str+= utf16->mb_charlen(*str)/sizeof(SQLWCHAR);
str+= DmUnicodeCs->mb_charlen(*str)/sizeof(SQLWCHAR);
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ SQLWCHAR *MADB_ConvertToWchar(const char *Ptr, SQLLEN PtrLength, Client_Charset*
{
size_t wstr_octet_len= sizeof(SQLWCHAR) * (PtrLength + 1);
/* TODO: Need error processing. i.e. if mariadb_convert_string returns -1 */
mariadb_convert_string(Ptr, &Length, cc->cs_info, (char*)WStr, &wstr_octet_len, utf16, NULL);
mariadb_convert_string(Ptr, &Length, cc->cs_info, (char*)WStr, &wstr_octet_len, DmUnicodeCs, NULL);
}

return WStr;
Expand Down Expand Up @@ -212,7 +212,7 @@ char *MADB_ConvertFromWChar(const SQLWCHAR *Ptr, SQLINTEGER PtrLength, SQLULEN *
if (!(AscStr = (char *)MADB_CALLOC(AscLen)))
return NULL;

AscLen= mariadb_convert_string((char*)Ptr, &PtrOctetLen, utf16, AscStr, &AscLen, cc->cs_info, Error);
AscLen= mariadb_convert_string((char*)Ptr, &PtrOctetLen, DmUnicodeCs, AscStr, &AscLen, cc->cs_info, Error);

if (AscLen != (size_t)-1)
{
Expand Down Expand Up @@ -286,7 +286,7 @@ int MADB_ConvertAnsi2Unicode(Client_Charset *cc, const char *AnsiString, SQLLEN
dest_octet_len= sizeof(SQLWCHAR) * RequiredLength;

RequiredLength= mariadb_convert_string(AnsiString, &src_octet_len, cc->cs_info,
(char*)Tmp, &dest_octet_len, utf16, &error);
(char*)Tmp, &dest_octet_len, DmUnicodeCs, &error);

if (RequiredLength < 1)
{
Expand Down
4 changes: 2 additions & 2 deletions ma_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*************************************************************************************/
#include <ma_odbc.h>

extern MARIADB_CHARSET_INFO* utf16;
extern MARIADB_CHARSET_INFO* DmUnicodeCs;

char *MADB_GetTableName(MADB_Stmt *Stmt)
{
Expand Down Expand Up @@ -531,7 +531,7 @@ SQLINTEGER SqlwcsCharLen(SQLWCHAR *str, SQLLEN octets)
{
while (str < end && *str)
{
str+= (utf16->mb_charlen(*str))/sizeof(SQLWCHAR);
str+= (DmUnicodeCs->mb_charlen(*str))/sizeof(SQLWCHAR);

if (str > end)
{
Expand Down
2 changes: 2 additions & 0 deletions odbc_3_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,9 @@ SQLRETURN SQL_API SQLDriverConnectW(SQLHDBC ConnectionHandle,
MADB_Dbc *Dbc= (MADB_Dbc *)ConnectionHandle;

if (!ConnectionHandle)
{
return SQL_INVALID_HANDLE;
}

MDBUG_C_ENTER(Dbc, "SQLDriverConnectW");

Expand Down
4 changes: 2 additions & 2 deletions test/catalog2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,8 @@ ODBC_TEST(odbc185)
{
CHECK_STMT_RC(hstmt1, SQLFetch(hstmt1));
my_fetch_str(hstmt1, buff, COLUMN_NAME);
is_num(my_fetch_int(hstmt1, DATA_TYPE), expecteda[i]);
is_num(my_fetch_int(hstmt1, SQL_DATA_TYPE /* SQL_DATA_TYPE */), expecteda[i]);
is_num(my_fetch_int(hstmt1, DATA_TYPE), expectedw[i]);
is_num(my_fetch_int(hstmt1, SQL_DATA_TYPE /* SQL_DATA_TYPE */), expectedw[i]);

CHECK_STMT_RC(Stmt, SQLFetch(Stmt));
my_fetch_str(Stmt, buff, COLUMN_NAME);
Expand Down
27 changes: 18 additions & 9 deletions test/tap.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static int Travis= 0;
SQLWCHAR sqlwchar_buff[8192], sqlwchar_empty[]= {0};
SQLWCHAR *buff_pos= sqlwchar_buff;

static MARIADB_CHARSET_INFO *utf8= NULL, *utf16= NULL, *utf32= NULL;
static MARIADB_CHARSET_INFO *utf8= NULL, *utf16= NULL, *utf32= NULL, *DmUnicode= NULL;

int tests_planned= 0;
char *test_status[]= {"not ok", "ok", "skip"};
Expand Down Expand Up @@ -841,19 +841,28 @@ int run_tests(MA_ODBC_TESTS *tests)
utf16= mariadb_get_charset_by_name(little_endian() ? "utf16le" : "utf16");
utf32= little_endian() ? &fakeUtf32le : mariadb_get_charset_by_name("utf32");

if (sizeof(SQLWCHAR) == 4)
{
DmUnicode= utf32;
}
else
{
DmUnicode= utf16;
}

if (utf8 == NULL || utf16 == NULL || utf32 == NULL)
{
fprintf(stdout, "HALT! Could not load charset info %p %p %p\n", utf8, utf16, utf32);
return 1;
}

wdsn= str2sqlwchar_on_gbuff(my_dsn, strlen(my_dsn) + 1, utf8, utf16);
wuid= str2sqlwchar_on_gbuff(my_uid, strlen(my_uid) + 1, utf8, utf16);
wpwd= str2sqlwchar_on_gbuff(my_pwd, strlen(my_pwd) + 1, utf8, utf16);
wschema= str2sqlwchar_on_gbuff(my_schema, strlen(my_schema) + 1, utf8, utf16);
wservername= str2sqlwchar_on_gbuff(my_servername, strlen(my_servername) + 1, utf8, utf16);
wdrivername= str2sqlwchar_on_gbuff(my_drivername, strlen(my_drivername) + 1, utf8, utf16);
wstrport= str2sqlwchar_on_gbuff(ma_strport, strlen(ma_strport) + 1, utf8, utf16);
wdsn= str2sqlwchar_on_gbuff(my_dsn, strlen(my_dsn) + 1, utf8, DmUnicode);
wuid= str2sqlwchar_on_gbuff(my_uid, strlen(my_uid) + 1, utf8, DmUnicode);
wpwd= str2sqlwchar_on_gbuff(my_pwd, strlen(my_pwd) + 1, utf8, DmUnicode);
wschema= str2sqlwchar_on_gbuff(my_schema, strlen(my_schema) + 1, utf8, DmUnicode);
wservername= str2sqlwchar_on_gbuff(my_servername, strlen(my_servername) + 1, utf8, DmUnicode);
wdrivername= str2sqlwchar_on_gbuff(my_drivername, strlen(my_drivername) + 1, utf8, DmUnicode);
wstrport= str2sqlwchar_on_gbuff(ma_strport, strlen(ma_strport) + 1, utf8, DmUnicode);

if (getenv("TRAVIS") != NULL)
{
Expand Down Expand Up @@ -1117,7 +1126,7 @@ wchar_t *sqlwchar_to_wchar_t(SQLWCHAR *in)
*/
/*#define WC(string) dup_char_as_sqlwchar((string))*/
/* Char(utf8) to slqWchar */
#define CW(str) str2sqlwchar_on_gbuff(str, strlen(str)+1, utf8, utf16)
#define CW(str) str2sqlwchar_on_gbuff(str, strlen(str)+1, utf8, DmUnicode)

/* @n[in] - number of characters to compare. Negative means treating of strings as null-terminated */
int sqlwcharcmp(SQLWCHAR *s1, SQLWCHAR *s2, int n)
Expand Down
1 change: 0 additions & 1 deletion wininstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ ELSE()
SET(GUID_PLUGINS "B6355F5E-FA0B-427a-AC77-BC145887D11B")
SET(GUID_PLUGINS_DEBUG "B2CB2291-249C-4258-83CB-A3E9C4DC9CFE")
ENDIF()

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/wininstall/mariadb_odbc.xml.in
${CMAKE_BINARY_DIR}/wininstall/mariadb_odbc.xml)
IF(${revno})
Expand Down
2 changes: 1 addition & 1 deletion wininstall/mariadb_odbc.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Directory Id="@FOLDER@">
<Directory Id="MariaDB" Name="@PRODUCT_MANUFACTURER@">
<Directory Id="INSTALLFOLDER" Name="@PRODUCT_NAME@">
<Directory Id="PLUGINSFOLDER" Name="@plugins_subdir_name@" />
<Directory Id="PLUGINSFOLDER" Name="$(var.plugins_subdir_name)" />
</Directory>
</Directory>
</Directory>
Expand Down

0 comments on commit 12cec4b

Please sign in to comment.