pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Regression tests for deprecated functions
7+ messages / 2 participants
[nested] [flat]

* Regression tests for deprecated functions
@ 2014-03-19 12:27  Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Michael Paquier @ 2014-03-19 12:27 UTC (permalink / raw)
  To: pgsql-odbc

Hi all,

I have created the attached patch, that adds a new set of regression
tests for all the deprecated functions of ODBC listed here:
http://msdn.microsoft.com/en-us/library/ms716309%28v=vs.85%29.aspx

Btw, I noticed that we use in most of the regression tests deprecated
functions  (SQLFreeStmt mainly). I think that we should change them to
the latest ODBC 3.X functions. I don't mind sending another patch for
that...
Regards,
-- 
Michael

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

20140319_pgodbc_deprecated.patch (text/plain, 11.3K) download diff --git a/test/expected/deprecated.out b/test/expected/deprecated.out new file mode 100644 index 0000000..191101d --- /dev/null +++ b/test/expected/deprecated.out @@ -0,0 +1,32 @@ +\! ./src/deprecated-test +Check for SQLAllocEnv +Check for SQLAllocConnect +Check for SQLAllocStmt +Check for SQLSetConnectOption +Check for SQLError +Error check: ERROR: relation "table_not_here" does not exist; +Error while executing the query +Check for SQLFreeStmt +Check for SQLBindParam +Result set: +bar +Check for SQLSetParam +Result set: +100 +Check for SQLGetStmtOption +Cursor type is: forward +Check for SQLSetStmtOption +Cursor type is: static +Check for SQLSetScrollOptions +Cursor type is: forward +Check for SQLColAttributes +Column 1: foo +Column 2: bar +Check for SQLParamOptions +Status of execution +Check for SQLFreeConnect +Check for SQLFreeEnv +connected +Check for SQLTransact +Result set: +disconnecting diff --git a/test/src/common.c b/test/src/common.c index 091dd1a..904b10d 100644 --- a/test/src/common.c +++ b/test/src/common.c @@ -68,7 +68,7 @@ test_disconnect(void) exit(1); } - rc = SQLFreeConnect(conn); + rc = SQLFreeHandle(SQL_HANDLE_DBC, conn); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn); @@ -76,7 +76,7 @@ test_disconnect(void) } conn = NULL; - rc = SQLFreeEnv(env); + rc = SQLFreeHandle(SQL_HANDLE_ENV, env); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env); diff --git a/test/src/deprecated-test.c b/test/src/deprecated-test.c new file mode 100644 index 0000000..a960b57 --- /dev/null +++ b/test/src/deprecated-test.c @@ -0,0 +1,347 @@ +/* + * Tests for deprecated functions. + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "common.h" + +void +print_cursor_type(SQLINTEGER cursor_type) +{ + printf( "Cursor type is: " ) ; + if (cursor_type == SQL_CURSOR_FORWARD_ONLY) + printf("forward\n"); + else if (cursor_type == SQL_CURSOR_STATIC) + printf("static\n"); + else if (cursor_type == SQL_SCROLL_DYNAMIC) + printf("dynamic\n"); + else + { + printf("Incorrect type of cursor\n"); + exit(1); + } +} + +/* Array size for SQLParamOptions test */ +#define ARRAY_SIZE 10 + +int +main(int argc, char **argv) +{ + SQLRETURN rc; + HSTMT hstmt = SQL_NULL_HSTMT; + SQLHDBC conn2; + SQLHENV env2; + SQLSMALLINT val; + SQLINTEGER valint; + SQLLEN paramlen; + char buffer[256]; + char message[1000]; + int i; + + /* Parameters for SQLParamOptions */ + SQLULEN nprocessed; + SQLLEN int_ind_array[ARRAY_SIZE]; + SQLLEN str_ind_array[ARRAY_SIZE]; + SQLUSMALLINT status_array[ARRAY_SIZE]; + SQLUINTEGER int_array[ARRAY_SIZE]; + SQLCHAR str_array[ARRAY_SIZE][30]; + + /* + * SQLAllocConnect -> SQLAllocHandle + * SQLAllocEnv -> SQLAllocHandle + * Get a connection. + */ + printf("Check for SQLAllocEnv\n"); + rc = SQLAllocEnv(&env2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocEnv failed", SQL_HANDLE_ENV, env2); + exit(1); + } + SQLSetEnvAttr(env2, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); + printf("Check for SQLAllocConnect\n"); + rc = SQLAllocConnect(env2, &conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + rc = SQLDriverConnect(conn2, NULL, "DSN=psqlodbc_test_dsn;", SQL_NTS, + NULL, 0, &val, + SQL_DRIVER_COMPLETE); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLDriverConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + /* + * SQLAllocStmt -> SQLAllocHandle + * Allocate a statement handle. + */ + printf("Check for SQLAllocStmt\n"); + rc = SQLAllocStmt(conn2, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocStmt failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + /* + * SQLGetConnectOption -> SQLGetConnectAttr + * Test connection attribute. + */ + printf("Check for SQLSetConnectOption\n"); + rc = SQLSetConnectOption(conn2, + SQL_ATTR_ACCESS_MODE, + SQL_MODE_READ_WRITE); + CHECK_STMT_RESULT(rc, "SQLSetConnectOption failed", hstmt); + + /* + * SQLError -> SQLGetDiagRec + * Trigger an error. + */ + printf("Check for SQLError\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO table_not_here VALUES (1)", + SQL_NTS); + rc = SQLError(env2, conn2, hstmt, buffer, &valint, + message, 256, &val); + CHECK_STMT_RESULT(rc, "SQLError failed", hstmt); + printf("Error check: %s\n", (CHAR *)message); + + /* + * SQLFreeStmt -> SQLFreeHandle + * Free the statement handle used. + */ + printf("Check for SQLFreeStmt\n"); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLBindParam[1] -> SQLBindParameter + * Test for bind parameter. + */ + printf("Check for SQLBindParam\n"); + paramlen = SQL_NTS; + strcpy(buffer, "bar"); + rc = SQLBindParam(hstmt, 1, + SQL_C_CHAR, + SQL_CHAR, + 20, + 0, + buffer, + &paramlen); + CHECK_STMT_RESULT(rc, "SQLBindParam failed", hstmt); + rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT ?::text AS foo", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLSetParam[2] -> SQLBindParameter + * Test for set parameter, somewhat similar to last example. + */ + printf("Check for SQLSetParam\n"); + val = 100; + SQLSetParam(hstmt, 1, SQL_C_SHORT, SQL_SMALLINT, 0, 0, + &val, NULL); + CHECK_STMT_RESULT(rc, "SQLSetParam failed", hstmt); + rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT ?::int AS foo", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLGetStmtOption -> SQLGetStmtAttr + * SQLSetStmtOption -> SQLSetStmtAttr + * SQLSetScrollOptions -> SQLSetStmtAttr + * Test for statement and cursor options. + */ + + /* Pointer should be forward-only here */ + printf("Check for SQLGetStmtOption\n"); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + + /* Change it to static and check its new value */ + printf("Check for SQLSetStmtOption\n"); + rc = SQLSetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_STATIC); + CHECK_STMT_RESULT(rc, "SQLSetStmtOption failed", hstmt); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Change it now to dynamic using another function */ + printf("Check for SQLSetScrollOptions\n"); + rc = SQLSetScrollOptions(hstmt, SQL_CONCUR_READ_ONLY, + SQL_SCROLL_FORWARD_ONLY, 1); + CHECK_STMT_RESULT(rc, "SQLSetScrollOptions failed", hstmt); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLColAttributes -> SQLColAttribute + * Test for column attributes. Return column attributes of + * a simple query. + */ + printf("Check for SQLColAttributes\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "SELECT '1'::int AS foo, 'foobar'::text AS bar", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + for (i = 0 ; i < 2; i++) + { + char buffer[64]; + rc = SQLColAttribute(hstmt, (SQLUSMALLINT) i + 1, + SQL_DESC_LABEL, buffer, 64, NULL, NULL); + CHECK_STMT_RESULT(rc, "SQLColAttribute failed", hstmt); + printf("Column %d: %s\n", i + 1, buffer); + } + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLParamOptions -> SQLSetStmtAttr + * Test for parameter options. SQLParamOptions is mapped using + * SQL_ATTR_PARAMS_PROCESSED_PTR and SQL_ATTR_PARAMSET_SIZE. Here + * we insert a set of values in a temporary table. + */ + + /* Fill in array values */ + for (i = 0; i < ARRAY_SIZE; i++) + { + int_array[i] = i; + int_ind_array[i] = 0; + sprintf(str_array[i], "column num %d", i); + str_ind_array[i] = SQL_NTS; + } + printf("Check for SQLParamOptions\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "CREATE TEMPORARY TABLE tmptable (i int4, t text)", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed for table creation", hstmt); + + rc = SQLParamOptions(hstmt, (SQLULEN) ARRAY_SIZE, &nprocessed); + CHECK_STMT_RESULT(rc, "SQLParamOptions failed", hstmt); + + /* Set some extra parameters */ + SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0); + SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, status_array, 0); + + /* Bind the parameter arrays. */ + SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, + int_array, 0, int_ind_array); + SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 29, 0, + str_array, 30, str_ind_array); + + /* Execute and fetch statuses */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO tmptable VALUES (?, ?)", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + printf("Status of execution\n"); + for (i = 0; i < nprocessed; i++) + { + switch (status_array[i]) + { + case SQL_PARAM_SUCCESS: + case SQL_PARAM_SUCCESS_WITH_INFO: + break; + + case SQL_PARAM_ERROR: + printf("%d\tError\n", i); + break; + + case SQL_PARAM_UNUSED: + printf("%d\tUnused\n", i); + break; + + case SQL_PARAM_DIAG_UNAVAILABLE: + printf("%d\tDiag unavailable\n", i); + break; + } + } + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLFreeConnect -> SQLFreeHandle + * SQLFreeEnv -> SQLFreeHandle + * Disconnect and free connection. + */ + rc = SQLDisconnect(conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLDisconnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + printf("Check for SQLFreeConnect\n"); + rc = SQLFreeConnect(conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + printf("Check for SQLFreeEnv\n"); + rc = SQLFreeEnv(env2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env2); + exit(1); + } + + /* Grab new connection and handle for the next tests */ + test_connect(); + rc = SQLAllocStmt(conn, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); + exit(1); + } + + /* + * SQLTransact -> SQLEndTran + * Check transaction ROLLBACK using SQLTransact. + */ + printf("Check for SQLTransact\n"); + + /* First disable autocommit */ + rc = SQLSetConnectAttr(conn, + SQL_ATTR_AUTOCOMMIT, + (SQLPOINTER)SQL_AUTOCOMMIT_OFF, + SQL_IS_UINTEGER); + + /* Insert a row and rollback it */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO testtab1 VALUES (200, 'foo')", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + rc = SQLTransact(SQL_NULL_HENV, conn, SQL_ROLLBACK); + CHECK_STMT_RESULT(rc, "SQLTransact failed", hstmt); + + /* Now check that the row is not inserted */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "SELECT t FROM testtab1 WHERE id = 200", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Clean up */ + test_disconnect(); +}
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Regression tests for deprecated functions
@ 2014-03-20 00:15  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Heikki Linnakangas @ 2014-03-20 00:15 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-odbc

On 03/19/2014 01:27 PM, Michael Paquier wrote:
> I have created the attached patch, that adds a new set of regression
> tests for all the deprecated functions of ODBC listed here:
> http://msdn.microsoft.com/en-us/library/ms716309%28v=vs.85%29.aspx

SQLFreeStmt isn't completely deprecated, just the SQL_DROP option. Which 
you're not testing ;-).

SQLBindParam isn't really deprecated, see 
http://msdn.microsoft.com/en-us/library/ms710955%28v=vs.85%29.aspx. I 
think we'll want to keep that, even if we remove the rest of the 
deprecated functions, to stay compatible with a ISO / Open Group driver 
manager that doesn't know about the Microsoft extensions. (AFAIK no such 
driver manager actually exists, but as a matter of principle...)

Please also add the new test case to test/Makefile and Makefile.am

> Btw, I noticed that we use in most of the regression tests deprecated
> functions  (SQLFreeStmt mainly). I think that we should change them to
> the latest ODBC 3.X functions.

I agree.

- Heikki


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Regression tests for deprecated functions
@ 2014-03-20 00:45  Michael Paquier <michael.paquier@gmail.com>
  parent: Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Michael Paquier @ 2014-03-20 00:45 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc

Updated patch is attached.

On Thu, Mar 20, 2014 at 9:15 AM, Heikki Linnakangas
<hlinnakangas@vmware.com> wrote:
> On 03/19/2014 01:27 PM, Michael Paquier wrote:
>>
>> I have created the attached patch, that adds a new set of regression
>> tests for all the deprecated functions of ODBC listed here:
>> http://msdn.microsoft.com/en-us/library/ms716309%28v=vs.85%29.aspx
>
>
> SQLFreeStmt isn't completely deprecated, just the SQL_DROP option. Which
> you're not testing ;-).
Oops. It looks like a typo. I changed the test to use SQL_DROP.

