Mercurial > sqlpython
changeset 181:b5114b8828b1
autobind to :1, :2, etc.
author | catherine@Elli.myhome.westell.com |
---|---|
date | Fri, 07 Nov 2008 06:43:06 -0500 |
parents | 9e6c1ec07ebc |
children | 2ab3a24d7974 34d895615a94 |
files | sqlpython/exampleSession.txt sqlpython/sqlpyPlus.py |
diffstat | 2 files changed, 69 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/exampleSession.txt Wed Nov 05 17:01:01 2008 -0500 +++ b/sqlpython/exampleSession.txt Fri Nov 07 06:43:06 2008 -0500 @@ -1,27 +1,27 @@ -SQL.No_Connection> connect testschema/testschema@eqtest -testschema@eqtest> CREATE TABLE play ( +SQL.No_Connection> connect testschema/testschema@orcl +testschema@orcl> CREATE TABLE play ( > title VARCHAR2(40) CONSTRAINT xpk_play PRIMARY KEY, > author VARCHAR2(40)); Executed -testschema@eqtest> INSERT INTO play VALUES ('Twelfth Night', 'Shakespeare'); +testschema@orcl> INSERT INTO play VALUES ('Twelfth Night', 'Shakespeare'); Executed (1 rows) -testschema@eqtest> INSERT INTO play VALUES ('The Tempest', 'Shakespeare'); +testschema@orcl> INSERT INTO play VALUES ('The Tempest', 'Shakespeare'); Executed (1 rows) -testschema@eqtest> INSERT INTO play VALUES ('Agamemnon', 'Aeschylus'); +testschema@orcl> INSERT INTO play VALUES ('Agamemnon', 'Aeschylus'); Executed (1 rows) -testschema@eqtest> commit; +testschema@orcl> commit; Executed -testschema@eqtest> select +testschema@orcl> select > * > from > play; @@ -34,12 +34,24 @@ 3 rows selected. -testschema@eqtest> ls +testschema@orcl> ls + +NAME +-------------- INDEX/XPK_PLAY +TABLE/PLAY + +2 rows selected. + +testschema@orcl> ls table + +NAME +---------- TABLE/PLAY -testschema@eqtest> ls table -TABLE/PLAY -testschema@eqtest> desc play + +1 row selected. + +testschema@orcl> desc play TABLE TESTSCHEMA.PLAY COLUMN_NAME Null? DATA_TYPE @@ -49,15 +61,15 @@ 2 rows selected. -testschema@eqtest> COMMENT ON COLUMN play.author IS 'Primary author (if multiple)'; +testschema@orcl> COMMENT ON COLUMN play.author IS 'Primary author (if multiple)'; Executed -testschema@eqtest> COMMENT ON TABLE play IS 'I like plays.'; +testschema@orcl> COMMENT ON TABLE play IS 'I like plays.'; Executed -testschema@eqtest> comments play +testschema@orcl> comments play TABLE TESTSCHEMA.PLAY: I like plays. COLUMN_NAME COMMENTS @@ -67,7 +79,7 @@ 2 rows selected. -testschema@eqtest> cat play +testschema@orcl> cat play TITLE AUTHOR ------------- ----------- @@ -77,7 +89,7 @@ 3 rows selected. -testschema@eqtest> help terminators +testschema@orcl> help terminators ; standard Oracle format \c CSV (with headings) \C CSV (no headings) @@ -93,7 +105,7 @@ \L scatter plot (no lines) \b bar graph \p pie chart -testschema@eqtest> select * from play where author='Shakespeare'\c +testschema@orcl> select * from play where author='Shakespeare'\c "TITLE","AUTHOR" "Twelfth Night","Shakespeare" @@ -101,7 +113,7 @@ 2 rows selected. -testschema@eqtest> select * from play where author='Shakespeare'\g +testschema@orcl> select * from play where author='Shakespeare'\g @@ -116,7 +128,7 @@ 2 rows selected. -testschema@eqtest> select * from play where author='Shakespeare'\h +testschema@orcl> select * from play where author='Shakespeare'\h <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> @@ -152,14 +164,14 @@ 2 rows selected. -testschema@eqtest> select * from play where author='Shakespeare'\i +testschema@orcl> select * from play where author='Shakespeare'\i INSERT INTO play (TITLE,AUTHOR) VALUES ('Twelfth Night','Shakespeare'); INSERT INTO play (TITLE,AUTHOR) VALUES ('The Tempest','Shakespeare'); 2 rows selected. -testschema@eqtest> select * from play where author='Shakespeare'\t +testschema@orcl> select * from play where author='Shakespeare'\t COLUMN NAME ROW N.1 ROW N.2 @@ -169,7 +181,7 @@ 2 rows selected. -testschema@eqtest> select * from play where author='Shakespeare'\x +testschema@orcl> select * from play where author='Shakespeare'\x <xml> @@ -187,35 +199,47 @@ 2 rows selected. -testschema@eqtest> set -maxtselctrows: 10 -maxfetch: 1000 +testschema@orcl> set autobind: False +commit_on_exit: True +echo: False +maxfetch: 1000 +maxtselctrows: 10 timeout: 30 -commit_on_exit: True -testschema@eqtest> set autobind on +testschema@orcl> print +testschema@orcl> set autobind on autobind - was: False now: True -testschema@eqtest> select * from play where author like 'A%'; +testschema@orcl> select * from play where author like 'A%'; -TITLE AUTHOR +TITLE AUTHOR --------- --------- Agamemnon Aeschylus 1 row selected. -testschema@eqtest> print +testschema@orcl> print +:1 = Agamemnon +:2 = Aeschylus :title = Agamemnon :author = Aeschylus -testschema@eqtest> select * from play where author = :author; +testschema@orcl> select * from play where title = :1; -TITLE AUTHOR +TITLE AUTHOR --------- --------- Agamemnon Aeschylus 1 row selected. -testschema@eqtest> help grep +testschema@orcl> select * from play where author = :author; + +TITLE AUTHOR +--------- --------- +Agamemnon Aeschylus + +1 row selected. + +testschema@orcl> help grep grep PATTERN TABLE - search for term in any of TABLE's fields Usage: grep [options] arg @@ -223,7 +247,7 @@ -h, --help show this help message and exit -i, --ignore-case Case-insensitive search -testschema@eqtest> grep -i EM play +testschema@orcl> grep -i EM play play TITLE AUTHOR @@ -232,6 +256,7 @@ Agamemnon Aeschylus 2 rows selected. -testschema@eqtest> ls play -INDEX/XPK_PLAY -TABLE/PLAY + +testschema@orcl> drop table play; + +Executed
--- a/sqlpython/sqlpyPlus.py Wed Nov 05 17:01:01 2008 -0500 +++ b/sqlpython/sqlpyPlus.py Fri Nov 07 06:43:06 2008 -0500 @@ -2,7 +2,7 @@ Features include: - SQL*Plus-style bind variables - - Query result stored in special bind variable ":_" if one row, one item + - `set autobind on` stores single-line result sets in bind variables automatically - SQL buffer with list, run, ed, get, etc.; unlike SQL*Plus, buffer stores session's full history - @script.sql loads and runs (like SQL*Plus) - ! runs operating-system command @@ -364,8 +364,8 @@ sqlpython.sqlpython.__init__(self) self.binds = CaselessDict() self.sqlBuffer = [] - self.settable = ['maxtselctrows', 'maxfetch', 'autobind', - 'timeout', 'commit_on_exit'] # settables must be lowercase + self.settable = 'autobind commit_on_exit echo maxfetch maxtselctrows timeout'.split() + # settables must be lowercase self.stdoutBeforeSpool = sys.stdout self.spoolFile = None self.autobind = False @@ -553,8 +553,10 @@ print '\n1 row selected.\n' if self.autobind: self.binds.update(dict(zip([''.join(l for l in d[0] if l.isalnum()) for d in self.desc], self.rows[0]))) - if len(self.desc) == 1: - self.binds['_'] = self.rows[0][0] + for (i, val) in enumerate(self.rows[0]): + varname = ''.join(letter for letter in self.desc[i][0] if letter.isalnum() or letter == '_') + self.binds[varname] = val + self.binds[str(i+1)] = val elif self.rc < self.maxfetch: print '\n%d rows selected.\n' % self.rc else: