changeset 318:0aad38fbc361

finished replacing descQueries with metaqueries
author Catherine Devlin <catherine.devlin@gmail.com>
date Tue, 31 Mar 2009 13:02:34 -0400
parents f200a222a936
children 3c58df9bcf14
files sqlpython/metadata.py sqlpython/sqlpyPlus.py
diffstat 2 files changed, 57 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/metadata.py	Tue Mar 31 12:03:49 2009 -0400
+++ b/sqlpython/metadata.py	Tue Mar 31 13:02:34 2009 -0400
@@ -3,8 +3,8 @@
 metaqueries = defaultdict(defaultdict)
 
 metaqueries['desc']['oracle'] = defaultdict(defaultdict)
-metaqueries['desc']['oracle']['TABLE']['long'] = """
-SELECT atc.column_id "#",
+metaqueries['desc']['oracle']['TABLE']['long'] = (
+"""SELECT atc.column_id "#",
 atc.column_name,
 CASE atc.nullable WHEN 'Y' THEN 'NULL' ELSE 'NOT NULL' END "Null?",
 atc.data_type ||
@@ -22,10 +22,10 @@
 JOIN all_col_comments acc ON (acc.owner = atc.owner AND acc.table_name = atc.table_name AND acc.column_name = atc.column_name)
 WHERE atc.table_name = :object_name
 AND      atc.owner = :owner
-ORDER BY atc.column_id;"""
+ORDER BY atc.column_id;""",)
 
-metaqueries['desc']['oracle']['TABLE']['short'] = """
-SELECT atc.column_name,
+metaqueries['desc']['oracle']['TABLE']['short'] = (
+"""SELECT atc.column_name,
 CASE atc.nullable WHEN 'Y' THEN 'NULL' ELSE 'NOT NULL' END "Null?",
 atc.data_type ||
 CASE atc.data_type WHEN 'DATE' THEN ''
@@ -40,10 +40,10 @@
 FROM all_tab_columns atc
 WHERE atc.table_name = :object_name
 AND      atc.owner = :owner
-ORDER BY atc.column_id;"""
+ORDER BY atc.column_id;""",)
 
-metaqueries['desc']['oracle']['PROCEDURE'] = """
-SELECT NVL(argument_name, 'Return Value') argument_name,             
+metaqueries['desc']['oracle']['PROCEDURE'] = (
+"""SELECT NVL(argument_name, 'Return Value') argument_name,             
 data_type,
 in_out,
 default_value
@@ -51,16 +51,16 @@
 WHERE object_name = :object_name
 AND      owner = :owner
 AND      package_name IS NULL
-ORDER BY sequence;"""
+ORDER BY sequence;""",)
 
-metaqueries['desc']['oracle']['PackageObjects'] = """
-SELECT DISTINCT object_name
+metaqueries['desc']['oracle']['PackageObjects'] = (
+"""SELECT DISTINCT object_name
 FROM all_arguments
 WHERE package_name = :package_name
-AND      owner = :owner"""
+AND      owner = :owner""",)
 
-metaqueries['desc']['oracle']['PackageObjArgs'] = """
-SELECT object_name,
+metaqueries['desc']['oracle']['PackageObjArgs'] = (
+"""SELECT object_name,
 argument_name,             
 data_type,
 in_out,
@@ -70,4 +70,44 @@
 AND      object_name = :object_name
 AND      owner = :owner
 AND      argument_name IS NOT NULL
