Exemplo n.º 1
0
/************************************************************************
* name: SQLGetDescFieldW
* arguments:
* returns/side-effects:
* description:
* NOTE:
************************************************************************/
ODBC_INTERFACE RETCODE SQL_API
SQLGetDescFieldW (SQLHDESC hdesc, SQLSMALLINT record, SQLSMALLINT field,
                  SQLPOINTER value, SQLINTEGER value_max, SQLINTEGER *value_len)
{
  RETCODE ret = ODBC_ERROR;
  char* cb_value = NULL;
  int cb_value_len = 0;
  ODBC_DESC *DescriptorHandle = (ODBC_DESC*)hdesc;
  OutputDebugString ("SQLGetDescFieldW called.\n");
  
  cb_value = UT_ALLOC (value_max);
  if (cb_value == NULL && value_max > 0)
    {
      odbc_set_diag (DescriptorHandle->diag, "HY001", 0, "malloc failed");
      return ODBC_ERROR;
    }
  memset (cb_value, 0 , value_max);
    
  SQLGetDescField(hdesc, record, field, cb_value, value_max, &cb_value_len);
  if (ret == ODBC_ERROR)
   {
     UT_FREE (cb_value);
     return ret;
   }  
   
  bytes_to_wide_char (cb_value, cb_value_len, (wchar_t**)&value, value_max, (int*)value_len, NULL);
  UT_FREE (cb_value);
  return ret;
}
Exemplo n.º 2
0
static void
check_attr_ard(ATTR_PARAMS)
{
    SQLINTEGER i, ind;
    SQLSMALLINT si;
    SQLLEN li;
    SQLRETURN ret;
    SQLHDESC desc = SQL_NULL_HDESC;
    char buf[128];

    /* get ARD */
    SQLGetStmtAttr(odbc_stmt, SQL_ATTR_APP_ROW_DESC, &desc, sizeof(desc), &ind);

    ret = SQL_ERROR;
    switch (attr->type) {
    case type_INTEGER:
        i = 0xdeadbeef;
        ret = SQLGetDescField(desc, 1, attr->value, (SQLPOINTER) & i, sizeof(SQLINTEGER), &ind);
        break;
    case type_SMALLINT:
        si = 0xbeef;
        ret = SQLGetDescField(desc, 1, attr->value, (SQLPOINTER) & si, sizeof(SQLSMALLINT), &ind);
        i = si;
        break;
    case type_LEN:
        li = 0xdeadbeef;
        ret = SQLGetDescField(desc, 1, attr->value, (SQLPOINTER) & li, sizeof(SQLLEN), &ind);
        i = li;
        break;
    case type_CHARP:
        ret = SQLGetDescField(desc, 1, attr->value, buf, sizeof(buf), &ind);
        if (!SQL_SUCCEEDED(ret))
            fatal("Line %u: failure not expected\n", line_num);
        if (strcmp(buf, expected_value) != 0) {
            g_result = 1;
            fprintf(stderr, "Line %u: invalid %s got %s expected %s\n", line_num, attr->name, buf, expected_value);
        }
        return;
    }
    if (!SQL_SUCCEEDED(ret))
        fatal("Line %u: failure not expected\n", line_num);
    if (i != lookup(expected_value, attr->lookup)) {
        g_result = 1;
        fprintf(stderr, "Line %u: invalid %s got %ld expected %s\n", line_num, attr->name, (long int) i, expected_value);
    }
}
Exemplo n.º 3
0
//
// get number of column/param records in descriptor
// count does not include bookmark record ever
//
SQLSMALLINT getDescRecCount (SQLHDESC descriptor) {

    SQLRETURN retcode;
    SQLSMALLINT descCount=0;

    // get number of fields in the descriptor
    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_COUNT, &descCount, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (COUNT)",
                      descriptor, SQL_HANDLE_DESC);
        descCount=0;
    }
    return descCount;
}
Exemplo n.º 4
0
static void
print_results(SQLHSTMT hStmt) 
{
	static const char dashes[] = "----------------------------------------------------------------" /* each line is 64 */
				     "----------------------------------------------------------------"
				     "----------------------------------------------------------------"
				     "----------------------------------------------------------------";
	
	struct METADATA *metadata = NULL;
	
	struct DATA *data = NULL;
	
	SQLSMALLINT ncols = 0;
	RETCODE erc;
	int c, ret;

	/* 
	 * Process each resultset
	 */
	do {
		/* free metadata, in case it was previously allocated */
		free_metadata(metadata, data, ncols);
		metadata = NULL;
		data = NULL;
		ncols = 0;
		
		/* 
		 * Allocate memory for metadata and bound columns 
		 */
		if ((erc = SQLNumResultCols(hStmt, &ncols)) != SQL_SUCCESS){
			odbc_perror(hStmt, erc, "SQLNumResultCols", "failed");
			exit(EXIT_FAILURE);
		} 
		
		metadata = (struct METADATA*) calloc(ncols, sizeof(struct METADATA));
		assert(metadata);

		data = (struct DATA*) calloc(ncols, sizeof(struct DATA));
		assert(data);
		
		/* 
		 * For each column, get its name, type, and size. 
		 * Allocate a buffer to hold the data, and bind the buffer to the column.
		 * "bind" here means to give the address of the buffer we want filled as each row is fetched.
		 */

		fprintf(options.verbose, "Metadata\n");
		fprintf(options.verbose, "%-6s  %-30s  %-10s  %-18s  %-6s  %-6s  \n", 
					 "col", "name", "type value", "type name", "size", "varies");
		fprintf(options.verbose, "%.6s  %.30s  %.10s  %.18s  %.6s  %.6s  \n", 
					 dashes, dashes, dashes, dashes, dashes, dashes);
		for (c=0; c < ncols; c++) {
			/* Get and print the metadata.  Optional: get only what you need. */
			SQLCHAR name[512];
			SQLSMALLINT namelen, ndigits, fnullable;

			if ((erc = SQLDescribeCol(hStmt, c+1, name, sizeof(name), &namelen, 
							&metadata[c].type, &metadata[c].size,
							&ndigits, &fnullable)) != SQL_SUCCESS) {
				odbc_perror(hStmt, erc, "SQLDescribeCol", "failed");
				exit(EXIT_FAILURE);
			} 
			assert(namelen < sizeof(name));
			name[namelen] = '\0';
			metadata[c].name = strdup((char *) name);
			metadata[c].width = (ndigits > metadata[c].size)? ndigits : metadata[c].size;
			
			if (is_character_data(metadata[c].type)) {
				SQLHDESC hDesc;
				SQLINTEGER buflen;
				
				metadata[c].nchars = metadata[c].size;
				
				if ((erc = SQLAllocHandle(SQL_HANDLE_DESC, hStmt, &hDesc)) != SQL_SUCCESS) {
					odbc_perror(hStmt, erc, "SQLAllocHandle", "failed");
					exit(EXIT_FAILURE);
				} 
				if ((erc = SQLGetDescField(hDesc, c+1, SQL_DESC_OCTET_LENGTH, 
								&metadata[c].size, sizeof(metadata[c].size), 
								&buflen)) != SQL_SUCCESS) {
					odbc_perror(hStmt, erc, "SQLGetDescField", "failed");
					exit(EXIT_FAILURE);
				} 
				
				if ((erc = SQLFreeHandle(SQL_HANDLE_DESC, hStmt)) != SQL_SUCCESS) {
					odbc_perror(hStmt, erc, "SQLFreeHandle", "failed");
					exit(EXIT_FAILURE);
				} 
			}

			fprintf(options.verbose, "%6d  %30s  %10d  %18s  %6lu  %6d  \n", 
				c+1, metadata[c].name, (int)metadata[c].type, prtype(metadata[c].type), 
				(long unsigned int) metadata[c].size,  -1);

#if 0
			fprintf(options.verbose, "%6d  %30s  %30s  %15s  %6d  %6d  \n", 
				c+1, metadata[c].name, metadata[c].source, dbprtype(metadata[c].type), 
				metadata[c].size,  dbvarylen(dbproc, c+1));

			metadata[c].width = get_printable_size(metadata[c].type, metadata[c].size);
			if (metadata[c].width < strlen(metadata[c].name))
				metadata[c].width = strlen(metadata[c].name);
#endif				
			/* 
			 * Build the column header format string, based on the column width. 
			 * This is just one solution to the question, "How wide should my columns be when I print them out?"
			 */
			ret = set_format_string(&metadata[c], (c+1 < ncols)? options.colsep : "\n");
			if (ret <= 0) {
				fprintf(stderr, "%s:%d: asprintf(), column %d failed\n", options.appname, __LINE__, c+1);
				return;
			}

			/* 
			 * Bind the column to our variable.
			 * We bind everything to strings, because we want to convert everything to strings for us.
			 * If you're performing calculations on the data in your application, you'd bind the numeric data
			 * to C integers and floats, etc. instead. 
			 * 
			 * It is not necessary to bind to every column returned by the query.  
			 * Data in unbound columns are simply never copied to the user's buffers and are thus 
			 * inaccesible to the application.  
			 */

			data[c].buffer = calloc(1, bufsize(&metadata[c]));
			assert(data[c].buffer);

			if ((erc = SQLBindCol(hStmt, c+1, SQL_C_CHAR, (SQLPOINTER)data[c].buffer, 
						bufsize(&metadata[c]), &data[c].len)) != SQL_SUCCESS){
				odbc_perror(hStmt, erc, "SQLBindCol", "failed");
				exit(EXIT_FAILURE);
			} 

		}
		
		if (!options.fquiet) {
			/* Print the column headers to stderr to keep them separate from the data.  */
			for (c=0; c < ncols; c++) {
				fprintf(options.headers, metadata[c].format_string, metadata[c].name);
			}

			/* Underline the column headers.  */
			for (c=0; c < ncols; c++) {
				fprintf(options.headers, metadata[c].format_string, dashes);
			}
		}
		/* 
		 * Print the data to stdout.  
		 */
		while (ncols > 0 && (erc = SQLFetch(hStmt)) != SQL_NO_DATA) {
			switch(erc) {
			case SQL_SUCCESS_WITH_INFO:
				print_error_message(SQL_HANDLE_STMT, hStmt);
			case SQL_SUCCESS:
				break;
			default:
				odbc_perror(hStmt, erc, "SQLFetch", "failed");
				exit(EXIT_FAILURE);
			}
			for (c=0; c < ncols; c++) {
				char *s;
				switch (data[c].len) { /* handle nulls */
				case SQL_NULL_DATA: /* is null */
					fprintf(stdout, metadata[c].format_string, "NULL");
					break;
				default:
					assert(data[c].len > 0);
					s = calloc(1, 1 + data[c].len);
					assert(s);
					memcpy(s, data[c].buffer, data[c].len);
					fprintf(stdout, metadata[c].format_string, s);
					free(s);
					break;
				}
			}
		}
		if (ncols > 0 && erc == SQL_NO_DATA)
			print_error_message(SQL_HANDLE_STMT, hStmt);

		erc = SQLMoreResults(hStmt);
		fprintf(options.verbose, "SQLMoreResults returned %s\n", prret(erc));
		switch (erc) {
		case SQL_NO_DATA:
			print_error_message(SQL_HANDLE_STMT, hStmt);
			break;
		case SQL_SUCCESS_WITH_INFO:
			print_error_message(SQL_HANDLE_STMT, hStmt);
		case SQL_SUCCESS:
			continue;
		default:
			odbc_perror(hStmt, erc, "SQLMoreResults", "failed");
			exit(EXIT_FAILURE);
		}
	} while (erc != SQL_NO_DATA);
	
	if (erc != SQL_NO_DATA) {
		assert(erc != SQL_STILL_EXECUTING);
		odbc_perror(hStmt, erc, "SQLMoreResults", "failed");
		exit(EXIT_FAILURE);
	} 
}
Exemplo n.º 5
0
int
main(int argc, char **argv)
{
	const struct type *p;
	char buf[16];
	SQLINTEGER ind;
	SQLLEN lind;
	SQLHDESC desc;

	odbc_connect();

	/*
	 * test setting two time a descriptor
	 * success all user allocated are ARD or APD so type cheching can be done
	 * TODO freeing descriptor dissociate it from statements
	 */

	/* test C types */
	for (p = types; p->name; ++p) {
		if (SQL_SUCCEEDED
		    (SQLBindParameter(odbc_stmt, 1, SQL_PARAM_INPUT, p->type, SQL_VARCHAR, (SQLUINTEGER) (-1), 0, buf, 16, &lind))) {
			SQLSMALLINT concise_type, type, code;
			SQLHDESC desc;

			concise_type = type = code = 0;

			/* get APD */
			SQLGetStmtAttr(odbc_stmt, SQL_ATTR_APP_PARAM_DESC, &desc, sizeof(desc), &ind);

			SQLGetDescField(desc, 1, SQL_DESC_TYPE, &type, sizeof(SQLSMALLINT), &ind);
			SQLGetDescField(desc, 1, SQL_DESC_CONCISE_TYPE, &concise_type, sizeof(SQLSMALLINT), &ind);
			SQLGetDescField(desc, 1, SQL_DESC_DATETIME_INTERVAL_CODE, &code, sizeof(SQLSMALLINT), &ind);
			printf("Setted type %s -> [%d (%s), %d (%s), %d]\n",
			       p->name, (int) concise_type, get_type_name(concise_type), (int) type, get_type_name(type), code);
			check_msg(p->flags & FLAG_C, "Type not C successed to be set in APD");
		} else {
			SQLSMALLINT concise_type, type, code;
			SQLHDESC desc;

			concise_type = type = code = 0;

			fprintf(stderr, "Error setting type %d (%s)\n", (int) p->type, p->name);

			concise_type = p->type;
			SQLGetStmtAttr(odbc_stmt, SQL_ATTR_APP_PARAM_DESC, &desc, sizeof(desc), &ind);
			if (SQL_SUCCEEDED
			    (SQLSetDescField(desc, 1, SQL_DESC_CONCISE_TYPE, int2ptr(concise_type), sizeof(SQLSMALLINT))))
			{
				SQLGetDescField(desc, 1, SQL_DESC_TYPE, &type, sizeof(SQLSMALLINT), &ind);
				SQLGetDescField(desc, 1, SQL_DESC_CONCISE_TYPE, &concise_type, sizeof(SQLSMALLINT), &ind);
				SQLGetDescField(desc, 1, SQL_DESC_DATETIME_INTERVAL_CODE, &code, sizeof(SQLSMALLINT), &ind);
				printf("Setted type %s -> [%d (%s), %d (%s), %d]\n",
				       p->name,
				       (int) concise_type, get_type_name(concise_type), (int) type, get_type_name(type), code);
				check_msg(p->flags & FLAG_C, "Type not C successed to be set in APD");
			} else {
				check_msg(!(p->flags & FLAG_C), "Type C failed to be set in APD");
			}
		}
	}

	printf("\n\n");

	/* test SQL types */
	SQLGetStmtAttr(odbc_stmt, SQL_ATTR_IMP_PARAM_DESC, &desc, sizeof(desc), &ind);
	for (p = types; p->name; ++p) {
		SQLSMALLINT concise_type = p->type;

		if (SQL_SUCCEEDED
		    (SQLSetDescField(desc, 1, SQL_DESC_CONCISE_TYPE, int2ptr(concise_type), sizeof(SQLSMALLINT)))) {
			SQLSMALLINT concise_type, type, code;

			concise_type = type = code = 0;

			SQLGetDescField(desc, 1, SQL_DESC_TYPE, &type, sizeof(SQLSMALLINT), &ind);
			SQLGetDescField(desc, 1, SQL_DESC_CONCISE_TYPE, &concise_type, sizeof(SQLSMALLINT), &ind);
			SQLGetDescField(desc, 1, SQL_DESC_DATETIME_INTERVAL_CODE, &code, sizeof(SQLSMALLINT), &ind);
			printf("Setted type %s -> [%d (%s), %d (%s), %d]\n",
			       p->name, (int) concise_type, get_type_name(concise_type), (int) type, get_type_name(type), code);
			check_msg(p->flags & FLAG_SQL, "Type not SQL successed to be set in IPD");
		} else {
			fprintf(stderr, "Error setting type %d (%s)\n", (int) p->type, p->name);
			check_msg(!(p->flags & FLAG_SQL), "Type SQL failed to be set in IPD");
		}
	}

	odbc_disconnect();

	return result;
}
Exemplo n.º 6
0
static int odbc_dispatch22(void)
{
	unsigned long retval;
	PWord rval; int rtype;
	PWord arg1; int type1;
	PWord arg2; int type2;
	PWord arg3; int type3;
	PWord arg4; int type4;
	PWord arg5; int type5;
	PWord arg6; int type6;
	PWord arg7; int type7;
	PWord arg8; int type8;

	PI_getan(&arg1,&type1,1);
	if (type1 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg1,type1))
			PI_FAIL;
	PI_getan(&arg2,&type2,2);
	if (type2 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg2,type2))
			PI_FAIL;
	PI_getan(&arg3,&type3,3);
	if (type3 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg3,type3))
			PI_FAIL;
	PI_getan(&arg4,&type4,4);
	if (type4 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg4,type4))
			PI_FAIL;
	PI_getan(&arg5,&type5,5);
	if (type5 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg5,type5))
			PI_FAIL;
	PI_getan(&arg6,&type6,6);
	if (type6 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg6,type6))
			PI_FAIL;
	PI_getan(&arg7,&type7,7);
	if (type7 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg7,type7))
			PI_FAIL;
	PI_getan(&arg8,&type8,8);


	switch(arg1)
	{
		case 0:
			retval = (unsigned long) SQLDescribeParam(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLSMALLINT * ) arg4),((SQLUINTEGER * ) arg5),((SQLSMALLINT * ) arg6),((SQLSMALLINT * ) arg7));
			break;
		case 1:
			retval = (unsigned long) SQLGetDescField(((SQLHDESC  ) arg2),((SQLSMALLINT  ) arg3),((SQLSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLINTEGER  ) arg6),((SQLINTEGER * ) arg7));
			break;
		case 2:
			retval = (unsigned long) SQLGetData(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLINTEGER  ) arg6),((SQLINTEGER * ) arg7));
			break;
		case 3:
			retval = (unsigned long) SQLBindCol(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLINTEGER  ) arg6),((SQLINTEGER * ) arg7));
			break;
		default:
			PI_FAIL;
	}
	PI_makedouble(&rval,&rtype,(double) retval);
	if (PI_unify(arg8,type8,rval,rtype))
		PI_SUCCEED;
	PI_FAIL;
}
Exemplo n.º 7
0
//
// Dump out descriptor records fields using ODBC function SQLGetDescField ()
//
void dumpDescriptorRecordFields (SQLHDESC descriptor, int incBookmarkRec) {

    SQLINTEGER      descAutoUniqueValue;
    SQLCHAR         descBaseColumnName[255];
    SQLCHAR         descBaseTableName[255];
    SQLINTEGER      descCaseSensitive;
    SQLCHAR         descCatalogName[255];
    SQLSMALLINT     descConsiseType;
    SQLPOINTER      descDataPtr;
    SQLSMALLINT     descDatetimeIntervalCode;
    SQLINTEGER      descDatetimeIntervalPrecision;
    SQLLEN          descDisplaySize;
    SQLSMALLINT     descFixedPreCScale;
    SQLLEN         *descIndicatorPtr;
    SQLCHAR         descLabel[255];
    SQLULEN         descLength;
    SQLCHAR         descLiteralPrefix[255];
    SQLCHAR         descLiteralSuffix[255];
    SQLCHAR         descLocalTypeName[255];
    SQLCHAR         descName[255];
    SQLSMALLINT     descNullable;
    SQLINTEGER      descNumPrecRadix;
    SQLLEN          descOctetLength;
    SQLLEN         *descOctetLengthPtr;
    SQLSMALLINT     descParameterType;
    SQLSMALLINT     descPrecision;
    SQLSMALLINT     descRowver;
    SQLSMALLINT     descScale;
    SQLCHAR         descSchemaName[255];
    SQLSMALLINT     descSearchable;
    SQLCHAR         descTableName[255];
    SQLSMALLINT     descType=0;
    SQLCHAR         descTypeName[255];
    SQLSMALLINT     descUnnamed;
    SQLSMALLINT     descUnsigned;
    SQLSMALLINT     descUpdatable;
    SQLINTEGER      Len;

    SQLRETURN retcode;
    SQLSMALLINT descCount;

    descCount=getDescRecCount (descriptor);

    printf ("\n  Descriptor Record Fields");
    printf ("\n  ------------------------\n");

    int i;
    if (incBookmarkRec) {
        i=-1;
    } else {
        i=0;
    }
    for (; i<descCount; i++) {
        printf ("\n  Record %i ", i+1);
        if (i==-1) printf ("(BOOKMARK RECORD)");
        printf ("\n");
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_AUTO_UNIQUE_VALUE ,
                                  &descAutoUniqueValue, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (AUTO_UNIQUE_VALUE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_AUTO_UNIQUE_VALUE  : %i\n", descAutoUniqueValue);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_BASE_COLUMN_NAME ,
                                  descBaseColumnName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (BASE_COLUMN_NAME)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_BASE_COLUMN_NAME  : '%s'\n",
                    descBaseColumnName);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_BASE_TABLE_NAME ,
                                  descBaseTableName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (BASE_TABLE_NAME)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_BASE_TABLE_NAME  : '%s'\n", descBaseTableName);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_CASE_SENSITIVE ,
                                  &descCaseSensitive, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (CASE_SENSITIVE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_CASE_SENSITIVE  : %i\n", descCaseSensitive);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_CATALOG_NAME ,
                                  &descCatalogName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (CATALOG_NAME)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_CATALOG_NAME  : '%s'\n", descCatalogName);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_CONCISE_TYPE ,
                                  &descConsiseType, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (CONCISE_TYPE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_CONCISE_TYPE  : %i\n", descConsiseType);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_DATA_PTR ,
                                  &descDataPtr, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (DATA_PTR)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_DATA_PTR  : %p\n", descDataPtr);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_DATETIME_INTERVAL_CODE ,
                                  &descDatetimeIntervalCode, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (DATETIME_INTERVAL_CODE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_DATETIME_INTERVAL_CODE  : %i\n",
                    (int)descDatetimeIntervalCode);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_DATETIME_INTERVAL_PRECISION ,
                                  &descDatetimeIntervalPrecision, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (DATETIME_INTERVAL_PRECISION)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_DATETIME_INTERVAL_PRECISION  : %i\n",
                    descDatetimeIntervalPrecision);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_DISPLAY_SIZE ,
                                  &descDisplaySize, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (DISPLAY_SIZE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_DISPLAY_SIZE  : %i\n", (int)descDisplaySize);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_FIXED_PREC_SCALE ,
                                  &descFixedPreCScale, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (FIXED_PREC_SCALE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_FIXED_PREC_SCALE  : %i\n",
                    (int)descFixedPreCScale);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_INDICATOR_PTR ,
                                  &descIndicatorPtr, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (INDICATOR_PTR)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_INDICATOR_PTR  : %p\n", descIndicatorPtr);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_LABEL ,
                                  descLabel, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (LABEL )",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_LABEL  : '%s'\n", descLabel);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_LENGTH ,
                                  &descLength, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (LENGTH)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_LENGTH  : %i\n", (unsigned int)descLength);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_LITERAL_PREFIX ,
                                  descLiteralPrefix, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (LITERAL_PREFIX)",
                          descriptor, SQL_HANDLE_DESC);

        } else {
            printf (" SQL_DESC_LITERAL_PREFIX  : '%s'\n", descLiteralPrefix);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_LITERAL_SUFFIX ,
                                  descLiteralSuffix, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (LITERAL_SUFFIX)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_LITERAL_SUFFIX  : '%s'\n", descLiteralSuffix);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_LOCAL_TYPE_NAME ,
                                  descLocalTypeName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (LOCAL_TYPE_NAME)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_LOCAL_TYPE_NAME  : '%s'\n", descLocalTypeName);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_NAME ,
                                  descName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (NAME )",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_NAME  : '%s'\n", descName);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_NULLABLE ,
                                  &descNullable, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (NULLABLE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_NULLABLE  : %i\n", (int)descNullable);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_NUM_PREC_RADIX ,
                                  &descNumPrecRadix, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (NUM_PREC_RADIX)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_NUM_PREC_RADIX  : %i\n", (int)descNumPrecRadix);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_OCTET_LENGTH ,
                                  &descOctetLength, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (OCTET_LENGTH)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_OCTET_LENGTH  : %i\n", (int)descOctetLength);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_OCTET_LENGTH_PTR ,
                                  &descOctetLengthPtr, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (OCTET_LENGTH_PTR)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_OCTET_LENGTH_PTR  : %p\n", descOctetLengthPtr);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_PARAMETER_TYPE ,
                                  &descParameterType, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (PARAMETER_TYPE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_PARAMETER_TYPE  : %i\n", (int)descParameterType);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_PRECISION ,
                                  &descPrecision, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (PRECISION)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_PRECISION  : %i\n", (int)descPrecision);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_ROWVER ,
                                  &descRowver, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (ROWVER)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_ROWVER  : %i\n", (int)descRowver);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_SCALE ,
                                  &descScale, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (SCALE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_SCALE  : %i\n", (int)descScale);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_SCHEMA_NAME ,
                                  &descSchemaName, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (SCHEMA_NAME)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_SCHEMA_NAME  : '%s'\n", descSchemaName);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_SEARCHABLE ,
                                  &descSearchable, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (SEARCHABLE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_SEARCHABLE  : %i\n", (int)descSearchable);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_TYPE ,
                                  &descType, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (TYPE )",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_TYPE  : %i\n", (int)descType);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_TYPE_NAME ,
                                  descTypeName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (TYPE_NAME )",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_TYPE_NAME  : '%s'\n", descTypeName);
        }

        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_UNNAMED ,
                                  &descUnnamed, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (UNNAMED)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_UNNAMED  : %i\n", descUnnamed);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_UNSIGNED ,
                                  &descUnsigned, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (UNSIGNED)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_UNSIGNED  : %i\n", descUnsigned);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_UPDATABLE ,
                                  &descUpdatable, 0, 0);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (UPDATABLE)",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_UPDATABLE  : %i\n", descUpdatable);
        }
        retcode = SQLGetDescField(descriptor, i+1,
                                  SQL_DESC_TABLE_NAME ,
                                  descTableName, 255, &Len);
        if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
            extract_error("SQLGetDescField (TABLE_NAME )",
                          descriptor, SQL_HANDLE_DESC);
        } else {
            printf (" SQL_DESC_TABLE_NAME  : '%s'\n", descTableName);
        }

    }

    return;
}
Exemplo n.º 8
0
//
// Dumps out descriptor header record fields using ODBC
// function SQLGetDescField ()
//
void dumpDescriptorHeaderFields (SQLHDESC descriptor) {

    SQLRETURN       retcode;

    //
    // Header fields
    //
    SQLSMALLINT     descAllocType=0;
    SQLULEN         descArraySize=0;
    SQLUSMALLINT   *descArrayStatusPtr;
    SQLLEN         *descBindOffsetPtr;
    SQLINTEGER      descBindType=0;
    SQLSMALLINT     descCount=0;
    SQLULEN        *descRowsProcessesPtr;

    printf ("\n  Descriptor Header Fields");
    printf ("\n  ------------------------\n");
    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_ALLOC_TYPE,
                              &descAllocType, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (ALLOC_TYPE)",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_ALLOC_TYPE : %i\n", (int) descAllocType);
    }

    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_ARRAY_SIZE,
                              &descArraySize, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (ARRAY_SIZE)",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_ARRAY_SIZE : %i\n", (int) descArraySize);
    }

    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_ARRAY_STATUS_PTR ,
                              &descArrayStatusPtr, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (ARRAY_STATUS_PTR )",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_ARRAY_STATUS_PTR  : %p\n", descArrayStatusPtr);
    }

    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_BIND_OFFSET_PTR ,
                              &descBindOffsetPtr, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (BIND_OFFSET_PTR )",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_BIND_OFFSET_PTR  : %p\n", descBindOffsetPtr);
    }

    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_BIND_TYPE ,
                              &descBindType, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (BIND_TYPE )",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_BIND_TYPE  : %i\n", descBindType);
    }

    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_COUNT ,
                              &descCount, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (COUNT )",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_COUNT  : %i\n", descCount);
    }

    retcode = SQLGetDescField(descriptor, 0, SQL_DESC_ROWS_PROCESSED_PTR ,
                              &descRowsProcessesPtr, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetDescField (ROWS_PROCESSED_PTR )",
                      descriptor, SQL_HANDLE_DESC);
        return;
    } else {
        printf (" SQL_DESC_ROWS_PROCESSED_PTR  : %p\n", descRowsProcessesPtr);
    }

    return;
}