Skip to content

Commit

Permalink
[odbc-137] fix variant. 133 and 139 testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrinn committed May 22, 2018
1 parent b68cc3d commit 2d4fce5
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 128 deletions.
112 changes: 64 additions & 48 deletions ma_connection.c

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions ma_dsn.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,4 @@ void MADB_DsnUpdateOptionsFields(MADB_Dsn *Dsn);
memcpy((dsn)->item, (value),(len));\
}

#define MADB_DSN_GET_UTF8(dsn, item, len) \
((dsn)->item) ? MADB_ConvertFromWChar((dsn)->item, wcslen((dsn)->item)+1, (len)) : NULL


#endif /* _ma_dsn_h_ */
5 changes: 4 additions & 1 deletion ma_environment.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013,2105 MariaDB Corporation AB
Copyright (C) 2013,2018 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand All @@ -20,6 +20,7 @@

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

CHARSET_INFO * mysql_find_charset_name(const char *name);

Expand Down Expand Up @@ -54,6 +55,7 @@ SQLRETURN MADB_EnvFree(MADB_Env *Env)
/* }}} */

const char* GetDefaultLogDir();
int GetSourceAnsiCs(Client_Charset *cc);

/* {{{ MADB_EnvInit */
MADB_Env *MADB_EnvInit()
Expand Down Expand Up @@ -103,6 +105,7 @@ MADB_Env *MADB_EnvInit()
}
utf8.cs_info= my_charset_utf8_general_ci;
GetDefaultLogDir();
GetSourceAnsiCs(&SourceAnsiCs);

