JNIEXPORT void JNICALL Java_org_trafodion_jdbc_t2_SQLMXStatement_closeUsingLabel (JNIEnv *jenv, jclass jclass, jstring server, jlong dialogueId, jstring stmtLabel, jboolean dropStmt) { FUNCTION_ENTRY("Java_org_trafodion_jdbc_t2_SQLMXStatement_closeUsingLabel",("... stmtLabel=%s, dialogueId=0x%08x, dropStmt=%s", DebugJString(jenv,stmtLabel), dialogueId, DebugBoolStr(dropStmt))); ExceptionStruct exception_; long rowsAffected; ERROR_DESC_LIST_def sqlWarning; ERROR_DESC_def *error_desc_def; const char *nStmtLabel; if (stmtLabel) nStmtLabel = JNI_GetStringUTFChars(jenv,stmtLabel, NULL); else { throwSQLException(jenv, INVALID_STMT_LABEL_ERROR, NULL, "HY000"); FUNCTION_RETURN_VOID(("stmtLabel is NULL")); } odbc_SQLSvc_CloseUsingLabel_sme_(NULL, NULL, &exception_, dialogueId, (char *)nStmtLabel, (dropStmt ? SQL_DROP : SQL_CLOSE), &rowsAffected, &sqlWarning); if (stmtLabel) JNI_ReleaseStringUTFChars(jenv,stmtLabel, nStmtLabel); // Ignore setting warning since the input is jclass and not jobject switch (exception_.exception_nr) { case CEE_SUCCESS: break; case odbc_SQLSvc_Close_SQLError_exn_: 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)); }
//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 jobject JNICALL Java_org_trafodion_jdbc_t2_SQLMXDatabaseMetaData_getSchemas (JNIEnv *jenv, jobject jobj, jstring server, jlong dialogueId, jint txid, jboolean autoCommit, jint txnMode, jstring schemaPattern) { FUNCTION_ENTRY("Java_org_trafodion_jdbc_t2_SQLMXDatabaseMetaData_getSchemas",("server=%s, dialogueId=0x%08x, txid=0x%08x, autoCommit=%s, txnMode=%ld, schemaPattern=%s", DebugJString(jenv,server), dialogueId, txid, DebugBoolStr(autoCommit), txnMode, DebugJString(jenv,schemaPattern))); jobject rc = getSQLCatalogsInfo(jenv, jobj, server, dialogueId, txid, autoCommit, txnMode, SQL_API_SQLTABLES_JDBC, NULL, schemaPattern, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 1, NULL, NULL, NULL); FUNCTION_RETURN_PTR(rc, (NULL)); }
JNIEXPORT jboolean JNICALL Java_org_trafodion_jdbc_t2_SQLMXResultSet_fetchN (JNIEnv *jenv, jobject jobj, jstring server, jlong dialogueId, jint txid, jint txnMode, jlong stmtId, jint maxRowCnt, jint queryTimeout, jint holdability) { FUNCTION_ENTRY("Java_org_trafodion_jdbc_t2_SQLMXResultSet_fetchN",("server=%s, dialogueId=0x%08x, txid=0x%08x, txnMode=%ld, stmtId=0x%08x, maxRowCnt=%ld, queryTimeout=%ld, holdability=%ld", DebugJString(jenv,server), dialogueId, txid, txnMode, stmtId, maxRowCnt, queryTimeout, holdability)); ExceptionStruct exception_; SQLValueList_def outputValueList; long rowsAffected; BOOL retCode = FALSE; ERROR_DESC_LIST_def sqlWarning; jint currentTxid = txid; jint externalTxid = 0; const char *nStmtLabel; SRVR_STMT_HDL *pSrvrStmt; long sqlcode; short txn_status; if ((pSrvrStmt = getSrvrStmt(dialogueId, stmtId, &sqlcode)) == NULL) { throwSQLException(jenv, INVALID_HANDLE_ERROR, NULL, "HY000", sqlcode); FUNCTION_RETURN_NUMERIC(false,("getSrvrStmt() returned NULL")); } if ((txn_status = beginTxnControl(jenv, currentTxid, externalTxid, txnMode, holdability)) != 0) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_NUMERIC(false,("beginTxnControl() failed")); } odbc_SQLSvc_FetchN_sme_(NULL, NULL, &exception_, dialogueId, stmtId, maxRowCnt, FALSE, queryTimeout, &rowsAffected, &outputValueList, &sqlWarning); if ((txn_status = endTxnControl(jenv, currentTxid, 0, FALSE, (exception_.exception_nr == odbc_SQLSvc_FetchN_SQLNoDataFound_exn_ ? CEE_SUCCESS : exception_.exception_nr), TRUE, txnMode, externalTxid)) != 0) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_NUMERIC(false,("endTxnControl() Failed")); } switch (exception_.exception_nr) { case CEE_SUCCESS: if (sqlWarning._length != 0) setSQLWarning(jenv, jobj, &sqlWarning); setFetchOutputs(jenv, jobj, pSrvrStmt, &outputValueList, rowsAffected, rowsAffected < maxRowCnt ? TRUE : FALSE, TRUE, currentTxid); retCode = TRUE; break; case odbc_SQLSvc_FetchN_SQLNoDataFound_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); break; case odbc_SQLSvc_FetchN_SQLQueryCancelled_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwSQLException(jenv, QUERY_CANCELLED_ERROR, NULL, "HY008", exception_.u.SQLQueryCancelled.sqlcode); break; case odbc_SQLSvc_FetchN_SQLError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwSQLException(jenv, &exception_.u.SQLError); break; case odbc_SQLSvc_FetchN_ParamError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwSQLException(jenv, PROGRAMMING_ERROR, exception_.u.ParamError.ParamDesc, "HY000"); break; case odbc_SQLSvc_FetchN_SQLInvalidHandle_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwSQLException(jenv, INVALID_HANDLE_ERROR, NULL, "HY000", exception_.u.SQLInvalidHandle.sqlcode); break; case odbc_SQLSvc_FetchN_SQLStillExecuting_exn_: case odbc_SQLSvc_FetchN_InvalidConnection_exn_: case odbc_SQLSvc_FetchN_TransactionError_exn_: default: // TFDS jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidRSMethodId, currentTxid); throwSQLException(jenv, PROGRAMMING_ERROR, NULL, "HY000", exception_.exception_nr); break; } FUNCTION_RETURN_NUMERIC(retCode,(DebugBoolStr(retCode))); }
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)); }
JNIEXPORT void JNICALL Java_org_trafodion_jdbc_t2_SQLMXStatement_executeDirect (JNIEnv *jenv, jobject jobj, jstring server, jlong dialogueId, jint txid, jboolean autoCommit, jint txnMode, jstring stmtLabel, jstring cursorName, jstring sql, jboolean isSelect, jint queryTimeout, jint holdability, jobject resultSet, jlong currentStmtId) { FUNCTION_ENTRY_LEVEL(DEBUG_LEVEL_STMT,"Java_org_trafodion_jdbc_t2_SQLMXStatement_executeDirect", ("... dialogueId=0x%08x, txid=%ld, autoCommit=%s, stmtLabel=%s, cursorName=%s, sql=%s, txnMode=%ld, isSelect=%s, holdability=%ld, resultSet=0x%08x", dialogueId, txid, DebugBoolStr(autoCommit), DebugJString(jenv,stmtLabel), DebugJString(jenv,cursorName), DebugJString(jenv,sql), txnMode, DebugBoolStr(isSelect), holdability, resultSet)); ExceptionStruct exception_; long estimatedCost; long rowsAffected; ERROR_DESC_LIST_def sqlWarning; SQLItemDescList_def outputDesc; jint currentTxid = txid; jint externalTxid = 0; long stmtId; const char *nSql; const char *nStmtLabel; const char *nCursorName; jbyteArray sqlByteArray; jboolean isCopy; jsize len; SQLValue_def sqlString; short txn_status; sqlString.dataCharset = 0; sqlString.dataInd = 0; sqlString.dataType = SQLTYPECODE_VARCHAR; if (sql) { if ((sqlByteArray = (jbyteArray)jenv->CallObjectMethod(sql, gJNICache.getBytesMethodId)) == NULL) { throwSQLException(jenv, INVALID_SQL_STRING_ERROR, NULL, "HY090"); FUNCTION_RETURN_VOID(("getBytesMethod returned NULL")); } if ((nSql = (const char *)JNI_GetByteArrayElements(jenv,sqlByteArray, &isCopy)) == NULL) { throwSQLException(jenv, INVALID_SQL_STRING_ERROR, NULL, "HY090"); FUNCTION_RETURN_VOID(("GetByteArrayElements returned NULL")); } len = JNI_GetArrayLength(jenv,sqlByteArray); sqlString.dataValue._buffer = (unsigned char *)nSql; sqlString.dataValue._length = len; DEBUG_OUT(DEBUG_LEVEL_CLI,("sqlString = '%s', length =%ld", nSql, len)); MEMORY_DUMP(DEBUG_LEVEL_CLI, nSql, len); } else { throwSQLException(jenv, INVALID_SQL_STRING_ERROR, NULL, "HY090"); FUNCTION_RETURN_VOID(("sql is NULL")); } if (stmtLabel) nStmtLabel = JNI_GetStringUTFChars(jenv,stmtLabel, NULL); else { throwSQLException(jenv, INVALID_STMT_LABEL_ERROR, NULL, "HY000"); FUNCTION_RETURN_VOID(("stmtLabel is NULL")); } if (cursorName) nCursorName = JNI_GetStringUTFChars(jenv,cursorName, NULL); else nCursorName = NULL; if ((txn_status = beginTxnControl(jenv, currentTxid, externalTxid, txnMode, -1) != 0)) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("beginTxnControl() failed")); } exception_.u.SQLError.errorList._buffer = NULL; odbc_SQLSvc_ExecDirect_sme_(NULL, NULL, &exception_, dialogueId, nStmtLabel, (char *)nCursorName, "", // StmtExplainName EXTERNAL_STMT, (isSelect ? TYPE_SELECT : TYPE_UNKNOWN), &sqlString, holdability, queryTimeout, (long) resultSet, &estimatedCost, &outputDesc, &rowsAffected, &sqlWarning, &stmtId, currentStmtId); if (sql) JNI_ReleaseByteArrayElements(jenv,sqlByteArray, (jbyte *)nSql, JNI_ABORT); if (stmtLabel) JNI_ReleaseStringUTFChars(jenv,stmtLabel, nStmtLabel); if (cursorName) JNI_ReleaseStringUTFChars(jenv,cursorName, nCursorName); if ((txn_status = endTxnControl(jenv, currentTxid, txid, autoCommit, exception_.exception_nr, isSelect, txnMode, externalTxid)) != 0) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("endTxnControl() Failed")); } switch (exception_.exception_nr) { case CEE_SUCCESS: if (sqlWarning._length != 0) setSQLWarning(jenv, jobj, &sqlWarning); setExecuteDirectOutputs(jenv, jobj, &outputDesc, rowsAffected, currentTxid, stmtId); break; case odbc_SQLSvc_ExecDirect_ParamError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, PROGRAMMING_ERROR, exception_.u.ParamError.ParamDesc, "HY000"); break; case odbc_SQLSvc_ExecDirect_SQLError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, &exception_.u.SQLError); break; case odbc_SQLSvc_ExecDirect_SQLQueryCancelled_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, QUERY_CANCELLED_ERROR, NULL, "HY008", exception_.u.SQLQueryCancelled.sqlcode); break; case odbc_SQLSvc_ExecDirect_SQLInvalidHandle_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, INVALID_HANDLE_ERROR, NULL, "HY000", exception_.u.SQLInvalidHandle.sqlcode); break; case odbc_SQLSvc_ExecDirect_SQLStillExecuting_exn_: case odbc_SQLSvc_ExecDirect_InvalidConnection_exn_: case odbc_SQLSvc_ExecDirect_TransactionError_exn_: default: // TFDS - These error should not happen jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, PROGRAMMING_ERROR, NULL, "HY000", exception_.exception_nr); break; } FUNCTION_RETURN_VOID((NULL)); }
/* RFE: Batch update improvements * executeBatch() now contains an additional argument: contBatchOnError */ JNIEXPORT void JNICALL Java_org_trafodion_jdbc_t2_SQLMXStatement_executeBatch (JNIEnv *jenv, jobject jobj, jstring server, jlong dialogueId, jint txid, jboolean autoCommit, jint txnMode, jstring stmtLabel, jstring cursorName, jobjectArray sqlCommands, jboolean isSelect, jint queryTimeout, jboolean contBatchOnError, jlong currentStmtId) { FUNCTION_ENTRY("Java_org_trafodion_jdbc_t2_SQLMXStatement_executeBatch", ("... dialogueId=0x%08x, txid=%ld, autoCommit=%s, stmtLabel=%s, cursorName=%s,txnMode=%ld, isSelect=%s,contBatchOnError=%s ...", dialogueId, txid, DebugBoolStr(autoCommit), DebugJString(jenv,stmtLabel), DebugJString(jenv,cursorName), txnMode, DebugBoolStr(isSelect), DebugBoolStr(contBatchOnError))); ExceptionStruct exception_; long estimatedCost; long rowsAffected; ERROR_DESC_LIST_def sqlWarning; SQLItemDescList_def outputDesc; jint currentTxid = txid; jint externalTxid = 0; jsize noOfCommands; jstring sql; jint i; const char *nSql; const char *nStmtLabel; const char *nCursorName = NULL; jbyteArray sqlByteArray; jboolean isCopy; long stmtId; jsize len; SQLValue_def sqlString; short txn_status; // RFE: Batch update improvements jthrowable queuedException = NULL; jthrowable exceptionHead = NULL; bool isSuspended = false; exception_.exception_nr = CEE_SUCCESS; if (stmtLabel) nStmtLabel = JNI_GetStringUTFChars(jenv,stmtLabel, NULL); else { throwSQLException(jenv, INVALID_STMT_LABEL_ERROR, NULL, "HY000"); FUNCTION_RETURN_VOID(("stmtLabel is NULL")); } if (cursorName) nCursorName = JNI_GetStringUTFChars(jenv,cursorName, NULL); if ((txn_status = beginTxnControl(jenv, currentTxid, externalTxid, txnMode, -1) != 0)) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("beginTxnControl() failed")); } sqlString.dataCharset = 0; sqlString.dataInd = 0; sqlString.dataType = SQLTYPECODE_VARCHAR; noOfCommands = JNI_GetArrayLength(jenv,sqlCommands); for (i = 0; i < noOfCommands ; i++) { /* RFE: Batch update improvements * Resume the transaction if it was earlier suspended, by checking the * variable isSuspended. This is reset to false after the transaction is resumed. */ if(isSuspended) { if ((txn_status = beginTxnControl(jenv, currentTxid, externalTxid, txnMode, -1) != 0)) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("beginTxnControl() failed")); } isSuspended = false; } sql = (jstring) JNI_GetObjectArrayElement(jenv,sqlCommands, i); if (sql) { if ((sqlByteArray = (jbyteArray)jenv->CallObjectMethod(sql, gJNICache.getBytesMethodId)) == NULL) { throwSQLException(jenv, INVALID_SQL_STRING_ERROR, NULL, "HY090"); FUNCTION_RETURN_VOID(("getBytesMethod() returned NULL")); } if ((nSql = (const char *)JNI_GetByteArrayElements(jenv,sqlByteArray, &isCopy)) == NULL) { throwSQLException(jenv, INVALID_SQL_STRING_ERROR, NULL, "HY090"); FUNCTION_RETURN_VOID(("GetByteArrayElements() returned NULL")); } len = JNI_GetArrayLength(jenv,sqlByteArray); sqlString.dataValue._buffer = (unsigned char *)nSql; sqlString.dataValue._length = len; } else { throwSQLException(jenv, INVALID_SQL_STRING_ERROR, NULL, "HY090"); FUNCTION_RETURN_VOID(("sql is NULL")); } odbc_SQLSvc_ExecDirect_sme_(NULL, NULL, &exception_, dialogueId, nStmtLabel, (char *)nCursorName, "", // StmtExplainName EXTERNAL_STMT, (isSelect ? TYPE_SELECT : TYPE_UNKNOWN), &sqlString, CLOSE_CURSORS_AT_COMMIT, queryTimeout, NULL, &estimatedCost, &outputDesc, &rowsAffected, &sqlWarning, &stmtId ,currentStmtId); if (sql) JNI_ReleaseByteArrayElements(jenv,sqlByteArray, (jbyte *)nSql, JNI_ABORT); /* RFE: Batch update improvements * Perform pre-function exit processing only if contBatchOnError is not set to true */ if (exception_.exception_nr != CEE_SUCCESS) { //RFE: Batch update improvements if(!contBatchOnError) { if (stmtLabel) JNI_ReleaseStringUTFChars(jenv,stmtLabel, nStmtLabel); if (cursorName) JNI_ReleaseStringUTFChars(jenv,cursorName, nCursorName); } // Commit the transaction so all good statements are processed. txn_status = endTxnControl(jenv, currentTxid, txid, autoCommit, CEE_SUCCESS, isSelect, txnMode, externalTxid); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); if (txn_status != 0) { throwTransactionException(jenv, txn_status); DEBUG_OUT(DEBUG_LEVEL_ENTRY|DEBUG_LEVEL_TXN,("endTxnControl() Failed after ExecDirect failure")); } //RFE: Batch update improvements if(contBatchOnError) isSuspended = true; } switch (exception_.exception_nr) { case CEE_SUCCESS: if (sqlWarning._length != 0) setSQLWarning(jenv, jobj, &sqlWarning); jenv->CallVoidMethod(jobj, gJNICache.execDirectBatchOutputsMethodId, i, rowsAffected, currentTxid); break; case odbc_SQLSvc_ExecDirect_ParamError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); throwSQLException(jenv, PROGRAMMING_ERROR, exception_.u.ParamError.ParamDesc, "HY000"); break; case odbc_SQLSvc_ExecDirect_SQLError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); throwSQLException(jenv, &exception_.u.SQLError); break; case odbc_SQLSvc_ExecDirect_SQLQueryCancelled_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); throwSQLException(jenv, QUERY_CANCELLED_ERROR, NULL, "HY008", exception_.u.SQLQueryCancelled.sqlcode); break; case odbc_SQLSvc_ExecDirect_SQLInvalidHandle_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); throwSQLException(jenv, INVALID_HANDLE_ERROR, NULL, "HY000", exception_.u.SQLInvalidHandle.sqlcode); break; case odbc_SQLSvc_ExecDirect_SQLStillExecuting_exn_: case odbc_SQLSvc_ExecDirect_InvalidConnection_exn_: case odbc_SQLSvc_ExecDirect_TransactionError_exn_: default: // TFDS - These error should not happen jenv->CallVoidMethod(jobj, gJNICache.setCurrentStmtIdMethodId, stmtId); throwSQLException(jenv, PROGRAMMING_ERROR, NULL, "HY000", exception_.exception_nr); break; } /* RFE: Batch update improvements * Return to caller on error and if contBatchOnError is not true. */ if (exception_.exception_nr != CEE_SUCCESS && !contBatchOnError) FUNCTION_RETURN_VOID(("exception_.exception_nr(%ld) is not CEE_SUCCESS",exception_.exception_nr)); /* RFE: Batch update improvements * Queue up the exceptions. */ if(jenv->ExceptionOccurred()) { queuedException = jenv->ExceptionOccurred(); if(exceptionHead) jenv->CallVoidMethod(exceptionHead, gJNICache.setNextExceptionMethodId, queuedException); else exceptionHead = queuedException; } }//end of for if (stmtLabel) JNI_ReleaseStringUTFChars(jenv,stmtLabel, nStmtLabel); if (cursorName) JNI_ReleaseStringUTFChars(jenv,cursorName, nCursorName); /* RFE: Batch update improvements * If contBatchOnError is true, CEE_SUCCESS is always passed instead of * exception_.exception_nr, so that endTxnControl suspends the transaction. */ txn_status = endTxnControl(jenv, currentTxid, txid, autoCommit, (contBatchOnError ? CEE_SUCCESS:exception_.exception_nr), isSelect, txnMode, externalTxid); jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); if (txn_status != 0) { throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("endTxnControl() failed")); } /* RFE: Batch update improvements * Throw the queued exception if any */ if(exceptionHead) jenv->Throw(exceptionHead); FUNCTION_RETURN_VOID((NULL)); }
//venu changed dialogueId and stmtId from int to long for 64 bit JNIEXPORT void JNICALL Java_org_trafodion_jdbc_t2_SQLMXStatement_executeRS (JNIEnv *jenv, jobject jobj, jstring server, jlong dialogueId, jint txid, jboolean autoCommit, jint txnMode, jstring stmtLabel, jstring RSstmtLabel, jboolean isSelect, jlong stmtId, jint ResultSetIndex, jobject resultSet) { FUNCTION_ENTRY_LEVEL(DEBUG_LEVEL_STMT, "Java_org_trafodion_jdbc_t2_SQLMXStatement_executeRS", ("...dialogueId=0x%08x, txid=0x%08x, stmtLabel=%s, RSstmtLabel=%s, isSelect=%s, stmtId=0x%08x, ResultSetIndex=%ld, resultSet=0x%08x", dialogueId, txid, DebugJString(jenv,stmtLabel), DebugJString(jenv,RSstmtLabel), DebugBoolStr(isSelect), stmtId, ResultSetIndex, resultSet)); ExceptionStruct exception_; ERROR_DESC_LIST_def sqlWarning; SQLItemDescList_def outputDesc; jint currentTxid = txid; jint externalTxid = 0; long RSstmtId; const char *nStmtLabel; const char *nRSStmtLabel; jboolean isCopy; short txn_status; if (stmtLabel) nStmtLabel = JNI_GetStringUTFChars(jenv,stmtLabel, NULL); else { throwSQLException(jenv, INVALID_STMT_LABEL_ERROR, NULL, "HY000"); FUNCTION_RETURN_VOID(("stmtLabel is NULL")); } if (RSstmtLabel) nRSStmtLabel = JNI_GetStringUTFChars(jenv,RSstmtLabel, NULL); else { throwSQLException(jenv, INVALID_STMT_LABEL_ERROR, NULL, "HY000"); FUNCTION_RETURN_VOID(("RSstmtLabel is NULL")); } if ((txn_status = beginTxnControl(jenv, currentTxid, externalTxid, txnMode, -1) != 0)) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("beginTxnControl() failed")); } jdbc_SQLSvc_ExecSPJRS_sme_(NULL, NULL, &exception_, dialogueId, nStmtLabel, nRSStmtLabel, EXTERNAL_STMT, (isSelect ? TYPE_SELECT : TYPE_UNKNOWN), (long) resultSet, ResultSetIndex, &outputDesc, &sqlWarning, &RSstmtId, stmtId); if (stmtLabel) JNI_ReleaseStringUTFChars(jenv, stmtLabel, nStmtLabel); if (RSstmtLabel) JNI_ReleaseStringUTFChars(jenv, RSstmtLabel, nRSStmtLabel); if ((txn_status = endTxnControl(jenv, currentTxid, txid, autoCommit, exception_.exception_nr, isSelect, txnMode, externalTxid)) != 0) { jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwTransactionException(jenv, txn_status); FUNCTION_RETURN_VOID(("endTxnControl() Failed")); } switch (exception_.exception_nr) { case CEE_SUCCESS: if (sqlWarning._length != 0) setSQLWarning(jenv, jobj, &sqlWarning); setExecuteRSOutputs(jenv, jobj, &outputDesc, currentTxid, RSstmtId, ResultSetIndex); break; case jdbc_SQLSvc_ExecSPJRS_ParamError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, PROGRAMMING_ERROR, exception_.u.ParamError.ParamDesc, "HY000"); break; case jdbc_SQLSvc_ExecSPJRS_SQLError_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, &exception_.u.SQLError); break; case jdbc_SQLSvc_ExecSPJRS_SQLQueryCancelled_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, QUERY_CANCELLED_ERROR, NULL, "HY008", exception_.u.SQLQueryCancelled.sqlcode); break; case jdbc_SQLSvc_ExecSPJRS_SQLInvalidHandle_exn_: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, INVALID_HANDLE_ERROR, NULL, "HY000", exception_.u.SQLInvalidHandle.sqlcode); break; case jdbc_SQLSvc_ExecSPJRS_SQLStillExecuting_exn_: case jdbc_SQLSvc_ExecSPJRS_InvalidConnection_exn_: case jdbc_SQLSvc_ExecSPJRS_TransactionError_exn_: default: jenv->CallVoidMethod(jobj, gJNICache.setCurrentTxidStmtMethodId, currentTxid); throwSQLException(jenv, PROGRAMMING_ERROR, NULL, "HY000", exception_.exception_nr); break; } FUNCTION_RETURN_VOID((NULL)); }