Ticket #10070: base.diff

File base.diff, 1.9 KB (added by anonymous, 15 years ago)

Another approach using try and a pseudo dictionary

Line 
1*** base.py.orig 2009-08-19 14:49:53.000000000 -0400
2--- base.py 2009-10-27 16:21:06.000000000 -0400
3***************
4*** 166,184 ****
5 you'll need to use "%%s".
6 """
7 def execute(self, query, params=()):
8! query = self.convert_query(query, len(params))
9 return Database.Cursor.execute(self, query, params)
10
11 def executemany(self, query, param_list):
12 try:
13! query = self.convert_query(query, len(param_list[0]))
14 return Database.Cursor.executemany(self, query, param_list)
15 except (IndexError,TypeError):
16 # No parameter list provided
17 return None
18
19! def convert_query(self, query, num_params):
20! return query % tuple("?" * num_params)
21
22 def _sqlite_extract(lookup_type, dt):
23 if dt is None:
24--- 166,197 ----
25 you'll need to use "%%s".
26 """
27 def execute(self, query, params=()):
28! query = self.convert_query(query, params)
29 return Database.Cursor.execute(self, query, params)
30
31 def executemany(self, query, param_list):
32 try:
33! query = self.convert_query(query, param_list[0])
34 return Database.Cursor.executemany(self, query, param_list)
35 except (IndexError,TypeError):
36 # No parameter list provided
37 return None
38
39! # Or, if it wouldn't be too confusing, could put the __getitem__
40! # method on this class and convert_query could use "self" where
41! # I use _colonifier below. Probably too much of a restriction
42! # on Database.cursor.
43! class _colonify_class:
44! def __getitem__(self, name, default=None):
45! return ":" + name
46!
47! _colonifier = _colonify_class()
48!
49! def convert_query(self, query, params):
50! try:
51! return query % tuple("?" * len(params))
52! except TypeError:
53! return query % self._colonifier
54
55 def _sqlite_extract(lookup_type, dt):
56 if dt is None:
Back to Top