diff --git a/ma_connection.c b/ma_connection.c index 5d50989f..9372eafe 100644 --- a/ma_connection.c +++ b/ma_connection.c @@ -1057,14 +1057,13 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV break; case SQL_DBMS_VER: { - char Version[11]; + char Version[13]; ulong ServerVersion= 0L; - unsigned int Major=0, Minor=0, Patch= 0; if (Dbc->mariadb) { ServerVersion= mysql_get_server_version(Dbc->mariadb); - my_snprintf(Version, 11, "%02u.%02u.%06u", ServerVersion / 10000, + _snprintf(Version, sizeof(Version), "%02u.%02u.%06u", ServerVersion / 10000, (ServerVersion % 10000) / 100, ServerVersion % 100); } else diff --git a/ma_error.c b/ma_error.c index 1f321ced..dc9a91a6 100644 --- a/ma_error.c +++ b/ma_error.c @@ -267,8 +267,8 @@ SQLRETURN MADB_GetDiagRec(MADB_Error *Err, SQLSMALLINT RecNumber, /* check if we have to map the SQLState to ODBC version 2 state */ if (OdbcVersion == SQL_OV_ODBC2) { - int i=0; - while (MADB_ErrorList[i].SqlState) + int i= 0; + while (MADB_ErrorList[i].SqlState[0]) { if (strcmp(Err->SqlState, MADB_ErrorList[i].SqlState) == 0) { @@ -276,7 +276,7 @@ SQLRETURN MADB_GetDiagRec(MADB_Error *Err, SQLSMALLINT RecNumber, SqlStateVersion= MADB_ErrorList[i].SqlStateV2; break; } - i++; + ++i; } } diff --git a/ma_result.c b/ma_result.c index 819d2a73..7995f987 100644 --- a/ma_result.c +++ b/ma_result.c @@ -27,19 +27,8 @@ SQLRETURN MADB_StmtDataSeek(MADB_Stmt *Stmt, my_ulonglong FetchOffset) { return SQL_NO_DATA_FOUND; } - /* - Stmt->Cursor.Position= 0; - for (tmp= Stmt->stmt->result.data; FetchOffset-- && tmp ; tmp = tmp->next) - Stmt->Cursor.Position++; - Stmt->stmt->result_cursor= tmp; - */ mysql_stmt_data_seek(Stmt->stmt, FetchOffset); - /* We need to fetch lengths, so SQLGetData will return correct results. - Since we need to prevent overwriting bound variables we will set buffer_types - to SQL_TYPE_NULL temporarily - */ - return SQL_SUCCESS; } /* }}} */ diff --git a/test/error.c b/test/error.c index da57c7c2..f0942aea 100644 --- a/test/error.c +++ b/test/error.c @@ -1,6 +1,6 @@ /* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. - 2013 MontyProgram AB + 2013, 2017 MariaDB Corporation AB The MySQL Connector/ODBC is licensed under the terms of the GPLv2 , like most @@ -594,7 +594,35 @@ ODBC_TEST(t_bug49466) } +ODBC_TEST(t_odbc94) +{ + SQLHANDLE henv1; + SQLHANDLE Connection1; + SQLHANDLE Stmt1; + SQLCHAR conn[512]; + SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1]; + SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1]; + SQLINTEGER error; + SQLSMALLINT len; + sprintf((char *)conn, "DRIVER=%s;SERVER=%s;UID=%s;PASSWORD=%s;DATABASE=%s%s;", + my_drivername, my_servername, my_uid, my_pwd, my_schema, ma_strport); + + CHECK_ENV_RC(henv1, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv1)); + CHECK_ENV_RC(henv1, SQLSetEnvAttr(henv1, SQL_ATTR_ODBC_VERSION, + (SQLPOINTER)SQL_OV_ODBC2, SQL_IS_INTEGER)); + CHECK_ENV_RC(henv1, SQLAllocHandle(SQL_HANDLE_DBC, henv1, &Connection1)); + CHECK_DBC_RC(Connection1, SQLDriverConnect(Connection1, NULL, conn, (SQLSMALLINT)strlen(conn), NULL, 0, + NULL, SQL_DRIVER_NOPROMPT)); + CHECK_DBC_RC(Connection1, SQLAllocHandle(SQL_HANDLE_STMT, Connection1, &Stmt1)); + + EXPECT_STMT(Stmt1, SQLExecDirect(Stmt1, "GRANT ALL PRIVILEGES on odbc94 to public", SQL_NTS), SQL_ERROR); + + CHECK_STMT_RC(Stmt, SQLGetDiagRec(SQL_HANDLE_STMT, Stmt1, 1, sqlstate, &error, + message, sizeof(message), &len)); + + return OK; +} MA_ODBC_TESTS my_tests[]= @@ -615,6 +643,7 @@ MA_ODBC_TESTS my_tests[]= {t_bug13542600, "t_bug13542600"}, {t_bug14285620, "t_bug14285620"}, {t_bug49466, "t_bug49466"}, + {t_odbc94, "t_odbc94"}, {NULL, NULL} }; diff --git a/test/result2.c b/test/result2.c index 1201e8bf..d3d1adbf 100644 --- a/test/result2.c +++ b/test/result2.c @@ -1054,12 +1054,13 @@ ODBC_TEST(t_odbc77) EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA); CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); -#ifdef MDEV_11966_FIXED - OK_SIMPLE_STMT(Stmt, "ANALYZE SELECT 1"); - CHECK_STMT_RC(Stmt, SQLFetch(Stmt)); - EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA); - CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); -#endif + if (ServerNewerThan(Connection, 10, 2, 5)) + { + OK_SIMPLE_STMT(Stmt, "ANALYZE SELECT 1"); + CHECK_STMT_RC(Stmt, SQLFetch(Stmt)); + EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA); + CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); + } OK_SIMPLE_STMT(Stmt, "EXPLAIN SELECT 1"); CHECK_STMT_RC(Stmt, SQLFetch(Stmt)); EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA); @@ -1072,6 +1073,17 @@ ODBC_TEST(t_odbc77) EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA); CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));*/ + /* Just to test some more exotic commands */ + OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS odbc77"); + OK_SIMPLE_STMT(Stmt, "CREATE TABLE odbc77(id INT NOT NULL)"); + OK_SIMPLE_STMT(Stmt, "TRUNCATE TABLE odbc77"); + OK_SIMPLE_STMT(Stmt, "DROP TABLE odbc77"); + + OK_SIMPLE_STMT(Stmt, "SELECT 1"); + CHECK_STMT_RC(Stmt, SQLFetch(Stmt)); + EXPECT_STMT(Stmt, SQLFetch(Stmt), SQL_NO_DATA); + CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); + return OK; } diff --git a/test/tap.h b/test/tap.h index ce331515..e7bad589 100644 --- a/test/tap.h +++ b/test/tap.h @@ -1116,4 +1116,21 @@ char* hide_pwd(char *connstr) return connstr; } + +BOOL ServerNewerThan(SQLHDBC Conn, unsigned int major, unsigned int minor, unsigned int patch) +{ + unsigned int ServerMajor= 0, ServerMinor= 0, ServerPatch= 0; + SQLCHAR ServerVersion[32]; + + SQLGetInfo(Conn, SQL_DBMS_VER, ServerVersion, sizeof(ServerVersion), NULL); + + sscanf(ServerVersion, "%u.%u.%u", &ServerMajor, &ServerMinor, &ServerPatch); + + if (ServerMajor < major || ServerMajor == major && (ServerMinor < minor || ServerMinor == minor && ServerPatch < patch)) + { + return FALSE; + } + + return TRUE; +} #endif /* #ifndef _tap_h_ */