> SQLBindParam isn't really deprecated, see
> http://msdn.microsoft.com/en-us/library/ms710955%28v=vs.85%29.aspx. I think
> we'll want to keep that, even if we remove the rest of the deprecated
> functions, to stay compatible with a ISO / Open Group driver manager that
> doesn't know about the Microsoft extensions. (AFAIK no such driver manager
> actually exists, but as a matter of principle...)
OK, I thought so... Now test is removed.

> Please also add the new test case to test/Makefile and Makefile.am
Fixed.

Regards,
-- 
Michael

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

20140320_pgodbc_deprecated_v2.patch (text/plain, 11.6K) download diff --git a/Makefile.am b/Makefile.am index c67afca..2ddf177 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,6 +129,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \ test/src/cursors-test.c \ test/src/cvtnulldate-test.c \ test/src/dataatexecution-test.c \ + test/src/deprecated-test.c \ test/src/getresult-test.c \ test/src/insertreturning-test.c \ test/src/lfconversion-test.c \ diff --git a/test/Makefile.in b/test/Makefile.in index c9b82e8..cb4ed02 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1,7 +1,7 @@ TESTS = connect stmthandles select commands multistmt getresult prepare \ params notice arraybinding insertreturning dataatexecution \ boolsaschar cvtnulldate alter quotes cursors positioned-update \ - catalogfunctions bindcol lfconversion cte + catalogfunctions bindcol lfconversion cte deprecated TESTBINS = $(patsubst %,src/%-test, $(TESTS)) TESTSQLS = $(patsubst %,sql/%.sql, $(TESTS)) diff --git a/test/expected/deprecated.out b/test/expected/deprecated.out new file mode 100644 index 0000000..7e31d76 --- /dev/null +++ b/test/expected/deprecated.out @@ -0,0 +1,29 @@ +\! ./src/deprecated-test +Check for SQLAllocEnv +Check for SQLAllocConnect +Check for SQLAllocStmt +Check for SQLSetConnectOption +Check for SQLError +Error check: ERROR: relation "table_not_here" does not exist; +Error while executing the query +Check for SQLSetParam +Result set: +100 +Check for SQLGetStmtOption +Cursor type is: forward +Check for SQLSetStmtOption +Cursor type is: static +Check for SQLSetScrollOptions +Cursor type is: forward +Check for SQLColAttributes +Column 1: foo +Column 2: bar +Check for SQLParamOptions +Status of execution +Check for SQLFreeStmt +Check for SQLFreeConnect +Check for SQLFreeEnv +connected +Check for SQLTransact +Result set: +disconnecting diff --git a/test/src/common.c b/test/src/common.c index 091dd1a..904b10d 100644 --- a/test/src/common.c +++ b/test/src/common.c @@ -68,7 +68,7 @@ test_disconnect(void) exit(1); } - rc = SQLFreeConnect(conn); + rc = SQLFreeHandle(SQL_HANDLE_DBC, conn); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn); @@ -76,7 +76,7 @@ test_disconnect(void) } conn = NULL; - rc = SQLFreeEnv(env); + rc = SQLFreeHandle(SQL_HANDLE_ENV, env); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env); diff --git a/test/src/deprecated-test.c b/test/src/deprecated-test.c new file mode 100644 index 0000000..533c18d --- /dev/null +++ b/test/src/deprecated-test.c @@ -0,0 +1,324 @@ +/* + * Tests for deprecated functions. + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "common.h" + +void +print_cursor_type(SQLINTEGER cursor_type) +{ + printf( "Cursor type is: " ) ; + if (cursor_type == SQL_CURSOR_FORWARD_ONLY) + printf("forward\n"); + else if (cursor_type == SQL_CURSOR_STATIC) + printf("static\n"); + else if (cursor_type == SQL_SCROLL_DYNAMIC) + printf("dynamic\n"); + else + { + printf("Incorrect type of cursor\n"); + exit(1); + } +} + +/* Array size for SQLParamOptions test */ +#define ARRAY_SIZE 10 + +int +main(int argc, char **argv) +{ + SQLRETURN rc; + HSTMT hstmt = SQL_NULL_HSTMT; + SQLHDBC conn2; + SQLHENV env2; + SQLSMALLINT val; + SQLINTEGER valint; + SQLLEN paramlen; + char buffer[256]; + char message[1000]; + int i; + + /* Parameters for SQLParamOptions */ + SQLULEN nprocessed; + SQLLEN int_ind_array[ARRAY_SIZE]; + SQLLEN str_ind_array[ARRAY_SIZE]; + SQLUSMALLINT status_array[ARRAY_SIZE]; + SQLUINTEGER int_array[ARRAY_SIZE]; + SQLCHAR str_array[ARRAY_SIZE][30]; + + /* + * SQLAllocConnect -> SQLAllocHandle + * SQLAllocEnv -> SQLAllocHandle + * Get a connection. + */ + printf("Check for SQLAllocEnv\n"); + rc = SQLAllocEnv(&env2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocEnv failed", SQL_HANDLE_ENV, env2); + exit(1); + } + SQLSetEnvAttr(env2, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); + printf("Check for SQLAllocConnect\n"); + rc = SQLAllocConnect(env2, &conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + rc = SQLDriverConnect(conn2, NULL, "DSN=psqlodbc_test_dsn;", SQL_NTS, + NULL, 0, &val, + SQL_DRIVER_COMPLETE); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLDriverConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + /* + * SQLAllocStmt -> SQLAllocHandle + * Allocate a statement handle. + */ + printf("Check for SQLAllocStmt\n"); + rc = SQLAllocStmt(conn2, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocStmt failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + /* + * SQLGetConnectOption -> SQLGetConnectAttr + * Test connection attribute. + */ + printf("Check for SQLSetConnectOption\n"); + rc = SQLSetConnectOption(conn2, + SQL_ATTR_ACCESS_MODE, + SQL_MODE_READ_WRITE); + CHECK_STMT_RESULT(rc, "SQLSetConnectOption failed", hstmt); + + /* + * SQLError -> SQLGetDiagRec + * Trigger an error. + */ + printf("Check for SQLError\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO table_not_here VALUES (1)", + SQL_NTS); + rc = SQLError(env2, conn2, hstmt, buffer, &valint, + message, 256, &val); + CHECK_STMT_RESULT(rc, "SQLError failed", hstmt); + printf("Error check: %s\n", (CHAR *)message); + + /* + * SQLSetParam[2] -> SQLBindParameter + * Test for set parameter, somewhat similar to last example. + */ + printf("Check for SQLSetParam\n"); + val = 100; + SQLSetParam(hstmt, 1, SQL_C_SHORT, SQL_SMALLINT, 0, 0, + &val, NULL); + CHECK_STMT_RESULT(rc, "SQLSetParam failed", hstmt); + rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT ?::int AS foo", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLGetStmtOption -> SQLGetStmtAttr + * SQLSetStmtOption -> SQLSetStmtAttr + * SQLSetScrollOptions -> SQLSetStmtAttr + * Test for statement and cursor options. + */ + + /* Pointer should be forward-only here */ + printf("Check for SQLGetStmtOption\n"); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + + /* Change it to static and check its new value */ + printf("Check for SQLSetStmtOption\n"); + rc = SQLSetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_STATIC); + CHECK_STMT_RESULT(rc, "SQLSetStmtOption failed", hstmt); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Change it now to dynamic using another function */ + printf("Check for SQLSetScrollOptions\n"); + rc = SQLSetScrollOptions(hstmt, SQL_CONCUR_READ_ONLY, + SQL_SCROLL_FORWARD_ONLY, 1); + CHECK_STMT_RESULT(rc, "SQLSetScrollOptions failed", hstmt); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLColAttributes -> SQLColAttribute + * Test for column attributes. Return column attributes of + * a simple query. + */ + printf("Check for SQLColAttributes\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "SELECT '1'::int AS foo, 'foobar'::text AS bar", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + for (i = 0 ; i < 2; i++) + { + char buffer[64]; + rc = SQLColAttribute(hstmt, (SQLUSMALLINT) i + 1, + SQL_DESC_LABEL, buffer, 64, NULL, NULL); + CHECK_STMT_RESULT(rc, "SQLColAttribute failed", hstmt); + printf("Column %d: %s\n", i + 1, buffer); + } + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLParamOptions -> SQLSetStmtAttr + * Test for parameter options. SQLParamOptions is mapped using + * SQL_ATTR_PARAMS_PROCESSED_PTR and SQL_ATTR_PARAMSET_SIZE. Here + * we insert a set of values in a temporary table. + */ + + /* Fill in array values */ + for (i = 0; i < ARRAY_SIZE; i++) + { + int_array[i] = i; + int_ind_array[i] = 0; + sprintf(str_array[i], "column num %d", i); + str_ind_array[i] = SQL_NTS; + } + printf("Check for SQLParamOptions\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "CREATE TEMPORARY TABLE tmptable (i int4, t text)", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed for table creation", hstmt); + + rc = SQLParamOptions(hstmt, (SQLULEN) ARRAY_SIZE, &nprocessed); + CHECK_STMT_RESULT(rc, "SQLParamOptions failed", hstmt); + + /* Set some extra parameters */ + SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0); + SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, status_array, 0); + + /* Bind the parameter arrays. */ + SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, + int_array, 0, int_ind_array); + SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 29, 0, + str_array, 30, str_ind_array); + + /* Execute and fetch statuses */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO tmptable VALUES (?, ?)", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + printf("Status of execution\n"); + for (i = 0; i < nprocessed; i++) + { + switch (status_array[i]) + { + case SQL_PARAM_SUCCESS: + case SQL_PARAM_SUCCESS_WITH_INFO: + break; + + case SQL_PARAM_ERROR: + printf("%d\tError\n", i); + break; + + case SQL_PARAM_UNUSED: + printf("%d\tUnused\n", i); + break; + + case SQL_PARAM_DIAG_UNAVAILABLE: + printf("%d\tDiag unavailable\n", i); + break; + } + } + + /* + * SQLFreeStmt -> SQLFreeHandle + * Free the statement handle used. + */ + printf("Check for SQLFreeStmt\n"); + rc = SQLFreeStmt(hstmt, SQL_DROP); + CHECK_STMT_RESULT(rc, "SQLFreeStmt with SQL_DROP failed", hstmt); + + /* + * SQLFreeConnect -> SQLFreeHandle + * SQLFreeEnv -> SQLFreeHandle + * Disconnect and free connection. + */ + rc = SQLDisconnect(conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLDisconnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + printf("Check for SQLFreeConnect\n"); + rc = SQLFreeConnect(conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + printf("Check for SQLFreeEnv\n"); + rc = SQLFreeEnv(env2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env2); + exit(1); + } + + /* Grab new connection and handle for the next tests */ + test_connect(); + rc = SQLAllocStmt(conn, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); + exit(1); + } + + /* + * SQLTransact -> SQLEndTran + * Check transaction ROLLBACK using SQLTransact. + */ + printf("Check for SQLTransact\n"); + + /* First disable autocommit */ + rc = SQLSetConnectAttr(conn, + SQL_ATTR_AUTOCOMMIT, + (SQLPOINTER)SQL_AUTOCOMMIT_OFF, + SQL_IS_UINTEGER); + + /* Insert a row and rollback it */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO testtab1 VALUES (200, 'foo')", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + rc = SQLTransact(SQL_NULL_HENV, conn, SQL_ROLLBACK); + CHECK_STMT_RESULT(rc, "SQLTransact failed", hstmt); + + /* Now check that the row is not inserted */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "SELECT t FROM testtab1 WHERE id = 200", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Clean up */ + test_disconnect(); +}
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Regression tests for deprecated functions
@ 2014-03-20 05:24  Michael Paquier <michael.paquier@gmail.com>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Michael Paquier @ 2014-03-20 05:24 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc

