Beispiel #1
0
static int
get_attr_stmt(ATTR_PARAMS)
{
	SQLINTEGER i, ind;
	SQLSMALLINT si;
	SQLLEN li;
	SQLRETURN ret;

	ret = SQL_ERROR;
	switch (attr->type) {
	case type_INTEGER:
	case type_UINTEGER:
		i = 0xdeadbeef;
		ret = SQLGetStmtAttr(odbc_stmt, attr->value, (SQLPOINTER) & i, sizeof(SQLINTEGER), &ind);
		break;
	case type_SMALLINT:
		si = 0xbeef;
		ret = SQLGetStmtAttr(odbc_stmt, attr->value, (SQLPOINTER) & si, sizeof(SQLSMALLINT), &ind);
		i = si;
		break;
	case type_LEN:
		li = 0xdeadbeef;
		ret = SQLGetStmtAttr(odbc_stmt, attr->value, (SQLPOINTER) & li, sizeof(SQLLEN), &ind);
		i = li;
		break;
	case type_VOIDP:
	case type_DESC:
	case type_CHARP:
		fatal("Line %u: CHAR* check still not supported\n", line_num);
		break;
	}
	if (!SQL_SUCCEEDED(ret))
		fatal("Line %u: failure not expected\n", line_num);
	return i;
}
SQLRETURN unixodbc_backend_debug::do_get_statement_attribute(SQLHSTMT statement_handle, SQLINTEGER attribute, SQLPOINTER value_ptr, SQLINTEGER buffer_length, SQLINTEGER * string_length_ptr) const
{
	std::cout << " *DEBUG* get_statement_attribute";
	auto const return_code = SQLGetStmtAttr(statement_handle, attribute, value_ptr, buffer_length, string_length_ptr);
	std::cout << " (return code " << return_code << ")" << std::endl;
	return return_code;
}
Beispiel #3
0
/**
 * Check if query was executed
 * 
 * @param chan R ODBC handle
 * @retval 0 if query not executed, 1 if query executed, -1 on error
 */
SEXP RODBCQueryStatus(SEXP chan){
  pRODBCHandle thisHandle = R_ExternalPtrAddr(chan);
  SQLRETURN res = 0;
  SQLINTEGER len;
  SQLCHAR sqlState[6];
  SQLINTEGER nativeError;
  SQLSMALLINT msgLen;

  res = SQLGetStmtAttr(thisHandle->hStmt, SQL_ATTR_ROW_NUMBER, NULL, 0, &len);
  if(res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO){
    /* get the error code */
    res = SQLGetDiagRec(SQL_HANDLE_STMT, thisHandle->hStmt, 1, sqlState, &nativeError, NULL, 0, &msgLen);
    if(res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO){
      return ScalarInteger(-1);
    }
    /* check if it is an INVALID CURSOR STATE error */
    if(strncmp((const char *)sqlState, "24000", 5) == 0){
      return ScalarInteger(0);
    }
    /* check if it is an NOT POSITIONED ON A VALID ROW error */
    if(strncmp((const char *)sqlState, "07005", 5) == 0){
      return ScalarInteger(1);
    }
    warning(_("SQL error code: %s"), sqlState);
    return ScalarInteger(-1);
  }

  return ScalarInteger(1);
}
Beispiel #4
0
/**
  Internal function to test retrieving a SQL_NUMERIC_STRUCT value.

  @todo Printing some additional output (sqlnum->val as hex, dec)

  @param[in]  hstmt       Statement handle
  @param[in]  numstr      String to retrieve as SQL_NUMERIC_STRUCT
  @param[in]  prec        Precision to retrieve
  @param[in]  scale       Scale to retrieve
  @param[in]  sign        Expected sign (1=+,0=-)
  @param[in]  expdata     Expected byte array value (need this or expnum)
  @param[in]  expnum      Expected numeric value (if it fits)
  @param[in]  overflow    Whether to expect a retrieval failure (22003)
  @return OK/FAIL just like a test.
*/
int sqlnum_test_from_str(SQLHANDLE Stmt,
                         const char *numstr, SQLCHAR prec, SQLSCHAR scale,
                         SQLCHAR sign, SQLCHAR *expdata, int expnum,
                         int overflow)
{
  SQL_NUMERIC_STRUCT *sqlnum= malloc(sizeof(SQL_NUMERIC_STRUCT));
  SQLCHAR buf[512];
  SQLHANDLE ard;
  unsigned long numval;

  sprintf((char *)buf, "select %s", numstr);
  /* OK_SIMPLE_STMT(Stmt, buf); */
  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLExecDirect(Stmt, buf, SQL_NTS));

  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLGetStmtAttr(Stmt, SQL_ATTR_APP_ROW_DESC, &ard, 0, NULL));

  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_TYPE,
                               (SQLPOINTER) SQL_C_NUMERIC, SQL_IS_INTEGER));
  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_PRECISION,
                               (SQLPOINTER)(SQLLEN) prec, SQL_IS_INTEGER));
  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_SCALE,
                               (SQLPOINTER)(SQLLEN) scale, SQL_IS_INTEGER));
  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_DATA_PTR,
                               sqlnum, SQL_IS_POINTER));

  if (overflow)
  {
    FAIL_IF(SQLFetch(Stmt) != SQL_ERROR, "expected SQL_ERROR");
    FAIL_IF(check_sqlstate(Stmt, "22003") != OK, "expected error 22003");
  }
  else
    CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLFetch(Stmt));

  is_num(sqlnum->precision, prec);
  is_num(sqlnum->scale, scale);
  is_num(sqlnum->sign, sign);
  if (expdata)
  {
    IS(!memcmp(sqlnum->val, expdata, SQL_MAX_NUMERIC_LEN));
  }
  else
  {
    /* only use this for <=32bit values */
    int i;
    numval= 0;
    for (i= 0; i < 8; ++i)
      numval += sqlnum->val[7 - i] << (8 * (7 - i));
    
    if (numval != expnum)
      diag("compare %d %d", numval, expnum);
    is_num(numval, expnum);
  }

  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

  free(sqlnum);
  return OK;
}
Beispiel #5
0
RETCODE SQL_API SQLGetStmtAttrW ( SQLHSTMT    pStmt,
                                  SQLINTEGER  pAttr,
                                  SQLPOINTER  pDataPtr,
                                  SQLINTEGER  pDataSize,
                                  SQLINTEGER* pDataSizePtr ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLGetStmtAttrW, Attr: %d, DataPtr: %d, DataSize: %d", pAttr, pDataPtr,
                              pDataSize ) );
    return SQLGetStmtAttr ( pStmt, pAttr, pDataPtr, pDataSize, pDataSizePtr );
}
Beispiel #6
0
ODBC_INTERFACE RETCODE SQL_API
SQLGetStmtAttrW (SQLHSTMT StatementHandle,
                 SQLINTEGER Attribute,
                 SQLPOINTER Value,
                 SQLINTEGER BufferLength, SQLINTEGER * StringLength)
{
  OutputDebugString ("SQLGetStmtAttrW called\n");
  return SQLGetStmtAttr (StatementHandle, Attribute, Value, BufferLength, StringLength);
}
Beispiel #7
0
SQLRETURN SQL_API
SQLGetStmtAttrA(SQLHSTMT StatementHandle,
                SQLINTEGER Attribute,
                SQLPOINTER ValuePtr,
                SQLINTEGER BufferLength,
                SQLINTEGER *StringLengthPtr)
{
    return SQLGetStmtAttr(StatementHandle,
                          Attribute,
                          ValuePtr,
                          BufferLength,
                          StringLengthPtr);
}
Beispiel #8
0
//
// returns true/false if descriptor has/hasn't bookmark record
//
int hasBookmarkRecord (SQLHANDLE handle) {

    SQLRETURN retcode;
    SQLULEN   bookmark;

    retcode = SQLGetStmtAttr(handle, SQL_ATTR_USE_BOOKMARKS,
                             &bookmark, 0, 0);
    if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
        extract_error("SQLGetStmtAttr (SQL_ATTR_USE_BOOKMARKS)",
                      handle, SQL_HANDLE_ENV);
        return 0;
    }
    if (bookmark==SQL_UB_OFF)
        return 0;
    else
        return 1;
}
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);
    }
}
Beispiel #10
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;
}
Beispiel #11
0
CDB_Object* CODBC_RowResult::x_LoadItem(I_Result::EGetItem policy, CDB_Object* item_buf)
{
    char buffer[8*1024];
    int outlen;

    switch(m_ColFmt[m_CurrItem].DataType) {
    case SQL_WCHAR:
    case SQL_WVARCHAR:
        switch (item_buf->GetType()) {
        case eDB_VarBinary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_VarBinary*)item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_Binary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_Binary*)item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_LongBinary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_LongBinary*)item_buf)->SetValue(buffer, outlen);
            break;
