changeset 327:7cc5cc19891f

added rows_remembered
author Catherine Devlin <catherine.devlin@gmail.com>
date Sat, 04 Apr 2009 22:10:47 -0400
parents 82937b8dcbfe
children b2fbb9de8845
files sqlpython/sqlpyPlus.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py	Sat Apr 04 11:55:44 2009 -0400
+++ b/sqlpython/sqlpyPlus.py	Sat Apr 04 22:10:47 2009 -0400
@@ -316,7 +316,7 @@
     def __init__(self):
         sqlpython.sqlpython.__init__(self)
         self.binds = CaselessDict()
-        self.settable += 'autobind commit_on_exit maxfetch maxtselctrows scan serveroutput sql_echo store_results timeout heading wildsql'.split()
+        self.settable += 'autobind commit_on_exit maxfetch maxtselctrows rows_remembered scan serveroutput sql_echo store_results timeout heading wildsql'.split()
         self.settable.remove('case_insensitive')
         self.settable.sort()
         self.stdoutBeforeSpool = sys.stdout
@@ -331,6 +331,7 @@
         self.substvars = {}
         self.result_history = []
         self.store_results = True
+        self.rows_remembered = 10
         
         self.pystate = {'r': [], 'binds': self.binds, 'substs': self.substvars}
         
@@ -663,6 +664,14 @@
         except IndexError:
             print self.do_bind.__doc__
         
+    def age_out_resultsets(self):
+        total_len = sum(len(rs) for rs in self.pystate['r'])
+        while (self.rows_remembered and (total_len >= self.rows_remembered)):
+            for (i, rset) in enumerate(self.pystate['r'][:-1]):
+                if rset:
+                    self.pystate['r'][i] = []
+                    break
+            total_len = sum(len(rs) for rs in self.pystate['r'])
     def do_select(self, arg, bindVarsIn=None, terminator=None):
         """Fetch rows from a table.
 
@@ -700,6 +709,7 @@
             for row in resultset:
                 row.resultset = resultset
             self.pystate['r'].append(resultset)
+            self.age_out_resultsets()
             self.stdout.write('\n%s\n' % (self.output(arg.parsed.terminator, rowlimit)))
         if self.rc == 0:
             print '\nNo rows Selected.\n'