Skip to content

Commit

Permalink
Some minor changes done while merged 2.0 to the main branch
Browse files Browse the repository at this point in the history
Types/typos correstions, casts etc
But couple of tests in catalog have been fixed
  • Loading branch information
lawrinn committed Dec 8, 2015
1 parent 182673d commit bbe3c2c
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 127 deletions.
18 changes: 8 additions & 10 deletions ma_connection.c
Expand Up @@ -167,10 +167,8 @@ SQLRETURN MADB_DbcSetAttr(MADB_Dbc *Dbc, SQLINTEGER Attribute, SQLPOINTER ValueP
break;
case SQL_ATTR_AUTOCOMMIT:
{
SQLINTEGER ValidAttrs[]= {2, SQL_AUTOCOMMIT_ON, SQL_AUTOCOMMIT_OFF};
/* (Here and in other places)We need to double-cast to avoid compiler warnings.
size_t is chosen as integer type that has the same size with pointer */
MADB_CHECK_ATTRIBUTE(Dbc, (SQLINTEGER)(size_t)ValuePtr, ValidAttrs);
SQLULEN ValidAttrs[]= {2, SQL_AUTOCOMMIT_ON, SQL_AUTOCOMMIT_OFF};
MADB_CHECK_ATTRIBUTE(Dbc, ValuePtr, ValidAttrs);
/* if a connection is open, try to apply setting to the connection */
if (Dbc->mariadb)
{
Expand All @@ -184,7 +182,7 @@ SQLRETURN MADB_DbcSetAttr(MADB_Dbc *Dbc, SQLINTEGER Attribute, SQLPOINTER ValueP
return SQL_ERROR;
}
}
Dbc->AutoCommit= (SQLUINTEGER)(size_t)ValuePtr;
Dbc->AutoCommit= (SQLUINTEGER)(SQLULEN)ValuePtr;
}
break;
case SQL_ATTR_CONNECTION_DEAD:
Expand All @@ -209,15 +207,15 @@ SQLRETURN MADB_DbcSetAttr(MADB_Dbc *Dbc, SQLINTEGER Attribute, SQLPOINTER ValueP
}
break;
case SQL_ATTR_LOGIN_TIMEOUT:
Dbc->LoginTimeout= (SQLUINTEGER)(size_t)ValuePtr;
Dbc->LoginTimeout= (SQLUINTEGER)(SQLULEN)ValuePtr;
break;
case SQL_ATTR_METADATA_ID:
Dbc->MetadataId= (SQLUINTEGER)(size_t)ValuePtr;
Dbc->MetadataId= (SQLUINTEGER)(SQLULEN)ValuePtr;
break;
case SQL_ATTR_ODBC_CURSORS:
{
SQLINTEGER ValidAttrs[]= {3, SQL_CUR_USE_IF_NEEDED, SQL_CUR_USE_ODBC, SQL_CUR_USE_DRIVER};
MADB_CHECK_ATTRIBUTE(Dbc, (SQLULEN)ValuePtr, ValidAttrs);
SQLULEN ValidAttrs[]= {3, SQL_CUR_USE_IF_NEEDED, SQL_CUR_USE_ODBC, SQL_CUR_USE_DRIVER};
MADB_CHECK_ATTRIBUTE(Dbc, ValuePtr, ValidAttrs);
if ((SQLULEN)ValuePtr != SQL_CUR_USE_ODBC)
MADB_SetError(&Dbc->Error, MADB_ERR_01S02, NULL, 0);
Dbc->OdbcCursors= SQL_CUR_USE_ODBC;
Expand All @@ -235,7 +233,7 @@ SQLRETURN MADB_DbcSetAttr(MADB_Dbc *Dbc, SQLINTEGER Attribute, SQLPOINTER ValueP
MADB_SetError(&Dbc->Error, MADB_ERR_HY001, NULL, 0);
return Dbc->Error.ReturnValue;
}
Dbc->PacketSize= (SQLUINTEGER)(size_t)ValuePtr;
Dbc->PacketSize= (SQLUINTEGER)(SQLULEN)ValuePtr;
break;
case SQL_ATTR_QUIET_MODE:
Dbc->QuietMode= (HWND)ValuePtr;
Expand Down
4 changes: 2 additions & 2 deletions ma_connection.h
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013 SkySQL AB
Copyright (C) 2013,2015 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 @@ -62,7 +62,7 @@ SQLRETURN MADB_Dbc_GetCurrentDB(MADB_Dbc *Connection, SQLPOINTER CurrentDB, SQLI
/**************** Helper macros ****************/
/* check if the connection is established */
#define MADB_Dbc_ACTIVE(a) \
((a)->mariadb && mysql_get_socket((a)->mariadb) != -1)
((a)->mariadb && mysql_get_socket((a)->mariadb) != MARIADB_INVALID_SOCKET)

#define MADB_Dbc_DSN(a) \
(a) && (a)->Dsn
Expand Down
4 changes: 2 additions & 2 deletions ma_desc.c
@@ -1,6 +1,6 @@
/************************************************************************************
Copyright (C) 2013,2015 MariaDB Corporation AB
Copyright (C) 2013, 2015 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
License as published by the Free Software Foundation; either
Expand Down
17 changes: 0 additions & 17 deletions ma_platform_posix.c
Expand Up @@ -118,23 +118,6 @@ int DSNPrompt_Free (MADB_Prompt *prompt)
}


/* Length in SQLWCHAR units*/
SQLINTEGER SqlwcsLen(SQLWCHAR *str)
{
SQLINTEGER result= 0;

if (str)
{
while (*str)
{
++result;
/* str+= (utf16->mb_charlen(*str))/sizeof(SQLWCHAR)); */
++str;
}
}
return result;
}


/* CharLen < 0 - treat as NTS */
SQLINTEGER SqlwcsOctetLen(SQLWCHAR *str, SQLINTEGER *CharLen)
Expand Down
14 changes: 7 additions & 7 deletions ma_statement.c
Expand Up @@ -494,7 +494,7 @@ SQLRETURN MADB_StmtPutData(MADB_Stmt *Stmt, SQLPOINTER DataPtr, SQLLEN StrLen_or
/* To make sure that we will not consume the doble amount of memory, we need to send
data via mysql_send_long_data directly to the server instead of allocating a separate
buffer. This means we need to process Update and Insert statements row by row. */
if (mysql_stmt_send_long_data(MyStmt->stmt, Stmt->PutParam, (wDataPtr ? (char *)wDataPtr : DataPtr), (unsigned long)Length))
if (mysql_stmt_send_long_data(MyStmt->stmt, Stmt->PutParam, (wDataPtr ? (char *)wDataPtr : DataPtr), (size_t)Length))
{
MADB_SetNativeError(&Stmt->Error, SQL_HANDLE_STMT, MyStmt->stmt);
}
Expand Down Expand Up @@ -1882,28 +1882,28 @@ SQLRETURN MADB_StmtSetAttr(MADB_Stmt *Stmt, SQLINTEGER Attribute, SQLPOINTER Val
Stmt->Options.SimulateCursor= (SQLULEN) ValuePtr;
break;
case SQL_ATTR_CURSOR_SCROLLABLE:
Stmt->Options.CursorType= ((SQLLEN)ValuePtr == SQL_NONSCROLLABLE) ?
Stmt->Options.CursorType= ((SQLULEN)ValuePtr == SQL_NONSCROLLABLE) ?
SQL_CURSOR_FORWARD_ONLY : SQL_CURSOR_STATIC;
break;
case SQL_ATTR_CURSOR_SENSITIVITY:
/* we only support default value = SQL_UNSPECIFIED */
if ((SQLLEN)ValuePtr != SQL_UNSPECIFIED)
if ((SQLULEN)ValuePtr != SQL_UNSPECIFIED)
{
MADB_SetError(&Stmt->Error, MADB_ERR_01S02, "Option value changed to default cursor sensitivity", 0);
ret= SQL_SUCCESS_WITH_INFO;
}
break;
case SQL_ATTR_CURSOR_TYPE:
/* We need to check global DSN/Connection settings */
if (MA_ODBC_CURSOR_FORWARD_ONLY(Stmt->Connection) && (SQLLEN)ValuePtr != SQL_CURSOR_FORWARD_ONLY)
if (MA_ODBC_CURSOR_FORWARD_ONLY(Stmt->Connection) && (SQLULEN)ValuePtr != SQL_CURSOR_FORWARD_ONLY)
{
Stmt->Options.CursorType= SQL_CURSOR_FORWARD_ONLY;
MADB_SetError(&Stmt->Error, MADB_ERR_01S02, "Option value changed to default (SQL_CURSOR_FORWARD_ONLY)", 0);
return Stmt->Error.ReturnValue;
}
else if (MA_ODBC_CURSOR_DYNAMIC(Stmt->Connection))
{
if ((SQLLEN)ValuePtr == SQL_CURSOR_KEYSET_DRIVEN)
if ((SQLULEN)ValuePtr == SQL_CURSOR_KEYSET_DRIVEN)
{
Stmt->Options.CursorType= SQL_CURSOR_STATIC;
MADB_SetError(&Stmt->Error, MADB_ERR_01S02, "Option value changed to default (SQL_CURSOR_STATIC)", 0);
Expand All @@ -1914,8 +1914,8 @@ SQLRETURN MADB_StmtSetAttr(MADB_Stmt *Stmt, SQLINTEGER Attribute, SQLPOINTER Val
/* only FORWARD or Static is allowed */
else
{
if ((SQLLEN)ValuePtr != SQL_CURSOR_FORWARD_ONLY &&
(SQLLEN)ValuePtr != SQL_CURSOR_STATIC)
if ((SQLULEN)ValuePtr != SQL_CURSOR_FORWARD_ONLY &&
(SQLULEN)ValuePtr != SQL_CURSOR_STATIC)
{
Stmt->Options.CursorType= SQL_CURSOR_STATIC;
MADB_SetError(&Stmt->Error, MADB_ERR_01S02, "Option value changed to default (SQL_CURSOR_STATIC)", 0);
Expand Down
18 changes: 18 additions & 0 deletions ma_string.c
Expand Up @@ -534,3 +534,21 @@ SQLINTEGER SqlwcsCharLen(SQLWCHAR *str, SQLLEN octets)
return result;
}


/* Length in SQLWCHAR units*/
SQLINTEGER SqlwcsLen(SQLWCHAR *str)
{
SQLINTEGER result= 0;

if (str)
{
while (*str)
{
++result;
/* str+= (utf16->mb_charlen(*str))/sizeof(SQLWCHAR)); */
++str;
}
}
return result;
}

7 changes: 4 additions & 3 deletions ma_string.h
Expand Up @@ -38,9 +38,10 @@ size_t MADB_SetString(Client_Charset* cc, void *Dest, unsigned int DestLength,
my_bool MADB_ValidateStmt(char *StmtStr);
my_bool MADB_IsStatementSupported(char *StmtStr, char *token1, char *token2);

SQLINTEGER MbstrOctetLen(char *str, SQLLEN *CharLen, CHARSET_INFO *cs);
SQLLEN MbstrCharLen(char *str, SQLINTEGER OctetLen, CHARSET_INFO *cs);
SQLINTEGER SqlwcsCharLen(SQLWCHAR *str, SQLLEN octets);
SQLINTEGER MbstrOctetLen(char *str, SQLLEN *CharLen, CHARSET_INFO *cs);
SQLLEN MbstrCharLen(char *str, SQLINTEGER OctetLen, CHARSET_INFO *cs);
SQLINTEGER SqlwcsCharLen(SQLWCHAR *str, SQLLEN octets);
SQLINTEGER SqlwcsLen(SQLWCHAR *str);

#define ADJUST_LENGTH(ptr, len)\
if((ptr) && ((len) == SQL_NTS))\
Expand Down
23 changes: 12 additions & 11 deletions test/basic.c
@@ -1,6 +1,6 @@
/*
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2013 MontyProgram AB
2013, 2015 MariaDB Corporation AB
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
Expand Down Expand Up @@ -497,7 +497,7 @@ ODBC_TEST(charset_utf8)

CHECK_STMT_RC(hstmt1, SQLFreeStmt(hstmt1, SQL_CLOSE));

CHECK_STMT_RC(hstmt1, SQLColumns(hstmt1, (SQLCHAR *)"odbc_test", SQL_NTS, NULL, 0,
CHECK_STMT_RC(hstmt1, SQLColumns(hstmt1, (SQLCHAR *)my_schema, SQL_NTS, NULL, 0,
(SQLCHAR *)"t_bug19345", SQL_NTS,
(SQLCHAR *)"%", 1));

Expand Down Expand Up @@ -906,6 +906,7 @@ ODBC_TEST(t_bug32014)
SQLHDBC hdbc1;
SQLHSTMT hstmt1;
SQLUINTEGER info;
SQLULEN attr;
long i=0;
SQLSMALLINT value_len;

Expand Down Expand Up @@ -944,26 +945,26 @@ ODBC_TEST(t_bug32014)
CHECK_STMT_RC(hstmt1, SQLSetStmtOption(hstmt1, SQL_CURSOR_TYPE
, SQL_CURSOR_FORWARD_ONLY ));
CHECK_STMT_RC(hstmt1, SQLGetStmtOption(hstmt1, SQL_CURSOR_TYPE,
(SQLPOINTER) &info));
is_num(info, expectedCurType[i][SQL_CURSOR_FORWARD_ONLY]);
(SQLPOINTER) &attr));
is_num(attr, expectedCurType[i][SQL_CURSOR_FORWARD_ONLY]);

CHECK_STMT_RC(hstmt1, SQLSetStmtOption(hstmt1, SQL_CURSOR_TYPE,
SQL_CURSOR_KEYSET_DRIVEN ));
CHECK_STMT_RC(hstmt1, SQLGetStmtOption(hstmt1, SQL_CURSOR_TYPE,
(SQLPOINTER) &info));
is_num(info, expectedCurType[i][SQL_CURSOR_KEYSET_DRIVEN]);
(SQLPOINTER) &attr));
is_num(attr, expectedCurType[i][SQL_CURSOR_KEYSET_DRIVEN]);

CHECK_STMT_RC(hstmt1, SQLSetStmtOption(hstmt1, SQL_CURSOR_TYPE,
SQL_CURSOR_DYNAMIC ));
CHECK_STMT_RC(hstmt1, SQLGetStmtOption(hstmt1, SQL_CURSOR_TYPE,
(SQLPOINTER) &info));
is_num(info, expectedCurType[i][SQL_CURSOR_DYNAMIC]);
(SQLPOINTER) &attr));
is_num(attr, expectedCurType[i][SQL_CURSOR_DYNAMIC]);

CHECK_STMT_RC(hstmt1, SQLSetStmtOption(hstmt1, SQL_CURSOR_TYPE,
SQL_CURSOR_STATIC ));
CHECK_STMT_RC(hstmt1, SQLGetStmtOption(hstmt1, SQL_CURSOR_TYPE,
(SQLPOINTER) &info));
is_num(info, expectedCurType[i][SQL_CURSOR_STATIC]);
(SQLPOINTER) &attr));
is_num(attr, expectedCurType[i][SQL_CURSOR_STATIC]);

ODBC_Disconnect(henv1, hdbc1, hstmt1);

Expand Down Expand Up @@ -1300,7 +1301,7 @@ MA_ODBC_TESTS my_tests[]=
{bug19823, "bug19823", NORMAL},
{t_basic, "t_basic", NORMAL},
{t_reconnect, "t_reconnect", NORMAL},
{charset_utf8, "charset_utf8", KNOWN_FAILURE},
{charset_utf8, "charset_utf8", NORMAL},
{charset_gbk, "charset_gbk", NORMAL},
{t_bug30774, "t_bug30774", NORMAL},
#ifdef WE_HAVE_SETUPLIB
Expand Down
2 changes: 1 addition & 1 deletion test/catalog.c
@@ -1,6 +1,6 @@
/*
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2013 MontyProgram AB
2013, 2015 MariaDB Corporation AB
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
Expand Down
2 changes: 1 addition & 1 deletion test/multistatement.c
@@ -1,6 +1,6 @@
/*
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2013 MontyProgram AB
2013, 2015 MariaDB Corporation AB
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
Expand Down
2 changes: 1 addition & 1 deletion test/result2.c
Expand Up @@ -911,7 +911,7 @@ ODBC_TEST(t_bug11766437)
CHECK_STMT_RC(Stmt, SQLFetch(Stmt));

ptr= rows;
for (i= 0; i < rowcnt; ++i)
for (i= 0; (SQLUINTEGER)i < rowcnt; ++i)
{
/* Verifying inserted id field */
is_num(*((SQLINTEGER *)ptr), i);
Expand Down
5 changes: 1 addition & 4 deletions test/tap.h
Expand Up @@ -582,7 +582,7 @@ int ODBC_Connect(SQLHANDLE *Env, SQLHANDLE *Connection, SQLHANDLE *Stmt)
rc= SQLAllocHandle(SQL_HANDLE_DBC, *Env, Connection);
FAIL_IF(rc != SQL_SUCCESS, "Couldn't allocate connection handle");

/*my_options |= 4;*/
/* my_options |= 4; */
_snprintf(DSNString, 1024, "DSN=%s;UID=%s;PWD=%s;PORT=%u;DATABASE=%s;OPTION=%ul;SERVER=%s", my_dsn, my_uid,
my_pwd, my_port, my_schema, my_options, my_servername);
diag("DSN: DSN=%s;UID=%s;PWD=%s;PORT=%u;DATABASE=%s;OPTION=%ul;SERVER=%s", my_dsn, my_uid,
Expand Down Expand Up @@ -868,9 +868,6 @@ SQLWCHAR *dup_char_as_sqlwchar(SQLCHAR *from)
SQLWCHAR* latin_as_sqlwchar(char *str, SQLWCHAR *buffer)
{
SQLWCHAR *res= buffer;
int error, char_size;
size_t len_in= strlen(str);
size_t len_out= len_in*2 + 8;

if (str == NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion test/types.c
@@ -1,6 +1,6 @@
/*
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2013 MontyProgram AB
2013, 2015 MariaDB Corporation AB
The MySQL Connector/ODBC is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
Expand Down

0 comments on commit bbe3c2c

Please sign in to comment.