changeset 465:0be350ab306c

fixed \dt
author catherine@Drou
date Tue, 02 Mar 2010 15:58:31 -0500
parents 26f60d5910a0
children 750da8dd1253
files sqlpython/connections.py sqlpython/pgSession.txt sqlpython/sqlpyPlus.py
diffstat 3 files changed, 184 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Mon Mar 01 23:26:38 2010 -0500
+++ b/sqlpython/connections.py	Tue Mar 02 15:58:31 2010 -0500
@@ -43,6 +43,7 @@
         if r'\.' in pattern:
             return compiled.match(self.fullname) or compiled.match(self.path)
         return right_owner and (compiled.match(self.type) or 
+                                compiled.match(self.type + r'/') or
                                  compiled.match(self.unqualified_name) or
                                  compiled.match(self.unqualified_path))
         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sqlpython/pgSession.txt	Tue Mar 02 15:58:31 2010 -0500
@@ -0,0 +1,172 @@
+Transcript file for testing of sqlpython; run tests with 
+`python mysqlpy.py --test pgSession.txt`.
+The database ``testplatform`` must be running and must include 
+user ``testuser``, password ``testpassword``, with full rights on
+schema ``testuser``.
+
+SQL.No_Connection> set color off
+
+SQL.No_Connection> connect --postgres --password=testpassword testplatform testuser
+0:testuser@testplatform> drop table play;
+/.*/
+
+0:testuser@testplatform> rollback;
+
+Executed
+
+0:testuser@testplatform> CREATE TABLE play (
+>   title VARCHAR(40) CONSTRAINT xpk_play PRIMARY KEY,
+>   author VARCHAR(40));
+
+Executed
+
+0:testuser@testplatform> INSERT INTO play VALUES ('Twelfth Night', 'Shakespeare');
+
+Executed (1 rows)
+
+0:testuser@testplatform> INSERT INTO play VALUES ('The Tempest', 'Shakespeare');
+ 
+Executed (1 rows)
+
+0:testuser@testplatform> cat play
+
+title         author     
+------------- -----------
+Twelfth Night Shakespeare
+The Tempest   Shakespeare
+
+2 rows selected.
+
+0:testuser@testplatform> INSERT INTO play VALUES ('Agamemnon', 'Aeschylus'),
+>   ('Dreigroschenoper', 'Brecht'),
+>   ('Faust', 'Goethe');
+
+Executed (3 rows)
+
+0:testuser@testplatform> commit;
+
+Executed
+
+0:testuser@testplatform> select
+> *
+> from
+> play
+> ;
+
+title            author     
+---------------- -----------
+Twelfth Night    Shakespeare
+The Tempest      Shakespeare
+Agamemnon        Aeschylus  
+Dreigroschenoper Brecht     
+Faust            Goethe     
+
+5 rows selected.
+
+0:testuser@testplatform> ls
+0:testuser@testplatform> refresh
+0:testuser@testplatform> ls
+table/play
+0:testuser@testplatform> ls -l
+table/play
+0:testuser@testplatform> ls table/*
+table/play
+0:testuser@testplatform> desc play
+play
+Name   Nullable Type       
+------ -------- -----------
+title  NOT NULL varchar(40)
+author NULL     varchar(40)
+
+0:testuser@testplatform> COMMENT ON COLUMN play.author IS 'Primary author (if multiple)';
+
+Executed
+
+0:testuser@testplatform> COMMENT ON TABLE play IS 'I like plays.';
+
+Executed
+
+-- undone: reading comments!
+-- ls -l
+-- bind variable set using quotes fails
+-- \dt total fail
+-- set color off fail (in testing; weird)
+
+0:testuser@testplatform> :author = Shakespeare
+0:testuser@testplatform> select * from play where author = %(author)s;
+
+title         author     
+------------- -----------
+Twelfth Night Shakespeare
+The Tempest   Shakespeare
+
+2 rows selected.
+
+0:testuser@testplatform> py binds['author'] = 'Brecht'
+0:testuser@testplatform> select * from play where author = %(author)s;
+
+title            author
+---------------- ------
+Dreigroschenoper Brecht
+
+1 row selected.
+
+0:testuser@testplatform> select * from play where author = %(author)s\c
+
+
+title,author
+"Dreigroschenoper","Brecht"
+
+1 row selected.
+
+0:testuser@testplatform> select * from play where author = %(author)s\i
+
+
+INSERT INTO play (title, author) VALUES ('Dreigroschenoper', 'Brecht');
+
+1 row selected.
+
+
+0:testschema@orcl> select * from play where author='Shakespeare'\t
+
+
+COLUMN NAME ROW N.1       ROW N.2
+----------- ------------- -----------
+TITLE       Twelfth Night The Tempest
+AUTHOR      Shakespeare   Shakespeare
+
+2 rows selected.
+
+0:testuser@testplatform> set autobind on
+autobind - was: False
+now: True
+0:testuser@testplatform> grep -i aesch play
+play
+
+title     author   
+--------- ---------
+Agamemnon Aeschylus
+
+1 row selected.
+
+0:testuser@testplatform> :
+:1 = Agamemnon
+:2 = Aeschylus
+:author = Aeschylus
+:title = Agamemnon
+0:testuser@testplatform> cat play where title = :1
+syntax error at or near ":"
+LINE 1: select * FROM play where title = :1
+                                         ^
+
+0:testuser@testplatform> cat play where title = %(1)s
+
+title     author   
+--------- ---------
+Agamemnon Aeschylus
+
+1 row selected.
+
+0:testuser@testplatform> drop table play;
+
+Executed
--- a/sqlpython/sqlpyPlus.py	Mon Mar 01 23:26:38 2010 -0500
+++ b/sqlpython/sqlpyPlus.py	Tue Mar 02 15:58:31 2010 -0500
@@ -1244,7 +1244,7 @@
             self.perror(self.do_psql.__doc__)
             
     def _do_dir(self, type, arg, opts):
-        self.do_ls("%s/%s%s%s" % (type, str(arg), arg.parsed.terminator, arg.parsed.suffix), opts)
+        self._do_ls("%s/%s%s%s" % (type, str(arg), arg.parsed.terminator, arg.parsed.suffix), opts)
 
     standard_options = [
               all_users_option,
@@ -1581,18 +1581,22 @@
             if descrip.match_pattern(seek, specific_owner = ((not opts.all) and username)):
                 yield descrip
    
+    def _do_ls(self, arg, opts):
+        'Functional core of ``do_ls``, split out into an undecorated version to be callable from other methods'
+        opts.exact = True
+        (username, schemas) = self.metadata()
+        result = [descrip.path for descrip in self._matching_database_objects(arg, opts)]
+        if result:
+            result.sort(reverse=bool(opts.reverse))
+            self.poutput('\n'.join(result))
+                
     @options(standard_options)
     def do_ls(self, arg, opts):
         '''
         Lists objects as through they were in an {object_type}/{object_name} UNIX
         directory structure.  `*` and `%` may be used as wildcards.
         '''
-        opts.exact = True
-        (username, schemas) = self.metadata()
-        result = [descrip.path for descrip in self._matching_database_objects(arg, opts)]
-        if result:
-            result.sort(reverse=bool(opts.reverse))
-            self.poutput('\n'.join(result))
+        return self._do_ls(arg, opts)
         
     @options([make_option('-i', '--ignore-case', dest='ignorecase', action='store_true', help='Case-insensitive search'),
               make_option('-a', '--all', action='store_true', help="all schemas' objects")])