changeset 246:b5d4a122354a

can round-trip a package now
author catherine@dellzilla
date Wed, 04 Mar 2009 14:52:02 -0500
parents 05c90f80815c
children f0f293d83337
files sqlpython/sqlpyPlus.py sqlpython/sqlpython.py
diffstat 2 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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=''):