Skip to content

Commit

Permalink
ODBC-313 The testcase for the fix, that has been already committed
Browse files Browse the repository at this point in the history
Added inclusion of header limits.h in ma_connection.c missing in some of
previous commits(ODBC-377 fix) containing reference to UINT_MAX, and
corrected testcase for that issue

Fix of "deprecated" warnings in testcases.
Small cleaning of ma_odbc.h
  • Loading branch information
lawrinn committed Mar 24, 2023
1 parent 2168db0 commit 373ade1
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 93 deletions.
1 change: 1 addition & 0 deletions ma_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <ma_odbc.h>
#include <limits.h>

extern const char* DefaultPluginLocation;
static const char* utf8mb3 = "utf8mb3";
Expand Down
64 changes: 19 additions & 45 deletions ma_odbc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/************************************************************************************
Copyright (C) 2013,2022 MariaDB Corporation AB
Copyright (C) 2013,2023 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 @@ -19,7 +19,7 @@
#ifndef _ma_odbc_h_
#define _ma_odbc_h_

#include <ma_odbc_version.h>
#include "ma_odbc_version.h"

#ifdef _WIN32
# include "ma_platform_win32.h"
Expand Down Expand Up @@ -69,29 +69,6 @@ typedef struct
SQLRETURN ReturnValue;
} MADB_Error;

typedef struct
{
SQLPOINTER TargetValuePtr;
SQLLEN BufferLength;
SQLLEN Utf8BufferLength;
SQLLEN *StrLen_or_Ind;
void *InternalBuffer; /* used for conversion */
SQLUINTEGER TargetType;
} MADB_ColBind;

typedef struct
{
SQLSMALLINT InputOutputType;
SQLSMALLINT ValueType;
SQLSMALLINT ParameterType;
SQLULEN ColumnSize;
SQLSMALLINT DecimalDigits;
SQLPOINTER ParameterValuePtr;
SQLLEN BufferLength;
SQLLEN *StrLen_or_IndPtr;
void *InternalBuffer; /* used for conversion */
} MADB_ParmBind;

typedef struct
{
/* Header */
Expand All @@ -108,34 +85,32 @@ typedef struct

typedef struct
{
SQLUSMALLINT *RowOperationPtr;
SQLULEN *RowOffsetPtr;
/*MADB_ColBind *ColumnBind;*/
MYSQL_BIND *Bind;
SQLLEN dummy;
SQLUINTEGER BindSize; /* size of each structure if using * Row-wise Binding */
SQLSMALLINT Allocated;
SQLUSMALLINT *RowOperationPtr;
SQLULEN *RowOffsetPtr;
MYSQL_BIND *Bind;
SQLLEN dummy;
SQLUINTEGER BindSize; /* size of each structure if using * Row-wise Binding */
SQLSMALLINT Allocated;
} MADB_Ard;

typedef struct
{
SQLUSMALLINT *ParamOperationPtr;
SQLULEN *ParamOffsetPtr;
/*MADB_ParmBind *ParamBind;*/
MYSQL_BIND *Bind;
SQLLEN ParamsetSize;
SQLUINTEGER ParamBindType;
SQLSMALLINT Allocated;
SQLUSMALLINT *ParamOperationPtr;
SQLULEN *ParamOffsetPtr;
MYSQL_BIND *Bind;
SQLLEN ParamsetSize;
SQLUINTEGER ParamBindType;
SQLSMALLINT Allocated;
} MADB_Apd;

typedef struct
{
MADB_Stmt* stmt;
SQLULEN* RowsFetched;
SQLUSMALLINT* RowStatusArray;
SQLULEN* RowsFetched;
SQLUSMALLINT* RowStatusArray;
MYSQL_FIELD* Fields;
SQLUINTEGER FieldCount;
SQLSMALLINT Allocated;
SQLUINTEGER FieldCount;
SQLSMALLINT Allocated;
} MADB_Ird;

typedef struct
Expand All @@ -147,7 +122,6 @@ typedef struct
SQLULEN *ParamProcessedPtr; /* SQLParamOptions */
#endif /* ODBCVER */
SQLUSMALLINT *ParamStatusPtr;
/*MADB_ParmBind* Parameters;*/
SQLSMALLINT Allocated;
} MADB_Ipd;

