Add test case for SQLDescribeParam
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 2 Sep 2013 08:29:41 +0000 (11:29 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 2 Sep 2013 08:29:41 +0000 (11:29 +0300)
test/expected/params.out
test/src/common.c
test/src/common.h
test/src/params-test.c

index c9154d83658acd34f1475e01a9d95d7393405885..63c96bee29a91b52814c7793f03ea0b2f73f1a7c 100644 (file)
@@ -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
index 57c9e4e444488570821704c5f00183931f99921b..528c22f671ff8aeac23f4c32d7443f49825e8e74 100644 (file)
@@ -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];
 
index 7c47f5b26f17f79aafad42aa30543b0dec02686a..2feceb923e18233972fd69165e47267634443431 100644 (file)
@@ -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);
index 720cce2e73214bc07458dc4b37b7b5fb803a1f79..eccd6263896eb069c365b6e81cf11c4c631d0407 100644 (file)
@@ -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, &paramSize, &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();