#ifdef HAVE_WSTRING
        case eDB_VarChar:
            outlen = xGetData(SQL_C_WCHAR, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else *((CDB_VarChar*)item_buf) = CODBCString((wchar_t*)buffer).ConvertTo(GetClientEncoding());
            break;
        case eDB_Char:
            outlen = xGetData(SQL_C_WCHAR, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Char*)item_buf) = CODBCString((wchar_t*)buffer).ConvertTo(GetClientEncoding());
            break;
        case eDB_LongChar:
            outlen = xGetData(SQL_C_WCHAR, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else *((CDB_LongChar*)item_buf) = CODBCString((wchar_t*)buffer).ConvertTo(GetClientEncoding());
            break;
#endif
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    case SQL_VARCHAR:
    case SQL_CHAR: {
        switch (item_buf->GetType()) {
        case eDB_VarBinary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_VarBinary*) item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_Binary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_Binary*) item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_LongBinary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_LongBinary*) item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_VarChar:
            outlen = xGetData(SQL_C_CHAR, buffer, sizeof(buffer));
            if ( outlen < 0) item_buf->AssignNULL();
            else *((CDB_VarChar*)  item_buf) = buffer;
            break;
        case eDB_Char:
            outlen = xGetData(SQL_C_CHAR, buffer, sizeof(buffer));
            if ( outlen < 0) item_buf->AssignNULL();
            else *((CDB_Char*)     item_buf) = buffer;
            break;
        case eDB_LongChar:
            outlen = xGetData(SQL_C_CHAR, buffer, sizeof(buffer));
            if ( outlen < 0) item_buf->AssignNULL();
            else *((CDB_LongChar*)     item_buf) = buffer;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_BINARY:
    case SQL_VARBINARY: {
        switch ( item_buf->GetType() ) {
        case eDB_VarBinary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_VarBinary*) item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_Binary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_Binary*) item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_LongBinary:
            outlen = xGetData(SQL_C_BINARY, buffer, sizeof(buffer));
            if ( outlen <= 0) item_buf->AssignNULL();
            else ((CDB_LongBinary*) item_buf)->SetValue(buffer, outlen);
            break;
        case eDB_VarChar:
            outlen = xGetData(SQL_C_CHAR, buffer, sizeof(buffer));
            if (outlen < 0) item_buf->AssignNULL();
            else *((CDB_VarChar*)  item_buf) = buffer;
            break;
        case eDB_Char:
            outlen = xGetData(SQL_C_CHAR, buffer, sizeof(buffer));
            if (outlen < 0) item_buf->AssignNULL();
            else *((CDB_Char*) item_buf) = buffer;
            break;
        case eDB_LongChar:
            outlen = xGetData(SQL_C_CHAR, buffer, sizeof(buffer));
            if (outlen < 0) item_buf->AssignNULL();
            else *((CDB_LongChar*) item_buf) = buffer;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }

        break;
    }

    case SQL_BIT: {
        SQLCHAR v;
        switch (  item_buf->GetType()  ) {
        case eDB_Bit:
            outlen = xGetData(SQL_C_BIT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Bit*) item_buf) = (int) v;
            break;
        case eDB_TinyInt:
            outlen = xGetData(SQL_C_BIT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_TinyInt*)  item_buf) = v ? 1 : 0;
            break;
        case eDB_SmallInt:
            outlen = xGetData(SQL_C_BIT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_SmallInt*) item_buf) = v ? 1 : 0;
            break;
        case eDB_Int:
            outlen = xGetData(SQL_C_BIT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Int*)      item_buf) = v ? 1 : 0;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_TYPE_TIMESTAMP: {
        SQL_TIMESTAMP_STRUCT v;
        switch ( item_buf->GetType() ) {
        case eDB_SmallDateTime: {
            outlen = xGetData(SQL_C_TYPE_TIMESTAMP, &v, sizeof(SQL_TIMESTAMP_STRUCT));
            if (outlen <= 0) item_buf->AssignNULL();
            else {
                CTime t((int)v.year, (int)v.month, (int)v.day,
                        (int)v.hour, (int)v.minute, (int)v.second,
                        (long)v.fraction);

                *((CDB_SmallDateTime*) item_buf)= t;
            }
            break;
        }
        case eDB_DateTime: {
            outlen = xGetData(SQL_C_TYPE_TIMESTAMP, &v, sizeof(SQL_TIMESTAMP_STRUCT));
            if (outlen <= 0) item_buf->AssignNULL();
            else {
                CTime t((int)v.year, (int)v.month, (int)v.day,
                        (int)v.hour, (int)v.minute, (int)v.second,
                        (long)v.fraction);

                *((CDB_DateTime*) item_buf)= t;
            }
            break;
        }
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_TINYINT: {
        SQLCHAR v;
        switch (  item_buf->GetType()  ) {
        case eDB_TinyInt:
            outlen = xGetData(SQL_C_UTINYINT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_TinyInt*)  item_buf) = (Uint1) v;
            break;
        case eDB_SmallInt:
            outlen = xGetData(SQL_C_UTINYINT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_SmallInt*) item_buf) = (Int2) v;
            break;
        case eDB_Int:
            outlen = xGetData(SQL_C_UTINYINT, &v, sizeof(SQLCHAR));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Int*)      item_buf) = (Int4) v;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_SMALLINT: {
        SQLSMALLINT v;
        switch (  item_buf->GetType()  ) {
        case eDB_SmallInt:
            outlen = xGetData(SQL_C_SSHORT, &v, sizeof(SQLSMALLINT));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_SmallInt*) item_buf) = (Int2) v;
            break;
        case eDB_Int:
            outlen = xGetData(SQL_C_SSHORT, &v, sizeof(SQLSMALLINT));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Int*) item_buf) = (Int4) v;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_INTEGER: {
        SQLINTEGER v;
        switch (  item_buf->GetType()  ) {
        case eDB_Int:
            outlen = xGetData(SQL_C_SLONG, &v, sizeof(SQLINTEGER));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Int*) item_buf) = (Int4) v;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_DOUBLE:
    case SQL_FLOAT: {
        SQLDOUBLE v;
        switch (  item_buf->GetType()  ) {
        case eDB_Double:
            outlen = xGetData(SQL_C_DOUBLE, &v, sizeof(SQLDOUBLE));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Double*)      item_buf) = v;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_REAL: {
        SQLREAL v;
        switch (  item_buf->GetType()  ) {
        case eDB_Float:
            outlen = xGetData(SQL_C_FLOAT, &v, sizeof(SQLREAL));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_Float*)      item_buf) = v;
            break;
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_BIGINT:
    case SQL_DECIMAL:
    case SQL_NUMERIC: {
        switch (  item_buf->GetType()  ) {
        case eDB_Numeric: {
            SQL_NUMERIC_STRUCT v;
            SQLHDESC hdesc;
            SQLGetStmtAttr(GetHandle(), SQL_ATTR_APP_ROW_DESC, &hdesc, 0, NULL);
            SQLSetDescField(hdesc, m_CurrItem + 1, SQL_DESC_TYPE, (VOID*)SQL_C_NUMERIC, 0);
            SQLSetDescField(hdesc, m_CurrItem + 1, SQL_DESC_PRECISION,
                    (VOID*)(m_ColFmt[m_CurrItem].ColumnSize), 0);
            SQLSetDescField(hdesc, m_CurrItem + 1, SQL_DESC_SCALE,
                    reinterpret_cast<VOID*>(m_ColFmt[m_CurrItem].DecimalDigits), 0);

            // outlen = xGetData(SQL_ARD_TYPE, &v, sizeof(SQL_NUMERIC_STRUCT));
            outlen = xGetData(SQL_C_NUMERIC, &v, sizeof(SQL_NUMERIC_STRUCT));
            if (outlen <= 0) item_buf->AssignNULL();
            else xConvert2CDB_Numeric((CDB_Numeric*)item_buf, v);
            break;
        }
        case eDB_BigInt: {
            SQLBIGINT v;
            outlen = xGetData(SQL_C_SBIGINT, &v, sizeof(SQLBIGINT));
            if (outlen <= 0) item_buf->AssignNULL();
            else *((CDB_BigInt*) item_buf) = (Int8) v;
            break;
        }
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    }

    case SQL_WLONGVARCHAR:
        switch(item_buf->GetType()) {
#ifdef HAVE_WSTRING
        case eDB_Text: {
			if (policy == I_Result::eAssignLOB) {
				static_cast<CDB_Stream*>(item_buf)->Truncate();
			}

            while (CheckSIENoD_WText((CDB_Stream*)item_buf)) {
                continue;
            }
            break;
        }
#endif
        case eDB_Image: {
			if (policy == I_Result::eAssignLOB) {
				static_cast<CDB_Stream*>(item_buf)->Truncate();
			}

            while (CheckSIENoD_Binary((CDB_Stream*)item_buf)) {
                continue;
            }
            break;
        }
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    case SQL_LONGVARBINARY:
    case SQL_LONGVARCHAR:
        switch(item_buf->GetType()) {
        case eDB_Text:
        case eDB_VarCharMax: {
			if (policy == I_Result::eAssignLOB) {
				static_cast<CDB_Stream*>(item_buf)->Truncate();
			}

            while (CheckSIENoD_Text((CDB_Stream*)item_buf)) {
                continue;
            }
            break;
        }
        case eDB_Image:
        case eDB_VarBinaryMax: {
			if (policy == I_Result::eAssignLOB) {
				static_cast<CDB_Stream*>(item_buf)->Truncate();
			}

            while (CheckSIENoD_Binary((CDB_Stream*)item_buf)) {
                continue;
            }
            break;
        }
        default:
            {
                string err_message = wrong_type + GetDbgInfo();
                DATABASE_DRIVER_ERROR( err_message, 430020 );
            }
        }
        break;
    default:
        {
            string err_message = "Unsupported column type." + GetDbgInfo();
            DATABASE_DRIVER_ERROR( err_message, 430025 );
        }

    }
    return item_buf;
}
Beispiel #12
0
/*
---------------------------------------------------------
   TestSQLGetDescRec
---------------------------------------------------------
*/
PassFail TestMXSQLGetDescRec(TestInfo *pTestInfo)
{   
	TEST_DECLARE;
	RETCODE				returncode;
	SQLHANDLE 			henv;
	SQLHANDLE 			hdbc;
	SQLHANDLE			hstmt, hstmt1;
	
	//Common input params to the apis
	SQLHDESC			hIrd, hImArd, hImIrd, hImApd, hImIpd, hExArd, hExApd;
	SWORD				RecNumber = 0;

	//SQLGetDescRec: params
	SQLHDESC			getDescRecHandle;				//input
	SWORD				getDescRecNumber;				//input
	TCHAR				getDescName[MAXLEN];		 
	SWORD				getNameMaxLength;				//input; MAXLEN = 100 : defined in Common.h
	SWORD				getDescNameActualLength;
	SQLSMALLINT			getDescType;
	SWORD				getDescIntervalCode;
	SQLLEN				getDescOctectLength; 
	SWORD				getDescPrecision;
	SWORD				getDescScale;
	SWORD				getDescNullable;

	//SQLSetDescRec: params
	SQLHDESC			setDescRecHandle;
	SQLSMALLINT			setDescRecNumber;
	SQLSMALLINT			setDescType;
	SQLSMALLINT			setDescIntervalCode;
	SQLINTEGER			setDescOctetLength;
	SQLSMALLINT			setDescPrecision;
	SQLSMALLINT			setDescScale;
	SQLPOINTER			setDescDataPtr;
	SQLLEN				setDescOctectLengthPtr; 
	SQLLEN				setDescIndicatorPtr; 

	TCHAR				setDescName[1];
	
	SQLINTEGER			setDescNullable = SQL_NULL_DATA;
	short int			i;

	// Template for a Descriptor record
	typedef struct {
	  //	TCHAR				DescName[MAXLEN];
	TCHAR				*DescName;
	short int			DescType;
	short int			DescDatetimeIntervalCode;
	short int			DescOctetLength;
	short int			DescPrecision;
	short int			DescScale;
	void*				DescDataPtr;
	short int			DescOctectLengthPtr;
	short int			DescIndicatorPtr;
	short int			DescNullable;
	}DescRec;

	DescRec TestDataAPD[DATA_ARR_LEN] = 
	{
	//APD
	//	DescName		Type				DatetimeIntervalCode	DescOctetLength		Precision	DescScale	DescDataPtr		OctectLengthPtr		IndicatorPtr				DescNullable
		{_T(""),			SQL_C_DEFAULT,				0,						0,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TCHAR,					0,						80,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TCHAR,					0,						300,			0,			0,			NULL,		SQL_NTS,			SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_NUMERIC,				0,						0,				0,			0,			NULL,		SQL_DATA_AT_EXEC,	SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TYPE_TIMESTAMP,	SQL_CODE_TIMESTAMP,			0,				6,			1,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_INTERVAL_SECOND,	SQL_CODE_SECOND,			0,				2,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN }
	};

	DescRec TestDataARD[DATA_ARR_LEN] =
	{
	//ARD
	//	DescName		Type				DatetimeIntervalCode	DescOctetLength		Precision	DescScale	DescDataPtr		OctectLengthPtr		IndicatorPtr				DescNullable
		{_T(""),			SQL_C_DEFAULT,				0,						0,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TCHAR,					0,						80,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TCHAR,					0,						300,			0,			0,			NULL,		SQL_NTS,			SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_NUMERIC,				0,						0,				0,			0,			NULL,		SQL_DATA_AT_EXEC,	SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TYPE_TIMESTAMP,	SQL_CODE_TIMESTAMP,			0,				6,			1,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_INTERVAL_SECOND,	SQL_CODE_SECOND,			0,				2,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN }
	};

	DescRec TestDataIPD[DATA_ARR_LEN] =
	{
	//IPD
	//	DescName		Type				DatetimeIntervalCode	DescOctetLength		Precision	DescScale	DescDataPtr		OctectLengthPtr		IndicatorPtr				DescNullable
		{_T(""),			SQL_C_DEFAULT,				0,						0,				0,			0,			0,				0,					0,					SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_TCHAR,					0,						80,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_TCHAR,					0,						300,			0,			0,			NULL,		SQL_NTS,			SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_NUMERIC,				0,						0,				0,			0,			NULL,		SQL_DATA_AT_EXEC,	SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_TYPE_TIMESTAMP,		SQL_CODE_TIMESTAMP,			0,				6,			1,			0,				0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_INTERVAL_SECOND,	SQL_CODE_SECOND,			0,				2,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN }
	};

	DescRec TestDataIRD[DATA_ARR_LEN] =
	{
	//IRD can only be read
	//	DescName		Type				DatetimeIntervalCode	DescOctetLength		Precision	DescScale	DescDataPtr		OctectLengthPtr		IndicatorPtr				DescNullable
		{_T(""),			SQL_C_DEFAULT,				0,						0,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TCHAR,					0,						80,				0,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TCHAR,					0,						300,			0,			0,			NULL,		SQL_NTS,			SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_NUMERIC,				0,						0,				0,			0,			NULL,		SQL_DATA_AT_EXEC,	SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_TIMESTAMP,		SQL_CODE_TIMESTAMP,			0,				6,			1,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN },
		{_T(""),			SQL_C_INTERVAL_SECOND,	SQL_CODE_SECOND,			0,				2,			0,			NULL,			0,				SQL_NULL_DATA,			SQL_NULLABLE_UNKNOWN }
	};
	_tcscpy(setDescName, _T(""));
// ================================================================================================================
//		begin common test setup 
//==================================================================================================================
	LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => SQLSetDescRec and SQLGetDescRec.\n"));
	TEST_INIT;

	if(!FullConnectWithOptions(pTestInfo, CONNECT_ODBC_VERSION_3))
	{
		LogMsg(NONE,_T("Unable to connect\n"));
		TEST_FAILED;
		TEST_RETURN;
	}
	
	henv = pTestInfo->henv;
 	hdbc = pTestInfo->hdbc;

	returncode = SQLAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE)hdbc, &hstmt);	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		FullDisconnect(pTestInfo);
		TEST_FAILED;
		TEST_RETURN;
	}

	//Explicit APD
	//allocate an Explicit APD desc
	returncode = SQLAllocHandle(SQL_HANDLE_DESC, (SQLHANDLE)hdbc, &hExApd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle to get explicit APD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		FullDisconnect(pTestInfo);
		TEST_FAILED;
		TEST_RETURN;
	}	

	//Explicit ARD
	returncode = SQLAllocHandle(SQL_HANDLE_DESC, (SQLHANDLE)hdbc, &hExArd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle to get explicit ARD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		FullDisconnect(pTestInfo);
		TEST_FAILED;
		TEST_RETURN;
	}

