summaryrefslogtreecommitdiff
path: root/test/src/common.c
diff options
context:
space:
mode:
authorHeikki Linnakangas2014-03-18 19:35:29 +0000
committerHeikki Linnakangas2014-03-18 19:35:29 +0000
commite3d578fd901bde1b462e725613bd7ef826b0b432 (patch)
treeafc85ab46392c3fa08e579d0df78d1150aa80ef6 /test/src/common.c
parent02dbf707424e2d58bf5845b6e418947349e19eea (diff)
Add more test cases for ODBC catalog functions.
Michael Paquier
Diffstat (limited to 'test/src/common.c')
-rw-r--r--test/src/common.c68
1 files changed, 51 insertions, 17 deletions
diff --git a/test/src/common.c b/test/src/common.c
index 962d7d3..091dd1a 100644
--- a/test/src/common.c
+++ b/test/src/common.c
@@ -163,23 +163,17 @@ const char *nullable_str(SQLSMALLINT nullable)
}
void
-print_result_meta(HSTMT hstmt)
+print_result_meta_series(HSTMT hstmt,
+ SQLSMALLINT *colids,
+ SQLSMALLINT numcols)
{
- SQLRETURN rc;
- SQLSMALLINT numcols;
int i;
- rc = SQLNumResultCols(hstmt, &numcols);
- if (!SQL_SUCCEEDED(rc))
- {
- print_diag("SQLNumResultCols failed", SQL_HANDLE_STMT, hstmt);
- return;
- }
-
printf("Result set metadata:\n");
- for (i = 1; i <= numcols; i++)
+ for (i = 0; i < numcols; i++)
{
+ SQLRETURN rc;
SQLCHAR colname[50];
SQLSMALLINT colnamelen;
SQLSMALLINT datatype;
@@ -187,7 +181,7 @@ print_result_meta(HSTMT hstmt)
SQLSMALLINT decdigits;
SQLSMALLINT nullable;
- rc = SQLDescribeCol(hstmt, i,
+ rc = SQLDescribeCol(hstmt, colids[i],
colname, sizeof(colname),
&colnamelen,
&datatype,
@@ -206,10 +200,11 @@ print_result_meta(HSTMT hstmt)
}
void
-print_result(HSTMT hstmt)
+print_result_meta(HSTMT hstmt)
{
SQLRETURN rc;
- SQLSMALLINT numcols;
+ SQLSMALLINT numcols, i;
+ SQLSMALLINT *colids;
rc = SQLNumResultCols(hstmt, &numcols);
if (!SQL_SUCCEEDED(rc))
@@ -218,6 +213,21 @@ print_result(HSTMT hstmt)
return;
}
+ colids = (SQLSMALLINT *) malloc(numcols * sizeof(SQLSMALLINT));
+ for (i = 0; i < numcols; i++)
+ colids[i] = i + 1;
+ print_result_meta_series(hstmt, colids, numcols);
+ free(colids);
+}
+
+/*
+ * Print result only for the selected columns.
+ */
+void
+print_result_series(HSTMT hstmt, SQLSMALLINT *colids, SQLSMALLINT numcols)
+{
+ SQLRETURN rc;
+
printf("Result set:\n");
while(1)
{
@@ -230,9 +240,9 @@ print_result(HSTMT hstmt)
int i;
SQLLEN ind;
- for (i = 1; i <= numcols; i++)
+ for (i = 0; i < numcols; i++)
{
- rc = SQLGetData(hstmt,i, SQL_C_CHAR, buf, sizeof(buf), &ind);
+ rc = SQLGetData(hstmt, colids[i], SQL_C_CHAR, buf, sizeof(buf), &ind);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLGetData failed", SQL_HANDLE_STMT, hstmt);
@@ -240,7 +250,7 @@ print_result(HSTMT hstmt)
}
if (ind == SQL_NULL_DATA)
strcpy(buf, "NULL");
- printf("%s%s", (i > 1) ? "\t" : "", buf);
+ printf("%s%s", (i > 0) ? "\t" : "", buf);
}
printf("\n");
}
@@ -251,3 +261,27 @@ print_result(HSTMT hstmt)
}
}
}
+
+/*
+ * Print result on all the columns
+ */
+void
+print_result(HSTMT hstmt)
+{
+ SQLRETURN rc;
+ SQLSMALLINT numcols, i;
+ SQLSMALLINT *colids;
+
+ rc = SQLNumResultCols(hstmt, &numcols);
+ if (!SQL_SUCCEEDED(rc))
+ {
+ print_diag("SQLNumResultCols failed", SQL_HANDLE_STMT, hstmt);
+ return;
+ }
+
+ colids = (SQLSMALLINT *) malloc(numcols * sizeof(SQLSMALLINT));
+ for (i = 0; i < numcols; i++)
+ colids[i] = i + 1;
+ print_result_series(hstmt, colids, numcols);
+ free(colids);
+}