On Thu, Mar 20, 2014 at 9:45 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
>> Please also add the new test case to test/Makefile and Makefile.am
> Fixed.
Please find attached an updated patch, I forgot to add deprecated.out
in Makefile.am.
Thanks.
-- 
Michael

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

20140320_pgodbc_deprecated_v3.patch (text/plain, 11.9K) download diff --git a/Makefile.am b/Makefile.am index c67afca..270f49e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -98,6 +98,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \ test/expected/cursors_1.out \ test/expected/cvtnulldate.out \ test/expected/dataatexecution.out \ + test/expected/deprecated.out \ test/expected/getresult.out \ test/expected/insertreturning.out \ test/expected/lfconversion.out \ @@ -129,6 +130,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \ test/src/cursors-test.c \ test/src/cvtnulldate-test.c \ test/src/dataatexecution-test.c \ + test/src/deprecated-test.c \ test/src/getresult-test.c \ test/src/insertreturning-test.c \ test/src/lfconversion-test.c \ diff --git a/test/Makefile.in b/test/Makefile.in index c9b82e8..cb4ed02 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1,7 +1,7 @@ TESTS = connect stmthandles select commands multistmt getresult prepare \ params notice arraybinding insertreturning dataatexecution \ boolsaschar cvtnulldate alter quotes cursors positioned-update \ - catalogfunctions bindcol lfconversion cte + catalogfunctions bindcol lfconversion cte deprecated TESTBINS = $(patsubst %,src/%-test, $(TESTS)) TESTSQLS = $(patsubst %,sql/%.sql, $(TESTS)) diff --git a/test/expected/deprecated.out b/test/expected/deprecated.out new file mode 100644 index 0000000..7e31d76 --- /dev/null +++ b/test/expected/deprecated.out @@ -0,0 +1,29 @@ +\! ./src/deprecated-test +Check for SQLAllocEnv +Check for SQLAllocConnect +Check for SQLAllocStmt +Check for SQLSetConnectOption +Check for SQLError +Error check: ERROR: relation "table_not_here" does not exist; +Error while executing the query +Check for SQLSetParam +Result set: +100 +Check for SQLGetStmtOption +Cursor type is: forward +Check for SQLSetStmtOption +Cursor type is: static +Check for SQLSetScrollOptions +Cursor type is: forward +Check for SQLColAttributes +Column 1: foo +Column 2: bar +Check for SQLParamOptions +Status of execution +Check for SQLFreeStmt +Check for SQLFreeConnect +Check for SQLFreeEnv +connected +Check for SQLTransact +Result set: +disconnecting diff --git a/test/src/common.c b/test/src/common.c index 091dd1a..904b10d 100644 --- a/test/src/common.c +++ b/test/src/common.c @@ -68,7 +68,7 @@ test_disconnect(void) exit(1); } - rc = SQLFreeConnect(conn); + rc = SQLFreeHandle(SQL_HANDLE_DBC, conn); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn); @@ -76,7 +76,7 @@ test_disconnect(void) } conn = NULL; - rc = SQLFreeEnv(env); + rc = SQLFreeHandle(SQL_HANDLE_ENV, env); if (!SQL_SUCCEEDED(rc)) { print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env); diff --git a/test/src/deprecated-test.c b/test/src/deprecated-test.c new file mode 100644 index 0000000..533c18d --- /dev/null +++ b/test/src/deprecated-test.c @@ -0,0 +1,324 @@ +/* + * Tests for deprecated functions. + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "common.h" + +void +print_cursor_type(SQLINTEGER cursor_type) +{ + printf( "Cursor type is: " ) ; + if (cursor_type == SQL_CURSOR_FORWARD_ONLY) + printf("forward\n"); + else if (cursor_type == SQL_CURSOR_STATIC) + printf("static\n"); + else if (cursor_type == SQL_SCROLL_DYNAMIC) + printf("dynamic\n"); + else + { + printf("Incorrect type of cursor\n"); + exit(1); + } +} + +/* Array size for SQLParamOptions test */ +#define ARRAY_SIZE 10 + +int +main(int argc, char **argv) +{ + SQLRETURN rc; + HSTMT hstmt = SQL_NULL_HSTMT; + SQLHDBC conn2; + SQLHENV env2; + SQLSMALLINT val; + SQLINTEGER valint; + SQLLEN paramlen; + char buffer[256]; + char message[1000]; + int i; + + /* Parameters for SQLParamOptions */ + SQLULEN nprocessed; + SQLLEN int_ind_array[ARRAY_SIZE]; + SQLLEN str_ind_array[ARRAY_SIZE]; + SQLUSMALLINT status_array[ARRAY_SIZE]; + SQLUINTEGER int_array[ARRAY_SIZE]; + SQLCHAR str_array[ARRAY_SIZE][30]; + + /* + * SQLAllocConnect -> SQLAllocHandle + * SQLAllocEnv -> SQLAllocHandle + * Get a connection. + */ + printf("Check for SQLAllocEnv\n"); + rc = SQLAllocEnv(&env2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocEnv failed", SQL_HANDLE_ENV, env2); + exit(1); + } + SQLSetEnvAttr(env2, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0); + printf("Check for SQLAllocConnect\n"); + rc = SQLAllocConnect(env2, &conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + rc = SQLDriverConnect(conn2, NULL, "DSN=psqlodbc_test_dsn;", SQL_NTS, + NULL, 0, &val, + SQL_DRIVER_COMPLETE); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLDriverConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + /* + * SQLAllocStmt -> SQLAllocHandle + * Allocate a statement handle. + */ + printf("Check for SQLAllocStmt\n"); + rc = SQLAllocStmt(conn2, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLAllocStmt failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + + /* + * SQLGetConnectOption -> SQLGetConnectAttr + * Test connection attribute. + */ + printf("Check for SQLSetConnectOption\n"); + rc = SQLSetConnectOption(conn2, + SQL_ATTR_ACCESS_MODE, + SQL_MODE_READ_WRITE); + CHECK_STMT_RESULT(rc, "SQLSetConnectOption failed", hstmt); + + /* + * SQLError -> SQLGetDiagRec + * Trigger an error. + */ + printf("Check for SQLError\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO table_not_here VALUES (1)", + SQL_NTS); + rc = SQLError(env2, conn2, hstmt, buffer, &valint, + message, 256, &val); + CHECK_STMT_RESULT(rc, "SQLError failed", hstmt); + printf("Error check: %s\n", (CHAR *)message); + + /* + * SQLSetParam[2] -> SQLBindParameter + * Test for set parameter, somewhat similar to last example. + */ + printf("Check for SQLSetParam\n"); + val = 100; + SQLSetParam(hstmt, 1, SQL_C_SHORT, SQL_SMALLINT, 0, 0, + &val, NULL); + CHECK_STMT_RESULT(rc, "SQLSetParam failed", hstmt); + rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT ?::int AS foo", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLGetStmtOption -> SQLGetStmtAttr + * SQLSetStmtOption -> SQLSetStmtAttr + * SQLSetScrollOptions -> SQLSetStmtAttr + * Test for statement and cursor options. + */ + + /* Pointer should be forward-only here */ + printf("Check for SQLGetStmtOption\n"); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + + /* Change it to static and check its new value */ + printf("Check for SQLSetStmtOption\n"); + rc = SQLSetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_STATIC); + CHECK_STMT_RESULT(rc, "SQLSetStmtOption failed", hstmt); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Change it now to dynamic using another function */ + printf("Check for SQLSetScrollOptions\n"); + rc = SQLSetScrollOptions(hstmt, SQL_CONCUR_READ_ONLY, + SQL_SCROLL_FORWARD_ONLY, 1); + CHECK_STMT_RESULT(rc, "SQLSetScrollOptions failed", hstmt); + rc = SQLGetStmtOption(hstmt, SQL_ATTR_CURSOR_TYPE, &valint); + CHECK_STMT_RESULT(rc, "SQLGetStmtOption failed", hstmt); + print_cursor_type(valint); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLColAttributes -> SQLColAttribute + * Test for column attributes. Return column attributes of + * a simple query. + */ + printf("Check for SQLColAttributes\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "SELECT '1'::int AS foo, 'foobar'::text AS bar", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + for (i = 0 ; i < 2; i++) + { + char buffer[64]; + rc = SQLColAttribute(hstmt, (SQLUSMALLINT) i + 1, + SQL_DESC_LABEL, buffer, 64, NULL, NULL); + CHECK_STMT_RESULT(rc, "SQLColAttribute failed", hstmt); + printf("Column %d: %s\n", i + 1, buffer); + } + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* + * SQLParamOptions -> SQLSetStmtAttr + * Test for parameter options. SQLParamOptions is mapped using + * SQL_ATTR_PARAMS_PROCESSED_PTR and SQL_ATTR_PARAMSET_SIZE. Here + * we insert a set of values in a temporary table. + */ + + /* Fill in array values */ + for (i = 0; i < ARRAY_SIZE; i++) + { + int_array[i] = i; + int_ind_array[i] = 0; + sprintf(str_array[i], "column num %d", i); + str_ind_array[i] = SQL_NTS; + } + printf("Check for SQLParamOptions\n"); + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "CREATE TEMPORARY TABLE tmptable (i int4, t text)", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed for table creation", hstmt); + + rc = SQLParamOptions(hstmt, (SQLULEN) ARRAY_SIZE, &nprocessed); + CHECK_STMT_RESULT(rc, "SQLParamOptions failed", hstmt); + + /* Set some extra parameters */ + SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0); + SQLSetStmtAttr(hstmt, SQL_ATTR_PARAM_STATUS_PTR, status_array, 0); + + /* Bind the parameter arrays. */ + SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, + int_array, 0, int_ind_array); + SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 29, 0, + str_array, 30, str_ind_array); + + /* Execute and fetch statuses */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO tmptable VALUES (?, ?)", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + printf("Status of execution\n"); + for (i = 0; i < nprocessed; i++) + { + switch (status_array[i]) + { + case SQL_PARAM_SUCCESS: + case SQL_PARAM_SUCCESS_WITH_INFO: + break; + + case SQL_PARAM_ERROR: + printf("%d\tError\n", i); + break; + + case SQL_PARAM_UNUSED: + printf("%d\tUnused\n", i); + break; + + case SQL_PARAM_DIAG_UNAVAILABLE: + printf("%d\tDiag unavailable\n", i); + break; + } + } + + /* + * SQLFreeStmt -> SQLFreeHandle + * Free the statement handle used. + */ + printf("Check for SQLFreeStmt\n"); + rc = SQLFreeStmt(hstmt, SQL_DROP); + CHECK_STMT_RESULT(rc, "SQLFreeStmt with SQL_DROP failed", hstmt); + + /* + * SQLFreeConnect -> SQLFreeHandle + * SQLFreeEnv -> SQLFreeHandle + * Disconnect and free connection. + */ + rc = SQLDisconnect(conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLDisconnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + printf("Check for SQLFreeConnect\n"); + rc = SQLFreeConnect(conn2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLFreeConnect failed", SQL_HANDLE_DBC, conn2); + exit(1); + } + printf("Check for SQLFreeEnv\n"); + rc = SQLFreeEnv(env2); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("SQLFreeEnv failed", SQL_HANDLE_ENV, env2); + exit(1); + } + + /* Grab new connection and handle for the next tests */ + test_connect(); + rc = SQLAllocStmt(conn, &hstmt); + if (!SQL_SUCCEEDED(rc)) + { + print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); + exit(1); + } + + /* + * SQLTransact -> SQLEndTran + * Check transaction ROLLBACK using SQLTransact. + */ + printf("Check for SQLTransact\n"); + + /* First disable autocommit */ + rc = SQLSetConnectAttr(conn, + SQL_ATTR_AUTOCOMMIT, + (SQLPOINTER)SQL_AUTOCOMMIT_OFF, + SQL_IS_UINTEGER); + + /* Insert a row and rollback it */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "INSERT INTO testtab1 VALUES (200, 'foo')", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + rc = SQLTransact(SQL_NULL_HENV, conn, SQL_ROLLBACK); + CHECK_STMT_RESULT(rc, "SQLTransact failed", hstmt); + + /* Now check that the row is not inserted */ + rc = SQLExecDirect(hstmt, + (SQLCHAR *) "SELECT t FROM testtab1 WHERE id = 200", + SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); + print_result(hstmt); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Clean up */ + test_disconnect(); +}
^ permalink raw reply [nested|flat] 7+ messages in thread