//===============================================================================================================
//			Begin Testing:Positive Test for Implicit APD 
//===============================================================================================================	
	//Get Implicit APD handle
	returncode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_DESC, &hImApd, 0, NULL);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetStmtAttr: get APD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG,_T("Cannot allocate descriptor: Aborting Implicit APD tests.\n"));
		TEST_FAILED;
		goto ExAPDtests;		// transfers control to the next set of tests
	}

	for (i = 0;i < DATA_ARR_LEN; i++)		// i = index to TestDataAPD
	{
		TESTCASE_BEGIN("Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Implicit APD.\n");


		//set multiple Fields
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		
		setDescRecHandle		= hImApd ;
		setDescRecNumber		= RecNumber;
		setDescType				= TestDataAPD[i].DescType; 
		setDescIntervalCode		= TestDataAPD[i].DescDatetimeIntervalCode;
		setDescOctetLength		= TestDataAPD[i].DescOctetLength;	
		setDescPrecision		= TestDataAPD[i].DescPrecision;	
		setDescScale			= TestDataAPD[i].DescScale;	
		setDescDataPtr			= TestDataAPD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataAPD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataAPD[i].DescIndicatorPtr;	

		/*LogMsg(NONE,_T("SQLSetDescRec(handle,%d,%d,%d,%d,%d,%d,%s,%d,%d)\n"),
											setDescRecNumber, 
											setDescType, 
											setDescIntervalCode, 
											setDescOctetLength , 
											setDescPrecision, 
											setDescScale, 
											setDescDataPtr,
											setDescOctectLengthPtr, 
											setDescIndicatorPtr);  */

		returncode = SQLSetDescRec(setDescRecHandle, setDescRecNumber, setDescType, setDescIntervalCode, setDescOctetLength , setDescPrecision, setDescScale, setDescDataPtr,&setDescOctectLengthPtr, &setDescIndicatorPtr);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetDescRec "))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLSetDescRec: positive tests for Implicit APD: TestDataAPD['%d'].\n"),i);
			//FullDisconnect(pTestInfo);
			TEST_FAILED;
			//TEST_RETURN;
			continue;
		}
		
		//Get the Implicit APD Descriptor 
		//LogMsg(SHORTTIMESTAMP,"SQLGetDescRec: test for Implicit APD.\n");
		LogMsg(NONE,_T("SQLSetDescRec / SQLGetDescRec: positive tests for Implicit APD.\n"));


		getDescRecHandle		= hImApd;					
		getDescRecNumber		= RecNumber;				
		getNameMaxLength		= MAXLEN;
		_tcscpy(getDescName	,_T(""));	//initialize
		setDescNullable			= TestDataAPD[i].DescNullable;

		returncode = SQLGetDescRec(getDescRecHandle, getDescRecNumber, (SQLTCHAR*)getDescName, getNameMaxLength, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLGetDescRec: positive tests for Implicit APD: TestDataAPD['%d'].\n"),i);
			//FullDisconnect(pTestInfo);
			TEST_FAILED;
			//TEST_RETURN;
			continue;
		}

		//begin checking  APD values ----------
		
		//check  SQL_DESC_NAME
		if (!(_tcscmp(getDescName, setDescName)))
		{
			LogMsg(NONE,_T("SQL_DESC_NAME value returned is '%s'\n"),getDescName);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NAME: '%s' and actual: '%s' are not matched\n"), setDescName,getDescName);
		}
		
		//check SQL_DESC_TYPE
		if (getDescType == setDescType)
		{
			LogMsg(NONE,_T("SQL_DESC_TYPE value returned is '%d'\n"),getDescType);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_TYPE: '%d' and actual: '%d' are not matched\n"), setDescType, getDescType);
		}

		//check SQL_DESC_DATETIME_INTERVAL_CODE
		if (getDescIntervalCode == setDescIntervalCode)
		{
			LogMsg(NONE,_T("SQL_DESC_DATETIME_INTERVAL_CODE value returned is '%d'\n"),getDescIntervalCode);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_DATETIME_INTERVAL_CODE: '%d' and actual: '%d' are not matched\n"), setDescIntervalCode, getDescIntervalCode);
		}
		//check SQL_DESC_OCTECT_LENGTH
		if (getDescOctectLength == setDescOctetLength)
		{
			LogMsg(NONE,_T("SQL_DESC_OCTECT_LENGTH value returned is '%d'\n"),getDescOctectLength);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_OCTECT_LENGTH: '%d' and actual: '%d' are not matched\n"), setDescOctetLength,getDescOctectLength);
		}

		//check SQL_DESC_PRECISION
		if (getDescPrecision == setDescPrecision)
		{
			LogMsg(NONE,_T("SQL_DESC_PRECISION value returned is '%d'\n"),getDescPrecision);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_PRECISION: '%d' and actual: '%d' are not matched\n"), setDescPrecision,getDescPrecision);
		}

		//check SQL_DESC_SCALE
		if (getDescScale == setDescScale)
		{
			LogMsg(NONE,_T("SQL_DESC_SCALE value returned is '%d'\n"),getDescScale);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_SCALE: '%d' and actual: '%d' are not matched\n"), setDescScale,getDescScale);
		}

		//check SQL_DESCNULLABLE
		if (getDescNullable == setDescNullable)
		{
			LogMsg(NONE,_T("SQL_DESC_NULLABLE value returned is '%d'\n"),getDescNullable);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NULLABLE: '%d' and actual: '%d' are not matched\n"), setDescNullable, getDescNullable);
		}
		// end of checks 
		TESTCASE_END;

	} //end for loop; end of positive tests for APD
	 

