Mercurial > sqlpython
changeset 165:6b47784322a5
before inserting unittests
author | catherine@Elli.myhome.westell.com |
---|---|
date | Wed, 22 Oct 2008 16:33:37 -0400 |
parents | c04f5c9d0906 |
children | 7e7fd8e12015 |
files | sqlpython/setup_test_db.sql sqlpython/sqlpyPlus.py |
diffstat | 2 files changed, 38 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqlpython/setup_test_db.sql Wed Oct 22 16:33:37 2008 -0400 @@ -0,0 +1,14 @@ +CREATE USER testdata IDENTIFIED BY testdata; +GRANT connect, resource TO testdata; +CONNECT testdata/testdata@orcl +DROP TABLE species; +CREATE TABLE species ( + id NUMBER(6,0) CONSTRAINT xpk_species PRIMARY KEY + CONSTRAINT xnn1_species NOT NULL, + name VARCHAR2(40) CONSTRAINT xnn2_species NOT NULL ); + +INSERT INTO species VALUES (0, 'turtle'); +INSERT INTO species VALUES (1, 'python'); +INSERT INTO species VALUES (2, 'parrot'); + +
--- a/sqlpython/sqlpyPlus.py Mon Sep 29 17:10:51 2008 -0400 +++ b/sqlpython/sqlpyPlus.py Wed Oct 22 16:33:37 2008 -0400 @@ -163,6 +163,15 @@ WHERE atc.table_name = :object_name AND atc.owner = :owner ORDER BY atc.column_id;""", +'oneColComments': """ +atc.column_name, +acc.comments +FROM all_tab_columns atc +JOIN all_col_comments acc ON (atc.owner = acc.owner and atc.table_name = acc.table_name and atc.column_name = acc.column_name) +WHERE atc.table_name = :object_name +AND atc.owner = :owner +AND acc.column_name = :column_name +ORDER BY atc.column_id;""", #thanks to Senora.pm for "refs" 'refs': """ NULL referenced_by, @@ -647,11 +656,12 @@ def do_comments(self, arg): 'Prints comments on a table and its columns.' arg = self.parsed(arg).unterminated.upper() - object_type, owner, object_name = self.resolve(arg) + object_type, owner, object_name, colName = self.resolve_with_column(arg) if object_type: self.curs.execute(queries['tabComments'],{'table_name':object_name, 'owner':owner}) self.stdout.write("%s %s.%s: %s\n" % (object_type, owner, object_name, self.curs.fetchone()[0])) - self.do_select(queries['colComments'],bindVarsIn={'owner':owner, 'object_name': object_name}) + query = 'oneColComments' if colName else 'colComments' + self.do_select(queries[query],bindVarsIn={'owner':owner, 'object_name': object_name, 'column_name': colName}) def resolve(self, identifier): """Checks (my objects).name, (my synonyms).name, (public synonyms).name @@ -667,11 +677,22 @@ object_name = parts[0] self.curs.execute(queries['resolve'], {'objName':object_name}) object_type, object_name, owner = self.curs.fetchone() - except TypeError: + except (TypeError, IndexError): print 'Could not resolve object %s.' % identifier object_type, owner, object_name = '', '', '' return object_type, owner, object_name + def resolve_with_column(self, identifier): + colName = None + object_type, owner, object_name = self.resolve(identifier) + if not object_type: + parts = identifier.split('.') + if len(parts) > 1: + colName = parts[-1] + identifier = '.'.join(parts[:-1]) + object_type, owner, object_name = self.resolve(identifier) + return object_type, owner, object_name, colName + def do_resolve(self, arg): arg = self.parsed(arg).unterminated.upper() self.stdout.write(','.join(self.resolve(arg))+'\n')