Repository: trafodion Updated Branches: refs/heads/master 0cf2e6b0b -> 7d77dd4f9
COMMENT-ON Bug fix : add escape quote support for single quote character in comment string. 1. fix error when single quote in comment string 2. add escape quote for SHOWDDL statement Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/f2ed5d6f Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/f2ed5d6f Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/f2ed5d6f Branch: refs/heads/master Commit: f2ed5d6fbe6ae89bb90866775c33faaad484df91 Parents: 5339170 Author: eedy <[email protected]> Authored: Fri Mar 23 14:08:31 2018 +0800 Committer: eedy <[email protected]> Committed: Fri Mar 23 14:08:56 2018 +0800 ---------------------------------------------------------------------- core/sql/parser/StmtDDLCommentOn.h | 1 + core/sql/parser/StmtDDLCreate.cpp | 16 +++++++++ core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp | 43 ++++++++++++++++++++---- 3 files changed, 54 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/f2ed5d6f/core/sql/parser/StmtDDLCommentOn.h ---------------------------------------------------------------------- diff --git a/core/sql/parser/StmtDDLCommentOn.h b/core/sql/parser/StmtDDLCommentOn.h index adf64bb..4064dd1 100644 --- a/core/sql/parser/StmtDDLCommentOn.h +++ b/core/sql/parser/StmtDDLCommentOn.h @@ -100,6 +100,7 @@ public: inline const enum COMMENT_ON_TYPES getObjectType() { return type_; } inline const NAString getObjectName() const; inline const NAString &getComment() const { return comment_; } + NAString getCommentEscaped(); inline const NAString &getColName() const { return colRef_->getColRefNameObj().getColName(); } inline NABoolean getIsViewCol() { return isViewCol_; } inline Lng32 getColNum() { return colNum_; } http://git-wip-us.apache.org/repos/asf/trafodion/blob/f2ed5d6f/core/sql/parser/StmtDDLCreate.cpp ---------------------------------------------------------------------- diff --git a/core/sql/parser/StmtDDLCreate.cpp b/core/sql/parser/StmtDDLCreate.cpp index 72d014e..460c16b 100644 --- a/core/sql/parser/StmtDDLCreate.cpp +++ b/core/sql/parser/StmtDDLCreate.cpp @@ -7210,6 +7210,22 @@ StmtDDLCommentOn * StmtDDLCommentOn::castToStmtDDLCommentOn() return this; } +/* add escape quote for single quote */ +NAString StmtDDLCommentOn::getCommentEscaped() +{ + NAString ret(comment_); + int idx = ret.length() - 1; + + for (; idx >= 0; idx--) + { + if (ret[idx] == '\'') + ret.insert(idx, "'"); + } + + return ret; +} + + // // End of File // http://git-wip-us.apache.org/repos/asf/trafodion/blob/f2ed5d6f/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp index 7622bd8..cc4b00e 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommentOn.cpp @@ -66,6 +66,37 @@ #include "ComUser.h" +static char *doEscapeComment(char *src, CollHeap *heap) +{ + char *ret = NULL; + int head = 0; + int tail = 0; + int src_len = strlen(src); + + if (NULL == src) + { + NAAssert("invalid comment string fetched", __FILE__ , __LINE__ ); + } + + ret = new (heap) char[src_len * 2 + 1]; + ret[0] = '\0'; + for (; tail <= src_len; tail++) + { + if (src[tail] == '\'') + { + strncat(ret, src+head, tail-head+1); + strcat(ret, "'"); + head = tail + 1; + } + else if (src[tail] == '\0') + { + strncat(ret, src+head, tail-head+1); + } + } + + return ret; +} + short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid, enum ComObjectType object_type, ComTdbVirtObjCommentInfo & comment_info, @@ -105,7 +136,7 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid, { objQueue->position(); OutputInfo * vi = (OutputInfo*)objQueue->getNext(); - comment_info.objectComment = (char*)vi->get(0); + comment_info.objectComment = doEscapeComment((char*)vi->get(0), heap); } //get index comments of table @@ -143,7 +174,7 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid, // get the index full name indexComment.indexFullName = (char*) oi->get(0); - indexComment.indexComment = (char*) oi->get(1); + indexComment.indexComment = doEscapeComment((char*) oi->get(1), heap); } } } @@ -180,7 +211,7 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid, // get the column name colComment.columnName = (char*) oi->get(0); - colComment.columnComment = (char*) oi->get(1); + colComment.columnComment = doEscapeComment((char*) oi->get(1), heap); } } } @@ -188,7 +219,6 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid, return 0; } - void CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn *commentOnNode, NAString &currCatName, NAString &currSchName) @@ -290,14 +320,15 @@ void CmpSeabaseDDL::doSeabaseCommentOn(StmtDDLCommentOn *commentOnNode, //check for overflow - NAString & comment = (NAString &) commentOnNode->getComment(); - if (comment.length() > COM_MAXIMUM_LENGTH_OF_COMMENT) + if (commentOnNode->getComment().length() > COM_MAXIMUM_LENGTH_OF_COMMENT) { *CmpCommon::diags() << DgSqlCode(-8402); processReturn (); return; } + NAString comment = commentOnNode->getCommentEscaped(); + // add, remove, change comment of object/column enum ComTextType textType = COM_OBJECT_COMMENT_TEXT; Lng32 subID = 0;