//===============================================================================================================
//			Begin Testing:Positive Test for Explicit APD 
//===============================================================================================================
	ExAPDtests: ;		// beginning next set of tests
	
	//mark the beginning of tests in log file
	//LogMsg(SHORTTIMESTAMP, "Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Explicit APD.\n");
	
	//Get Explicit APD handle
	returncode = SQLAllocHandle(SQL_HANDLE_DESC, (SQLHANDLE)hdbc, &hExApd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle: get Explicit APD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG,_T("Cannot allocate descriptor: Aborting Explicit APD tests.\n"));
		TEST_FAILED;
		//TEST_RETURN;
		goto ARDtests;		// transfers control to the next set of tests
	}

	//associate with a statement
	returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_DESC, (SQLPOINTER)hExApd, SQL_IS_POINTER);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr: explicit APD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG, _T("Cannot set Explicit APD for statement.\n"));
		TEST_FAILED;
	}

	setDescRecHandle = hExApd ;

	for (i = 0;i < DATA_ARR_LEN; i++)		// i = index to TestDataAPD
	{
		TESTCASE_BEGIN("Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Explicit APD.\n");


		//set multiple Fields
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		

		setDescRecNumber		= RecNumber;
		setDescType				= TestDataAPD[i].DescType; 
		setDescIntervalCode		= TestDataAPD[i].DescDatetimeIntervalCode;
		setDescOctetLength		= TestDataAPD[i].DescOctetLength;	
		setDescPrecision		= TestDataAPD[i].DescPrecision;	
		setDescScale			= TestDataAPD[i].DescScale;	
		setDescDataPtr			= TestDataAPD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataAPD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataAPD[i].DescIndicatorPtr;	


		/*LogMsg(NONE,_T("SQLSetDescRect(handle,%d,%d,%d,%d,%d,%d,%s,%d,%d)\n"),
									setDescRecNumber, 
									setDescType, 
									setDescIntervalCode, 
									setDescOctetLength , 
									setDescPrecision, 
									setDescScale, 
									setDescDataPtr,
									setDescOctectLengthPtr, 
									setDescIndicatorPtr);*/

		returncode = SQLSetDescRec(setDescRecHandle, setDescRecNumber, setDescType, setDescIntervalCode, setDescOctetLength , setDescPrecision, setDescScale, setDescDataPtr,&setDescOctectLengthPtr, &setDescIndicatorPtr);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLSetDescRec: positive tests for Explicit APD: TestDataAPD['%d'].\n"),i);
			TEST_FAILED;
			//TEST_RETURN;
			continue;
		}
		
			
		//Get the Explicit APD Descriptor 
		//LogMsg(SHORTTIMESTAMP,"SQLGetDescRec: test for Implicit APD.\n");
		LogMsg(NONE,_T("SQLSetDescRec / SQLGetDescRec: positive tests for Explicit APD.\n"));


		getDescRecHandle		= 	setDescRecHandle;					
		getDescRecNumber		= RecNumber;				
		getNameMaxLength		= MAXLEN;
		_tcscpy(getDescName	,_T(""));	//initialize		
		setDescNullable			= TestDataAPD[i].DescNullable;

		returncode = SQLGetDescRec(getDescRecHandle, getDescRecNumber, (SQLTCHAR*)getDescName, getNameMaxLength, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetDescRec and SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLGetDescRec: positive tests for Explicit APD: TestDataAPD['%d'].\n"),i);
			TEST_FAILED;
			continue;
		}

		//begin checking  APD values 
		
		//check  SQL_DESC_NAME
		if (!(_tcscmp(getDescName, setDescName)))
		{
			LogMsg(NONE,_T("SQL_DESC_NAME value returned is '%s'\n"),getDescName);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NAME: '%s' and actual: '%s' are not matched\n"), setDescName,getDescName);
		}
		
		//check SQL_DESC_TYPE
		if (getDescType == setDescType)
		{
			LogMsg(NONE,_T("SQL_DESC_TYPE value returned is '%d'\n"),getDescType);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_TYPE: '%d' and actual: '%d' are not matched\n"), setDescType, getDescType);
		}

		//check SQL_DESC_DATETIME_INTERVAL_CODE
		if (getDescIntervalCode == setDescIntervalCode)
		{
			LogMsg(NONE,_T("SQL_DESC_DATETIME_INTERVAL_CODE value returned is '%d'\n"),getDescIntervalCode);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_DATETIME_INTERVAL_CODE: '%d' and actual: '%d' are not matched\n"), setDescIntervalCode, getDescIntervalCode);
		}
		//check SQL_DESC_OCTECT_LENGTH
		if (getDescOctectLength == setDescOctetLength)
		{
			LogMsg(NONE,_T("SQL_DESC_OCTECT_LENGTH value returned is '%d'\n"),getDescOctectLength);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_OCTECT_LENGTH: '%d' and actual: '%d' are not matched\n"), setDescOctetLength,getDescOctectLength);
		}

		//check SQL_DESC_PRECISION
		if (getDescPrecision == setDescPrecision)
		{
			LogMsg(NONE,_T("SQL_DESC_PRECISION value returned is '%d'\n"),getDescPrecision);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_PRECISION: '%d' and actual: '%d' are not matched\n"), setDescPrecision,getDescPrecision);
		}

		//check SQL_DESC_SCALE
		if (getDescScale == setDescScale)
		{
			LogMsg(NONE,_T("SQL_DESC_SCALE value returned is '%d'\n"),getDescScale);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_SCALE: '%d' and actual: '%d' are not matched\n"), setDescScale,getDescScale);
		}

		//check SQL_DESCNULLABLE
		if (getDescNullable == setDescNullable)
		{
			LogMsg(NONE,_T("SQL_DESC_NULLABLE value returned is '%d'\n"),getDescNullable);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NULLABLE: '%d' and actual: '%d' are not matched\n"), setDescNullable, getDescNullable);
		}
		// end of checks 


		
		TESTCASE_END;

	} //end for loop; end of positive tests for Explicit APD


	 
//===============================================================================================================
//			Begin Testing: Statement reverts to Implicit APD after freeing Explicit Descriptor
//===============================================================================================================
	
	//mark the beginning of tests in log file
	//LogMsg(SHORTTIMESTAMP, "SQLGetDescRec for Explicit-Implicit APD: statement reverts to implicit descriptor after explicit descriptor has been freed.\n");
	
	//free Explicit APD
	returncode = SQLFreeHandle(SQL_HANDLE_DESC, hExApd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeHandle (for APD)"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG,_T("Cannot free explicit descriptor: Aborting Explicit-Implicit Descriptor tests.\n"));
		TEST_FAILED;
		goto ARDtests;		// transfers control to the next set of tests
	}

	//Use the previously allocated Implicit APD handle
	getDescRecHandle		= hImApd;

		TESTCASE_BEGIN("Test that the implicit descriptor get associated with statement after explicit descriptor has been freed.\n");


		//set multiple Fields
		i			= 0;
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		
		
		setDescRecNumber		= RecNumber;
		setDescType				= TestDataAPD[i].DescType; 
		setDescIntervalCode		= TestDataAPD[i].DescDatetimeIntervalCode;
		setDescOctetLength		= TestDataAPD[i].DescOctetLength;	
		setDescPrecision		= TestDataAPD[i].DescPrecision;	
		setDescScale			= TestDataAPD[i].DescScale;	
		setDescDataPtr			= TestDataAPD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataAPD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataAPD[i].DescIndicatorPtr;	

			
		//Get the Implicit APD Descriptor 
		LogMsg(NONE,_T("SQLGetDescRec: tests for Explicit-Implicit Descriptor.\n"));
			
		getDescRecNumber		= RecNumber;				
		getNameMaxLength		= MAXLEN;
		_tcscpy(getDescName	,_T(""));	//initialize		
		setDescNullable			= TestDataAPD[i].DescNullable;

		returncode = SQLGetDescRec(getDescRecHandle, getDescRecNumber, (SQLTCHAR*)getDescName, getNameMaxLength, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLGetDescRec: tests for Explicit-Implicit APD: TestDataAPD['%d'].\n"),i);
			TEST_FAILED;
			//continue;
		}

		//begin checking  APD values ----------
		
		//check  SQL_DESC_NAME
		if (!(_tcscmp(getDescName, setDescName)))
		{
			LogMsg(NONE,_T("SQL_DESC_NAME value returned is '%s'\n"),getDescName);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NAME: '%s' and actual: '%s' are not matched\n"), setDescName,getDescName);
		}
		
		//check SQL_DESC_TYPE
		if (getDescType == setDescType)
		{
			LogMsg(NONE,_T("SQL_DESC_TYPE value returned is '%d'\n"),getDescType);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_TYPE: '%d' and actual: '%d' are not matched\n"), setDescType, getDescType);
		}

		//check SQL_DESC_DATETIME_INTERVAL_CODE
		if (getDescIntervalCode == setDescIntervalCode)
		{
			LogMsg(NONE,_T("SQL_DESC_DATETIME_INTERVAL_CODE value returned is '%d'\n"),getDescIntervalCode);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_DATETIME_INTERVAL_CODE: '%d' and actual: '%d' are not matched\n"), setDescIntervalCode, getDescIntervalCode);
		}
		//check SQL_DESC_OCTECT_LENGTH
		if (getDescOctectLength == setDescOctetLength)
		{
			LogMsg(NONE,_T("SQL_DESC_OCTECT_LENGTH value returned is '%d'\n"),getDescOctectLength);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_OCTECT_LENGTH: '%d' and actual: '%d' are not matched\n"), setDescOctetLength,getDescOctectLength);
		}

		//check SQL_DESC_PRECISION
		if (getDescPrecision == setDescPrecision)
		{
			LogMsg(NONE,_T("SQL_DESC_PRECISION value returned is '%d'\n"),getDescPrecision);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_PRECISION: '%d' and actual: '%d' are not matched\n"), setDescPrecision,getDescPrecision);
		}

		//check SQL_DESC_SCALE
		if (getDescScale == setDescScale)
		{
			LogMsg(NONE,_T("SQL_DESC_SCALE value returned is '%d'\n"),getDescScale);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_SCALE: '%d' and actual: '%d' are not matched\n"), setDescScale,getDescScale);
		}

		//check SQL_DESCNULLABLE
		if (getDescNullable == setDescNullable)
		{
			LogMsg(NONE,_T("SQL_DESC_NULLABLE value returned is '%d'\n"),getDescNullable);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NULLABLE: '%d' and actual: '%d' are not matched\n"), setDescNullable, getDescNullable);
		}
		// end of checks 
		TESTCASE_END;