Expand Down Expand Up @@ -464,7 +438,7 @@ void CloseClientCharset(Client_Charset *cc);
#include <ma_debug.h>
#include <ma_desc.h>
#include <ma_statement.h>
#include <ma_string.h>
#include "ma_string.h"
#include <ma_result.h>
#include <ma_driver.h>
#include <ma_helper.h>
Expand Down
19 changes: 14 additions & 5 deletions test/basic.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2013, 2017 MariaDB Corporation AB
2013, 2023 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 @@ -299,7 +299,7 @@ ODBC_TEST(t_disconnect)
SQLHSTMT hstmt;

rc= SQLAllocHandle(SQL_HANDLE_DBC, Env, &hdbc1);
CHECK_ENV_RC(Env, rc);
CHECK_ENV_RC(Env, rc);
rc= SQLConnectW(hdbc1, wdsn, SQL_NTS, wuid, SQL_NTS, wpwd, SQL_NTS);
CHECK_DBC_RC(hdbc1, rc);

Expand Down Expand Up @@ -919,7 +919,6 @@ ODBC_TEST(t_describe_nulti)

ODBC_Connect(&henv1, &hdbc1, &hstmt1);


OK_SIMPLE_STMT(hstmt1, "DROP TABLE IF EXISTS t1");
OK_SIMPLE_STMT(hstmt1, "CREATE TABLE t1 (columnX VARCHAR(255))");

Expand Down Expand Up @@ -1642,6 +1641,7 @@ ODBC_TEST(t_odbc139)
CHECK_DBC_RC(Hdbc, SQLSetConnectAttr(Hdbc, SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER)"test", 4));
Hstmt= DoConnect(Hdbc, FALSE, NULL, NULL, NULL, 0, NULL, &Compression, NULL, NULL);

FAIL_IF(Hstmt == NULL, "Connection with compression failed");

Thread= CreateThread(NULL, 0, FireQueryInThread, Hstmt, 0, NULL);
WaitRc= WaitForSingleObject(Thread, 1500);
Expand Down Expand Up @@ -1789,6 +1789,7 @@ ODBC_TEST(t_odbc377)
{
SQLHDBC Hdbc;
SQLHSTMT Hstmt;
SQLCHAR Sqlstate[6];

CHECK_ENV_RC(Env, SQLAllocConnect(Env, &Hdbc));

Expand All @@ -1811,13 +1812,21 @@ ODBC_TEST(t_odbc377)

CHECK_STMT_RC(Hstmt, SQLSetStmtAttr(Hstmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)1, 0));
EXPECT_STMT(Hstmt, SQLExecDirect(Hstmt, "SELECT SLEEP(2)", SQL_NTS), SQL_ERROR);
CHECK_SQLSTATE_EX(Hstmt, SQL_HANDLE_STMT, "70100");
CHECK_STMT_RC(Hstmt, SQLGetDiagRec(SQL_HANDLE_STMT, Hstmt, 1, Sqlstate, NULL, NULL, 0, NULL));
if (strncmp(Sqlstate, "70100", 6) != 0 && strncmp(Sqlstate, "HY018", 6) != 0)
{
FAIL_IF(1, "Unexpected SQL State");
}
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

/* Verifying the same(i.e. query timeout works) for the case of prepare + execute */
CHECK_STMT_RC(Hstmt, SQLPrepare(Hstmt, "SELECT SLEEP(2)", SQL_NTS));
EXPECT_STMT(Hstmt, SQLExecute(Hstmt), SQL_ERROR);
CHECK_SQLSTATE_EX(Hstmt, SQL_HANDLE_STMT, "70100");
CHECK_STMT_RC(Hstmt, SQLGetDiagRec(SQL_HANDLE_STMT, Hstmt, 1, Sqlstate, NULL, NULL, 0, NULL));
if (strncmp(Sqlstate, "70100", 6) != 0 && strncmp(Sqlstate, "HY018", 6) != 0)
{
FAIL_IF(1, "Unexpected SQL State");
}

