[
https://issues.apache.org/jira/browse/TRAFODION-37?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14628431#comment-14628431
]
ASF GitHub Bot commented on TRAFODION-37:
-----------------------------------------
Github user DaveBirdsall commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/28#discussion_r34706740
--- Diff: core/conn/jdbc_type2/native/SrvrCommon.cpp ---
@@ -2210,3 +2266,136 @@ void print_outputValueList(SQLValueList_def *oVL,
long colCount, const char * fc
fflush(stdout);
}
#endif
+
+// DO NOT call this function using pSrvrStmt->sqlWarningOrErrorLength and
pSrvrStmt->sqlWarningOrError,
+// Since the WarningOrError is static and pSrvrStmt->sqlWarningOrError
will deallocate this memory.
+extern "C" void GETMXCSWARNINGORERROR(
+ /* In */ Int32 sqlcode
+ , /* In */ char *sqlState
+ , /* In */ char *msg_buf
+ , /* Out */ Int32 *MXCSWarningOrErrorLength
+ , /* Out */ BYTE *&MXCSWarningOrError)
+{
+ Int32 total_conds = 1;
+ Int32 buf_len;
+ Int32 curr_cond = 1;
+ Int32 msg_buf_len = strlen(msg_buf)+1;
+ Int32 time_and_msg_buf_len = 0;
+ Int32 msg_total_len = 0;
+ Int32 rowId = 0; // use this for rowset recovery.
+ char tsqlState[6];
+ BYTE WarningOrError[1024];
+ char strNow[TIMEBUFSIZE + 1];
+ char* time_and_msg_buf = NULL;
+
+ memset(tsqlState,0,sizeof(tsqlState));
+ memcpy(tsqlState,sqlState,sizeof(tsqlState)-1);
+
+ bzero(WarningOrError,sizeof(WarningOrError));
+
+ *MXCSWarningOrErrorLength = 0;
+ MXCSWarningOrError = WarningOrError; // Size of internally generated
message should be enough
+
+ *(Int32 *)(WarningOrError+msg_total_len) = total_conds;
+ msg_total_len += sizeof(total_conds);
+ *(Int32 *)(WarningOrError+msg_total_len) = rowId;
+ msg_total_len += sizeof(rowId);
+ *(Int32 *)(WarningOrError+msg_total_len) = sqlcode;
+ msg_total_len += sizeof(sqlcode);
+ time_and_msg_buf_len = msg_buf_len + TIMEBUFSIZE;
+ *(Int32 *)(WarningOrError+msg_total_len) = time_and_msg_buf_len;
+ msg_total_len += sizeof(time_and_msg_buf_len);
+ //Get the timetsamp
+ time_and_msg_buf = new char[time_and_msg_buf_len];
+ strncpy(time_and_msg_buf, msg_buf, msg_buf_len);
+ time_t now = time(NULL);
+ bzero(strNow, sizeof(strNow));
+ strftime(strNow, sizeof(strNow), " [%Y-%m-%d %H:%M:%S]",
localtime(&now));
+ strcat(time_and_msg_buf, strNow);
+ memcpy(WarningOrError+msg_total_len, time_and_msg_buf,
time_and_msg_buf_len);
+ msg_total_len += time_and_msg_buf_len;
+ delete time_and_msg_buf;
+ memcpy(WarningOrError+msg_total_len, tsqlState, sizeof(tsqlState));
+ msg_total_len += sizeof(tsqlState);
+
+ memcpy(MXCSWarningOrError, WarningOrError, sizeof(WarningOrError));
+ *MXCSWarningOrErrorLength = msg_total_len;
+ return;
+}
+
+bool isUTF8(const char *str)
+{
+ char c;
+ unsigned short byte = 1;
+ size_t len = strlen(str);
+
+ for (size_t i=0; i<len; i++)
+ {
+ c = str[i];
+
+ if (c >= 0x00 && c < 0x80 && byte == 1) // ascii
+ continue;
+ else if (c >= 0x80 && c < 0xc0 && byte > 1) // second, third, or
fourth byte of a multi-byte sequence
+ byte--;
+ else if (c == 0xc0 || c == 0xc1) // overlong encoding
+ return false;
+ else if (c >= 0xc2 && c < 0xe0 && byte == 1) // start of 2-byte
sequence
+ byte = 2;
+ else if (c >= 0xe0 && c < 0xf0 && byte == 1) // start of 3-byte
sequence
+ byte = 3;
+ else if (c >= 0xf0 && c < 0xf5 && byte == 1) // start of 4-byte
sequence
+ byte = 4;
+ else
+ return false;
+ }
+ return true;
+}
+
+char* strcpyUTF8(char *dest, const char *src, size_t destSize, size_t
copySize)
+{
+ char c;
+ size_t len;
+
+ if (copySize == 0)
+ len = strlen(src);
+ else
+ len = copySize;
+
+ if (len >= destSize)
+ len = destSize-1; // truncation
+
+ while (len > 0)
+ {
+ c = src[len-1];
+ if (c < 0x80 || c > 0xbf)
--- End diff --
I'm not sure these comparisons will work the way you want with signed char.
> Get "ROLLBACK WORK" and "COMMIT WORK" transactions be prepared when T2 driver
> is establishing connection
> --------------------------------------------------------------------------------------------------------
>
> Key: TRAFODION-37
> URL: https://issues.apache.org/jira/browse/TRAFODION-37
> Project: Apache Trafodion
> Issue Type: Improvement
> Reporter: RuoYu Zuo
> Assignee: RuoYu Zuo
> Labels: features
>
> To make T2 driver supports rowset operation to enhance the performance of
> batch insert and update, two SQL transactions ("commit" to make a succeeded
> execution and "rollback" for failure) are required to be prepared in advance,
> which shall be triggered in executing phase of rowset operation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)