//==================================================================================================================
//		Begin Testing: Positive Test for Implicit ARD 
//===================================================================================================================
	ARDtests:	;
	
	//mark the beginning of tests in log file
	//LogMsg(SHORTTIMESTAMP, "Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Implicit ARD.\n");
	

	//Get Implicit ARD handle
	returncode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, &hImArd, 0, NULL);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetStmtAttr: get ARD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG, _T("Cannot get ARD: Aborting Implicit ARD tests.\n"));
		TEST_FAILED;
		goto ExARDtests;		//go to next set of tests
	}
				
	for (i = 0;i < DATA_ARR_LEN; i++)		// i = index to TestDataARD
	{
		TESTCASE_BEGIN("Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Implicit ARD.\n");


		
		//set multiple Fields
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		
		setDescRecHandle		= hImArd ;
		setDescRecNumber		= RecNumber;
		setDescType				= TestDataARD[i].DescType; 
		setDescIntervalCode		= TestDataARD[i].DescDatetimeIntervalCode;	
		setDescOctetLength		= TestDataARD[i].DescOctetLength;	
		setDescPrecision		= TestDataARD[i].DescPrecision;	
		setDescScale			= TestDataARD[i].DescScale;		
		setDescDataPtr			= TestDataARD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataARD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataARD[i].DescIndicatorPtr;				


		returncode = SQLSetDescRec(setDescRecHandle, setDescRecNumber, setDescType, setDescIntervalCode, setDescOctetLength , setDescPrecision, setDescScale, setDescDataPtr,&setDescOctectLengthPtr, &setDescIndicatorPtr);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetDescRec and SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLSetDescRec: positive tests for Implicit ARD: TestDataARD['%d'].\n"),i);
			//FullDisconnect(pTestInfo);
			TEST_FAILED;
			//TEST_RETURN;
			continue;
		}
		
			
		//Get the Implicit ARD Descriptor 
		LogMsg(NONE,_T("SQLSetDescRec / SQLGetDescRec: positive tests for Implicit ARD.\n"));

		getDescRecHandle		= hImApd;					
		getDescRecNumber		= RecNumber;				
		getNameMaxLength		= MAXLEN;
		_tcscpy(getDescName	,_T(""));	//initialize		
		setDescNullable			= TestDataARD[i].DescNullable;

		returncode = SQLGetDescRec(getDescRecHandle, getDescRecNumber, (SQLTCHAR*)getDescName, getNameMaxLength, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetDescRec and SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLGetDescRec: positive tests for Implicit ARD: TestDataARD['%d'].\n"),i);
			//FullDisconnect(pTestInfo);
			TEST_FAILED;
			//TEST_RETURN;
			break;
		}

		//begin checking  ARD values 
		
		//check  SQL_DESC_NAME
		if (!(_tcscmp(getDescName, setDescName)))
		{
			LogMsg(NONE,_T("SQL_DESC_NAME value returned is '%s'\n"),getDescName);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NAME: '%s' and actual: '%s' are not matched\n"), setDescName,getDescName);
		}
		
		//check SQL_DESC_TYPE
		if (getDescType == setDescType)
		{
			LogMsg(NONE,_T("SQL_DESC_TYPE value returned is '%d'\n"),getDescType);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_TYPE: '%d' and actual: '%d' are not matched\n"), setDescType, getDescType);
		}

		//check SQL_DESC_DATETIME_INTERVAL_CODE
		if (getDescIntervalCode == setDescIntervalCode)
		{
			LogMsg(NONE,_T("SQL_DESC_DATETIME_INTERVAL_CODE value returned is '%d'\n"),getDescIntervalCode);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_DATETIME_INTERVAL_CODE: '%d' and actual: '%d' are not matched\n"), setDescIntervalCode, getDescIntervalCode);
		}
		//check SQL_DESC_OCTECT_LENGTH
		if (getDescOctectLength == setDescOctetLength)
		{
			LogMsg(NONE,_T("SQL_DESC_OCTECT_LENGTH value returned is '%d'\n"),getDescOctectLength);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_OCTECT_LENGTH: '%d' and actual: '%d' are not matched\n"), setDescOctetLength,getDescOctectLength);
		}

		//check SQL_DESC_PRECISION
		if (getDescPrecision == setDescPrecision)
		{
			LogMsg(NONE,_T("SQL_DESC_PRECISION value returned is '%d'\n"),getDescPrecision);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_PRECISION: '%d' and actual: '%d' are not matched\n"), setDescPrecision,getDescPrecision);
		}

		//check SQL_DESC_SCALE
		if (getDescScale == setDescScale)
		{
			LogMsg(NONE,_T("SQL_DESC_SCALE value returned is '%d'\n"),getDescScale);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_SCALE: '%d' and actual: '%d' are not matched\n"), setDescScale,getDescScale);
		}

		//check SQL_DESCNULLABLE
		if (getDescNullable == setDescNullable)
		{
			LogMsg(NONE,_T("SQL_DESC_NULLABLE value returned is '%d'\n"),getDescNullable);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NULLABLE: '%d' and actual: '%d' are not matched\n"), setDescNullable, getDescNullable);
		}
		// end of checks
		TESTCASE_END;

	} //end for loop; end of positive tests for ARD
	


//==================================================================================================================
//		Begin Testing: Positive Test for Explicit ARD 
//===================================================================================================================
	ExARDtests:	;
	
	//mark the beginning of tests in log file
	//LogMsg(SHORTTIMESTAMP, "Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Explicit ARD.\n");
	

	//Get Explicit ARD handle
	returncode = SQLAllocHandle(SQL_HANDLE_DESC, (SQLHANDLE)hdbc, &hExArd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle: get explicit ARD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG, _T("Cannot get ARD: Aborting Implicit ARD tests.\n"));
		TEST_FAILED;
		goto IPDtests;		//go to next set of tests
	}

	//associate with a statement
	returncode = SQLSetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, (SQLPOINTER)hExArd, SQL_IS_POINTER);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetStmtAttr: explicit ARD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG, _T("Cannot set Explicit ARD for statement.\n"));
		TEST_FAILED;
	}

				
	for (i = 0;i < DATA_ARR_LEN; i++)		// i = index to TestDataARD
	{
		TESTCASE_BEGIN("Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Explicit ARD.\n");


		
		//set multiple Fields
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		
		setDescRecHandle		= hExArd ;
		setDescRecNumber		= RecNumber;
		setDescType				= TestDataARD[i].DescType; 
		setDescIntervalCode		= TestDataARD[i].DescDatetimeIntervalCode;	
		setDescOctetLength		= TestDataARD[i].DescOctetLength;	
		setDescPrecision		= TestDataARD[i].DescPrecision;	
		setDescScale			= TestDataARD[i].DescScale;		
		setDescDataPtr			= TestDataARD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataARD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataARD[i].DescIndicatorPtr;				


		returncode = SQLSetDescRec(setDescRecHandle, setDescRecNumber, setDescType, setDescIntervalCode, setDescOctetLength , setDescPrecision, setDescScale, setDescDataPtr,&setDescOctectLengthPtr, &setDescIndicatorPtr);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLSetDescRec: positive tests for Explicit ARD: TestDataARD['%d'].\n"),i);
			TEST_FAILED;
			continue;
		}
		
			
		//Get the Explicit ARD Descriptor 
		LogMsg(NONE,_T("SQLSetDescRec and SQLGetDescRec: positive tests for Explicit ARD.\n"));

		getDescRecHandle		= hExArd;					
		getDescRecNumber		= RecNumber;				
		getNameMaxLength		= MAXLEN;
		_tcscpy(getDescName	,_T(""));	//initialize		
		setDescNullable			= TestDataARD[i].DescNullable;

		returncode = SQLGetDescRec(getDescRecHandle, getDescRecNumber, (SQLTCHAR*)getDescName, getNameMaxLength, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLGetDescRec: positive tests for Explicit ARD: TestDataARD['%d'].\n"),i);
			TEST_FAILED;
			break;
		}

		//begin checking  ARD values 
		
		//check  SQL_DESC_NAME
		if (!(_tcscmp(getDescName, setDescName)))
		{
			LogMsg(NONE,_T("SQL_DESC_NAME value returned is '%s'\n"),getDescName);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NAME: '%s' and actual: '%s' are not matched\n"), setDescName,getDescName);
		}
		
		//check SQL_DESC_TYPE
		if (getDescType == setDescType)
		{
			LogMsg(NONE,_T("SQL_DESC_TYPE value returned is '%d'\n"),getDescType);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_TYPE: '%d' and actual: '%d' are not matched\n"), setDescType, getDescType);
		}

		//check SQL_DESC_DATETIME_INTERVAL_CODE
		if (getDescIntervalCode == setDescIntervalCode)
		{
			LogMsg(NONE,_T("SQL_DESC_DATETIME_INTERVAL_CODE value returned is '%d'\n"),getDescIntervalCode);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_DATETIME_INTERVAL_CODE: '%d' and actual: '%d' are not matched\n"), setDescIntervalCode, getDescIntervalCode);
		}
		//check SQL_DESC_OCTECT_LENGTH
		if (getDescOctectLength == setDescOctetLength)
		{
			LogMsg(NONE,_T("SQL_DESC_OCTECT_LENGTH value returned is '%d'\n"),getDescOctectLength);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_OCTECT_LENGTH: '%d' and actual: '%d' are not matched\n"), setDescOctetLength,getDescOctectLength);
		}

		//check SQL_DESC_PRECISION
		if (getDescPrecision == setDescPrecision)
		{
			LogMsg(NONE,_T("SQL_DESC_PRECISION value returned is '%d'\n"), getDescPrecision);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_PRECISION: '%d' and actual: '%d' are not matched\n"), setDescPrecision,getDescPrecision);
		}

		//check SQL_DESC_SCALE
		if (getDescScale == setDescScale)
		{
			LogMsg(NONE,_T("SQL_DESC_SCALE value returned is '%d'\n"),getDescScale);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_SCALE: '%d' and actual: '%d' are not matched\n"), setDescScale,getDescScale);
		}

		//check SQL_DESCNULLABLE
		if (getDescNullable == setDescNullable)
		{
			LogMsg(NONE,_T("SQL_DESC_NULLABLE value returned is '%d'\n"),getDescNullable);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NULLABLE: '%d' and actual: '%d' are not matched\n"), setDescNullable, getDescNullable);
		}
		// end of checks
		TESTCASE_END;

	} //end for loop; end of positive tests for Explicit ARD

	//free explicit ARD
	returncode = SQLFreeHandle(SQL_HANDLE_DESC, hExArd);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeHandle (for ARD)"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		TEST_FAILED;
	}
	

