changeset 511:9dbf99653136

fixed body ddl for packages
author catherine.devlin@gmail.com
date Fri, 24 Sep 2010 20:38:00 -0400
parents c8de86e7cd06
children eccf817b0fbc
files sqlpython/sqlpyPlus.py
diffstat 1 files changed, 26 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py	Fri Sep 24 19:00:37 2010 -0400
+++ b/sqlpython/sqlpyPlus.py	Fri Sep 24 20:38:00 2010 -0400
@@ -868,30 +868,32 @@
         try:
             for (owner, object_type, name, synonym_name) in self.current_instance.objects(arg, opts):
                 obj = self.current_instance.object_metadata(owner, object_type, name)
-                txt = obj.get_ddl()
-                if opts.get('lines'):
-                    txt = self._with_line_numbers(txt)    
-                if opts.dump:
-                    path = os.path.join(owner.lower(), object_type.lower()).replace(' ', '_')
-                    try:
-                        os.makedirs(path)
-                    except OSError:
-                        pass
-                    filename = os.path.join(path, '%s.sql' % name.lower())
-                    self.stdout = open(filename, 'w')
-                if opts.get('num') is not None:
-                    txt = txt.splitlines()
-                    txt = centeredSlice(txt, center=opts.num+1, width=opts.width)
-                    txt = '\n'.join(txt)
-                else:
-                    txt = 'REMARK BEGIN %(object_label)s\n%(txt)s\nREMARK END %(object_label)s\n' % {
-                        'object_label': self.object_label(object_type, owner, name, None), 'txt': txt}
-                self.poutput(txt)
-                if opts.dump:
-                    self.stdout.close()
-                    statekeeper.restore()
-                    if vc:
-                        subprocess.call(vc + [filename])                    
+                txts = [(object_type, obj.get_ddl())]
+                if hasattr(obj, 'get_body_ddl'):
+                    txts.append(('PACKAGE BODY', obj.get_body_ddl()))
+                for (object_type, txt) in txts:
+                    if opts.get('lines'):
+                        txt = self._with_line_numbers(txt)    
+                    if opts.dump:
+                        path = os.path.join(owner.lower(), object_type.lower()).replace(' ', '_')
+                        try:
+                            os.makedirs(path)
+                        except OSError:
+                            pass
+                        filename = os.path.join(path, '%s.sql' % name.lower())
+                        self.stdout = open(filename, 'w')
+                    if opts.get('num') is not None:
+                        txt = txt.splitlines()
+                        txt = centeredSlice(txt, center=opts.num+1, width=opts.width)
+                        txt = '\n'.join(txt)
+                    else:
+                        txt = 'REMARK BEGIN\n%s\nREMARK END\n/\n\n' % txt
+                    self.poutput(txt)
+                    if opts.dump:
+                        self.stdout.close()
+                        statekeeper.restore()
+                        if vc:
+                            subprocess.call(vc + [filename])                    
         except:
             statekeeper.restore()
             raise