/* From CLI sample descrptr.c */ /* ... */ SQLCHAR * sqlstmt = "SELECT deptname, location from org where division = ? " ; /* ... */ /* macro to initalize server, uid and pwd */ INIT_UID_PWD ; /* allocate an environment handle */ rc = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv ) ; if ( rc != SQL_SUCCESS ) return( terminate( henv, rc ) ) ; /* allocate a connect handle, and connect */ rc = DBconnect( henv, &hdbc ) ; if ( rc != SQL_SUCCESS ) return( terminate( henv, rc ) ) ; rc = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ; CHECK_HANDLE( SQL_HANDLE_DBC, hdbc, rc ) ; /* Use SQLGetStmtAttr() to get implicit parameter descriptor handle */ rc = SQLGetStmtAttr ( hstmt, SQL_ATTR_IMP_PARAM_DESC, &hIPDdesc, SQL_IS_POINTER, NULL); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* Use SQLGetStmtAttr() to get implicit row descriptor handle */ rc = SQLGetStmtAttr ( hstmt, SQL_ATTR_IMP_ROW_DESC, &hIRDdesc, SQL_IS_POINTER, NULL); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* Call SQLGetDescField() to see how the header field */ /* SQL_DESC_ALLOC_TYPE is set. */ rc = SQLGetDescField( hIPDdesc, 0, /* ignored for header fields */ SQL_DESC_ALLOC_TYPE, &desc_smallint, /* The result */ SQL_IS_SMALLINT, NULL ); /* ignored */ CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* Print the descriptor information */ printf("The IPD header descriptor field SQL_DESC_ALLOC_TYPE is %s\n", ALLOCTYPES[desc_smallint]); /* prepare statement for multiple use */ rc = SQLPrepare(hstmt, sqlstmt, SQL_NTS); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* bind division to parameter marker in sqlstmt */ rc = SQLBindParameter( hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 10, 0, division.s, 11, NULL ) ; CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* bind deptname to first column in the result set */ rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) deptname.s, 15, &deptname.ind); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, (SQLPOINTER) location.s, 14, &location.ind); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* Call SQLGetDescField() to see how the descriptor record */ /* field SQL_DESC_PARAMETER_TYPE is set */ rc = SQLGetDescField( hIPDdesc, 1, /* Look at the parameter */ SQL_DESC_PARAMETER_TYPE, &desc_smallint, /* The result */ SQL_IS_SMALLINT, NULL ); /* ignored */ CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; printf("The IPD record descriptor field SQL_DESC_PARAMETER_TYPE is %s\n", PARAMTYPE[desc_smallint]); strcpy( division.s, "Eastern"); rc = SQLExecute(hstmt); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; printf("\nDepartments in %s Division:\n", division.s); printf("Department Location\n"); printf("-------------- -------------\n"); while ( ( rc = SQLFetch( hstmt ) ) == SQL_SUCCESS ) CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; printf( "%-14.14s %-13.13s \n", deptname.s, location.s ) ; if ( rc != SQL_NO_DATA_FOUND ) CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; /* Print out some implementation row descriptor fields */ /* from the last SQLFetch() above */ for (colCount = 1; colCount <=2; colCount++) { printf("\nInformation for column %i\n",colCount); /* Call SQLGetDescField() to see how the descriptor record */ /* field SQL_DESC_TYPE_NAME is set */ rc = SQLGetDescField( hIRDdesc, colCount, SQL_DESC_TYPE_NAME, /* record field */ desc_char, /* The result */ 25, NULL ); /* ignored */ CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; printf(" - IRD record descriptor field SQL_DESC_TYPE_NAME is %s\n", desc_char); /* Call SQLGetDescField() to see how the descriptor record */ /* field SQL_DESC_LABEL is set */ rc = SQLGetDescField( hIRDdesc, colCount, SQL_DESC_LABEL, /* record field */ desc_char, /* The result */ 25, NULL ); /* ignored */ CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; printf(" - IRD record descriptor field SQL_DESC_LABEL is %s\n", desc_char); } /* End of the for statement */