Mercurial > hg > ZDBInterface
comparison DBInterface.py @ 21:5f3d6623b71e
fixed bug when params to ZDBInlineSearch are not strings.
new method ZDBSlice.
author | casties |
---|---|
date | Fri, 08 Feb 2013 20:40:25 +0100 |
parents | 132ae1c0255a |
children |
comparison
equal
deleted
inserted
replaced
20:0e87d5d80709 | 21:5f3d6623b71e |
---|---|
18 def sqlName(s, lc=True, more=''): | 18 def sqlName(s, lc=True, more=''): |
19 """returns restricted ASCII-only version of string""" | 19 """returns restricted ASCII-only version of string""" |
20 if s is None: | 20 if s is None: |
21 return "" | 21 return "" |
22 | 22 |
23 if not isinstance(s, basestring): | |
24 s = str(s) | |
25 | |
23 # remove ' | 26 # remove ' |
24 s = s.replace("'","") | 27 s = s.replace("'","") |
25 # all else -> "_" | 28 # all else -> "_" |
26 s = re.sub('[^A-Za-z0-9_'+more+']','_',s) | 29 s = re.sub('[^A-Za-z0-9_'+more+']','_',s) |
27 if lc: | 30 if lc: |
89 dbc = self.getDB() | 92 dbc = self.getDB() |
90 res = dbc.query(query, max_rows=max_rows, query_data=args) | 93 res = dbc.query(query, max_rows=max_rows, query_data=args) |
91 # return result set as Result object with Brains | 94 # return result set as Result object with Brains |
92 return Results(res) | 95 return Results(res) |
93 | 96 |
97 | |
98 def ZDBSlice(self, results, size=0, offset=0): | |
99 """return a (subset-) list of rows from results. | |
100 ZRDB.Results doesn't do list-slicing.""" | |
101 res = [x for x in results] | |
102 if size > 0: | |
103 return res[offset:(offset+size)] | |
104 else: | |
105 return res[offset:] | |
94 | 106 |
95 # | 107 # |
96 # Old way using cursor from DA | 108 # Old way using cursor from DA |
97 # | 109 # |
98 | 110 |