-ORDER BY sequence;"""
+ORDER BY sequence;""",)
+
+metaqueries['desc']['oracle']['TRIGGER'] = (
+"""SELECT description
+FROM   all_triggers
+WHERE  owner = :owner
+AND    trigger_name = :object_name;
+""",
+"""SELECT table_owner,
+base_object_type,
+table_name,
+column_name,
+when_clause,
+status,
+action_type,
+crossedition
+FROM   all_triggers
+WHERE  owner = :owner
+AND    trigger_name = :object_name
+\\t""",)
+
+
+metaqueries['desc']['oracle']['INDEX'] = (
+"""SELECT index_type,
+table_owner,
+table_name,
+table_type,
+uniqueness,
+compression,
+partitioned,
+temporary,
+generated,
+secondary,
+dropped,
+visibility
+FROM   all_indexes
+WHERE  owner = :owner
+AND    index_name = :object_name\\t""",)
+
+metaqueries['desc']['oracle']['VIEW'] = metaqueries['desc']['oracle']['TABLE']['short']
+metaqueries['desc']['oracle']['FUNCTION'] = metaqueries['desc']['oracle']['PROCEDURE']
--- a/sqlpython/sqlpyPlus.py	Tue Mar 31 12:03:49 2009 -0400
+++ b/sqlpython/sqlpyPlus.py	Tue Mar 31 13:02:34 2009 -0400
@@ -33,80 +33,6 @@
 except (RuntimeError, ImportError):
     pass
 
-#TODO: keep DECLARE blocks in history; Oracle error location; YASQL-like SHOW x ON y;
-# round-trip PL/SQL packages; print/stdout inconsistency; \dt (show triggers);
-# spell check
-descQueries = {
-'PROCEDURE': ("""
-SELECT NVL(argument_name, 'Return Value') argument_name,             
-data_type,
-in_out,
-default_value
-FROM all_arguments
-WHERE object_name = :object_name
-AND      owner = :owner
-AND      package_name IS NULL
-ORDER BY sequence;""",),    
-'PackageObjects':("""
-SELECT DISTINCT object_name
-FROM all_arguments
-WHERE package_name = :package_name
-AND      owner = :owner""",),
-'PackageObjArgs':("""
-SELECT object_name,
-argument_name,             
-data_type,
-in_out,
-default_value
-FROM all_arguments
-WHERE package_name = :package_name
-AND      object_name = :object_name
-AND      owner = :owner
-AND      argument_name IS NOT NULL
-ORDER BY sequence;""",),
-'TRIGGER':("""
-SELECT description
-FROM   all_triggers
-WHERE  owner = :owner
-AND    trigger_name = :object_name;
-""",
-"""
-SELECT table_owner,
-base_object_type,
-table_name,
-column_name,
-when_clause,
-status,
-action_type,
-crossedition
-FROM   all_triggers
-WHERE  owner = :owner
-AND    trigger_name = :object_name
-\\t
-""",
-),
-'INDEX':("""
-SELECT index_type,
-table_owner,
-table_name,
-table_type,
-uniqueness,
-compression,
-partitioned,
-temporary,
-generated,
-secondary,
-dropped,
-visibility
-FROM   all_indexes
-WHERE  owner = :owner
-AND    index_name = :object_name
-\\t
-""",)
-}
-descQueries['VIEW'] = metaqueries['desc']['oracle']['TABLE']['short']
-descQueries['FUNCTION'] = descQueries['PROCEDURE'] 
-
 queries = {
 'resolve': """
 SELECT object_type, object_name, owner FROM (
@@ -993,9 +919,9 @@
                 if opts.long:
                     self._execute(queries['tabComments'], {'table_name':object_name, 'owner':owner})
                     self.stdout.write(self.curs.fetchone()[0])
-                descQ = metaqueries['desc'][object_type][self.rdbms][(opts.long and 'long') or 'short']
+                descQ = metaqueries['desc'][self.rdbms][object_type][(opts.long and 'long') or 'short']
             else:
-                descQ = descQueries[object_type][opts.long]                
+                descQ = metaqueries['desc'][self.rdbms][object_type]
             for q in descQ:
                 self.do_select(self.parsed(q, terminator=arg.parsed.terminator or ';' , suffix=arg.parsed.suffix), 
                                bindVarsIn={'object_name':object_name, 'owner':owner})