//======================================================================================================================
//		 Begin Testing: Positive Test for Implicit IPD 
//=====================================================================================================================	

	IPDtests:	;
	
	//mark the beginning of tests in log file
	//LogMsg(SHORTTIMESTAMP, "Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Implicit IPD.\n");
	

	//Get Implicit IPD handle
	returncode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, &hImIpd, 0, NULL);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetStmtAttr: get IPD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		LogMsg(ERRMSG, _T("Cannot get IPD: Aborting Implicit IPD tests.\n"));
		TEST_FAILED;
		goto IRDtests;		//go to next set of tests
	}	
	
	
	
	for (i = 0;i < DATA_ARR_LEN; i++)		// i = index to TestDataIPD
	{
		TESTCASE_BEGIN("Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Implicit IPD.\n");
		

		
		//set multiple Fields
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		
		setDescRecHandle		= hImIpd ;
		setDescRecNumber		= RecNumber;
		setDescType				= TestDataIPD[i].DescType; 
		setDescIntervalCode		= TestDataIPD[i].DescDatetimeIntervalCode;
		setDescOctetLength		= TestDataIPD[i].DescOctetLength;
		setDescPrecision		= TestDataIPD[i].DescPrecision;	
		setDescScale			= TestDataIPD[i].DescScale;		
		setDescDataPtr			= TestDataIPD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataIPD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataIPD[i].DescIndicatorPtr;				

		returncode = SQLSetDescRec(setDescRecHandle, setDescRecNumber, setDescType, setDescIntervalCode, setDescOctetLength , setDescPrecision, setDescScale, setDescDataPtr,&setDescOctectLengthPtr, &setDescIndicatorPtr);
		if(!CHECKRC(SQL_SUCCESS,returncode, "SQLSetDescRec and SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLSetDescRec: positive tests for Implicit IPD: TestDataIPD['%d'].\n"),i);
			//FullDisconnect(pTestInfo);
			TEST_FAILED;
			//TEST_RETURN;
			continue;
		}
		
			
		//Get the Implicit IPD Descriptor 
		LogMsg(NONE,_T("SQLSetDescRec and SQLGetDescRec: positive tests for Implicit IPD.\n"));


		getDescRecHandle		= hImApd;					
		getDescRecNumber		= RecNumber;				
		getNameMaxLength		= MAXLEN;
		_tcscpy(getDescName	,_T(""));	//initialize	
		setDescNullable			= TestDataIPD[i].DescNullable;

		returncode = SQLGetDescRec(getDescRecHandle, getDescRecNumber, (SQLTCHAR*)getDescName, getNameMaxLength, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG,_T("SQLGetDescRec: positive tests for Implicit IPD: TestDataIPD['%d'].\n"),i);
			//FullDisconnect(pTestInfo);
			TEST_FAILED;
			//TEST_RETURN;
			continue;
		}

		//begin checking  IPD values 
		
		//check  SQL_DESC_NAME
		if (!(_tcscmp(getDescName, setDescName)))
		{
			LogMsg(NONE,_T("SQL_DESC_NAME value returned is '%s'\n"),getDescName);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NAME: '%s' and actual: '%s' are not matched\n"), setDescName,getDescName);
		}
		
		//check SQL_DESC_TYPE
		if (getDescType == setDescType)
		{
			LogMsg(NONE,_T("SQL_DESC_TYPE value returned is '%d'\n"), getDescType);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_TYPE: '%d' and actual: '%d' are not matched\n"), setDescType, getDescType);
		}

		//check SQL_DESC_DATETIME_INTERVAL_CODE
		if (getDescIntervalCode == setDescIntervalCode)
		{
			LogMsg(NONE,_T("SQL_DESC_DATETIME_INTERVAL_CODE value returned is '%d'\n"),getDescIntervalCode);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_DATETIME_INTERVAL_CODE: '%d' and actual: '%d' are not matched\n"), setDescIntervalCode, getDescIntervalCode);
		}
		//check SQL_DESC_OCTECT_LENGTH
		if (getDescOctectLength == setDescOctetLength)
		{
			LogMsg(NONE,_T("SQL_DESC_OCTECT_LENGTH value returned is '%d'\n"),getDescOctectLength);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_OCTECT_LENGTH: '%d' and actual: '%d' are not matched\n"), setDescOctetLength,getDescOctectLength);
		}

		//check SQL_DESC_PRECISION
		if (getDescPrecision == setDescPrecision)
		{
			LogMsg(NONE,_T("SQL_DESC_PRECISION value returned is '%d'\n"),getDescPrecision);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_PRECISION: '%d' and actual: '%d' are not matched\n"), setDescPrecision,getDescPrecision);
		}

		//check SQL_DESC_SCALE
		if (getDescScale == setDescScale)
		{
			LogMsg(NONE,_T("SQL_DESC_SCALE value returned is '%d'\n"),getDescScale);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_SCALE: '%d' and actual: '%d' are not matched\n"), setDescScale,getDescScale);
		}

		//check SQL_DESCNULLABLE
		if (getDescNullable == setDescNullable)
		{
			LogMsg(NONE,_T("SQL_DESC_NULLABLE value returned is '%d'\n"),getDescNullable);
		}
		else
		{
			TEST_FAILED;					
			LogMsg(ERRMSG, _T("expect SQL_DESC_NULLABLE: '%d' and actual: '%d' are not matched\n"), setDescNullable, getDescNullable);
		}
		// end of checks 
		TESTCASE_END;

	} //end for loop; end of positive tests for IPD


//==================================================================================================================
//		 Begin Testing: Posituve Tests for IRD (IRD Desc Fields are read only) 
//==================================================================================================================
		IRDtests: ;

		//mark the beginning of tests in log file
		//LogMsg(SHORTTIMESTAMP, "Test the positive functionality of SQLSetDescRec and SQLGetDescRec for Implicit IRD.\n");
	
		//Get Implicit IRD handle
		returncode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_ROW_DESC, &hImIrd, 0, NULL);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetStmtAttr"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			LogMsg(ERRMSG, _T("Cannot get IRD: Aborting Implicit IRD tests.\n"));
			TEST_FAILED;
		//	TEST_RETURN;		//this will abort tests and perform a full disconnect.
		}

		//---------------------------------------------------------------------------------------------------------
		
		TESTCASE_BEGIN("Test SQLSetDescRec for Implicit IRD: IRD Descriptor Fields cannot be set by the application.\n");
		
		//set multiple Fields
		RecNumber = i + 1;		//increment the recnumber and thus set the next rec (change SQL_DESC_COUNT)
		
		setDescRecHandle		= hImIrd ;
		setDescRecNumber		= RecNumber;
		setDescType				= TestDataIRD[i].DescType; 
		setDescIntervalCode		= TestDataIRD[i].DescDatetimeIntervalCode;	
		setDescOctetLength		= TestDataIRD[i].DescOctetLength;	
		setDescPrecision		= TestDataIRD[i].DescPrecision;	
		setDescScale			= TestDataIRD[i].DescScale;		
		setDescDataPtr			= TestDataIRD[i].DescDataPtr;			
		setDescOctectLengthPtr	= TestDataIRD[i].DescOctectLengthPtr;			
		setDescIndicatorPtr		= TestDataIRD[i].DescIndicatorPtr;				

		returncode = SQLSetDescRec(setDescRecHandle, setDescRecNumber, setDescType, setDescIntervalCode, setDescOctetLength , setDescPrecision, setDescScale, setDescDataPtr,&setDescOctectLengthPtr, &setDescIndicatorPtr);
		if(!CHECKRC(SQL_ERROR,returncode,"SQLSetDescRec"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			TEST_FAILED;

		}
		TESTCASE_END;
		
		//-------------------------------------------------------------------------------------------------------------
		
		TESTCASE_BEGIN("Test SQLGetDescRec for Implicit IRD: IRD Descriptor Fields not populated before call to DB.\n");
		
		//This testcases use the Implicit IRD handle obtained in previous testcase

		returncode = SQLGetDescRec(hImIrd, 1, (SQLTCHAR*)getDescName, MAXLEN, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
		if(!CHECKRC(SQL_NO_DATA_FOUND,returncode,"SQLGetDescField"))
		{
			LogAllErrorsVer3(henv,hdbc,hstmt);
			TEST_FAILED;
			//TEST_RETURN;	//last test: valid to use TEST_RETURN when the test suite must be exited.
		}

		TESTCASE_END;

//===============================================================================================================
//			Begin Testing:Positive Test for populated Implicit IRD 
//===============================================================================================================

	TESTCASE_BEGIN("Test SQLGetDescRec for populated Implicit IRD.\n");

	//mark the beginning of tests in log file
	//LogMsg(SHORTTIMESTAMP, "Test the positive functionality of (SQLSetDescRec) and SQLGetDescRec for Implicit IRD.\n");
	
	//alloc new handle
	returncode = SQLAllocHandle(SQL_HANDLE_STMT, (SQLHANDLE)hdbc, &hstmt1);	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocHandle"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt1);
		LogMsg(ERRMSG,_T("Cannot allocate statement: Aborting populated Implicit IRD tests.\n"));
		FullDisconnect(pTestInfo);
		TEST_FAILED;
		goto Cleanup;		// transfers control to the next set 
	}

	//Get Implicit IRD handle
	returncode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_DESC, &hIrd, 0, NULL);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetStmtAttr: get IRD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt1);
		LogMsg(ERRMSG,_T("Cannot allocate descriptor: Aborting populated Implicit IRD tests.\n"));
		TEST_FAILED;
		goto Cleanup;		// transfers control to the next set 
	}

	//populate the IRD by executing an catalog api
	returncode = SQLGetTypeInfo(hstmt1, SQL_ALL_TYPES);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetTypeInfo: population of IRD"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt1);
		LogMsg(ERRMSG,_T("Cannot execute statement: Aborting populated Implicit IRD tests.\n"));
		TEST_FAILED;
		goto Cleanup;		// transfers control to the next set 
	}	

	//check IRD
	returncode = SQLGetDescRec(hIrd, 1, (SQLTCHAR*)getDescName, MAXLEN, &getDescNameActualLength, &getDescType, &getDescIntervalCode, &getDescOctectLength, &getDescPrecision, &getDescScale, &getDescNullable);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLGetDescField"))
	{
			LogAllErrorsVer3(henv,hdbc,hstmt1);
			TEST_FAILED;
			//TEST_RETURN;	//last test: valid to use TEST_RETURN when the test suite must be exited.
	}
	
	TESTCASE_END;

	// free implicitly allocated descriptors by freeing statement
	returncode = SQLFreeHandle(SQL_HANDLE_STMT,hstmt1);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeHandle"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt1);
		TEST_FAILED;
	}

