Mercurial > p > roundup > code
annotate roundup/backends/back_gadfly.py @ 1174:8e318dfaf479
Verify contents of tracker module when the tracker is opened
Performance improvements in *dbm and sq backends
New benchmark module. To use:
PYTHONPATH=. python2 test/benchmark.py
(yes, it's a little basic at present ;)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 20 Sep 2002 01:20:32 +0000 |
| parents | af104fa52746 |
| children | 08a13a84ed43 |
| rev | line source |
|---|---|
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
1 # $Id: back_gadfly.py,v 1.24 2002-09-20 01:20:31 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) |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 cursor = self.conn.cursor() |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 cursor.execute('create table schema (schema varchar)') |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 cursor.execute('create table ids (name varchar, num integer)') |
|
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: |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 cursor = self.conn.cursor() |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
79 cursor.execute('select schema from schema') |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 self.database_schema = cursor.fetchone()[0] |
|
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) |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
83 self.database_schema = self.load_dbschema(cursor) |
|
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 |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
88 def sql_fetchone(self, cursor): |
|
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: |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
92 return 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 |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
98 def save_dbschema(self, cursor, schema): |
|
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 ''' |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
101 self.sql(cursor, 'insert into schema values (?)', |
|
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
102 (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
|
103 |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
104 def load_dbschema(self, cursor): |
|
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
105 ''' 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
|
106 ''' |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
107 cursor.execute('select schema from 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
|
108 return cursor.fetchone()[0] |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
109 |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
110 def save_journal(self, cursor, classname, cols, nodeid, journaldate, |
|
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
111 journaltag, action, params): |
|
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
112 ''' 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
|
113 ''' |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
114 # 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
|
115 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
|
116 |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
117 # do the insert |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
118 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
|
119 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
|
120 cols) |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
121 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
|
122 print >>hyperdb.DEBUG, 'addjournal', (self, sql, entry) |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
123 cursor.execute(sql, entry) |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
125 def load_journal(self, cursor, classname, cols, nodeid): |
|
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
126 ''' 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
|
127 ''' |
|
972
ca0a542b2d19
That's gadfly done, mostly.
Richard Jones <richard@users.sourceforge.net>
parents:
968
diff
changeset
|
128 # now get the journal entries |
|
1165
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
129 sql = 'select %s from %s__journal where nodeid=%s'%(cols, classname, |
|
14467c765167
sqlite backend!
Richard Jones <richard@users.sourceforge.net>
parents:
1156
diff
changeset
|
130 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
|
131 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
|
132 print >>hyperdb.DEBUG, 'getjournal', (self, sql, nodeid) |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 cursor.execute(sql, (nodeid,)) |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 res = [] |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
135 for nodeid, date_stamp, user, action, params in cursor.fetchall(): |
|
07d8a4e296f8
Whee! It's not finished yet, but I can create a new instance...
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
136 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
|
137 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
|
138 |
|
1170
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
139 class GadflyClass: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
140 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
|
141 ''' 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
|
142 ''' |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
143 cn = self.classname |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
144 |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
145 # 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
|
146 props = self.getprops() |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
147 frum = ['_'+cn] |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
148 where = [] |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
149 args = [] |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
150 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
|
151 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
|
152 propclass = props[k] |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
153 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
|
154 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
|
155 frum.append(tn) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 args = args + v |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
160 else: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
161 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
|
162 args.append(v) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
163 else: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 args = args + v |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
168 else: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
169 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
|
170 args.append(v) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
171 |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
172 # 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 args = args + v |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
178 |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
179 # "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
|
180 # 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
|
181 orderby = [] |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
182 ordercols = [] |
|
1174
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] 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
|
184 if group[0] != '-': |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
185 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
|
186 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
|
187 else: |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
188 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
|
189 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
|
190 |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
191 # 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
|
192 group = '' |
|
1170
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
193 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
|
194 direction, colname = sort |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
195 if direction != '-': |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
196 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
|
197 orderby.append(colname) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
198 else: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
199 orderby.append('_'+colname) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
200 ordercols.append('_'+colname) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
201 else: |
|
1174
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
202 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
|
203 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
|
204 ordercols.append(colname) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
205 else: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
206 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
|
207 ordercols.append('_'+colname) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
208 |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
209 # construct the SQL |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
210 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
|
211 if where: |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
212 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
|
213 else: |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
214 where = '' |
|
8e318dfaf479
Verify contents of tracker module when the tracker is opened
Richard Jones <richard@users.sourceforge.net>
parents:
1170
diff
changeset
|
215 cols = ['id'] |
|
1170
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
216 if orderby: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
217 cols = cols + ordercols |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
218 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
|
219 else: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
220 order = '' |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
221 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
|
222 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
|
223 args = tuple(args) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
224 if __debug__: |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
225 print >>hyperdb.DEBUG, 'filter', (self, sql, args) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
226 cursor = self.db.conn.cursor() |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
227 cursor.execute(sql, args) |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
228 l = cursor.fetchall() |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
229 |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
230 # return the IDs |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
231 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
|
232 |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
233 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
|
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 IssueClass(GadflyClass, IssueClass): |
|
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 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
|
238 pass |
|
af104fa52746
Added some words to the installation doc about choosing backends.
Richard Jones <richard@users.sourceforge.net>
parents:
1165
diff
changeset
|
239 |
