def comment_table(self, o): if o.description or self.blanks: table_comment = self.comment('TABLE', (o.schema.name, o.name), o.description) else: table_comment = '' field_comments = [ (format_ident(f.name), self.get_description(f.description)) for f in o.field_list if f.description or self.blanks ] if field_comments: max_name_len = max(len(name) for (name, description) in field_comments) field_comments = ',\n'.join( '\t%-*s IS %s' % (max_name_len, name, description) for (name, description) in field_comments ) field_comments = """\ COMMENT ON %s.%s ( %s )%s""" % ( format_ident(o.schema.name), format_ident(o.name), field_comments, self.terminator, ) else: field_comments = '' return '\n'.join(s for s in (table_comment, field_comments) if s)
def comment_table(self, o): if o.description or self.blanks: table_comment = self.comment('TABLE', (o.schema.name, o.name), o.description) else: table_comment = '' field_comments = [(format_ident(f.name), self.get_description(f.description)) for f in o.field_list if f.description or self.blanks] if field_comments: max_name_len = max( len(name) for (name, description) in field_comments) field_comments = ',\n'.join( '\t%-*s IS %s' % (max_name_len, name, description) for (name, description) in field_comments) field_comments = """\ COMMENT ON %s.%s ( %s )%s""" % ( format_ident(o.schema.name), format_ident(o.name), field_comments, self.terminator, ) else: field_comments = '' return '\n'.join(s for s in (table_comment, field_comments) if s)
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) yield 'UPDATE %s.TABLES\n' % format_ident(self.schema) yield 'SET\n' yield '\tREMARKS = CLOB(%s)\n' % quote_str(desc) yield 'WHERE\n' yield '\tTABSCHEMA = %s\n' % quote_str(schema) yield '\tAND TABNAME = %s%s\n' % (quote_str(obj), self.terminator) yield 'UPDATE %s.COLUMNS\n' % format_ident(self.schema) yield 'SET\n' yield '\tREMARKS = CASE COLNAME\n' maxlen = max( len(quote_str(column)) + 1 for column in columns.iterkeys() ) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) yield '\t\tWHEN %-*s THEN CLOB(%s)\n' % ( maxlen, quote_str(column), quote_str(desc) ) yield '\tEND\n' yield 'WHERE\n' yield '\tTABSCHEMA = %s\n' % quote_str(schema) yield '\tAND TABNAME = %s%s\n' % (quote_str(obj), self.terminator) yield '\n'
def get_predicates(self, predicates, qualifier=None): if qualifier: qualifier = format_ident(qualifier) + '.' else: qualifier = '' return ' AND '.join('%s%s = %s' % (qualifier, format_ident(key), quote_str(value)) for (key, value) in predicates.iteritems())
def get_predicates(self, predicates, qualifier=None): if qualifier: qualifier = format_ident(qualifier) + '.' else: qualifier = '' return ' AND '.join( '%s%s = %s' % (qualifier, format_ident(key), quote_str(value)) for (key, value) in predicates.iteritems() )
def update(self, dbobject, table, predicates): if dbobject.description or self.blanks: return """\ UPDATE %s.%s SET REMARKS = %s WHERE %s%s""" % ( format_ident(self.schema), format_ident(table), self.get_description(dbobject.description), self.get_predicates(predicates), self.terminator, )
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) yield 'INSERT INTO %s.TABLES (TABSCHEMA, TABNAME, REMARKS)\n' % format_ident( self.schema) yield '\tVALUES (%s, %s, CLOB(%s))%s\n' % ( quote_str(schema), quote_str(obj), quote_str(desc), self.terminator, ) yield 'INSERT INTO %s.COLUMNS (TABSCHEMA, TABNAME, COLNAME, REMARKS)\n' % format_ident( self.schema) yield '\tSELECT %s, %s, COLNAME, REMARKS FROM (VALUES\n' % ( quote_str(schema), quote_str(obj), ) prefix = '' maxlen = max( len(quote_str(column)) + 1 for column in columns.iterkeys()) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) yield '%s\t\t(%-*s CLOB(%s))\n' % ( prefix, maxlen, quote_str(column) + ',', quote_str(desc)) prefix = ',' yield '\t) AS T(COLNAME, REMARKS)%s\n' % self.terminator yield '\n'
def update_param_type(self, o, type): param_comments = [ (p.position, p.name, self.get_description(p.description)) for p in o.param_list if p.type == type and (p.description or self.blanks) ] predicates = { 'ROUTINESCHEMA': o.schema.name, 'SPECIFICNAME': o.specific_name, 'ROWTYPE': {'I': 'P'}.get(type, type), } if param_comments: max_name_len = max(len(name) for (pos, name, description) in param_comments) max_pos_len = max(len(str(pos)) for (pos, name, description) in param_comments) param_comments = [ '\t\tWHEN %-*d /* %-*s */ THEN %s' % (max_pos_len, pos, max_name_len, name, description) for (pos, name, description) in param_comments ] if not self.blanks: param_comments.append('\t\tELSE REMARKS') param_comments = '\n'.join(param_comments) param_comments = """\ UPDATE %s.ROUTINEPARMS SET REMARKS = CASE ORDINAL %s END WHERE %s%s""" % ( format_ident(self.schema), param_comments, self.get_predicates(predicates), self.terminator, ) else: param_comments = '' return param_comments
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) yield 'INSERT INTO %s.TABLES (TABSCHEMA, TABNAME, REMARKS)\n' % format_ident(self.schema) yield '\tVALUES (%s, %s, CLOB(%s))%s\n' % ( quote_str(schema), quote_str(obj), quote_str(desc), self.terminator, ) yield 'INSERT INTO %s.COLUMNS (TABSCHEMA, TABNAME, COLNAME, REMARKS)\n' % format_ident(self.schema) yield '\tSELECT %s, %s, COLNAME, REMARKS FROM (VALUES\n' % ( quote_str(schema), quote_str(obj), ) prefix = '' maxlen = max( len(quote_str(column)) + 1 for column in columns.iterkeys() ) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) yield '%s\t\t(%-*s CLOB(%s))\n' % ( prefix, maxlen, quote_str(column) + ',', quote_str(desc) ) prefix = ',' yield '\t) AS T(COLNAME, REMARKS)%s\n' % self.terminator yield '\n'
def comment(self, label, name, description): if description or self.blanks: return 'COMMENT ON %s %s IS %s%s' % ( label, '.'.join(format_ident(s) for s in name), self.get_description(description), self.terminator, )
def merge_param_type(self, o, type): param_comments = [(p.position, quote_str(p.name), self.get_description(p.description)) for p in o.param_list if p.type == type and (p.description or self.blanks)] predicates = { 'ROUTINESCHEMA': o.schema.name, 'SPECIFICNAME': o.specific_name, 'ROWTYPE': { 'I': 'P' }.get(type, type), } if param_comments: max_name_len = max( len(name) for (pos, name, description) in param_comments) max_pos_len = max( len(str(pos)) for (pos, name, description) in param_comments) param_comments = [ '\t\t(%-*d, %-*s, %s)' % (max_pos_len, pos, max_name_len, name, description) for (pos, name, description) in param_comments ] param_comments = ',\n'.join(param_comments) param_comments = """\ MERGE INTO %s.ROUTINEPARMS AS T USING TABLE(VALUES %s ) AS S(ORDINAL, PARMNAME, REMARKS) ON %s AND T.ORDINAL = S.ORDINAL WHEN MATCHED THEN UPDATE SET REMARKS = S.REMARKS WHEN NOT MATCHED THEN INSERT (%s, ROWTYPE, ORDINAL, PARMNAME, REMARKS) VALUES (%s, %s, S.ORDINAL, S.PARMNAME, S.REMARKS)%s""" % ( format_ident(self.schema), param_comments, self.get_predicates(predicates), ', '.join(format_ident(k) for k in predicates.iterkeys()), ', '.join(quote_str(v) for v in predicates.itervalues()), type, self.terminator, ) else: param_comments = '' return param_comments
def merge(self, dbobject, table, predicates): if dbobject.description or self.blanks: return """\ MERGE INTO %s.%s T USING TABLE(VALUES(%s)) AS S(REMARKS) ON %s WHEN MATCHED THEN UPDATE SET REMARKS = S.REMARKS WHEN NOT MATCHED THEN INSERT (%s, REMARKS) VALUES (%s, S.REMARKS)%s""" % ( format_ident(self.schema), format_ident(table), self.get_description(dbobject.description), self.get_predicates(predicates, qualifier='T'), ', '.join(format_ident(k) for k in predicates.iterkeys()), ', '.join(quote_str(v) for v in predicates.itervalues()), self.terminator, )
def merge_table(self, o): predicates = { 'TABSCHEMA': o.schema.name, 'TABNAME': o.name, } if o.description or self.blanks: table_comment = self.merge(o, 'TABLES', predicates) else: table_comment = '' field_comments = [ (quote_str(f.name), self.get_description(f.description)) for f in o.field_list if f.description or self.blanks ] if field_comments: max_name_len = max(len(name) for (name, description) in field_comments) field_comments = [ '\t\t(%-*s, %s)' % (max_name_len, name, description) for (name, description) in field_comments ] field_comments = ',\n'.join(field_comments) field_comments = """\ MERGE INTO %s.COLUMNS AS T USING TABLE(VALUES %s ) AS S(COLNAME, REMARKS) ON %s AND T.COLNAME = S.COLNAME WHEN MATCHED THEN UPDATE SET REMARKS = S.REMARKS WHEN NOT MATCHED THEN INSERT (%s, COLNAME, REMARKS) VALUES (%s, S.COLNAME, S.REMARKS)%s""" % ( format_ident(self.schema), field_comments, self.get_predicates(predicates, qualifier='T'), ', '.join(format_ident(k) for k in predicates.iterkeys()), ', '.join(quote_str(v) for v in predicates.itervalues()), self.terminator, ) else: field_comments = '' return '\n'.join(s for s in (table_comment, field_comments) if s)
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) yield 'MERGE INTO %s.TABLES AS T\n' % format_ident(self.schema) yield 'USING TABLE(VALUES\n' yield '\t(%s, %s, CLOB(%s))\n' % (quote_str(schema), quote_str(obj), quote_str(desc)) yield ') AS S(TABSCHEMA, TABNAME, REMARKS)\n' yield 'ON T.TABSCHEMA = S.TABSCHEMA\n' yield 'AND T.TABNAME = S.TABNAME\n' yield 'WHEN MATCHED THEN\n' yield '\tUPDATE REMARKS = S.REMARKS\n' yield 'WHEN NOT MATCHED THEN\n' yield '\tINSERT (TABSCHEMA, TABNAME, REMARKS)\n' yield '\tVALUES (S.TABSCHEMA, S.TABNAME, S.REMARKS)%s\n' % self.terminator yield 'MERGE INTO %s.COLUMNS AS T\n' % format_ident(self.schema) yield 'USING TABLE(VALUES\n' prefix = '' maxlen = max( len(quote_str(column)) + 1 for column in columns.iterkeys() ) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) yield '%s\t(%s, %s, %-*s CLOB(%s))\n' % ( prefix, quote_str(schema), quote_str(obj), maxlen, quote_str(column) + ',', quote_str(desc) ) prefix = ',' yield ') AS S(TABSCHEMA, TABNAME, COLNAME, REMARKS)\n' yield 'ON T.TABSCHEMA = S.TABSCHEMA\n' yield 'AND T.TABNAME = S.TABNAME\n' yield 'AND T.COLNAME = S.COLNAME\n' yield 'WHEN MATCHED THEN\n' yield '\tUPDATE REMARKS = S.REMARKS\n' yield 'WHEN NOT MATCHED THEN\n' yield '\tINSERT (TABSCHEMA, TABNAME, COLNAME, REMARKS)\n' yield '\tVALUES (S.TABSCHEMA, S.TABNAME, S.COLNAME, S.REMARKS)%s\n' % self.terminator yield '\n'
def merge_table(self, o): predicates = { 'TABSCHEMA': o.schema.name, 'TABNAME': o.name, } if o.description or self.blanks: table_comment = self.merge(o, 'TABLES', predicates) else: table_comment = '' field_comments = [(quote_str(f.name), self.get_description(f.description)) for f in o.field_list if f.description or self.blanks] if field_comments: max_name_len = max( len(name) for (name, description) in field_comments) field_comments = [ '\t\t(%-*s, %s)' % (max_name_len, name, description) for (name, description) in field_comments ] field_comments = ',\n'.join(field_comments) field_comments = """\ MERGE INTO %s.COLUMNS AS T USING TABLE(VALUES %s ) AS S(COLNAME, REMARKS) ON %s AND T.COLNAME = S.COLNAME WHEN MATCHED THEN UPDATE SET REMARKS = S.REMARKS WHEN NOT MATCHED THEN INSERT (%s, COLNAME, REMARKS) VALUES (%s, S.COLNAME, S.REMARKS)%s""" % ( format_ident(self.schema), field_comments, self.get_predicates(predicates, qualifier='T'), ', '.join(format_ident(k) for k in predicates.iterkeys()), ', '.join(quote_str(v) for v in predicates.itervalues()), self.terminator, ) else: field_comments = '' return '\n'.join(s for s in (table_comment, field_comments) if s)
def merge_param_type(self, o, type): param_comments = [ (p.position, quote_str(p.name), self.get_description(p.description)) for p in o.param_list if p.type == type and (p.description or self.blanks) ] predicates = { 'ROUTINESCHEMA': o.schema.name, 'SPECIFICNAME': o.specific_name, 'ROWTYPE': {'I': 'P'}.get(type, type), } if param_comments: max_name_len = max(len(name) for (pos, name, description) in param_comments) max_pos_len = max(len(str(pos)) for (pos, name, description) in param_comments) param_comments = [ '\t\t(%-*d, %-*s, %s)' % (max_pos_len, pos, max_name_len, name, description) for (pos, name, description) in param_comments ] param_comments = ',\n'.join(param_comments) param_comments = """\ MERGE INTO %s.ROUTINEPARMS AS T USING TABLE(VALUES %s ) AS S(ORDINAL, PARMNAME, REMARKS) ON %s AND T.ORDINAL = S.ORDINAL WHEN MATCHED THEN UPDATE SET REMARKS = S.REMARKS WHEN NOT MATCHED THEN INSERT (%s, ROWTYPE, ORDINAL, PARMNAME, REMARKS) VALUES (%s, %s, S.ORDINAL, S.PARMNAME, S.REMARKS)%s""" %( format_ident(self.schema), param_comments, self.get_predicates(predicates), ', '.join(format_ident(k) for k in predicates.iterkeys()), ', '.join(quote_str(v) for v in predicates.itervalues()), type, self.terminator, ) else: param_comments = '' return param_comments
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) if len(desc) > self.maxlen: logging.warning('Description for object %s.%s has been truncated' % (schema, obj)) desc = desc[:self.maxlen - 3] + '...' yield 'COMMENT ON TABLE %s.%s IS %s%s\n' % ( format_ident(schema), format_ident(obj), quote_str(desc), self.terminator, ) yield 'COMMENT ON %s.%s (\n' % ( format_ident(schema), format_ident(obj), ) prefix = '' maxlen = max( len(format_ident(column)) for column in columns.iterkeys() ) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) if len(desc) > self.maxlen: logging.warning('Description for column %s.%s.%s has been truncated' % (schema, obj, column)) desc = desc[:self.maxlen - 3] + '...' yield '%s\t%-*s IS %s\n' % ( prefix, maxlen, format_ident(column), quote_str(desc) ) prefix = ',' yield ')%s\n' % self.terminator yield '\n'
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) if len(desc) > self.maxlen: logging.warning( 'Description for object %s.%s has been truncated' % (schema, obj)) desc = desc[:self.maxlen - 3] + '...' yield 'COMMENT ON TABLE %s.%s IS %s%s\n' % ( format_ident(schema), format_ident(obj), quote_str(desc), self.terminator, ) yield 'COMMENT ON %s.%s (\n' % ( format_ident(schema), format_ident(obj), ) prefix = '' maxlen = max( len(format_ident(column)) for column in columns.iterkeys()) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) if len(desc) > self.maxlen: logging.warning( 'Description for column %s.%s.%s has been truncated' % (schema, obj, column)) desc = desc[:self.maxlen - 3] + '...' yield '%s\t%-*s IS %s\n' % ( prefix, maxlen, format_ident(column), quote_str(desc)) prefix = ',' yield ')%s\n' % self.terminator yield '\n'
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) yield 'UPDATE %s.TABLES\n' % format_ident(self.schema) yield 'SET\n' yield '\tREMARKS = CLOB(%s)\n' % quote_str(desc) yield 'WHERE\n' yield '\tTABSCHEMA = %s\n' % quote_str(schema) yield '\tAND TABNAME = %s%s\n' % (quote_str(obj), self.terminator) yield 'UPDATE %s.COLUMNS\n' % format_ident(self.schema) yield 'SET\n' yield '\tREMARKS = CASE COLNAME\n' maxlen = max( len(quote_str(column)) + 1 for column in columns.iterkeys()) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) yield '\t\tWHEN %-*s THEN CLOB(%s)\n' % ( maxlen, quote_str(column), quote_str(desc)) yield '\tEND\n' yield 'WHERE\n' yield '\tTABSCHEMA = %s\n' % quote_str(schema) yield '\tAND TABNAME = %s%s\n' % (quote_str(obj), self.terminator) yield '\n'
def __iter__(self): for (schema, obj, desc, columns) in self.retriever: logging.info('Generating SQL for object %s.%s' % (schema, obj)) yield 'MERGE INTO %s.TABLES AS T\n' % format_ident(self.schema) yield 'USING TABLE(VALUES\n' yield '\t(%s, %s, CLOB(%s))\n' % (quote_str(schema), quote_str(obj), quote_str(desc)) yield ') AS S(TABSCHEMA, TABNAME, REMARKS)\n' yield 'ON T.TABSCHEMA = S.TABSCHEMA\n' yield 'AND T.TABNAME = S.TABNAME\n' yield 'WHEN MATCHED THEN\n' yield '\tUPDATE REMARKS = S.REMARKS\n' yield 'WHEN NOT MATCHED THEN\n' yield '\tINSERT (TABSCHEMA, TABNAME, REMARKS)\n' yield '\tVALUES (S.TABSCHEMA, S.TABNAME, S.REMARKS)%s\n' % self.terminator yield 'MERGE INTO %s.COLUMNS AS T\n' % format_ident(self.schema) yield 'USING TABLE(VALUES\n' prefix = '' maxlen = max( len(quote_str(column)) + 1 for column in columns.iterkeys()) for (column, desc) in sorted(columns.iteritems()): logging.debug('Generating SQL for column %s' % column) yield '%s\t(%s, %s, %-*s CLOB(%s))\n' % ( prefix, quote_str(schema), quote_str(obj), maxlen, quote_str(column) + ',', quote_str(desc)) prefix = ',' yield ') AS S(TABSCHEMA, TABNAME, COLNAME, REMARKS)\n' yield 'ON T.TABSCHEMA = S.TABSCHEMA\n' yield 'AND T.TABNAME = S.TABNAME\n' yield 'AND T.COLNAME = S.COLNAME\n' yield 'WHEN MATCHED THEN\n' yield '\tUPDATE REMARKS = S.REMARKS\n' yield 'WHEN NOT MATCHED THEN\n' yield '\tINSERT (TABSCHEMA, TABNAME, COLNAME, REMARKS)\n' yield '\tVALUES (S.TABSCHEMA, S.TABNAME, S.COLNAME, S.REMARKS)%s\n' % self.terminator yield '\n'
def update_param_type(self, o, type): param_comments = [(p.position, p.name, self.get_description(p.description)) for p in o.param_list if p.type == type and (p.description or self.blanks)] predicates = { 'ROUTINESCHEMA': o.schema.name, 'SPECIFICNAME': o.specific_name, 'ROWTYPE': { 'I': 'P' }.get(type, type), } if param_comments: max_name_len = max( len(name) for (pos, name, description) in param_comments) max_pos_len = max( len(str(pos)) for (pos, name, description) in param_comments) param_comments = [ '\t\tWHEN %-*d /* %-*s */ THEN %s' % (max_pos_len, pos, max_name_len, name, description) for (pos, name, description) in param_comments ] if not self.blanks: param_comments.append('\t\tELSE REMARKS') param_comments = '\n'.join(param_comments) param_comments = """\ UPDATE %s.ROUTINEPARMS SET REMARKS = CASE ORDINAL %s END WHERE %s%s""" % ( format_ident(self.schema), param_comments, self.get_predicates(predicates), self.terminator, ) else: param_comments = '' return param_comments
def update_table(self, o): predicates = { 'TABSCHEMA': o.schema.name, 'TABNAME': o.name, } if o.description or self.blanks: table_comment = self.update(o, 'TABLES', predicates) else: table_comment = '' field_comments = [(quote_str(f.name), self.get_description(f.description)) for f in o.field_list if f.description or self.blanks] if field_comments: max_name_len = max( len(name) for (name, description) in field_comments) field_comments = [ '\t\tWHEN %-*s THEN %s' % (max_name_len, name, description) for (name, description) in field_comments ] if not self.blanks: field_comments.append('\t\tELSE REMARKS') field_comments = '\n'.join(field_comments) field_comments = """\ UPDATE %s.COLUMNS SET REMARKS = CASE COLNAME %s END WHERE %s%s""" % ( format_ident(self.schema), field_comments, self.get_predicates(predicates), self.terminator, ) else: field_comments = '' return '\n'.join(s for s in (table_comment, field_comments) if s)
def update_table(self, o): predicates = { 'TABSCHEMA': o.schema.name, 'TABNAME': o.name, } if o.description or self.blanks: table_comment = self.update(o, 'TABLES', predicates) else: table_comment = '' field_comments = [ (quote_str(f.name), self.get_description(f.description)) for f in o.field_list if f.description or self.blanks ] if field_comments: max_name_len = max(len(name) for (name, description) in field_comments) field_comments = [ '\t\tWHEN %-*s THEN %s' % (max_name_len, name, description) for (name, description) in field_comments ] if not self.blanks: field_comments.append('\t\tELSE REMARKS') field_comments = '\n'.join(field_comments) field_comments = """\ UPDATE %s.COLUMNS SET REMARKS = CASE COLNAME %s END WHERE %s%s""" % ( format_ident(self.schema), field_comments, self.get_predicates(predicates), self.terminator, ) else: field_comments = '' return '\n'.join(s for s in (table_comment, field_comments) if s)