From 023003018df72d2ecfdd67725613d880be428773 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 2 Sep 2013 11:29:41 +0300 Subject: [PATCH] Add test case for SQLDescribeParam --- test/expected/params.out | 8 +++++++ test/src/common.c | 4 ++-- test/src/common.h | 2 ++ test/src/params-test.c | 47 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/test/expected/params.out b/test/expected/params.out index c9154d8..63c96be 100644 --- a/test/expected/params.out +++ b/test/expected/params.out @@ -3,7 +3,15 @@ connected # of result cols: 2 Result set: 1 0102030405060708 + +Testing SQLBindParameter with SQLExecDirect... Result set: foo bar + +Testing SQLDescribeParam... +Param 1: type INTEGER; size 10; dec digits -1; nullable +# of result cols: 2 +Result set: +3 foobar disconnecting diff --git a/test/src/common.c b/test/src/common.c index 57c9e4e..528c22f 100644 --- a/test/src/common.c +++ b/test/src/common.c @@ -85,7 +85,7 @@ test_disconnect(void) env = NULL; } -static const char * +const char * datatype_str(SQLSMALLINT datatype) { static char buf[100]; @@ -144,7 +144,7 @@ datatype_str(SQLSMALLINT datatype) } } -static const char *nullable_str(SQLSMALLINT nullable) +const char *nullable_str(SQLSMALLINT nullable) { static char buf[100]; diff --git a/test/src/common.h b/test/src/common.h index 7c47f5b..2feceb9 100644 --- a/test/src/common.h +++ b/test/src/common.h @@ -29,3 +29,5 @@ extern void test_connect(void); extern void test_disconnect(void); extern void print_result_meta(HSTMT hstmt); extern void print_result(HSTMT hstmt); +extern const char *datatype_str(SQLSMALLINT datatype); +extern const char *nullable_str(SQLSMALLINT nullable); diff --git a/test/src/params-test.c b/test/src/params-test.c index 720cce2..eccd626 100644 --- a/test/src/params-test.c +++ b/test/src/params-test.c @@ -12,6 +12,10 @@ int main(int argc, char **argv) long longparam; SQL_INTERVAL_STRUCT intervalparam; SQLSMALLINT colcount; + SQLSMALLINT dataType; + SQLULEN paramSize; + SQLSMALLINT decDigits; + SQLSMALLINT nullable; test_connect(); @@ -56,6 +60,7 @@ int main(int argc, char **argv) CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /*** Test SQLBindParameter with SQLExecDirect ***/ + printf("\nTesting SQLBindParameter with SQLExecDirect...\n"); /* bind param */ strcpy(param1, "bar"); @@ -77,6 +82,48 @@ int main(int argc, char **argv) rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + /*** Test SQLDescribeParam ***/ + printf("\nTesting SQLDescribeParam...\n"); + + rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + + /* Prepare a statement */ + rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT id, t FROM testtab1 WHERE id = ?", SQL_NTS); + CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); + + rc = SQLDescribeParam(hstmt, 1, &dataType, ¶mSize, &decDigits, &nullable); + CHECK_STMT_RESULT(rc, "SQLDescribeParams failed", hstmt); + printf("Param 1: type %s; size %d; dec digits %d; %s\n", + datatype_str(dataType), paramSize, decDigits, nullable_str(nullable)); + /* bind param */ + strcpy(param1, "3"); + cbParam1 = SQL_NTS; + rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, + SQL_C_CHAR, /* value type */ + SQL_CHAR, /* param type */ + 20, /* column size */ + 0, /* dec digits */ + param1, /* param value ptr */ + 0, /* buffer len */ + &cbParam1 /* StrLen_or_IndPtr */); + CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt); + + /* Test SQLNumResultCols, called before SQLExecute() */ + rc = SQLNumResultCols(hstmt, &colcount); + CHECK_STMT_RESULT(rc, "SQLNumResultCols failed", hstmt); + printf("# of result cols: %d\n", colcount); + + /* Execute */ + rc = SQLExecute(hstmt); + CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt); + + /* Fetch result */ + print_result(hstmt); + + rc = SQLFreeStmt(hstmt, SQL_CLOSE); + CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); + /* Clean up */ test_disconnect(); -- 2.39.5