CHECK_STMT_RC(Hstmt, SQLFreeStmt(Hstmt, SQL_DROP));
CHECK_DBC_RC(Hdbc, SQLDisconnect(Hdbc));
Expand Down
17 changes: 8 additions & 9 deletions test/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ ODBC_TEST(t_setpos_del_all)

CHECK_STMT_RC(Stmt, SQLSetCursorName(Stmt, (SQLCHAR *)"venu", SQL_NTS));

CHECK_STMT_RC(Stmt, SQLSetStmtOption(Stmt, SQL_ROWSET_SIZE, 4));
CHECK_STMT_RC(Stmt, SQLSetStmtAttr(Stmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)4, 0));

OK_SIMPLE_STMT(Stmt, "SELECT * FROM t_setpos_del_all ORDER BY a ASC");

Expand Down Expand Up @@ -344,7 +344,7 @@ ODBC_TEST(t_setpos_del_all)

CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

CHECK_STMT_RC(Stmt, SQLSetStmtOption(Stmt, SQL_ROWSET_SIZE, 1));
CHECK_STMT_RC(Stmt, SQLSetStmtAttr(Stmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)1, 0));

OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS t_setpos_del_all");

Expand Down Expand Up @@ -719,11 +719,11 @@ ODBC_TEST(t_pos_datetime_delete1)

SQLSetStmtAttr(Stmt, SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_ROWVER, 0);
SQLSetStmtAttr(Stmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_DYNAMIC, 0);
SQLSetStmtOption(Stmt,SQL_SIMULATE_CURSOR,SQL_SC_NON_UNIQUE);
SQLSetStmtAttr(Stmt, SQL_SIMULATE_CURSOR, (SQLPOINTER) SQL_SC_NON_UNIQUE, 0);

SQLSetStmtAttr(hstmt1, SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_ROWVER, 0);
SQLSetStmtAttr(hstmt1, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_DYNAMIC, 0);
SQLSetStmtOption(hstmt1,SQL_SIMULATE_CURSOR,SQL_SC_NON_UNIQUE);
SQLSetStmtAttr(hstmt1, SQL_SIMULATE_CURSOR, (SQLPOINTER) SQL_SC_NON_UNIQUE, 0);

rc = SQLSetCursorName(Stmt, (SQLCHAR *)"venu_cur",8);
CHECK_STMT_RC(Stmt,rc);
Expand Down Expand Up @@ -897,7 +897,7 @@ ODBC_TEST(t_acc_crash)
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));
CHECK_STMT_RC(Stmt, SQLSetStmtAttr(Stmt, SQL_ATTR_CURSOR_TYPE,
(SQLPOINTER)SQL_CURSOR_STATIC, 0));
CHECK_STMT_RC(Stmt, SQLSetStmtOption(Stmt, SQL_ROWSET_SIZE, 1));
CHECK_STMT_RC(Stmt, SQLSetStmtAttr(Stmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)1, 0));

OK_SIMPLE_STMT(Stmt, "SELECT * FROM t_acc_crash ORDER BY a ASC");

Expand Down Expand Up @@ -2030,8 +2030,7 @@ ODBC_TEST(t_setpos_upd_bug1)
rc = SQLExtendedFetch(Stmt,SQL_FETCH_FIRST,0,NULL,&rgfRowStatus);
CHECK_STMT_RC(Stmt,rc);

rc = SQLSetStmtOption(Stmt,SQL_QUERY_TIMEOUT,30);
CHECK_STMT_RC(Stmt,rc);
CHECK_STMT_RC(Stmt, SQLSetStmtAttr(Stmt, SQL_QUERY_TIMEOUT, (SQLPOINTER)30, 0));

strcpy((char *)fname , "updated");
strcpy((char *)lname , "updated01234567890");
Expand Down Expand Up @@ -2754,7 +2753,7 @@ ODBC_TEST(t_bug32420)

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

CHECK_STMT_RC(hstmt1, SQLSetStmtOption(hstmt1, SQL_ROWSET_SIZE, 4));
CHECK_STMT_RC(hstmt1, SQLSetStmtAttr(hstmt1, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)4, 0));

OK_SIMPLE_STMT(hstmt1, "SELECT * FROM bug32420");
CHECK_STMT_RC(hstmt1, SQLBindCol(hstmt1, 1, SQL_C_LONG, nData, 0, NULL));
Expand Down Expand Up @@ -2841,7 +2840,7 @@ ODBC_TEST(t_bug32420)

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

CHECK_STMT_RC(hstmt1, SQLSetStmtOption(hstmt1, SQL_ROWSET_SIZE, 4));
CHECK_STMT_RC(hstmt1, SQLSetStmtAttr(hstmt1, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)4, 0));

OK_SIMPLE_STMT(hstmt1, "SELECT * FROM bug32420");
CHECK_STMT_RC(hstmt1, SQLBindCol(hstmt1, 1, SQL_C_LONG, nData, 0, NULL));
Expand Down
29 changes: 27 additions & 2 deletions test/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ ODBC_TEST(odbc143)

/**
Test of connect attributes that used to be treated as wrong data type.
SQL_ATTR_TXN_ISOLATION aslo had issue, but it is already cared of by other test
SQL_ATTR_TXN_ISOLATION also had issue, but it is already cared of by other test
*/
ODBC_TEST(odbc317)
{
Expand All @@ -775,13 +775,15 @@ ODBC_TEST(odbc317)
/* We ourselves kinda return ODBC(TODO: need to check why), but all other DM's return DRIVER. iODBC 3.52.12 used to do that toTODO: need to check why. The test is anyway about using correct data type for the attribute */
if (iOdbc() && DmMinVersion(3, 52, 13))
{
#pragma warning(disable:4995)
#pragma warning(push)
is_num(lenAttr, SQL_CUR_USE_ODBC);
#pragma warning(pop)
}
else
{
is_num(lenAttr, SQL_CUR_USE_DRIVER);
}

return OK;
}

Expand Down Expand Up @@ -830,6 +832,28 @@ ODBC_TEST(odbc326)
return OK;
}

/* Some apps use 1212 attribute */
ODBC_TEST(odbc313)
{
SQLLEN attr1212= 0;
SQLRETURN rc= SQL_SUCCESS;

OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS t_odbc313");
OK_SIMPLE_STMT(Stmt, "CREATE TABLE t_odbc313 ( id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, a INT NOT NULL)");

OK_SIMPLE_STMT(Stmt, "SELECT id, a FROM t_odbc313");
rc= SQLColAttribute(Stmt, 1, 1212, NULL, 0, NULL, &attr1212);
FAIL_IF(rc != SQL_SUCCESS, "Only SQL_SUCCESS is expected");
is_num(attr1212, SQL_TRUE);
rc= SQLColAttribute(Stmt, 2, 1212, NULL, 0, NULL, &attr1212);
FAIL_IF(rc != SQL_SUCCESS, "Only SQL_SUCCESS is expected");
is_num(attr1212, SQL_FALSE);
CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

OK_SIMPLE_STMT(Stmt, "DROP TABLE t_odbc313");
return OK;
}


MA_ODBC_TESTS my_tests[]=
{
Expand All @@ -855,6 +879,7 @@ MA_ODBC_TESTS my_tests[]=
{ odbc143, "odbc143_odbc160_ANSI_QUOTES", NORMAL },
{ odbc317, "odbc317_conattributes", NORMAL },
{ odbc326, "odbc326", NORMAL },
{ odbc313, "odbc313", NORMAL },
{ NULL, NULL }
};

Expand Down
Loading

0 comments on commit 373ade1

Please sign in to comment.