annotate roundup/backends/back_gadfly.py @ 1183:08a13a84ed43

Some speedups - both of the SQL backends can handle using only one cursor. Better date unserialisation too.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 23 Sep 2002 06:48:35 +0000
parents 8e318dfaf479
children e0032f4ab334
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
1 # $Id: back_gadfly.py,v 1.25 2002-09-23 06:48:34 richard Exp $
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2 __doc__ = '''
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 About Gadfly
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4 ============
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
5
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
6 Gadfly is a collection of python modules that provides relational
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 database functionality entirely implemented in Python. It supports a
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
8 subset of the intergalactic standard RDBMS Structured Query Language
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
9 SQL.
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
10
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12 Basic Structure
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 ===============
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
15 We map roundup classes to relational tables. Automatically detect schema
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 changes and modify the gadfly table schemas appropriately. Multilinks
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17 (which represent a many-to-many relationship) are handled through
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
18 intermediate tables.
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
19
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
20 Journals are stored adjunct to the per-class tables.
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
21
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
22 Table names and columns have "_" prepended so the names can't
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23 clash with restricted names (like "order"). Retirement is determined by the
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
24 __retired__ column being true.
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
26 All columns are defined as VARCHAR, since it really doesn't matter what
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
27 type they're defined as. We stuff all kinds of data in there ;) [as long as
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
28 it's marshallable, gadfly doesn't care]
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
29
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
30
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
31 Additional Instance Requirements
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
32 ================================
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
33
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
34 The instance configuration must specify where the database is. It does this
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
35 with GADFLY_DATABASE, which is used as the arguments to the gadfly.gadfly()
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
36 method:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
37
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
38 Using an on-disk database directly (not a good idea):
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
39 GADFLY_DATABASE = (database name, directory)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
40
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
41 Using a network database (much better idea):
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
42 GADFLY_DATABASE = (policy, password, address, port)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
43
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
44 Because multiple accesses directly to a gadfly database aren't handled, but
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
45 multiple network accesses are, it's strongly advised that the latter setup be
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
46 used.
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
47
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48 '''
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
49
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
50 from roundup.backends.rdbms_common import *
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
51
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
52 # the all-important gadfly :)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
53 import gadfly
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
54 import gadfly.client
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
55 import gadfly.database
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
56
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
57 class Database(Database):
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
58 # char to use for positional arguments
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
59 arg = '?'
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
60
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
61 def open_connection(self):
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
62 db = getattr(self.config, 'GADFLY_DATABASE', ('database', self.dir))
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
63 if len(db) == 2:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
64 # ensure files are group readable and writable
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
65 os.umask(0002)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
66 try:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
67 self.conn = gadfly.gadfly(*db)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
68 except IOError, error:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
69 if error.errno != errno.ENOENT:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
70 raise
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
71 self.database_schema = {}
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
72 self.conn = gadfly.gadfly()
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
73 self.conn.startup(*db)
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
74 self.cursor = self.conn.cursor()
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
75 self.cursor.execute('create table schema (schema varchar)')
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
76 self.cursor.execute('create table ids (name varchar, num integer)')
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
77 else:
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
78 self.cursor = self.conn.cursor()
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
79 self.cursor.execute('select schema from schema')
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
80 self.database_schema = self.cursor.fetchone()[0]
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
81 else:
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
82 self.conn = gadfly.client.gfclient(*db)
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
83 self.database_schema = self.load_dbschema()
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
84
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
85 def __repr__(self):
1032
dd51e435fa9e *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1025
diff changeset
86 return '<roundfly 0x%x>'%id(self)
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
87
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
88 def sql_fetchone(self):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
89 ''' Fetch a single row. If there's nothing to fetch, return None.
1156
d0da32fbdedc gadfly backend now complete
Richard Jones <richard@users.sourceforge.net>
parents: 1145
diff changeset
90 '''
1145
81941abedb0a nicer error message for invalid class lookup
Richard Jones <richard@users.sourceforge.net>
parents: 1143
diff changeset
91 try:
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
92 return self.cursor.fetchone()
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
93 except gadfly.database.error, message:
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
94 if message == 'no more results':
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
95 return None
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
96 raise
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
98 def save_dbschema(self, schema):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
99 ''' Save the schema definition that the database currently implements
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
100 '''
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
101 self.sql('insert into schema values (?)', (self.database_schema,))
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
102
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
103 def load_dbschema(self):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
104 ''' Load the schema definition that the database currently implements
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
105 '''
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
106 self.cursor.execute('select schema from schema')
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
107 return self.cursor.fetchone()[0]
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
108
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
109 def save_journal(self, classname, cols, nodeid, journaldate,
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
110 journaltag, action, params):
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
111 ''' Save the journal entry to the database
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
112 '''
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
113 # nothing special to do
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
114 entry = (nodeid, journaldate, journaltag, action, params)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
115
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
116 # do the insert
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
117 a = self.arg
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
118 sql = 'insert into %s__journal (%s) values (?,?,?,?,?)'%(classname,
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
119 cols)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
120 if __debug__:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
121 print >>hyperdb.DEBUG, 'addjournal', (self, sql, entry)
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
122 self.cursor.execute(sql, entry)
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
123
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
124 def load_journal(self, classname, cols, nodeid):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
125 ''' Load the journal from the database
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
126 '''
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
127 # now get the journal entries
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
128 sql = 'select %s from %s__journal where nodeid=%s'%(cols, classname,
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
129 self.arg)
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
130 if __debug__:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 print >>hyperdb.DEBUG, 'getjournal', (self, sql, nodeid)
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
132 self.cursor.execute(sql, (nodeid,))
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
133 res = []
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
134 for nodeid, date_stamp, user, action, params in self.cursor.fetchall():
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
135 res.append((nodeid, date.Date(date_stamp), user, action, params))
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
136 return res
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
137
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
138 class GadflyClass:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
139 def filter(self, search_matches, filterspec, sort, group):
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
140 ''' Gadfly doesn't have a LIKE predicate :(
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
141 '''
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
142 cn = self.classname
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
143
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
144 # figure the WHERE clause from the filterspec
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
145 props = self.getprops()
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
146 frum = ['_'+cn]
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
147 where = []
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
148 args = []
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
149 a = self.db.arg
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
150 for k, v in filterspec.items():
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
151 propclass = props[k]
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
152 if isinstance(propclass, Multilink):
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
153 tn = '%s_%s'%(cn, k)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
154 frum.append(tn)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
155 if isinstance(v, type([])):
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
156 s = ','.join([a for x in v])
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
157 where.append('id=%s.nodeid and %s.linkid in (%s)'%(tn,tn,s))
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
158 args = args + v
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
159 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
160 where.append('id=%s.nodeid and %s.linkid = %s'%(tn, tn, a))
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
161 args.append(v)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
162 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
163 if isinstance(v, type([])):
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
164 s = ','.join([a for x in v])
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
165 where.append('_%s in (%s)'%(k, s))
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
166 args = args + v
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
167 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
168 where.append('_%s=%s'%(k, a))
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
169 args.append(v)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
171 # add results of full text search
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
172 if search_matches is not None:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
173 v = search_matches.keys()
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
174 s = ','.join([a for x in v])
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
175 where.append('id in (%s)'%s)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
176 args = args + v
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
177
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
178 # "grouping" is just the first-order sorting in the SQL fetch
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
179 # can modify it...)
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
180 orderby = []
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
181 ordercols = []
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
182 if group[0] is not None and group[1] is not None:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
183 if group[0] != '-':
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
184 orderby.append('_'+group[1])
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
185 ordercols.append('_'+group[1])
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
186 else:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
187 orderby.append('_'+group[1]+' desc')
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
188 ordercols.append('_'+group[1])
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
189
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
190 # now add in the sorting
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
191 group = ''
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
192 if sort[0] is not None and sort[1] is not None:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
193 direction, colname = sort
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
194 if direction != '-':
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
195 if colname == 'id':
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
196 orderby.append(colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
197 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
198 orderby.append('_'+colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
199 ordercols.append('_'+colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
200 else:
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
201 if colname == 'id':
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
202 orderby.append(colname+' desc')
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
203 ordercols.append(colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
204 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
205 orderby.append('_'+colname+' desc')
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
206 ordercols.append('_'+colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
207
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
208 # construct the SQL
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
209 frum = ','.join(frum)
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
210 if where:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
211 where = ' where ' + (' and '.join(where))
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
212 else:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
213 where = ''
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
214 cols = ['id']
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
215 if orderby:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
216 cols = cols + ordercols
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
217 order = ' order by %s'%(','.join(orderby))
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
218 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
219 order = ''
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
220 cols = ','.join(cols)
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
221 sql = 'select %s from %s %s%s%s'%(cols, frum, where, group, order)
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
222 args = tuple(args)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
223 if __debug__:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
224 print >>hyperdb.DEBUG, 'filter', (self, sql, args)
1183
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
225 self.db.cursor.execute(sql, args)
08a13a84ed43 Some speedups - both of the SQL backends can handle using only one cursor.
Richard Jones <richard@users.sourceforge.net>
parents: 1174
diff changeset
226 l = self.db.cursor.fetchall()
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
227
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
228 # return the IDs
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
229 return [row[0] for row in l]
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
230
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
231 class Class(GadflyClass, Class):
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
232 pass
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
233 class IssueClass(GadflyClass, IssueClass):
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
234 pass
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
235 class FileClass(GadflyClass, FileClass):
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
236 pass
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
237

Roundup Issue Tracker: http://roundup-tracker.org/