* Re: Regression tests for deprecated functions
@ 2014-03-20 08:20  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Heikki Linnakangas @ 2014-03-20 08:20 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-odbc

On 03/20/2014 06:24 AM, Michael Paquier wrote:
> On Thu, Mar 20, 2014 at 9:45 AM, Michael Paquier
> <michael.paquier@gmail.com> wrote:
>>> Please also add the new test case to test/Makefile and Makefile.am
>> Fixed.
> Please find attached an updated patch, I forgot to add deprecated.out
> in Makefile.am.

Thanks, pushed.

- Heikki


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Regression tests for deprecated functions
@ 2014-06-12 14:13  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Heikki Linnakangas @ 2014-06-12 14:13 UTC (permalink / raw)
  To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-odbc

I spotted one more issue in the regression test for deprecated functions:

The comment in it correctly states, SQLColAttributes has been replaced 
with SQLColAttribute. But the regression test then calls 
SQLColAttribute, i.e. the new functions, not the deprecated one. I 
haven't looked what difference it makes in practice.

(We don't have any other regression tests for the new SQLColAttribute, 
which would be nice to have anyway)

- Heikki


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Regression tests for deprecated functions
@ 2014-06-13 00:51  Michael Paquier <michael.paquier@gmail.com>
  parent: Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Michael Paquier @ 2014-06-13 00:51 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc

On Thu, Jun 12, 2014 at 11:13 PM, Heikki Linnakangas
<hlinnakangas@vmware.com> wrote:
> I spotted one more issue in the regression test for deprecated functions:
>
> The comment in it correctly states, SQLColAttributes has been replaced with
> SQLColAttribute. But the regression test then calls SQLColAttribute, i.e.
> the new functions, not the deprecated one. I haven't looked what difference
> it makes in practice.
The field identifiers have been changed from SQL_COLUMN_* to SQL_DESC_*:
http://msdn.microsoft.com/en-us/library/ms710910%28v=vs.85%29.aspx
Hence I think that the patch attached is enough, even if we do not
test all the field identifiers..

> (We don't have any other regression tests for the new SQLColAttribute, which
> would be nice to have anyway)
True.
-- 
Michael

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

20140613_pgodbc_deprecated_fix.patch (text/plain, 582B) download diff --git a/test/src/deprecated-test.c b/test/src/deprecated-test.c index 3e6a1fd..c359dd9 100644 --- a/test/src/deprecated-test.c +++ b/test/src/deprecated-test.c @@ -200,8 +200,8 @@ main(int argc, char **argv) for (i = 0 ; i < 2; i++) { char buffer[64]; - rc = SQLColAttribute(hstmt, (SQLUSMALLINT) i + 1, - SQL_DESC_LABEL, buffer, 64, NULL, NULL); + rc = SQLColAttributes(hstmt, (SQLUSMALLINT) i + 1, + SQL_COLUMN_LABEL, buffer, 64, NULL, NULL); CHECK_STMT_RESULT(rc, "SQLColAttribute failed", hstmt); printf("Column %d: %s\n", i + 1, buffer); }
^ permalink raw reply [nested|flat] 7+ messages in thread


end of thread, other threads:[~2014-06-13 00:51 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 12:27 Regression tests for deprecated functions Michael Paquier <michael.paquier@gmail.com>
2014-03-20 00:15 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-03-20 00:45   ` Michael Paquier <michael.paquier@gmail.com>
2014-03-20 05:24     ` Michael Paquier <michael.paquier@gmail.com>
2014-03-20 08:20       ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-06-12 14:13         ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-06-13 00:51           ` Michael Paquier <michael.paquier@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox