annotate roundup/backends/back_gadfly.py @ 1509:1d4ebe2a88fc

hope this will make Range class a little bit clearer
author Andrey Lebedev <kedder@users.sourceforge.net>
date Mon, 10 Mar 2003 20:32:53 +0000
parents 7cd110cee870
children a516bbb9896b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1500
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
1 # $Id: back_gadfly.py,v 1.33 2003-03-09 21:37:37 richard Exp $
1244
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1222
diff changeset
2 ''' Gadlfy relational database hypderb backend.
8dd4f736370b merge from maintenance branch
Richard Jones <richard@users.sourceforge.net>
parents: 1222
diff changeset
3
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4 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
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
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 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
8 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
9 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
10 SQL.
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
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 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
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
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 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
17 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
18 method:
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 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
21 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
22
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23 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
24 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
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 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
27 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
28 used.
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
1222
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
32 # standard python modules
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
33 import sys, os, time, re, errno, weakref, copy
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
34
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
35 # roundup modules
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
36 from roundup import hyperdb, date, password, roundupdb, security
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
37 from roundup.hyperdb import String, Password, Date, Interval, Link, \
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
38 Multilink, DatabaseError, Boolean, Number
1333
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
39 from roundup.backends import locking
1222
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
40
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
41 # basic RDBMS backen implementation
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
42 from roundup.backends import rdbms_common
968
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 # 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
45 import gadfly
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
46 import gadfly.client
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
47 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
48
1222
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
49 class Database(rdbms_common.Database):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
50 # char to use for positional arguments
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
51 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
52
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
53 def open_connection(self):
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
54 db = getattr(self.config, 'GADFLY_DATABASE', ('database', self.dir))
1333
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
55
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
56 # lock it
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
57 lockfilenm = os.path.join(db[1], db[0]) + '.lck'
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
58 self.lockfile = locking.acquire_lock(lockfilenm)
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
59 self.lockfile.write(str(os.getpid()))
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
60 self.lockfile.flush()
80d27b7d6db5 implemented whole-database locking
Richard Jones <richard@users.sourceforge.net>
parents: 1249
diff changeset
61
968
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
62 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
63 # 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
64 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
65 try:
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
66 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
67 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
68 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
69 raise
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 else:
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
81 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
82 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
83
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
84 def __repr__(self):
1032
dd51e435fa9e *** empty log message ***
Richard Jones <richard@users.sourceforge.net>
parents: 1025
diff changeset
85 return '<roundfly 0x%x>'%id(self)
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
86
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
87 def sql_fetchone(self):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
88 ''' 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
89 '''
1145
81941abedb0a nicer error message for invalid class lookup
Richard Jones <richard@users.sourceforge.net>
parents: 1143
diff changeset
90 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
91 return self.cursor.fetchone()
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
92 except gadfly.database.error, message:
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
93 if message == 'no more results':
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
94 return None
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
95 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
96
1195
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
97 def sql_fetchall(self):
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
98 ''' Fetch a single row. If there's nothing to fetch, return [].
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
99 '''
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
100 try:
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
101 return self.cursor.fetchall()
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
102 except gadfly.database.error, message:
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
103 if message == 'no more results':
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
104 return []
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
105 raise
e0032f4ab334 added missing stringFind to sql backends
Richard Jones <richard@users.sourceforge.net>
parents: 1183
diff changeset
106
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
107 def save_dbschema(self, schema):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
108 ''' 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
109 '''
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
110 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
111
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
112 def load_dbschema(self):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
113 ''' 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
114 '''
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
115 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
116 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
117
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
118 def save_journal(self, classname, cols, nodeid, journaldate,
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
119 journaltag, action, params):
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
120 ''' 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
121 '''
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
122 # 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
123 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
124
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
125 # do the insert
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
126 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
127 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
128 cols)
07d8a4e296f8 Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
129 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
130 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
131 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
132
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
133 def load_journal(self, classname, cols, nodeid):
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
134 ''' 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
135 '''
972
ca0a542b2d19 That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents: 968
diff changeset
136 # now get the journal entries
1165
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
137 sql = 'select %s from %s__journal where nodeid=%s'%(cols, classname,
14467c765167 sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents: 1156
diff changeset
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146
1500
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
147 def update_class(self, spec, old_spec):
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
148 ''' Determine the differences between the current spec and the
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
149 database version of the spec, and update where necessary
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
150
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
151 GADFLY requires a commit after the table drop!
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
152 '''
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
153 new_spec = spec
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
154 new_has = new_spec.properties.has_key
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
155
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
156 new_spec = new_spec.schema()
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
157 if new_spec == old_spec:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
158 # no changes
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
159 return 0
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
160
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
161 if __debug__:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
162 print >>hyperdb.DEBUG, 'update_class FIRING'
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
163
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
164 # key property changed?
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
165 if old_spec[0] != new_spec[0]:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
166 if __debug__:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
167 print >>hyperdb.DEBUG, 'update_class setting keyprop', `spec[0]`
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
168 # XXX turn on indexing for the key property
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
169
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
170 # detect multilinks that have been removed, and drop their table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
171 old_has = {}
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
172 for name,prop in old_spec[1]:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
173 old_has[name] = 1
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
174 if not new_has(name) and isinstance(prop, Multilink):
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
175 # it's a multilink, and it's been removed - drop the old
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
176 # table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
177 sql = 'drop table %s_%s'%(spec.classname, prop)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
178 if __debug__:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
179 print >>hyperdb.DEBUG, 'update_class', (self, sql)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
180 self.cursor.execute(sql)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
181 continue
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
182 old_has = old_has.has_key
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
183
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
184 # now figure how we populate the new table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
185 fetch = ['_activity', '_creation', '_creator']
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
186 properties = spec.getprops()
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
187 for propname,x in new_spec[1]:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
188 prop = properties[propname]
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
189 if isinstance(prop, Multilink):
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
190 if not old_has(propname):
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
191 # we need to create the new table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
192 self.create_multilink_table(spec, propname)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
193 elif old_has(propname):
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
194 # we copy this col over from the old table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
195 fetch.append('_'+propname)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
196
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
197 # select the data out of the old table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
198 fetch.append('id')
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
199 fetch.append('__retired__')
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
200 fetchcols = ','.join(fetch)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
201 cn = spec.classname
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
202 sql = 'select %s from _%s'%(fetchcols, cn)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
203 if __debug__:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
204 print >>hyperdb.DEBUG, 'update_class', (self, sql)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
205 self.cursor.execute(sql)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
206 olddata = self.cursor.fetchall()
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
207
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
208 # drop the old table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
209 self.cursor.execute('drop table _%s'%cn)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
210
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
211 # GADFLY requires a commit here, or the table spec screws up
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
212 self.conn.commit()
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
213
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
214 # create the new table
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
215 cols, mls = self.create_class_table(spec)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
216
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
217 # figure the new columns
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
218 extra = 0
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
219 for col in cols:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
220 if col not in fetch:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
221 fetch.append(col)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
222 extra += 1
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
223
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
224 if olddata:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
225 # do the insert
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
226 fetchcols = ','.join(fetch)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
227 args = ','.join([self.arg for x in fetch])
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
228 sql = 'insert into _%s (%s) values (%s)'%(cn, fetchcols, args)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
229 if __debug__:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
230 print >>hyperdb.DEBUG, 'update_class', (self, sql, olddata[0])
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
231 for entry in olddata:
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
232 self.cursor.execute(sql, tuple(entry) + (None,)*extra)
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
233
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
234 return 1
7cd110cee870 Fixed issue w. gadfly and exact column matching when table schemas are updated.
Richard Jones <richard@users.sourceforge.net>
parents: 1365
diff changeset
235
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
236 class GadflyClass:
1249
6c24a86a12ae Fixes for SourceForge tracker bugs.
Richard Jones <richard@users.sourceforge.net>
parents: 1244
diff changeset
237 def filter(self, search_matches, filterspec, sort=(None,None),
6c24a86a12ae Fixes for SourceForge tracker bugs.
Richard Jones <richard@users.sourceforge.net>
parents: 1244
diff changeset
238 group=(None,None)):
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
239 ''' 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
240 '''
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
241 cn = self.classname
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
242
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
243 # 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
244 props = self.getprops()
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
245 frum = ['_'+cn]
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
246 where = []
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
247 args = []
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
248 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
249 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
250 propclass = props[k]
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
251 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
252 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
253 frum.append(tn)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
254 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
255 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
256 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
257 args = args + v
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
258 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
259 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
260 args.append(v)
1351
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
261 elif isinstance(propclass, Date):
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
262 if isinstance(v, type([])):
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
263 s = ','.join([a for x in v])
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
264 where.append('_%s in (%s)'%(k, s))
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
265 args = args + [date.Date(x).serialise() for x in v]
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
266 else:
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
267 where.append('_%s=%s'%(k, a))
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
268 args.append(date.Date(v).serialise())
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
269 elif isinstance(propclass, Interval):
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
270 if isinstance(v, type([])):
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
271 s = ','.join([a for x in v])
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
272 where.append('_%s in (%s)'%(k, s))
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
273 args = args + [date.Interval(x).serialise() for x in v]
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
274 else:
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
275 where.append('_%s=%s'%(k, a))
d1bfb479e527 fixed searching on date / interval fields [SF#658157]
Richard Jones <richard@users.sourceforge.net>
parents: 1333
diff changeset
276 args.append(date.Interval(v).serialise())
1365
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
277 elif k == 'id':
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
278 if isinstance(v, type([])):
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
279 s = ','.join([a for x in v])
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
280 where.append('%s in (%s)'%(k, s))
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
281 args = args + v
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
282 else:
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
283 where.append('%s=%s'%(k, a))
4884fb0860f9 fixed rdbms searching by ID [SF#666615]
Richard Jones <richard@users.sourceforge.net>
parents: 1351
diff changeset
284 args.append(v)
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
285 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
286 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
287 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
288 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
289 args = args + v
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
290 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
291 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
292 args.append(v)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
293
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
294 # 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
295 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
296 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
297 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
298 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
299 args = args + v
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
300
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
301 # "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
302 # 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
303 orderby = []
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
304 ordercols = []
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
305 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
306 if group[0] != '-':
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
307 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
308 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
309 else:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
310 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
311 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
312
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
313 # 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
314 group = ''
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
315 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
316 direction, colname = sort
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
317 if direction != '-':
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
318 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
319 orderby.append(colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
320 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
321 orderby.append('_'+colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
322 ordercols.append('_'+colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
323 else:
1174
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
324 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
325 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
326 ordercols.append(colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
327 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
328 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
329 ordercols.append('_'+colname)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
330
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
331 # construct the SQL
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
332 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
333 if where:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
334 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
335 else:
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
336 where = ''
8e318dfaf479 Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents: 1170
diff changeset
337 cols = ['id']
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
338 if orderby:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
339 cols = cols + ordercols
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
340 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
341 else:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
342 order = ''
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
343 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
344 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
345 args = tuple(args)
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
346 if __debug__:
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
347 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
348 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
349 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
350
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
351 # return the IDs
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
352 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
353
1222
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
354 def find(self, **propspec):
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
355 ''' Overload to filter out duplicates in the result
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
356 '''
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
357 d = {}
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
358 for k in rdbms_common.Class.find(self, **propspec):
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
359 d[k] = 1
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
360 return d.keys()
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
361
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
362 class Class(GadflyClass, rdbms_common.Class):
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
363 pass
1222
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
364 class IssueClass(GadflyClass, rdbms_common.IssueClass):
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
365 pass
1222
bc3bc3248dd1 added Class.find() unit test, fixed implementations
Richard Jones <richard@users.sourceforge.net>
parents: 1195
diff changeset
366 class FileClass(GadflyClass, rdbms_common.FileClass):
1170
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
367 pass
af104fa52746 Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents: 1165
diff changeset
368

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