//venu changed dialogueId and stmtId from int to long for 64 bit JNIEXPORT jint JNICALL Java_org_trafodion_jdbc_t2_SQLMXStatement_close (JNIEnv *jenv, jclass jclass, jstring server, jlong dialogueId, jlong stmtId, jboolean dropStmt) { FUNCTION_ENTRY("Java_org_trafodion_jdbc_t2_SQLMXStatement_close", ("... dialogueId=0x%08x, stmtId=%ld, dropStmt=%s", dialogueId, stmtId, DebugBoolStr(dropStmt))); ExceptionStruct exception_; long rowsAffected; ERROR_DESC_LIST_def sqlWarning; jint retcode = -1; // 0 - Success, -1 = failure // 1= Cursor Not Found ERROR_DESC_def *error_desc_def; odbc_SQLSvc_Close_sme_(NULL, NULL, &exception_, dialogueId, stmtId, (dropStmt ? SQL_DROP : SQL_CLOSE), &rowsAffected, &sqlWarning); // Ignore setting warning since the input is jclass and not jobject switch (exception_.exception_nr) { case CEE_SUCCESS: retcode = 0; break; case odbc_SQLSvc_Close_SQLError_exn_: error_desc_def =((ERROR_DESC_LIST_def *)(&exception_.u.SQLError.errorList))->_buffer; if (error_desc_def->sqlcode == -8811) // Close a non-existant cursor) retcode = 1; break; case odbc_SQLSvc_Close_ParamError_exn_: throwSQLException(jenv, PROGRAMMING_ERROR, exception_.u.ParamError.ParamDesc, "HY000"); break; case odbc_SQLSvc_Close_InvalidConnection_exn_: case odbc_SQLSvc_Close_TransactionError_exn_: default: // TFDS - This exceptions should not happen throwSQLException(jenv, PROGRAMMING_ERROR, NULL, "HY000", exception_.exception_nr); break; } FUNCTION_RETURN_NUMERIC(retcode,(NULL)); }
JNIEXPORT void JNICALL Java_org_trafodion_jdbc_t2_SQLMXResultSet_close (JNIEnv *jenv, jobject jobj, jstring server, jlong dialogueId, jint txid, jboolean autoCommit, jint txnMode, jlong stmtId, jboolean dropStmt) { FUNCTION_ENTRY("Java_org_trafodion_jdbc_t2_SQLMXResultSet_close",("server=%s, dialogueId=0x%08x, txid=0x%08x, autoCommit=%s, txnMode=%ld, stmtId=0x%08x, dropStmt=%s", DebugJString(jenv,server), dialogueId, txid, DebugBoolStr(autoCommit), txnMode, stmtId, DebugBoolStr(dropStmt))); jint currentTxid = txid; jint externalTxid = 0; jboolean selectStmt = FALSE; ExceptionStruct exception_; long rowsAffected; ERROR_DESC_LIST_def sqlWarning; short txn_status; ERROR_DESC_def *error_desc_def; // Don't bother resuming the transaction, if it is already zero. Try and close the cursor if (currentTxid != 0) { if ((txn_status = beginTxnControl(jenv, currentTxid, externalTxid, txnMode, CLOSE_CURSORS_AT_COMMIT)) != 0 ) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("beginTxnControl() failed")); } } odbc_SQLSvc_Close_sme_(NULL, NULL, &exception_, dialogueId, stmtId, (dropStmt ? SQL_DROP : SQL_CLOSE), &rowsAffected, &sqlWarning); if (currentTxid != 0) { if ((txn_status = endTxnControl(jenv, currentTxid, 0, autoCommit, 0, selectStmt, txnMode, externalTxid)) != 0) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("endTxnControl() failed")); } jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); } switch (exception_.exception_nr) { case CEE_SUCCESS: // Not updating rowsAffected, since it is not useful in JDBC if (sqlWarning._length != 0) setSQLWarning(jenv, jobj, &sqlWarning); selectStmt = FALSE; break; case odbc_SQLSvc_Close_SQLError_exn_: error_desc_def =((ERROR_DESC_LIST_def *)(&exception_.u.SQLError.errorList))->_buffer; if (error_desc_def->sqlcode == -8811) // Close a non-existant cursor and hence don't end // the transaction by treating it like Select stmt selectStmt = TRUE; // sql Error in case of close could be treated as SQLWarning setSQLWarning(jenv, jobj, &exception_.u.SQLError.errorList); break; case odbc_SQLSvc_Close_ParamError_exn_: throwSQLException(jenv, PROGRAMMING_ERROR, exception_.u.ParamError.ParamDesc, "HY000"); break; case odbc_SQLSvc_Close_InvalidConnection_exn_: case odbc_SQLSvc_Close_TransactionError_exn_: default: // TFDS - This exceptions should not happen throwSQLException(jenv, PROGRAMMING_ERROR, NULL, "HY000", exception_.exception_nr); break; } FUNCTION_RETURN_VOID((NULL)); }
/* * Synchronous method function prototype for * operation 'odbc_SQLSvc_GetSQLCatalogs' */ void odbc_SQLSvc_GetSQLCatalogs_sme_( /* In */ void * objtag_ , /* In */ const CEE_handle_def *call_id_ , /* Out */ ExceptionStruct *exception_ , /* In */ long dialogueId , /* In */ short APIType , /* In */ const char *catalogNm , /* In */ const char *schemaNm , /* In */ const char *tableNm , /* In */ const char *tableTypeList , /* In */ const char *columnNm , /* In */ long columnType , /* In */ long rowIdScope , /* In */ long nullable , /* In */ long uniqueness , /* In */ long accuracy , /* In */ short sqlType , /* In */ unsigned long metadataId , /* Out */ char *catStmtLabel , /* Out */ SQLItemDescList_def *outputDesc , /* Out */ ERROR_DESC_LIST_def *sqlWarning , /* Out */ long *rowsAffected , /* Out */ SQLValueList_def *outputValueList , /* Out */ long *stmtId , /* In */ const char *fkcatalogNm , /* In */ const char *fkschemaNm , /* In */ const char *fktableNm) { FUNCTION_ENTRY("odbc_SQLSvc_GetSQLCatalogs_sme_",("")); DEBUG_OUT(DEBUG_LEVEL_ENTRY,(" %#x, %#x, %#x, %#x, %d, %s, %s, %s, %s, %s, %ld, %ld, %ld, %ld, %ld, %d, %#x, %#x, %#x", objtag_, call_id_, exception_, dialogueId, APIType, catalogNm, schemaNm, tableNm, tableTypeList, columnNm, columnType, rowIdScope, nullable, uniqueness, accuracy, sqlType, catStmtLabel, outputDesc, sqlWarning)); SRVRTRACE_ENTER(FILE_SME+14); enum CATAPI_TABLE_INDEX { COLUMNS = 0, DEFAULTS, INDEXES, KEYS, OBJECTS, OBJECTUID, TABLES, VIEWS, VIEWS_USAGE, VERSIONS }; char *smdCatAPITablesList[] = { "COLUMNS", "DEFAULTS", "INDEXES", "KEYS", "OBJECTS", "OBJECTUID", "TABLES", "VIEWS", "VIEWS_USAGE", "VERSIONS" }; const char *inputParam[16]; const char *tableParam[20]; short retCode; char tmpBuf[20]; char *odbcAppVersion = "3"; char *translationId = "3"; ExceptionStruct prepareException; CLEAR_EXCEPTION(prepareException); ExceptionStruct executeException; CLEAR_EXCEPTION(executeException); ExceptionStruct fetchException; CLEAR_EXCEPTION(fetchException); ExceptionStruct closeException; CLEAR_EXCEPTION(closeException); char expCatalogNm[MAX_ANSI_NAME_LEN+1]; char expSchemaNm[MAX_ANSI_NAME_LEN+1]; char expTableNm[MAX_ANSI_NAME_LEN+1]; char expColumnNm[MAX_ANSI_NAME_LEN+1]; char expProcNm[MAX_ANSI_NAME_LEN+1]; char catalogNmNoEsc[MAX_ANSI_NAME_LEN+1]; char schemaNmNoEsc[MAX_ANSI_NAME_LEN+1]; char tableNmNoEsc[MAX_ANSI_NAME_LEN+1]; char columnNmNoEsc[MAX_ANSI_NAME_LEN+1]; char procNmNoEsc[MAX_ANSI_NAME_LEN+1]; char tableName1[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName2[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName3[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName4[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName5[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName6[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName7[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char tableName8[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char SQLObjType[2]; char inParam1[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char inParam2[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; char inParam3[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; // catalog len + '.' + schema len + '.' + table len +'\0' char inParam4[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; // catalog len + '.' + schema len + '.' + table len +'\0' char schemaVersion[10]; // Holds SQL schema version from SQL_SCHEMAVERSION_ANSI_Q1 module call char fkstmtLabel[MAX_STMT_LABEL_LEN+1]; // Used for FK methods long rowsMPFetched; // # of tables to check for MP metadata long rowsFKFetched; // # of rows fetched from foreign keys method query 1 BOOL queryMP = FALSE; // Flag whether to pull MP metadata SQLValueList_def tempOutputValueList; // Intermediate and temp output value lists // Null out tempOutputValueList CLEAR_LIST(tempOutputValueList); long curRowNo = 0; long numOfCols = 0; long curColNo = 0; char schemaNmAct[MAX_ANSI_NAME_LEN+1]; char tableNmAct[MAX_ANSI_NAME_LEN+1]; char colNmAct[MAX_ANSI_NAME_LEN+1]; char ordinalAct[10]; char obuidAct[MAX_ANSI_NAME_LEN+1]; char riuidAct[MAX_ANSI_NAME_LEN+1]; short sqlStmtType; SQLItemDescList_def lc_outputDesc; BOOL tableViewGiven = FALSE; BOOL systemTableGiven = FALSE; short namelen; SQLValue_def *SQLValue; char userCatalogNm[MAX_ANSI_NAME_LEN+1]; char guardianNm[36]; // 8+1+8+1+8+1+8+1 char inParam[MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+MAX_ANSI_NAME_LEN+3]; // catalog len + '.' + schema len + '.' + table len +'\0' char MapDataType[2] = "0"; tmpBuf[0] = '\0'; fkstmtLabel[0] = '\0'; userCatalogNm[0] = '\0'; char catStmtLabelNew[128] = {'\0'}; // Trying to support max module name length inputParam[0] = srvrGlobal->SystemCatalog; if (catalogNm == NULL) strcpy(catalogNmNoEsc,""); //strcpy(catalogNmNoEsc,srvrGlobal->DefaultCatalog); // There is an OR condition with the catalog so it can be "" else strcpy(catalogNmNoEsc, catalogNm); inputParam[1] = catalogNmNoEsc; if (schemaNm == NULL ) strcpy(schemaNmNoEsc,"%"); else strcpy(schemaNmNoEsc, schemaNm); if (schemaNm != NULL ) { convertWildcardNoEsc(metadataId, FALSE, schemaNm, schemaNmNoEsc); convertWildcard(metadataId, TRUE, schemaNm, expSchemaNm); } inputParam[2] = schemaNmNoEsc; inputParam[3] = expSchemaNm; inputParam[4] = NULL; sqlStmtType = TYPE_SELECT; DEBUG_OUT(DEBUG_LEVEL_METADATA,("SQL_SCHEMAVERSION_NEW_ANSI_Q1 tableParams= |%s|%s| inputParams= |%s|", tableParam[0],tableParam[1], inputParam[0])); if (APIType != SQL_TXN_ISOLATION) { retCode = executeAndFetchSMDQuery(objtag_, call_id_, dialogueId, APIType, "SQL_CATALOG_API", sqlStmtType, &tableParam[0], &inputParam[0], catalogNm, schemaNm, tableNm, columnNm, tableTypeList, metadataId, outputDesc, &executeException, &fetchException, sqlWarning, rowsAffected, outputValueList, stmtId); if (retCode != CEE_SUCCESS && writeServerException(retCode,exception_,&prepareException,&executeException,&fetchException) != TRUE) { odbc_SQLSvc_Close_sme_(objtag_, call_id_, &closeException, dialogueId, *stmtId, SQL_DROP, rowsAffected, sqlWarning); FUNCTION_RETURN_VOID(("executeAndFetchSMDQuery() and writeServerException() Failed")); } if (retCode == FETCH_EXCEPTION && fetchException.exception_nr == odbc_SQLSvc_FetchN_SQLNoDataFound_exn_) { odbc_SQLSvc_Close_sme_(objtag_, call_id_, &closeException, dialogueId, *stmtId, SQL_DROP, rowsAffected, sqlWarning); FUNCTION_RETURN_VOID(("executeAndFetchSMDQuery() FETCH_EXCEPTION - SQLNoDataFound Expected")); } SQLValue = (SQLValue_def *)outputValueList->_buffer; if (SQLValue->dataInd == -1) //does not come here { inputParam[0] = srvrGlobal->SystemCatalog; inputParam[2] = "SYSTEM_SCHEMA"; memset(outputValueList, NULL, sizeof(SQLValueList_def)); retCode = executeAndFetchSMDQuery(objtag_, call_id_, dialogueId, APIType, "SQL_SCHEMAVERSION_NEW_ANSI_Q1", sqlStmtType, &tableParam[0], &inputParam[0], catalogNm, schemaNm, tableNm, columnNm, tableTypeList, metadataId, outputDesc, &executeException, &fetchException, sqlWarning, rowsAffected, outputValueList, stmtId); if (retCode != CEE_SUCCESS && writeServerException(retCode,exception_,&prepareException,&executeException,&fetchException) != TRUE) { odbc_SQLSvc_Close_sme_(objtag_, call_id_, &closeException, dialogueId, *stmtId, SQL_DROP, rowsAffected, sqlWarning); FUNCTION_RETURN_VOID(("executeAndFetchSMDQuery() and writeServerException() Failed")); } if (retCode == FETCH_EXCEPTION && fetchException.exception_nr == odbc_SQLSvc_FetchN_SQLNoDataFound_exn_) { odbc_SQLSvc_Close_sme_(objtag_, call_id_, &closeException, dialogueId, *stmtId, SQL_DROP, rowsAffected, sqlWarning); FUNCTION_RETURN_VOID(("executeAndFetchSMDQuery() and writeServerException() Failed")); } SQLValue = (SQLValue_def *)outputValueList->_buffer; if (SQLValue->dataInd == -1) { exception_->exception_nr = odbc_SQLSvc_GetSQLCatalogs_ParamError_exn_; exception_->u.ParamError.ParamDesc = SQLSVC_EXCEPTION_INVALID_SCHEMA_VERSION; FUNCTION_RETURN_VOID(("SQLValue->dataInd == -1")); } } } FUNCTION_RETURN_VOID((NULL)); }