ti = fi->ti;
field_type = getEffectiveOid(conn, fi);
}
+ else
+ {
+ fi = NULL;
+ }
MYLOG(0, "col %d field_type=%d fi,ti=%p,%p\n", col_idx, field_type, fi, ti);
connected
---1 Result set:
+--1
+Result set metadata:
+?column?: INTEGER(10) digits: 0, nullable
+Result set:
+?column?
1
---2 Result set:
+--2
+Result set metadata:
+?column?: INTEGER(10) digits: 0, nullable
+Result set:
+?column?
2
---1 Result set:
+--1
+Result set metadata:
+?column?: INTEGER(10) digits: 0, nullable
+Result set:
+?column?
1
---2 Result set:
+--2
+Result set metadata:
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+Result set:
+?column? ?column?
foo bar
---3 Result set:
+--3
+Result set metadata:
+?column?: INTEGER(10) digits: 0, nullable
+Result set:
+?column?
3
---4 Result set:
+--4
+Result set metadata:
+?column?: INTEGER(10) digits: 0, nullable
+Result set:
+?column?
4
---1 Result set:
+--1
+Result set metadata:
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+Result set:
+?column? ?column?
foo bar
---2 Result set:
+--2
+Result set metadata:
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+Result set:
+?column?
foobar
+--1
+Result set metadata:
+id: INTEGER(10) digits: 0, not nullable
+t: VARCHAR(20) digits: 0, nullable
+Result set:
+id t
+1 foo
+2 bar
+3 foobar
+--2
+Result set metadata:
+t: VARCHAR(20) digits: 0, nullable
+result: INTEGER(10) digits: 0, nullable
+Result set:
+t result
+foo 2
+bar 2
+foobar 2
# of result cols: 3
---1 Result set:
+--1
+Result set metadata:
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+id: INTEGER(10) digits: 0, not nullable
+t: VARCHAR(20) digits: 0, nullable
+Result set:
+?column? id t
first result set 1 foo
---2 Result set:
+--2
+Result set metadata:
+?column?: LONGVARCHAR(8190) digits: 0, nullable
+t: VARCHAR(20) digits: 0, nullable
+Result set:
+?column? t
second result set bar
disconnecting
#include "common.h"
/* define a macro to simplify function calls */
-#define PRINT_RESULT_SERIES(hstmt, idarray, rowcount) print_result_series(hstmt, idarray, sizeof(idarray)/sizeof(idarray[0]), rowcount)
+#define PRINT_RESULT_SERIES(hstmt, idarray, rowcount) print_result_series(hstmt, idarray, sizeof(idarray)/sizeof(idarray[0]), rowcount, FALSE)
int
main(int argc, char **argv)
* Print result only for the selected columns.
*/
void
-print_result_series(HSTMT hstmt, SQLSMALLINT *colids, SQLSMALLINT numcols, SQLINTEGER rowcount)
+print_result_series(HSTMT hstmt, SQLSMALLINT *colids, SQLSMALLINT numcols, SQLINTEGER rowcount, BOOL printcolnames)
{
SQLRETURN rc;
SQLINTEGER rowc = 0;
+ char buf[40];
+ int i;
printf("Result set:\n");
+
+ if (printcolnames)
+ {
+ for (i = 1; i <= numcols; i++)
+ {
+ invalidate_buf(buf, sizeof(buf));
+ rc = SQLColAttribute(hstmt, i, SQL_DESC_LABEL, buf, sizeof(buf), NULL, NULL);
+ if (!SQL_SUCCEEDED(rc))
+ {
+ print_diag("SQLColAttribute failed", SQL_HANDLE_STMT, hstmt);
+ return;
+ }
+ printf("%s%s", (i > 1) ? "\t" : "", buf);
+ }
+ printf("\n");
+ }
+
while (rowcount <0 || rowc < rowcount)
{
rc = SQLFetch(hstmt);
break;
if (rc == SQL_SUCCESS)
{
- char buf[40];
- int i;
SQLLEN ind;
rowc++;
* Print result on all the columns
*/
void
-print_result(HSTMT hstmt)
+print_result_all(HSTMT hstmt, BOOL printcolnames)
{
SQLRETURN rc;
SQLSMALLINT numcols, i;
colids = (SQLSMALLINT *) malloc(numcols * sizeof(SQLSMALLINT));
for (i = 0; i < numcols; i++)
colids[i] = i + 1;
- print_result_series(hstmt, colids, numcols, -1);
+ print_result_series(hstmt, colids, numcols, -1, printcolnames);
free(colids);
}
+
+/*
+ * Print result on all the columns (without column names)
+ */
+void
+print_result(HSTMT hstmt)
+{
+ print_result_all(hstmt, FALSE);
+}
+
+/*
+ * Print result on all the columns (with column names)
+ */
+void
+print_result_with_column_names(HSTMT hstmt)
+{
+ print_result_all(hstmt, TRUE);
+}
extern void print_result_series(HSTMT hstmt,
SQLSMALLINT *colids,
SQLSMALLINT numcols,
- SQLINTEGER rowcount);
+ SQLINTEGER rowcount,
+ BOOL printcolnames);
extern void print_result_meta(HSTMT hstmt);
extern void print_result(HSTMT hstmt);
+extern void print_result_with_column_names(HSTMT hstmt);
extern const char *datatype_str(SQLSMALLINT datatype);
extern const char *nullable_str(SQLSMALLINT nullable);
int rc = SQL_SUCCESS;
for (i = 1; rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO; i++)
{
- printf("--%d ", i);
- print_result(hstmt);
+ /*** Verify column metadata/name and row data in each result ***/
+ printf("--%d\n", i);
+ print_result_meta(hstmt);
+ print_result_with_column_names(hstmt);
rc = SQLMoreResults(hstmt);
}
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+ /*** Different column name, type and source between results for the same column index ***/
+
+ rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT id, t FROM testtab1; SELECT t, 2 result FROM testtab1", SQL_NTS);
+ CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+ print_all_results(hstmt);
+
+ rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+ CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
/*** Prepare/Execute a multi-statement with parameters ***/
rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT 'first result set', id, t FROM testtab1 WHERE t = ?; SELECT 'second result set', t FROM testtab1 WHERE t = ?", SQL_NTS);