Mercurial > sqlpython
changeset 76:9427aa0726fa
hopefully merged
author | catherine@cordelia |
---|---|
date | Mon, 21 Apr 2008 09:35:31 -0400 |
parents | 2060f9e4b27b (diff) 1551db32abff (current diff) |
children | 4b5d4e5798dd |
files | sqlpyPlus.py |
diffstat | 1 files changed, 52 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpyPlus.py Thu Apr 10 15:10:20 2008 -0400 +++ b/sqlpyPlus.py Mon Apr 21 09:35:31 2008 -0400 @@ -537,17 +537,16 @@ options, arg = self.pullflags.parse(arg) object_type, owner, object_name = self.resolve(arg.strip(self.terminator).upper()) - if object_type and owner and object_name: - self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) - self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, - [object_type, object_name, owner]))) - if options.has_key('full'): - for dependent_type in ('OBJECT_GRANT', 'CONSTRAINT', 'TRIGGER'): - try: - self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DEPENDENT_DDL', cx_Oracle.CLOB, - [dependent_type, object_name, owner]))) - except cx_Oracle.DatabaseError: - pass + self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) + self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, + [object_type, object_name, owner]))) + if options.has_key('full'): + for dependent_type in ('OBJECT_GRANT', 'CONSTRAINT', 'TRIGGER'): + try: + self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DEPENDENT_DDL', cx_Oracle.CLOB, + [dependent_type, object_name, owner]))) + except cx_Oracle.DatabaseError: + pass findflags = flagReader.FlagSet([flagReader.Flag('insensitive')]) def do_find(self, arg): @@ -743,30 +742,61 @@ except KeyError: self.stdout.write('No bind variable %s\n' % arg) else: - self.do_setbind('') - def do_setbind(self, arg): - args = arg.split(None, 2) - if len(args) == 0: for (var, val) in self.binds.items(): print ':%s = %s' % (var, val) - elif len(args) == 1: - try: - print ':%s = %s' % (args[0], self.binds[args[0]]) - except KeyError, e: - print noSuchBindMsg % args[0] + + def do_setbind(self, arg): + args = arg.split(None, 2) + if len(args) < 2: + self.do_print(arg) elif len(args) > 2 and args[1] in ('=',':='): var, val = args[0], args[2] if val[0] == val[-1] == "'" and len(val) > 1: val = val[1:-1] - self.binds[var] = val + try: + val = int(val) + except ValueError: + try: + val = float(val) + except ValueError: + val = self.curs.callfunc(val, []) + # submit to sql + + self.binds[var] = val # but what if val is a function call? else: print 'Could not parse ', args + def do_exec(self, arg): if arg[0] == ':': self.do_setbind(arg[1:]) else: - self.default('exec %s;' % arg) + try: + self.curs.execute('begin\n%s;end;' % arg) + except Exception, e: + print e + ''' + exec :x := 'box' + exec :y := sysdate + ''' + def anon_plsql(self, line1): + lines = [line1] + while True: + line = self.pseudo_raw_input(self.continuationPrompt) + if line.strip() == '/': + try: + self.curs.execute('\n'.join(lines)) + except Exception, e: + print e + return + lines.append(line) + + def do_begin(self, arg): + self.anon_plsql('begin ' + arg) + + def do_declare(self, arg): + self.anon_plsql('declare ' + arg) + def do_cat(self, arg): targets = arg.split() for target in targets: