void classSpecialColumns::LoadColumns() { CursorScoper s(listView()) ; SQLRETURN nReturn ; SQLCHAR szColumnName[MAX_COLUMN_WIDTH]; SQLCHAR szColumnType[MAX_COLUMN_WIDTH]; SQLCHAR szColumnSize[MAX_COLUMN_WIDTH]; SQLCHAR szRemarks [MAX_COLUMN_WIDTH]; QString qsDesc ; classColumn *pColumn = NULL ; // CREATE A STATEMENT StatementScoper stmt( hDbc ) ; if ( !stmt() ) return ; // EXECUTE OUR SQL/CALL if (!SQL_SUCCEEDED(nReturn=SQLSpecialColumns( stmt(), SQL_BEST_ROWID, 0, 0, (SQLCHAR*)qsLibrary.data(), SQL_NTS, (SQLCHAR*)qsTable.data(), SQL_NTS, SQL_SCOPE_SESSION, SQL_NULLABLE ) ) ) return my_msgBox( "classSpecialColumns", "SQLSpecialColumns", nReturn, NULL, NULL, stmt() ) ; // GET RESULTS while (SQL_SUCCEEDED(SQLFetch( stmt() ) ) ) { if (!SQL_SUCCEEDED(SQLGetData( stmt(), 2, SQL_C_CHAR, &szColumnName[0], sizeof(szColumnName), 0 ) ) ) strcpy( (char *)szColumnName, "Unknown" ); if (!SQL_SUCCEEDED(SQLGetData( stmt(), 4, SQL_C_CHAR, &szColumnType[0], sizeof(szColumnType), 0 ) ) ) strcpy( (char *)szColumnType, "Unknown" ); if (!SQL_SUCCEEDED(SQLGetData( stmt(), 5, SQL_C_CHAR, &szColumnSize[0], sizeof(szColumnSize), 0 ) ) ) strcpy( (char *)szColumnSize, "Unknown" ); qsDesc.sprintf("Len=%s", QString((char*)szColumnSize).stripWhiteSpace().data() ) ; listColumns.append( pColumn = new classColumn( this, pColumn, pCanvas, hDbc, QString((char*)szColumnName).stripWhiteSpace(), QString((char*)szColumnType).stripWhiteSpace(), qsDesc ) ) ; } }
/************************************************************************ * name: SQLSpecialColumnsW * arguments: * returns/side-effects: * description: * NOTE: ************************************************************************/ ODBC_INTERFACE RETCODE SQL_API SQLSpecialColumnsW (SQLHSTMT hstmt, SQLUSMALLINT type, SQLWCHAR *catalog, SQLSMALLINT catalog_len, SQLWCHAR *schema, SQLSMALLINT schema_len, SQLWCHAR *table, SQLSMALLINT table_len, SQLUSMALLINT scope, SQLUSMALLINT nullable) { RETCODE ret = ODBC_ERROR; SQLCHAR *cb_catalog = NULL, *cb_schema = NULL, *cb_table = NULL; int cb_catalog_len = 0, cb_schema_len = 0, cb_table_len = 0; OutputDebugString ("SQLSpecialColumnsW called.\n"); wide_char_to_bytes (catalog, catalog_len, &cb_catalog, &cb_catalog_len, NULL); wide_char_to_bytes (schema, schema_len, &cb_schema, &cb_schema_len, NULL); wide_char_to_bytes (table, table_len, &cb_table, &cb_table_len, NULL); ret = SQLSpecialColumns(hstmt, type, cb_catalog, cb_catalog_len, cb_schema, cb_schema_len, cb_table, cb_table_len, scope, nullable); UT_FREE(cb_catalog); UT_FREE(cb_schema); UT_FREE(cb_table); return ret; }
NS_IMETHODIMP mozSqlConnectionODBC::GetPrimaryKeys(const nsAString& aSchema, const nsAString& aTable, mozISqlResult** _retval) { //SQLPrimaryKeys isn't implemented in most drivers SQLHSTMT hstmt; SQLAllocHandle(SQL_HANDLE_STMT, mConnection, &hstmt); if(!SQL_SUCCEEDED(SQLSpecialColumns(hstmt, SQL_BEST_ROWID, NULL, 0, (SQLCHAR*) NULL, SQL_NTS, (SQLCHAR*) NS_LossyConvertUTF16toASCII(aTable).get(), SQL_NTS, 0, 0))){ SetError(hstmt, SQL_HANDLE_STMT); return NS_ERROR_FAILURE; } nsAutoString select; PRInt32 i = 0; select.AssignLiteral(""); while (SQL_SUCCEEDED(SQLFetch(hstmt))) { i++; if(i > 1) select.AppendLiteral(" UNION "); select.AppendLiteral("select NULL as TABLE_SCHEM, '"); select.Append(aTable); select.AppendLiteral("' as TABLE_NAME, '"); SQLCHAR colname[512]; SQLGetData(hstmt, 2, SQL_C_CHAR, colname, sizeof(colname), NULL); select.AppendASCII((char*)colname); select.AppendLiteral("' as COLUMN_NAME, "); char str[16]; sprintf(str, "%d", i); select.AppendLiteral(str); select.AppendLiteral(" as KEY_SEQ, NULL as PK_NAME"); } if(select.IsEmpty()) { select.AppendLiteral("SELECT * FROM "); select.Append(aTable); select.AppendLiteral(" WHERE 1 = 2"); } select.AppendLiteral(";"); return RealExec(select, _retval, nsnull); }
void classSpecialColumns::LoadColumns() { SQLHSTMT hstmt; SQLRETURN nReturn = -1; SQLCHAR szTableName[101] = ""; SQLCHAR szColumnName[101] = ""; QString qsError; // CREATE A STATEMENT nReturn = SQLAllocStmt( hDbc, &hstmt ); if ( nReturn != SQL_SUCCESS ) { QMessageBox::warning( pCanvas, "Data Manager", "Failed to SQLAllocStmt" ); return; } // EXECUTE OUR SQL/CALL strcpy( (char *)szTableName, qsTable.data() ); if ( SQL_SUCCESS != (nReturn=SQLSpecialColumns( hstmt, SQL_BEST_ROWID, 0, 0, 0, 0, szTableName, SQL_NTS, SQL_SCOPE_SESSION, SQL_NULLABLE )) ) { QMessageBox::warning( pCanvas, "Data Manager", "Failed to SQLSpecialColumns" ); return; } // GET RESULTS nReturn = SQLFetch( hstmt ); while ( nReturn == SQL_SUCCESS || nReturn == SQL_SUCCESS_WITH_INFO ) { nReturn = SQLGetData( hstmt, 2, SQL_C_CHAR, &szColumnName[0], sizeof(szColumnName), 0 ); if ( nReturn != SQL_SUCCESS ) strcpy( (char *)szColumnName, "Unknown" ); listColumns.append( new classColumn( this, pCanvas, hDbc, (char *)szColumnName ) ); nReturn = SQLFetch( hstmt ); } // FREE STATEMENT nReturn = SQLFreeStmt( hstmt, SQL_DROP ); if ( nReturn != SQL_SUCCESS ) QMessageBox::warning( pCanvas, "Data Manager", "Failed to SQLFreeStmt" ); }
SQLRETURN SQL_API SQLSpecialColumnsA(SQLHSTMT StatementHandle, SQLUSMALLINT IdentifierType, SQLCHAR *CatalogName, SQLSMALLINT NameLength1, SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName, SQLSMALLINT NameLength3, SQLUSMALLINT Scope, SQLUSMALLINT Nullable) { return SQLSpecialColumns(StatementHandle, IdentifierType, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, Scope, Nullable); }
SQLRETURN SQLSpecialColumnsA( SQLHSTMT statement_handle, SQLUSMALLINT identifier_type, SQLCHAR *catalog_name, SQLSMALLINT name_length1, SQLCHAR *schema_name, SQLSMALLINT name_length2, SQLCHAR *table_name, SQLSMALLINT name_length3, SQLUSMALLINT scope, SQLUSMALLINT nullable ) { return SQLSpecialColumns( statement_handle, identifier_type, catalog_name, name_length1, schema_name, name_length2, table_name, name_length3, scope, nullable ); }
static int odbc_dispatch15(void) { unsigned long retval; PWord rval; int rtype; PWord arg1; int type1; PWord arg2; int type2; PWord arg3; int type3; PWord arg4; int type4; PWord arg5; int type5; PWord arg6; int type6; PWord arg7; int type7; PWord arg8; int type8; PWord arg9; int type9; PWord arg10; int type10; PWord arg11; int type11; PWord arg12; int type12; 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_SYM) arg4 = (unsigned long) PI_getsymname(0,arg4,0); else 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_SYM) arg6 = (unsigned long) PI_getsymname(0,arg6,0); else if (!CI_get_integer((unsigned long *)&arg6,type6)) PI_FAIL; PI_getan(&arg7,&type7,7); if (type7 != PI_INT) if (!CI_get_integer((unsigned long *)&arg7,type7)) PI_FAIL; PI_getan(&arg8,&type8,8); if (type8 == PI_SYM) arg8 = (unsigned long) PI_getsymname(0,arg8,0); else if (!CI_get_integer((unsigned long *)&arg8,type8)) PI_FAIL; PI_getan(&arg9,&type9,9); if (type9 != PI_INT) if (!CI_get_integer((unsigned long *)&arg9,type9)) PI_FAIL; PI_getan(&arg10,&type10,10); if (type10 != PI_INT) if (!CI_get_integer((unsigned long *)&arg10,type10)) PI_FAIL; PI_getan(&arg11,&type11,11); if (type11 != PI_INT) if (!CI_get_integer((unsigned long *)&arg11,type11)) PI_FAIL; PI_getan(&arg12,&type12,12); switch(arg1) { case 0: retval = (unsigned long) SQLSpecialColumns(((SQLHSTMT ) arg2),((SQLUSMALLINT ) arg3),((SQLCHAR * ) arg4),((SQLSMALLINT ) arg5),((SQLCHAR * ) arg6),((SQLSMALLINT ) arg7),((SQLCHAR * ) arg8),((SQLSMALLINT ) arg9),((SQLUSMALLINT ) arg10),((SQLUSMALLINT ) arg11)); break; default: PI_FAIL; } PI_makedouble(&rval,&rtype,(double) retval); if (PI_unify(arg12,type12,rval,rtype)) PI_SUCCEED; PI_FAIL; }
int main(int argc, char **argv) { int rc; HSTMT hstmt = SQL_NULL_HSTMT; /* Cases where output is limited to relevant information only */ SQLSMALLINT sql_tab_privileges_ids[6] = {1, 2, 3, 4, 6, 7}; SQLSMALLINT sql_column_ids[6] = {1, 2, 3, 4, 5, 6}; test_connect(); rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt); if (!SQL_SUCCEEDED(rc)) { print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); exit(1); } /* Check for SQLGetTypeInfo */ printf("Check for SQLTypeInfo\n"); rc = SQLGetTypeInfo(hstmt, SQL_VARCHAR); CHECK_STMT_RESULT(rc, "SQLGetTypeInfo failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLTables */ printf("Check for SQLTables\n"); rc = SQLTables(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "%", SQL_NTS, (SQLCHAR *) "TABLE", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLTables failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLColumns */ printf("Check for SQLColumns\n"); rc = SQLColumns(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "%", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLColumns failed", hstmt); print_result_meta(hstmt); /* * Print only the 6 first columns, we do not want for example * to get the OID in output, and this information looks to be * enough. */ print_result_series(hstmt, sql_column_ids, 6); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLColumnPrivileges */ //printf("Check for SQLColumnPrivileges\n"); //rc = SQLColumnPrivileges(hstmt, // NULL, 0, // (SQLCHAR *) "public", SQL_NTS, // (SQLCHAR *) "testtab1", SQL_NTS, // (SQLCHAR *) "id", SQL_NTS); //CHECK_STMT_RESULT(rc, "SQLColumnPrivileges failed", hstmt); //print_result_meta(hstmt); //print_result(hstmt); //rc = SQLFreeStmt(hstmt, SQL_CLOSE); //CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLSpecialColumns */ printf("Check for SQLSpecialColumns\n"); rc = SQLSpecialColumns(hstmt, SQL_ROWVER, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "testtab1", SQL_NTS, SQL_SCOPE_SESSION, SQL_NO_NULLS); CHECK_STMT_RESULT(rc, "SQLSpecialColumns failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* * Check for SQLStatistics. It is important to note that this function * returns statistics like the number of pages used and the number of * index scans. */ printf("Check for SQLStatistics\n"); rc = SQLStatistics(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "testtab1", SQL_NTS, 0, 0); CHECK_STMT_RESULT(rc, "SQLStatistics failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLPrimaryKeys */ printf("Check for SQLPrimaryKeys\n"); rc = SQLPrimaryKeys(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "testtab1", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrimaryKeys failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLForeignKeys */ printf("Check for SQLForeignKeys\n"); rc = SQLForeignKeys(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "testtab1", SQL_NTS, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "testtab_fk", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLForeignKeys failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLProcedures */ printf("Check for SQLProcedures\n"); rc = SQLProcedures(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "simple_add", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLProcedures failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLProcedureColumns */ printf("Check for SQLProcedureColumns\n"); rc = SQLProcedureColumns(hstmt, NULL, 0, (SQLCHAR *) "public", SQL_NTS, (SQLCHAR *) "simple_add", SQL_NTS, NULL, 0); CHECK_STMT_RESULT(rc, "SQLProcedureColumns failed", hstmt); print_result_meta(hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Check for SQLTablePrivileges */ printf("Check for SQLTablePrivileges\n"); rc = SQLTablePrivileges(hstmt, NULL, 0, (SQLCHAR *) "public", 0, (SQLCHAR *) "testtab1", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLTablePrivileges failed", hstmt); print_result_meta(hstmt); print_result_series(hstmt, sql_tab_privileges_ids, 6); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* * Extra tests. * Older versions of the driver had a bug in handling table-types lists * longer than 32 entries. Check for that. */ rc = SQLTables(hstmt, "", SQL_NTS, "public", SQL_NTS, "testtab%", SQL_NTS, "1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5, TABLES", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLTables failed", hstmt); print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Clean up */ test_disconnect(); return 0; }
PassFail TestSQLSpecialColumns(TestInfo *pTestInfo, int MX_MP_SPECIFIC) { TEST_DECLARE; TCHAR Heading[MAX_HEADING_SIZE]; RETCODE returncode; SQLHANDLE henv; SQLHANDLE hdbc; SQLHANDLE hstmt; TCHAR TQualifier[NAME_LEN],TOwner[NAME_LEN],TName[NAME_LEN]; UWORD fColType[NUM_COLTYPE] = {SQL_BEST_ROWID,SQL_ROWVER}; UWORD Scope[NUM_SCOPE] = {SQL_SCOPE_CURROW,SQL_SCOPE_TRANSACTION,SQL_SCOPE_SESSION}; UWORD Nullable[NUM_NULL] = {SQL_NO_NULLS,SQL_NULLABLE}; TCHAR ocname[MAX_COLUMN_NAME],octype[MAX_COLUMN_NAME]; SWORD oscope,ocdatatype,ocsca,ocpc; SDWORD ocprec,oclen; SQLLEN oscopelen,ocnamelen,ocdatatypelen,octypelen,ocpreclen,oclenlen,ocscalen,ocpclen; struct { TCHAR *ColName; SWORD ColDataType; TCHAR *ColTypeName; TCHAR *ColTypeOutput; TCHAR *ColTypeLen; SDWORD ColPrec; SWORD ColSca; SDWORD ColLen; } Columns[] = { {_T("--"),SQL_CHAR,_T("char"),_T("CHAR"),_T("(10) CHARACTER SET ISO88591"),10,0,10}, {_T("--"),SQL_VARCHAR,_T("varchar"),_T("VARCHAR"),_T("(10) CHARACTER SET ISO88591"),10,0,10}, {_T("--"),SQL_VARCHAR,_T("varchar"),_T("VARCHAR"),_T("(255) CHARACTER SET ISO88591"),255,0,255}, {_T("--"),SQL_WCHAR,_T("char"),_T("NCHAR"),_T("(10) CHARACTER SET UCS2"),10,0,20}, {_T("--"),SQL_WVARCHAR,_T("varchar"),_T("NCHAR VARYING"),_T("(10) CHARACTER SET UCS2"),10,0,20}, {_T("--"),SQL_WVARCHAR,_T("varchar"),_T("NCHAR VARYING"),_T("(255) CHARACTER SET UCS2"),255,0,510}, {_T("--"),SQL_DECIMAL,_T("decimal"),_T("DECIMAL SIGNED"),_T("(10,5)"),10,5,12}, {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC SIGNED"),_T("(10,5)"),10,5,12}, {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC SIGNED"),_T("(19,0)"),19,0,21}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC SIGNED"),_T("(19,6)"),19,6,21}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC SIGNED"),_T("(128,0)"),128,0,130}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC SIGNED"),_T("(128,128)"),128,128,130}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC SIGNED"),_T("(128,64)"),128,64,130}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC UNSIGNED"),_T("(10,5) unsigned"),10,5,12}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC UNSIGNED"),_T("(18,5) unsigned"),18,5,20}, //Bignum {_T("--"),SQL_NUMERIC,_T("numeric"),_T("NUMERIC UNSIGNED"),_T("(30,10) unsigned"),30,10,32}, //Bignum {_T("--"),SQL_SMALLINT,_T("smallint"),_T("SMALLINT SIGNED"),_T(""),5,0,2}, {_T("--"),SQL_INTEGER,_T("integer"),_T("INTEGER SIGNED"),_T(""),10,0,4}, {_T("--"),SQL_BIGINT,_T("bigint"),_T("BIGINT SIGNED"),_T(""),19,0,20}, {_T("--"),SQL_DATE,_T("date"),_T("DATE"),_T(""),10,0,6}, {_T("--"),SQL_TIME,_T("time"),_T("TIME"),_T(""),8,0,6}, {_T("--"),SQL_TIMESTAMP,_T("TIMESTAMP"),_T("timestamp"),_T(""),26,6,16}, {_T("--"),SQL_BIT,_T("bit"),_T("BIT"),_T(""),1,1,0}, {_T("--"),SQL_TINYINT,_T("tinyint"),_T("TINYINT"),_T(""),3,0,2}, {_T("--"),SQL_BINARY,_T("binary"),_T("BINARY"),_T("(10)"),10,0,10}, {_T("--"),SQL_VARBINARY,_T("varbinary"),_T("VARBINARY"),_T("(10)"),10,0,10}, {_T("--"),SQL_WCHAR,_T("char"),_T("NCHAR"),_T("(10) CHARACTER SET UTF8"),10,0,20}, {_T("--"),SQL_WVARCHAR,_T("varchar"),_T("NCHAR VARYING"),_T("(10) CHARACTER SET UTF8"),10,0,20}, {_T("--"),SQL_WVARCHAR,_T("varchar"),_T("NCHAR VARYING"),_T("(255) CHARACTER SET UTF8"),255,0,510}, {_T("--"),0,_T("endloop"),_T(""),0,0,0,0} }; TCHAR *TableStr[4]; TCHAR ColStr[MAX_NOS_SIZE], KeyStr[MAX_NOS_SIZE], CreateTbl[MAX_NOS_SIZE],END_LOOP[10]; int i = 0, k = 0,ct = 0, s = 0, t = 0, n = 0, psc = 1; BOOL found = FALSE; //TCHAR *charNameUCS2 = _T("NCHAR"); //TCHAR *varcharNameUCS2 = _T("NCHAR VARYING"); //=========================================================================================================== var_list_t *var_list; var_list = load_api_vars(_T("SQLSpecialColumns"), charset_file); if (var_list == NULL) return FAILED; //print_list(var_list); Columns[0].ColName = var_mapping(_T("SQLSpecialColumns_Columns_1"), var_list); Columns[1].ColName = var_mapping(_T("SQLSpecialColumns_Columns_2"), var_list); Columns[2].ColName = var_mapping(_T("SQLSpecialColumns_Columns_3"), var_list); Columns[3].ColName = var_mapping(_T("SQLSpecialColumns_Columns_4"), var_list); Columns[4].ColName = var_mapping(_T("SQLSpecialColumns_Columns_5"), var_list); Columns[5].ColName = var_mapping(_T("SQLSpecialColumns_Columns_6"), var_list); Columns[6].ColName = var_mapping(_T("SQLSpecialColumns_Columns_7"), var_list); Columns[7].ColName = var_mapping(_T("SQLSpecialColumns_Columns_8"), var_list); Columns[8].ColName = var_mapping(_T("SQLSpecialColumns_Columns_9"), var_list); Columns[9].ColName = var_mapping(_T("SQLSpecialColumns_Columns_10"), var_list); Columns[10].ColName = var_mapping(_T("SQLSpecialColumns_Columns_11"), var_list); Columns[11].ColName = var_mapping(_T("SQLSpecialColumns_Columns_12"), var_list); Columns[12].ColName = var_mapping(_T("SQLSpecialColumns_Columns_13"), var_list); Columns[13].ColName = var_mapping(_T("SQLSpecialColumns_Columns_14"), var_list); Columns[14].ColName = var_mapping(_T("SQLSpecialColumns_Columns_15"), var_list); Columns[15].ColName = var_mapping(_T("SQLSpecialColumns_Columns_16"), var_list); Columns[16].ColName = var_mapping(_T("SQLSpecialColumns_Columns_17"), var_list); Columns[17].ColName = var_mapping(_T("SQLSpecialColumns_Columns_18"), var_list); Columns[18].ColName = var_mapping(_T("SQLSpecialColumns_Columns_19"), var_list); Columns[19].ColName = var_mapping(_T("SQLSpecialColumns_Columns_20"), var_list); Columns[20].ColName = var_mapping(_T("SQLSpecialColumns_Columns_21"), var_list); Columns[21].ColName = var_mapping(_T("SQLSpecialColumns_Columns_22"), var_list); Columns[22].ColName = var_mapping(_T("SQLSpecialColumns_Columns_23"), var_list); Columns[23].ColName = var_mapping(_T("SQLSpecialColumns_Columns_24"), var_list); Columns[24].ColName = var_mapping(_T("SQLSpecialColumns_Columns_25"), var_list); Columns[25].ColName = var_mapping(_T("SQLSpecialColumns_Columns_26"), var_list); Columns[26].ColName = var_mapping(_T("SQLSpecialColumns_Columns_27"), var_list); Columns[27].ColName = var_mapping(_T("SQLSpecialColumns_Columns_28"), var_list); Columns[28].ColName = var_mapping(_T("SQLSpecialColumns_Columns_29"), var_list); TableStr[0] = var_mapping(_T("SQLSpecialColumns_TableStr_1"), var_list); TableStr[1] = var_mapping(_T("SQLSpecialColumns_TableStr_2"), var_list); TableStr[2] = var_mapping(_T("SQLSpecialColumns_TableStr_3"), var_list); TableStr[3] = var_mapping(_T("SQLSpecialColumns_TableStr_4"), var_list); //========================================================================================= //if(isUCS2) { // LogMsg(NONE,_T("Setup for UCS2 mode testing: ColPrec has to be doubled\n")); // i = 0; // while(_tcsicmp(Columns[i].ColTypeName,_T("endloop")) != 0) { // if (Columns[i].ColDataType == SQL_WCHAR){ // Columns[i].ColDataType = SQL_WCHAR; // Columns[i].ColTypeOutput = charNameUCS2; // //Columns[i].ColPrec *= 2; --> This is in character, no need to double // Columns[i].ColLen *= 2; // } // else if (Columns[i].ColDataType == SQL_WVARCHAR) { // Columns[i].ColDataType = SQL_WVARCHAR; // Columns[i].ColTypeOutput = varcharNameUCS2; // //Columns[i].ColPrec *= 2; --> This is in character, no need to double // Columns[i].ColLen *= 2; // } // else if (Columns[i].ColDataType == SQL_WLONGVARCHAR) { // Columns[i].ColDataType = SQL_WLONGVARCHAR; // Columns[i].ColTypeOutput = varcharNameUCS2; // //Columns[i].ColPrec *= 2; --> This is in character, no need to double // Columns[i].ColLen *= 2; // } // i++; // } // i = 0; //} //========================================================================================= if (MX_MP_SPECIFIC == MX_SPECIFIC) LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => MX Specific SQLSpecialColumns.\n")); else LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => MP Specific SQLSpecialColumns.\n")); TEST_INIT; TESTCASE_BEGIN("Setup for SQLSpecialColumns tests\n"); if(!FullConnect(pTestInfo)){ LogMsg(NONE,_T("Unable to connect\n")); TEST_FAILED; TEST_RETURN; } henv = pTestInfo->henv; hdbc = pTestInfo->hdbc; hstmt = (SQLHANDLE)pTestInfo->hstmt; returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")){ LogAllErrors(henv,hdbc,hstmt); TEST_FAILED; TEST_RETURN; } TESTCASE_END; _tcscpy(ColStr,_T("")); _tcscpy(KeyStr,_T("")); _tcscpy(END_LOOP,_T("")); _tcscpy(TName,TableStr[2]); if (MX_MP_SPECIFIC == MX_SPECIFIC) { _tcscpy(TQualifier,pTestInfo->Catalog); _tcscpy(TOwner,pTestInfo->Schema); _tcscpy(END_LOOP,_T("bit")); } else { _tcscpy(TQualifier,_T("")); _tcscpy(TOwner,pTestInfo->UserID); _tcscpy(END_LOOP,_T("endloop")); } while (_tcsicmp(Columns[i].ColTypeName,END_LOOP) != 0) { SQLExecDirect(hstmt,(SQLTCHAR*) (SQLTCHAR *)TableStr[1],SQL_NTS); // cleanup if (i > 0) { _tcscat(ColStr,_T(",")); _tcscat(KeyStr,_T(",")); } _tcscat(ColStr,Columns[i].ColName); _tcscat(ColStr,_T(" ")); _tcscat(ColStr,Columns[i].ColTypeName); _tcscat(ColStr,Columns[i].ColTypeLen); _tcscat(ColStr,_T(" not null")); _tcscat(KeyStr,Columns[i].ColName); _tcscpy(CreateTbl,_T("")); _tcscat(CreateTbl,TableStr[0]); _tcscat(CreateTbl,_T("(")); _tcscat(CreateTbl,ColStr); _tcscat(CreateTbl,_T(", primary key(")); _tcscat(CreateTbl,KeyStr); _tcscat(CreateTbl,_T("))")); _stprintf(Heading,_T("Test Positive Functionality of SQLSpecialColumns for this table:\n")); _tcscat(Heading,CreateTbl); _tcscat(Heading,_T("\n")); TESTCASE_BEGINW(Heading); returncode = SQLExecDirect(hstmt,(SQLTCHAR*)CreateTbl,SQL_NTS); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){ TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else{ if (_tcslen(TQualifier) > 0) returncode = SQLSpecialColumns(hstmt,fColType[ct],(SQLTCHAR*)TQualifier,(SWORD)_tcslen(TQualifier),(SQLTCHAR*)TOwner,(SWORD)_tcslen(TOwner),(SQLTCHAR*)TName,(SWORD)_tcslen(TName),Scope[s],Nullable[n]); else returncode = SQLSpecialColumns(hstmt,fColType[ct],NULL,0,(SQLTCHAR*)TOwner,(SWORD)_tcslen(TOwner),(SQLTCHAR*)TName,(SWORD)_tcslen(TName),Scope[s],Nullable[n]); if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSpecialColumns")){ TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else{ oscope = 0; _tcscpy(ocname,_T("")); ocdatatype = 0; _tcscpy(octype,_T("")); ocprec = 0; oclen = 0; ocsca = 0; ocpc = 0; SQLBindCol(hstmt,1,SQL_C_SHORT,&oscope,0,&oscopelen); SQLBindCol(hstmt,2,SQL_C_TCHAR,ocname,MAX_COLUMN_NAME,&ocnamelen); SQLBindCol(hstmt,3,SQL_C_SHORT,&ocdatatype,0,&ocdatatypelen); SQLBindCol(hstmt,4,SQL_C_TCHAR,octype,MAX_COLUMN_NAME,&octypelen); SQLBindCol(hstmt,5,SQL_C_LONG,&ocprec,0,&ocpreclen); SQLBindCol(hstmt,6,SQL_C_LONG,&oclen,0,&oclenlen); SQLBindCol(hstmt,7,SQL_C_SHORT,&ocsca,0,&ocscalen); SQLBindCol(hstmt,8,SQL_C_SHORT,&ocpc,0,&ocpclen); k = 0; while (returncode == SQL_SUCCESS){ returncode = SQLFetch(hstmt); if((returncode!=SQL_NO_DATA_FOUND) &&(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))){ TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } else{ if (returncode == SQL_SUCCESS){ if (MX_MP_SPECIFIC == MX_SPECIFIC) { psc = SQL_PC_NOT_PSEUDO; } else { psc = 1; } LogMsg(NONE,_T("Comparing results for SQLSpecialColumns\n")); t = 0; found = FALSE; while(_tcscmp(Columns[t].ColTypeName,_T("endloop"))!=0) { if(cwcscmp(ocname, Columns[t].ColName,TRUE) == 0) { if ((oscope == Scope[s]) && (ocdatatype == Columns[t].ColDataType) && (_tcsicmp(octype,Columns[t].ColTypeOutput) == 0) && (ocprec == Columns[t].ColPrec) && (oclen == Columns[t].ColLen) && (ocsca == Columns[t].ColSca) && (ocpc == (SWORD)psc)){ /* LogMsg(NONE,_T("Scope expect: %d and actual: %d are matched\n"),Scope[s],oscope); LogMsg(NONE,_T("colname expect: %s and actual: %s are matched\n"),Columns[t].ColName,ocname); LogMsg(NONE,_T("ColDataType expect: %d and actual: %d are matched\n"),Columns[t].ColDataType,ocdatatype); LogMsg(NONE,_T("ColTypeOutput expect: %s and actual: %s are matched\n"),Columns[t].ColTypeOutput,octype); LogMsg(NONE,_T("ColPrec expect: %d and actual: %d are matched\n"),Columns[t].ColPrec,ocprec); LogMsg(NONE,_T("ColLen expect: %d and actual: %d are matched\n"),Columns[t].ColLen,oclen); LogMsg(NONE,_T("ColScale expect: %d and actual: %d are matched\n"),Columns[t].ColSca,ocsca); LogMsg(NONE,_T("ColPseudoCol expect: %d and actual: %d are matched\n\n"),(SWORD)psc,ocpc); */ } else { TEST_FAILED; if (oscope != Scope[s]) LogMsg(ERRMSG,_T("Scope expect: %d and actual: %d are not matched\n"),Scope[t],oscope); if (ocdatatype != Columns[t].ColDataType) LogMsg(ERRMSG,_T("ColDataType expect: %d and actual: %d are not matched\n"),Columns[t].ColDataType,ocdatatype); if (_tcsicmp(octype,Columns[t].ColTypeOutput) != 0) LogMsg(ERRMSG,_T("ColTypeName expect: %s and actual: %s are not matched\n"),Columns[t].ColTypeOutput,octype); if (ocprec != Columns[t].ColPrec) LogMsg(ERRMSG,_T("ColPrec expect: %d and actual: %d are not matched\n"),Columns[t].ColPrec,ocprec); if (oclen != Columns[t].ColLen) LogMsg(ERRMSG,_T("ColLen expect: %d and actual: %d are not matched\n"),Columns[t].ColLen,oclen); if (ocsca != Columns[t].ColSca) LogMsg(ERRMSG,_T("ColScale expect: %d and actual: %d are not matched\n"),Columns[t].ColSca,ocsca); if (ocpc != (SWORD)psc) LogMsg(ERRMSG,_T("ColPseudoCol expect: %d and actual: %d are not matched\n\n"),(SWORD)psc,ocpc); } found = TRUE; break; } else { t++; } } if(!found) { TEST_FAILED; LogMsg(ERRMSG,_T("Unexpected returned data: %s\n"), ocname); } } } if (returncode == SQL_SUCCESS) k++; } // end while if(k == 0) { TEST_FAILED; LogMsg(ERRMSG,_T("No Data Found => Atleast one row should be fetched\n")); } } SQLFreeStmt(hstmt,SQL_UNBIND); SQLFreeStmt(hstmt,SQL_CLOSE); } SQLExecDirect(hstmt,(SQLTCHAR*) (SQLTCHAR *)TableStr[1],SQL_NTS); i++; TESTCASE_END; } // end while //======================================================================================================== _stprintf(Heading,_T("SQLSpecialColumns: Negative test with NULL handle\n")); TESTCASE_BEGINW(Heading); hstmt = (SQLHANDLE)NULL; _tcscpy(TQualifier,_T("")); _tcscpy(TOwner,pTestInfo->UserID); _tcscpy(TName,TableStr[3]); i = 0; returncode = SQLSpecialColumns(hstmt,fColType[i],(SQLTCHAR*)TQualifier,(SWORD)_tcslen(TQualifier),(SQLTCHAR*)TOwner,(SWORD)_tcslen(TOwner),(SQLTCHAR*)TName,(SWORD)_tcslen(TName),Scope[i],Nullable[i]); if(!CHECKRC(SQL_INVALID_HANDLE,returncode,"SQLSpecialColumns")) { TEST_FAILED; LogAllErrors(henv,hdbc,hstmt); } TESTCASE_END; //======================================================================================================== FullDisconnect(pTestInfo); LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLSpecialColumns.\n")); free_list(var_list); TEST_RETURN; }