//===========================================================================================================
//		begin cleanup 
//==============================================================================================================
Cleanup: ;
		
	// free implicitly allocated descriptors by freeing statement
	returncode = SQLFreeHandle(SQL_HANDLE_STMT,hstmt);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFreeHandle"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		TEST_FAILED;
	}
	

	
	FullDisconnect3(pTestInfo);
	LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLSetDescRec and SQLGetDescRec.\n"));
    TEST_RETURN;
} //end of test ****************
Beispiel #13
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 >= 0 && (unsigned) 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 = SQLGetStmtAttr(hStmt, SQL_ATTR_IMP_ROW_DESC, &hDesc, sizeof(hDesc), NULL)) != SQL_SUCCESS) {
					odbc_perror(hStmt, erc, "SQLGetStmtAttr", "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);
				}
				metadata[c].size = metadata[c].size * 2 + 1;
			}

			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++) {
				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);
				case SQL_NO_TOTAL:
					fprintf(stdout, metadata[c].format_string, data[c].buffer);
					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);
	} 
}
Beispiel #14
0
/* TODO zaimplementowac FETCH_NEXT */
long db2_bmd_db_result_get_value(void *hDB,void *hRes,long which_row,long which_column,char **value,
							 EnumDbFetchMode_t fetch_mode,long *successfully_fetched)
{
	PRINT_INFO("\n");

	DB_bmd_db_conn_t *db_conn=NULL;
	//DB_bmd_db_result_t *db_res=NULL;
	SQLRETURN     rc;


	/*	walidacja parametrow	*/
	/******************************/
	if(hDB==NULL)			{	BMD_FOK(BMD_DB_INVALID_CONNECTION_HANDLE);	}
	if(which_row<0)					{	BMD_FOK(BMD_ERR_PARAM3);	}
	if(which_column<0)				{	BMD_FOK(BMD_ERR_PARAM4);	}
	if(value == NULL)				{	BMD_FOK(BMD_ERR_PARAM5);	}
	if(*value != NULL)				{       BMD_FOK(BMD_ERR_PARAM5);        }
	if(successfully_fetched == NULL)		{	BMD_FOK(BMD_ERR_PARAM6);	}
	if(*successfully_fetched < 0)			{	BMD_FOK(BMD_ERR_PARAM6);	}
	if( (*((long *)(hDB)) != BMD_DBCONN_MAGIC ) )
		return BMD_ERR_INVALID_PTR;


	db_conn=(DB_bmd_db_conn_t *)hDB;
	//db_res=(DB_bmd_db_result_t *)hRes;
	/*
	 * Only FETCH_NEXT mode implemented	 *
	 */


	//if(which_column != 0)
	//	return BMD_ERR_FORMAT;

	if(*successfully_fetched == 0){		
		rc = SQLFetch(*(db_conn->hstmt));
		long ret = print_error(rc, "SQLFetch");
		if(ret!=BMD_OK)
		{
		    if(ret == 5)
		   		return BMD_ERR_NODATA;
	   		else{
   				extract_error("SQLAllocHandle", *(db_conn->hstmt), SQL_HANDLE_STMT);
   				return BMD_DB_EXECUTION_ERROR;
   			}
		}
	}

    int colNum = 0;
    SQLINTEGER sql_ub;
    rc = SQLGetStmtAttr( *(db_conn->hstmt), SQL_ATTR_USE_BOOKMARKS, &sql_ub, 0, NULL ) ;
    if(print_error(rc, "SQLGetStmtAttr") != BMD_OK)
    			return BMD_ERR_OP_FAILED;
    if ( sql_ub == SQL_UB_OFF )
    	colNum = which_column + 1;
    else
    	colNum = which_column;


	//SQLCHAR *
	SQLINTEGER indicator;

	//TODO - koniecznie zrobiæ bufor dynamiczny!!!

	SQLCHAR buf[32000];
	/* retrieve column data as a string */
	rc = SQLGetData(*(db_conn->hstmt), colNum, SQL_C_CHAR, buf, sizeof(buf), &indicator);

	long retu = print_error(rc, "SQLGetData");
	if(retu!=BMD_OK)
	{
		if(retu == 5)
			return BMD_ERR_NODATA;
	   	else
	   		return BMD_ERR_OP_FAILED;
    }

//PRINT_INFO("Indicator: %d\n", (int)indicator);
if(indicator <= 0)
{
	//PRINT_INFO("Pobrano pust¹ wartoœæ\n");
	asprintf(value,"%s","");
	return BMD_OK;
}
	asprintf(value,"%s",buf);
    return BMD_OK;
}
Beispiel #15
0
long db2_bmd_db_result_get_row(void *hDB,void *hRes,long which_row,long max_columns,db_row_strings_t **rowstruct,
						   EnumDbFetchMode_t fetch_mode,long *successfully_fetched)
{
	long err = 0;
	SQLRETURN     rc;


		DB_bmd_db_conn_t *db_conn=NULL;
		//DB_bmd_db_result_t *db_res=NULL;
		//SQLUINTEGER   rowsFetchedNb		= 0;

		SQLSMALLINT   nResultCols=0;
		long colsprocess		= 0;
		long i				= 0;

		/******************************/
		/*	walidacja parametrow	*/
		/******************************/
		if(hDB==NULL)			{	BMD_FOK(BMD_DB_INVALID_CONNECTION_HANDLE);	}

		if(which_row < 0)				{	BMD_FOK(BMD_ERR_PARAM3);			}
		if(max_columns < 0)				{	BMD_FOK(BMD_ERR_PARAM4);			}
		if(rowstruct == NULL)				{       BMD_FOK(BMD_ERR_PARAM5);       			}
		if(*rowstruct != NULL)				{       BMD_FOK(BMD_ERR_PARAM5);                        }
		if( (*((long *)(hDB)) != BMD_DBCONN_MAGIC ) )
			return BMD_ERR_INVALID_PTR;

		db_conn=(DB_bmd_db_conn_t *)hDB;

		if( fetch_mode == FETCH_ABSOLUTE )
			return BMD_ERR_FORMAT;
		else
			if( fetch_mode == FETCH_NEXT )
				;
			else
			{
				return BMD_ERR_FORMAT;
			}


		*rowstruct = (db_row_strings_t *) malloc ( sizeof(db_row_strings_t) );
		if(*rowstruct == NULL)
		{
			PRINT_ERROR("LIBBMDPGERR Memory error. Error=%i\n",NO_MEMORY);
			return NO_MEMORY;
		}
		memset(*rowstruct, 0, sizeof(db_row_strings_t));



		/* identify the output columns */
		rc = SQLNumResultCols( *(db_conn->hstmt), &nResultCols);
		if(rc != SQL_SUCCESS)
		{
			extract_error("SQLNumResultCols", *(db_conn->hstmt), SQL_HANDLE_STMT);
			return BMD_DB_EXECUTION_ERROR;

		}

		if(max_columns <= 0)
		{
			colsprocess = nResultCols;
		}
		else
		{
			colsprocess = (nResultCols < max_columns)? nResultCols:max_columns;
		}

		/* przetwarzam mniejsza wartosc z colsreturned i max_columns */
		(*rowstruct)->size = colsprocess;

		(*rowstruct)->colvals = (char **) malloc (sizeof(char *) * colsprocess);
		if((*rowstruct)->colvals == NULL)
		{
			PRINT_ERROR("LIBBMDPGERR Memory error. Error=%i\n",NO_MEMORY);
			return NO_MEMORY;
		}
		memset((*rowstruct)->colvals, 0, sizeof(char *) * colsprocess);



		/*
		 * set up the values to return fetch information into
		 */

		rc = SQLFetch(*(db_conn->hstmt));
			long ret = print_error(rc, "SQLFetch");
		    if(ret!=BMD_OK)
		    {
			    if(ret == 5)
				{
					PRINT_INFO("No Data Found\n");
			   		return BMD_ERR_NODATA;
				}
			   	else{
			   		extract_error("SQLAllocHandle", *(db_conn->hstmt), SQL_HANDLE_STMT);
			   		return BMD_DB_EXECUTION_ERROR;
			   	}
		    }

		int colNum = 0;
		SQLINTEGER sql_ub;
		rc = SQLGetStmtAttr( *(db_conn->hstmt), SQL_ATTR_USE_BOOKMARKS, &sql_ub, 0, NULL ) ;

		if(print_error(rc, "SQLGetStmtAttr") != BMD_OK)
		{
			extract_error("SQLGetStmtAttr,SQL_ATTR_USE_BOOKMARKS ", *(db_conn->hstmt), SQL_HANDLE_STMT);
			return BMD_DB_EXECUTION_ERROR;
		}

		if ( sql_ub == SQL_UB_OFF )
		  	colNum = 1;
		else
		  	colNum = 0;



		/* Wypelnij wszystkie stringi z wiersza */
		for(i=0; i<colsprocess; i++)
		{
			/* retrieve column data as a string */
			SQLINTEGER indicator;
			//TODO - koniecznie zrobiæ bufor dynamiczny!!!
			SQLCHAR buf[32000];
			rc = SQLGetData(*(db_conn->hstmt), i+colNum, SQL_C_CHAR, buf, sizeof(buf), &indicator);
			if (print_error(rc, "SQLGetData") != BMD_OK)
			{
				extract_error("SQLGetData", *(db_conn->hstmt), SQL_HANDLE_STMT);
				return BMD_DB_EXECUTION_ERROR;
			}
			if(indicator > 0)
				asprintf(&((*rowstruct)->colvals[i]),"%s",buf);
			else
				asprintf(&((*rowstruct)->colvals[i]),"%s","");
		}

		return err;
}
Beispiel #16
0
static int odbc_dispatch10(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;

	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);


	switch(arg1)
	{
		case 0:
			retval = (unsigned long) SQLExtendedFetch(((SQLHSTMT  ) arg2),((SQLUSMALLINT  ) arg3),((SQLINTEGER  ) arg4),((SQLUINTEGER * ) arg5),((SQLUSMALLINT * ) arg6));
			break;
		case 1:
			retval = (unsigned long) SQLSetDescField(((SQLHDESC  ) arg2),((SQLSMALLINT  ) arg3),((SQLSMALLINT  ) arg4),((SQLPOINTER  ) arg5),((SQLINTEGER  ) arg6));
			break;
		case 2:
			retval = (unsigned long) SQLGetStmtAttr(((SQLHSTMT  ) arg2),((SQLINTEGER  ) arg3),((SQLPOINTER  ) arg4),((SQLINTEGER  ) arg5),((SQLINTEGER * ) arg6));
			break;
		case 3:
			retval = (unsigned long) SQLGetInfo(((SQLHDBC  ) arg2),((SQLUSMALLINT  ) arg3),((SQLPOINTER  ) arg4),((SQLSMALLINT  ) arg5),((SQLSMALLINT * ) arg6));
			break;
		case 4:
			retval = (unsigned long) SQLGetEnvAttr(((SQLHENV  ) arg2),((SQLINTEGER  ) arg3),((SQLPOINTER  ) arg4),((SQLINTEGER  ) arg5),((SQLINTEGER * ) arg6));
			break;
		case 5:
			retval = (unsigned long) SQLGetConnectAttr(((SQLHDBC  ) arg2),((SQLINTEGER  ) arg3),((SQLPOINTER  ) arg4),((SQLINTEGER  ) arg5),((SQLINTEGER * ) arg6));
			break;
		default:
			PI_FAIL;
	}
	PI_makedouble(&rval,&rtype,(double) retval);
	if (PI_unify(arg7,type7,rval,rtype))
		PI_SUCCEED;
	PI_FAIL;
}
Beispiel #17
0
SQLRETURN unixodbc_backend::do_get_statement_attribute(SQLHSTMT statement_handle, SQLINTEGER attribute, SQLPOINTER value_ptr, SQLINTEGER buffer_length, SQLINTEGER * string_length_ptr) const
{
	return SQLGetStmtAttr(statement_handle, attribute, value_ptr, buffer_length, string_length_ptr);
}
Beispiel #18
0
bool CDbStmt::Bind()
{
	assert (myRow == -1) ;

	// call SQLNumResultCols to calculate the number of columns
	SQLSMALLINT nCols;
	SQLRETURN nResult;

	if (!myHSTMT)
		return false;


	do {
		nResult = SQLNumResultCols(*myHSTMT, &nCols);
		if (nResult != SQL_ERROR && nCols == 0) {
			SQLRETURN nResultMore = SQLMoreResults(*myHSTMT);
			if (!SQL_SUCCEEDED(nResultMore))
				break;
		} else
			break;
	} while (nResult != SQL_ERROR && nCols == 0);

	if (nResult == SQL_ERROR || nCols == 0) {
	  // Close the open result set.
		myHSTMT->Close();
		myHSTMT = NULL;
		return false;
	} else {
		myCols = new CDbCol[(myColN = nCols)+1];
	}


	CDbLib *dbLib = GetDbConn()->GetDbLib();
	SQLSMALLINT nColName;
	SQLSMALLINT i;
	int nAlloc;

	myColMap.Clear();

	nAlloc = 0;
	for(i = 0; myCols && i < myColN; i++) {
		myCols[i].Name.Grow(3);
		SQLDescribeCol(*myHSTMT, i+1, (LPSQLC) (const char *) myCols[i].Name, 2, &nColName, &myCols[i].Type, &myCols[i].Size,
					&myCols[i].Digits, &myCols[i].Null);
		
		if (nColName) {
			myCols[i].Name.Grow(nColName);

			SQLDescribeCol(*myHSTMT, i+1, (LPSQLC) (const char *) myCols[i].Name, nColName+1, &nColName, 
						&myCols[i].Type, &myCols[i].Size,
						&myCols[i].Digits, &myCols[i].Null);
		} else {
			SQLColAttribute(*myHSTMT, i+1, SQL_DESC_CATALOG_NAME, 
				0, 0, &nColName, 0);
			if (nColName) {
				myCols[i].Name.Grow(nColName);
				SQLColAttribute(*myHSTMT, i+1, SQL_DESC_CATALOG_NAME, 
					(LPSQLC) (const char *) myCols[i].Name, nColName+1, &nColName, 0);
			} else  {
				myCols[i].Name.Grow(1);
				*(myCols[i].Name.GetBuffer()) = '\0';
			}
		}

		SQLColAttribute(*myHSTMT, i+1, SQL_DESC_DISPLAY_SIZE, 0, 0, 0, 
					&myCols[i].DispSize);


		myColMap.Set(myCols[i].Name,&myCols[i]);

		if (myCols[i].DispSize > DEFAULT_MAX_BUFFER) {
			myCols[i].DispSize = DEFAULT_MAX_BUFFER;
		}

		nAlloc += (myCols[i].DispSize + 1);
	}

	SQLINTEGER rowSetSize = max((long unsigned int) 1, (dbLib->GetMaxBuffer() / (nAlloc + (myColN * sizeof(SQLINTEGER)))));

	nResult = SQLSetStmtAttr(*myHSTMT, SQL_ATTR_ROW_ARRAY_SIZE, (void *) rowSetSize,   SQL_IS_INTEGER);
	nResult = SQLGetStmtAttr(*myHSTMT, SQL_ATTR_ROW_ARRAY_SIZE,   &rowSetSize,   SQL_IS_INTEGER,  NULL);
	nResult = SQLSetStmtAttr(*myHSTMT, SQL_ATTR_ROWS_FETCHED_PTR, &myRowsetSize, SQL_IS_POINTER);
	

	myRowsetMax = myRowsetSize = rowSetSize;
	myRow = 0;
	myBufIndex = 0;

	myMem = (char *) malloc(nAlloc * (myRowsetSize+1) + sizeof(SQLINTEGER) * (myColN+1) * (myRowsetSize+1));
	
	char *pB = myMem;
	long *pI = (long *) (myMem + nAlloc * (myRowsetSize+1));
	for(i = 0; i < myColN; i++) {
		myCols[i].SetBuf(pB);
		myCols[i].SetIndPtr(pI);
		myCols[i].SetStmt(this);

		SQLBindCol(*myHSTMT, (UWORD)(i+1), SQL_C_CHAR, myCols[i].GetBuf(), myCols[i].DispSize + 1, &myCols[i].GetInd());

		pB += (myCols[i].DispSize + 1) * myRowsetSize;
		pI += myRowsetSize;
	}
	myBufIndex = myRowsetSize;
	return true;
}
int
main(int argc, char *argv[])
{
#define TEST_FILE "describecol.in"
    const char *in_file = FREETDS_SRCDIR "/" TEST_FILE;
    FILE *f;
    char buf[256];
    SQLINTEGER i;
    SQLLEN len;
    check_attr_t check_attr_p = check_attr_none;

    odbc_connect();
    odbc_command("SET TEXTSIZE 4096");

    SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len);

    f = fopen(in_file, "r");
    if (!f)
        fopen(TEST_FILE, "r");
    if (!f) {
        fprintf(stderr, "error opening test file\n");
        exit(1);
    }

    line_num = 0;
    while (fgets(buf, sizeof(buf), f)) {
        char *p = buf, *cmd;

        ++line_num;

        while (isspace((unsigned char) *p))
            ++p;
        cmd = strtok(p, SEP);

        /* skip comments */
        if (!cmd || cmd[0] == '#' || cmd[0] == 0 || cmd[0] == '\n')
            continue;

        if (strcmp(cmd, "odbc") == 0) {
            int odbc3 = get_int(strtok(NULL, SEP)) == 3 ? 1 : 0;

            if (odbc_use_version3 != odbc3) {
                odbc_use_version3 = odbc3;
                odbc_disconnect();
                odbc_connect();
                odbc_command("SET TEXTSIZE 4096");
                SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len);
            }
        }

        /* select type */
        if (strcmp(cmd, "select") == 0) {
            const char *type = strtok(NULL, SEP);
            const char *value = strtok(NULL, SEP);
            char sql[sizeof(buf) + 40];

            SQLMoreResults(odbc_stmt);
            odbc_reset_statement();

            sprintf(sql, "SELECT CONVERT(%s, %s) AS col", type, value);

            /* ignore error, we only need precision of known types */
            check_attr_p = check_attr_none;
            if (odbc_command_with_result(odbc_stmt, sql) != SQL_SUCCESS) {
                odbc_reset_statement();
                SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len);
                continue;
            }

            CHKFetch("SI");
            SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len);
            check_attr_p = check_attr_ird;
        }

        /* set attribute */
        if (strcmp(cmd, "set") == 0) {
            const struct attribute *attr = lookup_attr(strtok(NULL, SEP));
            char *value = strtok(NULL, SEP);
            SQLHDESC desc;
            SQLRETURN ret;
            SQLINTEGER ind;

            if (!value)
                fatal("Line %u: value not defined\n", line_num);

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

            ret = SQL_ERROR;
            switch (attr->type) {
            case type_INTEGER:
                ret = SQLSetDescField(desc, 1, attr->value, int2ptr(lookup(value, attr->lookup)),
                                      sizeof(SQLINTEGER));
                break;
            case type_SMALLINT:
                ret = SQLSetDescField(desc, 1, attr->value, int2ptr(lookup(value, attr->lookup)),
                                      sizeof(SQLSMALLINT));
                break;
            case type_LEN:
                ret = SQLSetDescField(desc, 1, attr->value, int2ptr(lookup(value, attr->lookup)),
                                      sizeof(SQLLEN));
                break;
            case type_CHARP:
                ret = SQLSetDescField(desc, 1, attr->value, (SQLPOINTER) value, SQL_NTS);
                break;
            }
            if (!SQL_SUCCEEDED(ret))
                fatal("Line %u: failure not expected setting ARD attribute\n", line_num);
            check_attr_p = check_attr_ard;
        }

        /* test attribute */
        if (strcmp(cmd, "attr") == 0) {
            const struct attribute *attr = lookup_attr(strtok(NULL, SEP));
            char *expected = strtok(NULL, SEP);

            if (!expected)
                fatal("Line %u: value not defined\n", line_num);

            check_attr_p(attr, expected);
        }
    }

    fclose(f);
    odbc_disconnect();

    printf("Done.\n");
    return g_result;
}
Beispiel #20
0
//
// dump descriptors
//
void dumpDescriptors (SQLCHAR *comment,         // display heading/comment
                      SQLHSTMT hstmt,           // statement handle
                      USHORT header,            // display header record
                      USHORT records,           // display col/parm records
                      int incBookmarkRec) {     // include bookmark record

    SQLRETURN retcode;
    SQLHDESC  hArd, hIrd, hApd, hIpd;           // descriptors

    // Get ARD
    retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, &hArd, 0, NULL);
    CHECK_ERROR(retcode, "SQLGetStmtAttr(SQL_HANDLE_STMT)",
                hstmt, SQL_HANDLE_STMT);

    // Get IRD
    retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_ROW_DESC, &hIrd, 0, NULL);
    CHECK_ERROR(retcode, "SQLExecDirect(SQL_HANDLE_STMT)",
                hstmt, SQL_HANDLE_STMT);

    // Get APD
    retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_DESC, &hApd, 0, NULL);
    CHECK_ERROR(retcode, "SQLExecDirect(SQL_HANDLE_STMT)",
                hstmt, SQL_HANDLE_STMT);

    // Get IPD
    retcode = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_DESC, &hIpd, 0, NULL);
    CHECK_ERROR(retcode, "SQLExecDirect(SQL_HANDLE_STMT)",
                hstmt, SQL_HANDLE_STMT);

    printf ("\n---\n%s\n---\n", comment);
    dumpDescriptorRec ("ARD", hArd, incBookmarkRec);
    if (header=='Y') {
        dumpDescriptorHeaderFields (hArd);
    }
    if (records=='Y') {
        dumpDescriptorRecordFields (hArd, incBookmarkRec);
    }

    dumpDescriptorRec ("IRD", hIrd, incBookmarkRec);
    if (header=='Y') {
        dumpDescriptorHeaderFields (hIrd);
    }
    if (records='Y') {
        dumpDescriptorRecordFields (hIrd, incBookmarkRec);
    }

    dumpDescriptorRec ("APD", hApd, incBookmarkRec);
    if (header=='Y') {
        dumpDescriptorHeaderFields (hApd);
    }
    if (records='Y') {
        dumpDescriptorRecordFields (hApd, incBookmarkRec);
    }

    dumpDescriptorRec ("IPD", hIpd, incBookmarkRec);
    if (header=='Y') {
        dumpDescriptorHeaderFields (hIpd);
    }
    if (records='Y') {
        dumpDescriptorRecordFields (hIpd, incBookmarkRec);
    }

exit:

    return;
}