Mercurial > sqlpython
comparison sqlpyPlus.py @ 144:5a021524805a
fixed do_resolve
author | catherine@Elli.myhome.westell.com |
---|---|
date | Tue, 23 Sep 2008 07:29:30 -0400 |
parents | 3b3c78bad48f |
children | 7e5105efa15d |
comparison
equal
deleted
inserted
replaced
143:24b5daa7ebe1 | 144:5a021524805a |
---|---|
1 """sqlpyPlus - extra features (inspired by Oracle SQL*Plus) for Luca Canali's sqlpython.py | 1 """sqlpyPlus - extra features (inspired by Oracle SQL*Plus) for Luca Canali's sqlpython.py |
2 | 2 |
3 Features include: | 3 Features include: |
4 - SQL*Plus-style bind variables | 4 - SQL*Plus-style bind variables |
5 - Query result stored in special bind variable ":_" if one row, one item | 5 - Query result stored in special bind variable ":_" if one row, one item |
6 - SQL buffer with list, run, ed, get, etc.; unlike SQL*Plus, buffer stores session's full history | 6 - SQL buffer with list, run, ed, get, etc.; unlike SQL*Plus, buffer stores session's full history |
557 rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit') | 557 rowlimitPattern = pyparsing.Word(pyparsing.nums)('rowlimit') |
558 terminatorPattern = (pyparsing.oneOf('; \\s \\S \\c \\C \\t \\x \\h') | 558 terminatorPattern = (pyparsing.oneOf('; \\s \\S \\c \\C \\t \\x \\h') |
559 ^ pyparsing.Literal('\n/') ^ \ | 559 ^ pyparsing.Literal('\n/') ^ \ |
560 (pyparsing.Literal('\nEOF') + pyparsing.stringEnd)) \ | 560 (pyparsing.Literal('\nEOF') + pyparsing.stringEnd)) \ |
561 ('terminator') + \ | 561 ('terminator') + \ |
562 pyparsing.Optional(rowlimitPattern) | 562 pyparsing.Optional(rowlimitPattern) + \ |
563 pyparsing.FollowedBy(pyparsing.LineEnd()) | |
563 def do_select(self, arg, bindVarsIn=None, override_terminator=None): | 564 def do_select(self, arg, bindVarsIn=None, override_terminator=None): |
564 """Fetch rows from a table. | 565 """Fetch rows from a table. |
565 | 566 |
566 Limit the number of rows retrieved by appending | 567 Limit the number of rows retrieved by appending |
567 an integer after the terminator | 568 an integer after the terminator |
605 | 606 |
606 @options([make_option('-f', '--full', action='store_true', help='get dependent objects as well')]) | 607 @options([make_option('-f', '--full', action='store_true', help='get dependent objects as well')]) |
607 def do_pull(self, arg, opts): | 608 def do_pull(self, arg, opts): |
608 """Displays source code.""" | 609 """Displays source code.""" |
609 | 610 |
610 arg = self.parsed(arg).unterminated | 611 arg = self.parsed(arg).unterminated.upper() |
611 object_type, owner, object_name = self.resolve(arg.upper()) | 612 object_type, owner, object_name = self.resolve(arg) |
612 if not object_type: | 613 if not object_type: |
613 return | 614 return |
614 self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) | 615 self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name)) |
615 self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, | 616 self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, |
616 [object_type, object_name, owner]))) | 617 [object_type, object_name, owner]))) |
726 object_type, owner, object_name = '', '', '' | 727 object_type, owner, object_name = '', '', '' |
727 return object_type, owner, object_name | 728 return object_type, owner, object_name |
728 #todo: resolve not finding cwm$ table | 729 #todo: resolve not finding cwm$ table |
729 | 730 |
730 def do_resolve(self, arg): | 731 def do_resolve(self, arg): |
731 self.stdout.write(self.resolve(arg)+'\n') | 732 arg = self.parsed(arg).unterminated.upper() |
733 self.stdout.write(','.join(self.resolve(arg))+'\n') | |
732 | 734 |
733 def spoolstop(self): | 735 def spoolstop(self): |
734 if self.spoolFile: | 736 if self.spoolFile: |
735 self.stdout = self.stdoutBeforeSpool | 737 self.stdout = self.stdoutBeforeSpool |
736 print 'Finished spooling to ', self.spoolFile.name | 738 print 'Finished spooling to ', self.spoolFile.name |