You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by db...@apache.org on 2017/11/15 18:03:02 UTC
[05/11] incubator-trafodion git commit: new COMMENT-ON SQL statement:
review change - delete allocated spaces for function
CmpSeabaseDDL::getSeabaseObjectComment
new COMMENT-ON SQL statement: review change - delete allocated spaces for function CmpSeabaseDDL::getSeabaseObjectComment
1. delete allocated COMMENT spaces after used.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/4bdd4b84
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/4bdd4b84
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/4bdd4b84
Branch: refs/heads/master
Commit: 4bdd4b84e5c718898c43575fe993051fd4fedaba
Parents: 4127e1c
Author: eedy <cq...@gmail.com>
Authored: Mon Nov 6 13:39:16 2017 +0800
Committer: eedy <cq...@gmail.com>
Committed: Mon Nov 6 13:39:16 2017 +0800
----------------------------------------------------------------------
core/sql/comexe/ComTdb.h | 7 ++
core/sql/sqlcomp/CmpDescribe.cpp | 111 +++++++++++++++-----------
core/sql/sqlcomp/CmpSeabaseDDL.h | 3 +-
core/sql/sqlcomp/CmpSeabaseDDLschema.cpp | 14 ++--
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 82 +++++++------------
5 files changed, 110 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4bdd4b84/core/sql/comexe/ComTdb.h
----------------------------------------------------------------------
diff --git a/core/sql/comexe/ComTdb.h b/core/sql/comexe/ComTdb.h
index 73fa28a..1b90b90 100644
--- a/core/sql/comexe/ComTdb.h
+++ b/core/sql/comexe/ComTdb.h
@@ -1167,6 +1167,13 @@ class ComTdbVirtObjCommentInfo : public ComTdbVirtTableBase
: ComTdbVirtTableBase()
{
init();
+
+ objectUid = 0;
+ objectComment = NULL;
+ numColumnComment = 0;
+ columnCommentArray = NULL;
+ numIndexComment = 0;
+ indexCommentArray = NULL;
}
virtual Int32 size() { return sizeof(ComTdbVirtObjCommentInfo);}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4bdd4b84/core/sql/sqlcomp/CmpDescribe.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpDescribe.cpp b/core/sql/sqlcomp/CmpDescribe.cpp
index fed0087..2d9c9da 100644
--- a/core/sql/sqlcomp/CmpDescribe.cpp
+++ b/core/sql/sqlcomp/CmpDescribe.cpp
@@ -3070,35 +3070,41 @@ short CmpDescribeSeabaseTable (
return -1;
}
- ComTdbVirtObjCommentInfo * objCommentInfo = NULL;
- cmpSBD.getSeabaseObjectComment(objectUID, COM_VIEW_OBJECT, objCommentInfo);
+ ComTdbVirtObjCommentInfo objCommentInfo;
+ cmpSBD.getSeabaseObjectComment(objectUID, COM_VIEW_OBJECT, objCommentInfo, heap);
- if (objCommentInfo != NULL)
+ //display VIEW COMMENT statements
+ if (objCommentInfo.objectComment != NULL)
{
//new line
outputLine(*space, "", 0);
- //display VIEW COMMENT statements
- if (objCommentInfo->objectComment != NULL)
- {
- sprintf(buf, "COMMENT ON VIEW %s IS '%s' ;",
- tableName.data(),
- objCommentInfo->objectComment);
- outputLine(*space, buf, 0);
- }
+ sprintf(buf, "COMMENT ON VIEW %s IS '%s' ;",
+ tableName.data(),
+ objCommentInfo.objectComment);
+ outputLine(*space, buf, 0);
+ }
+ if (objCommentInfo.numColumnComment > 0 && objCommentInfo.columnCommentArray != NULL)
+ {
//display Column COMMENT statements
outputLine(*space, "", 0);
- for (int idx = 0; idx < objCommentInfo->numColumnComment; idx++)
+ for (int idx = 0; idx < objCommentInfo.numColumnComment; idx++)
{
sprintf(buf, "COMMENT ON COLUMN %s.%s IS '%s' ;",
tableName.data(),
- objCommentInfo->columnCommentArray[idx].columnName,
- objCommentInfo->columnCommentArray[idx].columnComment);
+ objCommentInfo.columnCommentArray[idx].columnName,
+ objCommentInfo.columnCommentArray[idx].columnComment);
outputLine(*space, buf, 0);
}
}
+ //do a comment info memory clean
+ if (objCommentInfo.columnCommentArray != NULL)
+ {
+ NADELETEBASIC(objCommentInfo.columnCommentArray, heap);
+ }
+
cmpSBD.switchBackCompiler();
}
@@ -3835,46 +3841,59 @@ short CmpDescribeSeabaseTable (
return -1;
}
- ComTdbVirtObjCommentInfo * objCommentInfo = NULL;
- cmpSBD.getSeabaseObjectComment(objectUID, objType, objCommentInfo);
-
- if (objCommentInfo != NULL)
+ ComTdbVirtObjCommentInfo objCommentInfo;
+ cmpSBD.getSeabaseObjectComment(objectUID, objType, objCommentInfo, heap);
+
+ //display Table COMMENT statements
+ if (objCommentInfo.objectComment != NULL)
{
- //new line
- outputLine(*space, "", 0);
+ //new line
+ outputLine(*space, "", 0);
+
+ sprintf(buf, "COMMENT ON %s %s IS '%s' ;",
+ objType == COM_BASE_TABLE_OBJECT? "TABLE" : "VIEW",
+ tableName.data(),
+ objCommentInfo.objectComment);
+ outputLine(*space, buf, 0);
+ }
- //display Table COMMENT statements
- if (objCommentInfo->objectComment != NULL)
- {
- sprintf(buf, "COMMENT ON %s %s IS '%s' ;",
- objType == COM_BASE_TABLE_OBJECT? "TABLE" : "VIEW",
- tableName.data(),
- objCommentInfo->objectComment);
- outputLine(*space, buf, 0);
- }
-
- //display Column COMMENT statements
+ //display Column COMMENT statements
+ if (objCommentInfo.numColumnComment > 0 && objCommentInfo.columnCommentArray != NULL)
+ {
outputLine(*space, "", 0);
- for (int idx = 0; idx < objCommentInfo->numColumnComment; idx++)
+ for (int idx = 0; idx < objCommentInfo.numColumnComment; idx++)
{
sprintf(buf, "COMMENT ON COLUMN %s.%s IS '%s' ;",
tableName.data(),
- objCommentInfo->columnCommentArray[idx].columnName,
- objCommentInfo->columnCommentArray[idx].columnComment);
+ objCommentInfo.columnCommentArray[idx].columnName,
+ objCommentInfo.columnCommentArray[idx].columnComment);
outputLine(*space, buf, 0);
}
+ }
- //display Index COMMENT statements
+ //display Index COMMENT statements
+ if (objCommentInfo.numIndexComment > 0 && objCommentInfo.indexCommentArray != NULL)
+ {
outputLine(*space, "", 0);
- for (int idx = 0; idx < objCommentInfo->numIndexComment; idx++)
+ for (int idx = 0; idx < objCommentInfo.numIndexComment; idx++)
{
sprintf(buf, "COMMENT ON INDEX %s IS '%s' ;",
- objCommentInfo->indexCommentArray[idx].indexFullName,
- objCommentInfo->indexCommentArray[idx].indexComment);
+ objCommentInfo.indexCommentArray[idx].indexFullName,
+ objCommentInfo.indexCommentArray[idx].indexComment);
outputLine(*space, buf, 0);
}
}
+ //do a comment info memory clean
+ if (objCommentInfo.columnCommentArray != NULL)
+ {
+ NADELETEBASIC(objCommentInfo.columnCommentArray, heap);
+ }
+ if (objCommentInfo.indexCommentArray != NULL)
+ {
+ NADELETEBASIC(objCommentInfo.indexCommentArray, heap);
+ }
+
cmpSBD.switchBackCompiler();
}
@@ -4239,17 +4258,17 @@ char buf[1000];
return -1;
}
- ComTdbVirtObjCommentInfo * objCommentInfo = NULL;
- cmpSBD.getSeabaseObjectComment(libraryUID, COM_LIBRARY_OBJECT, objCommentInfo);
+ ComTdbVirtObjCommentInfo objCommentInfo;
+ cmpSBD.getSeabaseObjectComment(libraryUID, COM_LIBRARY_OBJECT, objCommentInfo, heap);
- if (objCommentInfo != NULL && objCommentInfo->objectComment != NULL)
+ if (objCommentInfo.objectComment != NULL)
{
//new line
outputLine(*space, "", 0);
sprintf(buf, "COMMENT ON LIBRARY %s IS '%s' ;",
cn.getQualifiedNameObj().getQualifiedNameAsAnsiString(TRUE).data(),
- objCommentInfo->objectComment);
+ objCommentInfo.objectComment);
outputLine(*space, buf, 0);
}
@@ -4780,10 +4799,10 @@ short CmpDescribeRoutine (const CorrName & cn,
return -1;
}
- ComTdbVirtObjCommentInfo * objCommentInfo = NULL;
- cmpSBD.getSeabaseObjectComment(routineUID, COM_USER_DEFINED_ROUTINE_OBJECT, objCommentInfo);
+ ComTdbVirtObjCommentInfo objCommentInfo;
+ cmpSBD.getSeabaseObjectComment(routineUID, COM_USER_DEFINED_ROUTINE_OBJECT, objCommentInfo, heap);
- if (objCommentInfo != NULL && objCommentInfo->objectComment != NULL)
+ if (objCommentInfo.objectComment != NULL)
{
//new line
outputLine(*space, "", 0);
@@ -4791,7 +4810,7 @@ short CmpDescribeRoutine (const CorrName & cn,
sprintf(buf, "COMMENT ON %s %s IS '%s' ;",
routine->getRoutineType() == COM_PROCEDURE_TYPE ? "PROCEDURE" : "FUNCTION",
cn.getQualifiedNameObj().getQualifiedNameAsAnsiString(TRUE).data(),
- objCommentInfo->objectComment);
+ objCommentInfo.objectComment);
outputLine(*space, buf, 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4bdd4b84/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index a31ef52..a0e4e34 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -255,7 +255,8 @@ class CmpSeabaseDDL
short getSeabaseObjectComment(Int64 object_uid,
enum ComObjectType object_type,
- ComTdbVirtObjCommentInfo * & comment_info);
+ ComTdbVirtObjCommentInfo & comment_info,
+ CollHeap * heap);
short getObjectOwner(ExeCliInterface *cliInterface,
const char * catName,
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4bdd4b84/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
index 021a605..e44faeb 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
@@ -452,13 +452,13 @@ Int16 status = ComUser::getAuthNameFromAuthID(objectOwner,username,
output += "\";";
outlines.push_back(output.data());
-
+
// Display Comment of schema
{
- ComTdbVirtObjCommentInfo * objCommentInfo = NULL;
- cmpSBD.getSeabaseObjectComment(schemaUID, objectType, objCommentInfo);
+ ComTdbVirtObjCommentInfo objCommentInfo;
+ cmpSBD.getSeabaseObjectComment(schemaUID, objectType, objCommentInfo, STMTHEAP);
- if (objCommentInfo != NULL && objCommentInfo->objectComment != NULL)
+ if (objCommentInfo.objectComment != NULL)
{
outlines.push_back(" ");
@@ -467,13 +467,11 @@ Int16 status = ComUser::getAuthNameFromAuthID(objectOwner,username,
output += ".";
output += schemaName.data();
output += " IS '";
- output += objCommentInfo->objectComment;
+ output += objCommentInfo.objectComment;
output += "' ;";
-
- outlines.push_back(output.data());
+ outlines.push_back(output.data());
}
-
}
cmpSBD.switchBackCompiler();
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/4bdd4b84/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 5fd5794..886c42d 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -12942,13 +12942,20 @@ TrafDesc *CmpSeabaseDDL::getSeabaseRoutineDescInternal(const NAString &catName,
short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid,
enum ComObjectType object_type,
- ComTdbVirtObjCommentInfo * & comment_info)
+ ComTdbVirtObjCommentInfo & comment_info,
+ CollHeap * heap)
{
Lng32 retcode = 0;
Lng32 cliRC = 0;
char query[4000];
- comment_info = NULL;
+
+ comment_info.objectUid = object_uid;
+ comment_info.objectComment = NULL;
+ comment_info.numColumnComment = 0;
+ comment_info.columnCommentArray = NULL;
+ comment_info.numIndexComment = 0;
+ comment_info.indexCommentArray = NULL;
ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
CmpCommon::context()->sqlSession()->getParentQid());
@@ -12967,30 +12974,19 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid,
return -1;
}
- if (objQueue->numEntries() == 1)
+ //We should have only 1 comment for object
+ if (objQueue->numEntries() > 0)
{
objQueue->position();
-
- OutputInfo * vi = (OutputInfo*)objQueue->getNext();
-
- comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1];
- comment_info->objectUid = object_uid;
- comment_info->numColumnComment = 0;
- comment_info->columnCommentArray = NULL;
- comment_info->numIndexComment = 0;
- comment_info->indexCommentArray = NULL;
- comment_info->objectComment = (char*)vi->get(0);
- }
- else
- {
- return -1;
+ OutputInfo * vi = (OutputInfo*)objQueue->getNext();
+ comment_info.objectComment = (char*)vi->get(0);
}
+ //get index comments of table
if (COM_BASE_TABLE_OBJECT == object_type)
{
- //get index comment of table
str_sprintf(query, "select CATALOG_NAME||'.'||SCHEMA_NAME||'.'||OBJECT_NAME, COMMENT "
- "from %s.\"%s\".%s as O, %s.\"%s\".%s as I "
+ "from %s.\"%s\".%s as O, %s.\"%s\".%s as I "
"where I.BASE_TABLE_UID = %ld and O.OBJECT_UID = I.INDEX_UID and O.comment <> '' ;",
getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_OBJECTS,
getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_INDEXES,
@@ -13007,23 +13003,14 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid,
if (indexQueue->numEntries() > 0)
{
- if (NULL == comment_info)
- {
- comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1];
- comment_info->objectUid = object_uid;
- comment_info->objectComment = NULL;
- comment_info->numColumnComment = 0;
- comment_info->columnCommentArray = NULL;
- }
-
- comment_info->numIndexComment = indexQueue->numEntries();
- comment_info->indexCommentArray = new(STMTHEAP) ComTdbVirtIndexCommentInfo[comment_info->numIndexComment];
+ comment_info.numIndexComment = indexQueue->numEntries();
+ comment_info.indexCommentArray = new(heap) ComTdbVirtIndexCommentInfo[comment_info.numIndexComment];
indexQueue->position();
- for (Lng32 idx = 0; idx < comment_info->numIndexComment; idx++)
+ for (Lng32 idx = 0; idx < comment_info.numIndexComment; idx++)
{
OutputInfo * oi = (OutputInfo*)indexQueue->getNext();
- ComTdbVirtIndexCommentInfo &indexComment = comment_info->indexCommentArray[idx];
+ ComTdbVirtIndexCommentInfo &indexComment = comment_info.indexCommentArray[idx];
// get the index full name
indexComment.indexFullName = (char*) oi->get(0);
@@ -13032,9 +13019,9 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid,
}
}
+ //get column comments of table and view
if (COM_BASE_TABLE_OBJECT == object_type || COM_VIEW_OBJECT == object_type)
{
- //get column comment of table
str_sprintf(query, "select COLUMN_NAME, COMMENT from %s.\"%s\".%s where OBJECT_UID = %ld and comment <> '' order by COLUMN_NUMBER ;",
getSystemCatalog(), SEABASE_MD_SCHEMA, SEABASE_COLUMNS, object_uid);
@@ -13049,28 +13036,19 @@ short CmpSeabaseDDL::getSeabaseObjectComment(Int64 object_uid,
if (colQueue->numEntries() > 0)
{
- if (NULL == comment_info)
- {
- comment_info = new(STMTHEAP) ComTdbVirtObjCommentInfo[1];
- comment_info->objectUid = object_uid;
- comment_info->objectComment = NULL;
- comment_info->numIndexComment = 0;
- comment_info->indexCommentArray = NULL;
- }
-
- comment_info->numColumnComment = colQueue->numEntries();
- comment_info->columnCommentArray = new(STMTHEAP) ComTdbVirtColumnCommentInfo[comment_info->numColumnComment];
+ comment_info.numColumnComment = colQueue->numEntries();
+ comment_info.columnCommentArray = new(heap) ComTdbVirtColumnCommentInfo[comment_info.numColumnComment];
colQueue->position();
- for (Lng32 idx = 0; idx < comment_info->numColumnComment; idx++)
- {
- OutputInfo * oi = (OutputInfo*)colQueue->getNext();
- ComTdbVirtColumnCommentInfo &colComment = comment_info->columnCommentArray[idx];
+ for (Lng32 idx = 0; idx < comment_info.numColumnComment; idx++)
+ {
+ OutputInfo * oi = (OutputInfo*)colQueue->getNext();
+ ComTdbVirtColumnCommentInfo &colComment = comment_info.columnCommentArray[idx];
- // get the column name
- colComment.columnName = (char*) oi->get(0);
- colComment.columnComment = (char*) oi->get(1);
- }
+ // get the column name
+ colComment.columnName = (char*) oi->get(0);
+ colComment.columnComment = (char*) oi->get(1);
+ }
}
}