# HG changeset patch # User catherine@dellzilla # Date 1236196322 18000 # Node ID b5d4a122354ae68ad7b7512e5f74d18e5260f0e6 # Parent 05c90f80815c16ec4890d32cdb85b0a1f1a8692e can round-trip a package now diff -r 05c90f80815c -r b5d4a122354a sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Wed Mar 04 14:05:18 2009 -0500 +++ b/sqlpython/sqlpyPlus.py Wed Mar 04 14:52:02 2009 -0500 @@ -316,7 +316,8 @@ return dict.pop(self, key.lower(), def_val) class Parser(object): - comment_def = "--" + pyparsing.ZeroOrMore(pyparsing.CharsNotIn("\n")) + #comment_def = "--" + pyparsing.ZeroOrMore(pyparsing.CharsNotIn("\n")) + comment_def = "--" + ~ ('-' + pyparsing.CaselessKeyword('begin')) + pyparsing.ZeroOrMore(pyparsing.CharsNotIn("\n")) def __init__(self, scanner, retainSeparator=True): self.scanner = scanner self.scanner.ignore(pyparsing.sglQuotedString) @@ -360,6 +361,7 @@ create drop alter _multiline_comment'''.split() sqlpython.sqlpython.noSpecialParse.append('spool') commentGrammars = pyparsing.Or([pyparsing.Literal('--') + pyparsing.restOfLine, pyparsing.cStyleComment]) + commentGrammars = pyparsing.Or([Parser.comment_def, pyparsing.cStyleComment]) defaultFileName = 'afiedt.buf' def __init__(self): sqlpython.sqlpython.__init__(self) @@ -669,11 +671,14 @@ if vc: subprocess.call(vc + [filename]) try: - if object_type in ['CONTEXT', 'DIRECTORY', 'JOB']: - ddlargs = [object_type, object_name] + if object_type == 'PACKAGE': + ddl = [['PACKAGE_SPEC', object_name, owner],['PACKAGE_BODY', object_name, owner]] + elif object_type in ['CONTEXT', 'DIRECTORY', 'JOB']: + ddl = [[object_type, object_name]] else: - ddlargs = [object_type, object_name, owner] - self.stdout.write('REMARK BEGIN %s\n%s\nREMARK END\n\n' % (object_name, str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, ddlargs)))) + ddl = [[object_type, object_name, owner]] + for ddlargs in ddl: + self.stdout.write('REMARK BEGIN %s\n%s\nREMARK END\n\n' % (object_name, str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, ddlargs)))) except cx_Oracle.DatabaseError: if object_type == 'JOB': print '%s: DBMS_METADATA.GET_DDL does not support JOBs (MetaLink DocID 567504.1)' % object_name diff -r 05c90f80815c -r b5d4a122354a sqlpython/sqlpython.py --- a/sqlpython/sqlpython.py Wed Mar 04 14:05:18 2009 -0500 +++ b/sqlpython/sqlpython.py Wed Mar 04 14:52:02 2009 -0500 @@ -92,7 +92,11 @@ def default(self, arg): self.varsUsed = sqlpyPlus.findBinds(arg, self.binds, givenBindVars={}) - self.curs.execute('%s %s' % (arg.parsed.command, arg.parsed.args), self.varsUsed) + if arg.parsed.command.lower() in ('create',): + command = '%s %s;' + else: + command = '%s %s' + self.curs.execute(command % (arg.parsed.command, arg.parsed.args), self.varsUsed) print '\nExecuted%s\n' % ((self.curs.rowcount > 0) and ' (%d rows)' % self.curs.rowcount or '') def do_commit(self, arg=''):