cleanup:
#ifdef _WIN32
Expand Down
2 changes: 2 additions & 0 deletions ma_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ SQLRETURN MADB_EnvSetAttr(MADB_Env* Env, SQLINTEGER Attribute, SQLPOINTER ValueP
SQLRETURN MADB_EnvGetAttr(MADB_Env *Env, SQLINTEGER Attribute, SQLPOINTER ValuePtr, SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr);

extern Client_Charset SourceAnsiCs;

#endif /* _ma_environment_h_ */
10 changes: 7 additions & 3 deletions ma_odbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ struct st_ma_odbc_connection
MADB_Dsn *Dsn;
struct st_ma_connection_methods *Methods;
MADB_Error Error;
Client_Charset charset;

Client_Charset Charset;
Client_Charset *ConnOrSrcCharset; /* "Source" here stands for which charset Windows DM was using as source, when converted to unicode.
We have to use same charset to recode from unicode to get same string as application sent it.
For Unicode application that is the same as "Charset", or in case of ANSI on Windows - defaulst system codepage */
char *DataBase;
LIST ListItem;
LIST *Stmts;
Expand Down Expand Up @@ -420,9 +424,9 @@ typedef struct
SQLRETURN DSNPrompt_Lookup(MADB_Prompt *prompt, const char *SetupLibName, MADB_Dbc *Dbc);
int DSNPrompt_Free (MADB_Prompt *prompt);

Client_Charset* GetDefaultOsCharset(Client_Charset *cc);
int InitClientCharset (Client_Charset *cc, const char * name);
void CloseClientCharset (Client_Charset *cc);
void CopyClientCharset(Client_Charset * Src, Client_Charset * Dst);
void CloseClientCharset(Client_Charset *cc);

/* Default precision of SQL_NUMERIC */
#define MADB_DEFAULT_PRECISION 38
Expand Down
7 changes: 7 additions & 0 deletions ma_platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,10 @@ SQLLEN MADB_SetString(Client_Charset* cc, void *Dest, SQLULEN DestLength,
}
/* }}} */


/* Stub - needed on windows only */
int GetSourceAnsiCs(Client_Charset *cc)
{

return 0;
}
25 changes: 24 additions & 1 deletion ma_platform_win32.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2014,2015 MariaDB Corporation AB
Copyright (C) 2014,2018 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -29,6 +29,21 @@ extern Client_Charset utf8;
char LogFile[256];


char *strndup(const char *s, size_t n)
{
size_t len= MIN(strlen(s), n);
char *res= (char*)malloc(len + 1);

if (res != NULL)
{
memcpy(res, s, len);
res[len]= '\0';
}

return res;
}


const char* GetDefaultLogDir()
{
const char *DefaultLogDir= "c:";
Expand Down Expand Up @@ -259,3 +274,11 @@ SQLLEN MADB_SetString(Client_Charset* cc, void *Dest, SQLULEN DestLength,
return Length;
}
}


int GetSourceAnsiCs(Client_Charset *cc)
{
cc->CodePage= GetConsoleWindow() ? GetConsoleCP() : GetACP();
/* We don't need cs_info for this */
return cc->CodePage;
}
37 changes: 19 additions & 18 deletions ma_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ SQLRETURN MADB_StmtPutData(MADB_Stmt *Stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or
*/
if (Record->ConciseType == SQL_C_WCHAR)
{
ConvertedDataPtr= MADB_ConvertFromWChar((SQLWCHAR *)DataPtr, (SQLINTEGER)(StrLen_or_Ind/sizeof(SQLWCHAR)), &Length, &Stmt->Connection->charset, NULL);
/* Conn cs */
ConvertedDataPtr= MADB_ConvertFromWChar((SQLWCHAR *)DataPtr, (SQLINTEGER)(StrLen_or_Ind/sizeof(SQLWCHAR)), &Length, &Stmt->Connection->Charset, NULL);

if ((ConvertedDataPtr == NULL || Length == 0) && StrLen_or_Ind > 0)
{
Expand Down Expand Up @@ -1874,11 +1875,11 @@ SQLRETURN MADB_FixFetchedValues(MADB_Stmt *Stmt, int RowNumber, MYSQL_ROWS *Save
break;
case SQL_C_WCHAR:
{
SQLLEN CharLen= MADB_SetString(&Stmt->Connection->charset, DataPtr, ArdRec->OctetLength, (char *)Stmt->result[i].buffer,
SQLLEN CharLen= MADB_SetString(&Stmt->Connection->Charset, DataPtr, ArdRec->OctetLength, (char *)Stmt->result[i].buffer,
*Stmt->stmt->bind[i].length, &Stmt->Error);


/*MADB_ConvertAnsi2Unicode(&Stmt->Connection->charset, (char *)Stmt->result[i].buffer, *Stmt->stmt->bind[i].length,
/*MADB_ConvertAnsi2Unicode(&Stmt->Connection->Charset, (char *)Stmt->result[i].buffer, *Stmt->stmt->bind[i].length,
(SQLWCHAR *)DataPtr, ArdRec->OctetLength, &CharLen, 1, &Stmt->Error);*/
/* Not quite right */
if (IndicatorPtr)
Expand Down Expand Up @@ -2777,7 +2778,7 @@ SQLRETURN MADB_StmtGetData(SQLHSTMT StatementHandle,
size_t ReqBuffOctetLen;
/* Size in chars */
CharLength= MbstrCharLen(ClientValue, Stmt->stmt->fields[Offset].max_length - Stmt->CharOffset[Offset],
Stmt->Connection->charset.cs_info);
Stmt->Connection->Charset.cs_info);
/* MbstrCharLen gave us length in characters. For encoding of each character we might need
2 SQLWCHARs in case of UTF16, or 1 SQLWCHAR in case of UTF32. Probably we need calcualate better
number of required SQLWCHARs */
Expand All @@ -2798,13 +2799,13 @@ SQLRETURN MADB_StmtGetData(SQLHSTMT StatementHandle,
return MADB_SetError(&Stmt->Error, MADB_ERR_HY001, NULL, 0);
}

CharLength= MADB_SetString(&Stmt->Connection->charset, IrdRec->InternalBuffer, (SQLINTEGER)ReqBuffOctetLen,
CharLength= MADB_SetString(&Stmt->Connection->Charset, IrdRec->InternalBuffer, (SQLINTEGER)ReqBuffOctetLen,
ClientValue, Stmt->stmt->fields[Offset].max_length - Stmt->CharOffset[Offset], &Stmt->Error);
}
else
{
/* Application's buffer is big enough - writing directly there */
CharLength= MADB_SetString(&Stmt->Connection->charset, TargetValuePtr, (SQLINTEGER)(BufferLength / sizeof(SQLWCHAR)),
CharLength= MADB_SetString(&Stmt->Connection->Charset, TargetValuePtr, (SQLINTEGER)(BufferLength / sizeof(SQLWCHAR)),
ClientValue, Stmt->stmt->fields[Offset].max_length - Stmt->CharOffset[Offset], &Stmt->Error);
}

Expand Down Expand Up @@ -3154,13 +3155,13 @@ SQLRETURN MADB_StmtColAttr(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, SQLUSMALL
NumericAttribute= (SQLLEN)Record->AutoUniqueValue;
break;
case SQL_DESC_BASE_COLUMN_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : NULL,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : NULL,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->BaseColumnName, strlen(Record->BaseColumnName), &Stmt->Error);
IsNumericAttr= FALSE;
break;
case SQL_DESC_BASE_TABLE_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : NULL,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : NULL,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->BaseTableName, strlen(Record->BaseTableName), &Stmt->Error);
IsNumericAttr= FALSE;
Expand All @@ -3169,13 +3170,13 @@ SQLRETURN MADB_StmtColAttr(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, SQLUSMALL
NumericAttribute= (SQLLEN)Record->CaseSensitive;
break;
case SQL_DESC_CATALOG_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->CatalogName, strlen(Record->CatalogName), &Stmt->Error);
IsNumericAttr= FALSE;
break;
case SQL_DESC_SCHEMA_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
"", 0, &Stmt->Error);
IsNumericAttr= FALSE;
Expand All @@ -3201,32 +3202,32 @@ SQLRETURN MADB_StmtColAttr(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, SQLUSMALL
NumericAttribute= (SQLLEN)Record->Length;
break;
case SQL_DESC_LITERAL_PREFIX:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->LiteralPrefix, strlen(Record->LiteralPrefix), &Stmt->Error);
IsNumericAttr= FALSE;
break;
case SQL_DESC_LITERAL_SUFFIX:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->LiteralSuffix, strlen(Record->LiteralSuffix), &Stmt->Error);
IsNumericAttr= FALSE;
break;
case SQL_DESC_LOCAL_TYPE_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
"", 0, &Stmt->Error);
IsNumericAttr= FALSE;
break;
case SQL_DESC_LABEL:
case SQL_DESC_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->ColumnName, strlen(Record->ColumnName), &Stmt->Error);
IsNumericAttr= FALSE;
break;
case SQL_DESC_TYPE_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->TypeName, strlen(Record->TypeName), &Stmt->Error);
IsNumericAttr= FALSE;
Expand All @@ -3250,7 +3251,7 @@ SQLRETURN MADB_StmtColAttr(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, SQLUSMALL
NumericAttribute= Record->Scale;
break;
case SQL_DESC_TABLE_NAME:
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->charset : 0,
StringLength= (SQLSMALLINT)MADB_SetString(IsWchar ? &Stmt->Connection->Charset : 0,
CharacterAttributePtr, (IsWchar) ? BufferLength / sizeof(SQLWCHAR) : BufferLength,
Record->TableName, strlen(Record->TableName), &Stmt->Error);
IsNumericAttr= FALSE;
Expand Down Expand Up @@ -3965,7 +3966,7 @@ SQLRETURN MADB_StmtDescribeCol(MADB_Stmt *Stmt, SQLUSMALLINT ColumnNumber, void

if ((ColumnName || BufferLength) && Record->ColumnName)
{
size_t Length= MADB_SetString(isWChar ? &Stmt->Connection->charset : 0, ColumnName, ColumnName ? BufferLength : 0, Record->ColumnName, SQL_NTS, &Stmt->Error);
size_t Length= MADB_SetString(isWChar ? &Stmt->Connection->Charset : 0, ColumnName, ColumnName ? BufferLength : 0, Record->ColumnName, SQL_NTS, &Stmt->Error);
if (NameLengthPtr)
*NameLengthPtr= (SQLSMALLINT)Length;
if (!BufferLength)
Expand Down Expand Up @@ -4035,7 +4036,7 @@ SQLRETURN MADB_GetCursorName(MADB_Stmt *Stmt, void *CursorName, SQLSMALLINT Buff
my_snprintf(Stmt->Cursor.Name, MADB_MAX_CURSOR_NAME, "SQL_CUR%d",
Stmt->Connection->CursorCount++);
}
Length= (SQLSMALLINT)MADB_SetString(isWChar ? &Stmt->Connection->charset : 0, CursorName,
Length= (SQLSMALLINT)MADB_SetString(isWChar ? &Stmt->Connection->Charset : 0, CursorName,
BufferLength, Stmt->Cursor.Name, SQL_NTS, &Stmt->Error);
if (NameLengthPtr)
*NameLengthPtr= (SQLSMALLINT)Length;
Expand Down
11 changes: 4 additions & 7 deletions ma_string.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013,2016 MariaDB Corporation AB
Copyright (C) 2013,2018 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -453,13 +453,10 @@ int InitClientCharset(Client_Charset *cc, const char * name)
}


Client_Charset* GetDefaultOsCharset(Client_Charset *cc)
void CopyClientCharset(Client_Charset * Src, Client_Charset * Dst)
{
if (InitClientCharset(cc, madb_get_os_character_set()))
{
return NULL;
}
return cc;
Dst->CodePage= Src->CodePage;
Dst->cs_info= Src->cs_info;
}


Expand Down
Loading

0 comments on commit 2d4fce5

Please sign in to comment.