annotate roundup/backends/back_gadfly.py @ 1516:c8a596aa5aba maint-0.5

fixed rdbms table update detection logic [SF#703297]
author Richard Jones <richard@users.sourceforge.net>
date Fri, 14 Mar 2003 02:52:03 +0000
parents 8fd1ad93f920
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1516
c8a596aa5aba fixed rdbms table update detection logic [SF#703297]
Richard Jones <richard@users.sourceforge.net>
parents: 1501
diff changeset
1 # $Id: back_gadfly.py,v 1.31.2.3 2003-03-14 02:52:03 richard Exp $
1356
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2 ''' Gadlfy relational database hypderb backend.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4 About Gadfly
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
5 ============
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
6
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 Gadfly is a collection of python modules that provides relational
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
8 database functionality entirely implemented in Python. It supports a
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
9 subset of the intergalactic standard RDBMS Structured Query Language
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
10 SQL.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 Additional Instance Requirements
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14 ================================
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
15
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 The instance configuration must specify where the database is. It does this
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17 with GADFLY_DATABASE, which is used as the arguments to the gadfly.gadfly()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
18 method:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
19
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
20 Using an on-disk database directly (not a good idea):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
21 GADFLY_DATABASE = (database name, directory)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
22
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23 Using a network database (much better idea):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
24 GADFLY_DATABASE = (policy, password, address, port)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
25
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
26 Because multiple accesses directly to a gadfly database aren't handled, but
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
27 multiple network accesses are, it's strongly advised that the latter setup be
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
28 used.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
29
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
30 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
31
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
32 # standard python modules
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
33 import sys, os, time, re, errno, weakref, copy
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
34
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
35 # roundup modules
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
36 from roundup import hyperdb, date, password, roundupdb, security
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
37 from roundup.hyperdb import String, Password, Date, Interval, Link, \
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
38 Multilink, DatabaseError, Boolean, Number
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
39 from roundup.backends import locking
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
40
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
41 # basic RDBMS backen implementation
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
42 from roundup.backends import rdbms_common
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
43
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
44 # the all-important gadfly :)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
45 import gadfly
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
46 import gadfly.client
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
47 import gadfly.database
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
49 class Database(rdbms_common.Database):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
50 # char to use for positional arguments
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
51 arg = '?'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
52
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
53 def open_connection(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
54 db = getattr(self.config, 'GADFLY_DATABASE', ('database', self.dir))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
55
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
56 # lock it
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
57 lockfilenm = os.path.join(db[1], db[0]) + '.lck'
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
58 self.lockfile = locking.acquire_lock(lockfilenm)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
59 self.lockfile.write(str(os.getpid()))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
60 self.lockfile.flush()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
61
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
62 if len(db) == 2:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
63 # ensure files are group readable and writable
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
64 os.umask(0002)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
65 try:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
66 self.conn = gadfly.gadfly(*db)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
67 except IOError, error:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
68 if error.errno != errno.ENOENT:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
69 raise
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
70 self.database_schema = {}
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
71 self.conn = gadfly.gadfly()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
72 self.conn.startup(*db)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
73 self.cursor = self.conn.cursor()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
74 self.cursor.execute('create table schema (schema varchar)')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
75 self.cursor.execute('create table ids (name varchar, num integer)')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
76 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
77 self.cursor = self.conn.cursor()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
78 self.cursor.execute('select schema from schema')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
79 self.database_schema = self.cursor.fetchone()[0]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
80 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
81 self.conn = gadfly.client.gfclient(*db)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
82 self.database_schema = self.load_dbschema()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
83
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
84 def __repr__(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
85 return '<roundfly 0x%x>'%id(self)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
86
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
87 def sql_fetchone(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
88 ''' Fetch a single row. If there's nothing to fetch, return None.
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
89 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
90 try:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
91 return self.cursor.fetchone()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
92 except gadfly.database.error, message:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
93 if message == 'no more results':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
94 return None
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
95 raise
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
96
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
97 def sql_fetchall(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
98 ''' Fetch a single row. If there's nothing to fetch, return [].
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
99 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
100 try:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
101 return self.cursor.fetchall()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
102 except gadfly.database.error, message:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
103 if message == 'no more results':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
104 return []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
105 raise
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
106
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
107 def save_dbschema(self, schema):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
108 ''' Save the schema definition that the database currently implements
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
109 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
110 self.sql('insert into schema values (?)', (self.database_schema,))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
111
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
112 def load_dbschema(self):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
113 ''' Load the schema definition that the database currently implements
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
114 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
115 self.cursor.execute('select schema from schema')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
116 return self.cursor.fetchone()[0]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
117
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
118 def save_journal(self, classname, cols, nodeid, journaldate,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
119 journaltag, action, params):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
120 ''' Save the journal entry to the database
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
121 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
122 # nothing special to do
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
123 entry = (nodeid, journaldate, journaltag, action, params)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
124
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
125 # do the insert
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
126 a = self.arg
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
127 sql = 'insert into %s__journal (%s) values (?,?,?,?,?)'%(classname,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
128 cols)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
129 if __debug__:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
130 print >>hyperdb.DEBUG, 'addjournal', (self, sql, entry)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
131 self.cursor.execute(sql, entry)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
132
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
133 def load_journal(self, classname, cols, nodeid):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
134 ''' Load the journal from the database
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
135 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
136 # now get the journal entries
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
137 sql = 'select %s from %s__journal where nodeid=%s'%(cols, classname,
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
138 self.arg)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
139 if __debug__:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
140 print >>hyperdb.DEBUG, 'getjournal', (self, sql, nodeid)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
141 self.cursor.execute(sql, (nodeid,))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
142 res = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
143 for nodeid, date_stamp, user, action, params in self.cursor.fetchall():
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
144 res.append((nodeid, date.Date(date_stamp), user, action, params))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
145 return res
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
146
1501
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
147 def update_class(self, spec, old_spec):
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
148 ''' Determine the differences between the current spec and the
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
149 database version of the spec, and update where necessary
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
150
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
151 GADFLY requires a commit after the table drop!
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
152 '''
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
153 new_spec = spec
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
154 new_has = new_spec.properties.has_key
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
155
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
156 new_spec = new_spec.schema()
1516
c8a596aa5aba fixed rdbms table update detection logic [SF#703297]
Richard Jones <richard@users.sourceforge.net>
parents: 1501
diff changeset
157 new_spec[1].sort()
c8a596aa5aba fixed rdbms table update detection logic [SF#703297]
Richard Jones <richard@users.sourceforge.net>
parents: 1501
diff changeset
158 old_spec[1].sort()
1501
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
159 if new_spec == old_spec:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
160 # no changes
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
161 return 0
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
162
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
163 if __debug__:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
164 print >>hyperdb.DEBUG, 'update_class FIRING'
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
165
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
166 # key property changed?
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
167 if old_spec[0] != new_spec[0]:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
168 if __debug__:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
169 print >>hyperdb.DEBUG, 'update_class setting keyprop', `spec[0]`
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
170 # XXX turn on indexing for the key property
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
171
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
172 # detect multilinks that have been removed, and drop their table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
173 old_has = {}
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
174 for name,prop in old_spec[1]:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
175 old_has[name] = 1
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
176 if not new_has(name) and isinstance(prop, Multilink):
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
177 # it's a multilink, and it's been removed - drop the old
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
178 # table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
179 sql = 'drop table %s_%s'%(spec.classname, prop)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
180 if __debug__:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
181 print >>hyperdb.DEBUG, 'update_class', (self, sql)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
182 self.cursor.execute(sql)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
183 continue
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
184 old_has = old_has.has_key
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
185
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
186 # now figure how we populate the new table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
187 fetch = ['_activity', '_creation', '_creator']
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
188 properties = spec.getprops()
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
189 for propname,x in new_spec[1]:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
190 prop = properties[propname]
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
191 if isinstance(prop, Multilink):
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
192 if not old_has(propname):
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
193 # we need to create the new table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
194 self.create_multilink_table(spec, propname)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
195 elif old_has(propname):
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
196 # we copy this col over from the old table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
197 fetch.append('_'+propname)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
198
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
199 # select the data out of the old table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
200 fetch.append('id')
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
201 fetch.append('__retired__')
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
202 fetchcols = ','.join(fetch)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
203 cn = spec.classname
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
204 sql = 'select %s from _%s'%(fetchcols, cn)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
205 if __debug__:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
206 print >>hyperdb.DEBUG, 'update_class', (self, sql)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
207 self.cursor.execute(sql)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
208 olddata = self.cursor.fetchall()
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
209
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
210 # drop the old table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
211 self.cursor.execute('drop table _%s'%cn)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
212
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
213 # GADFLY requires a commit here, or the table spec screws up
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
214 self.conn.commit()
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
215
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
216 # create the new table
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
217 cols, mls = self.create_class_table(spec)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
218
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
219 # figure the new columns
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
220 extra = 0
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
221 for col in cols:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
222 if col not in fetch:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
223 fetch.append(col)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
224 extra += 1
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
225
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
226 if olddata:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
227 # do the insert
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
228 fetchcols = ','.join(fetch)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
229 args = ','.join([self.arg for x in fetch])
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
230 sql = 'insert into _%s (%s) values (%s)'%(cn, fetchcols, args)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
231 if __debug__:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
232 print >>hyperdb.DEBUG, 'update_class', (self, sql, olddata[0])
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
233 for entry in olddata:
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
234 self.cursor.execute(sql, tuple(entry) + (None,)*extra)
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
235
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
236 return 1
8fd1ad93f920 backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1366
diff changeset
237
1356
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
238 class GadflyClass:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
239 def filter(self, search_matches, filterspec, sort=(None,None),
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
240 group=(None,None)):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
241 ''' Gadfly doesn't have a LIKE predicate :(
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
242 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
243 cn = self.classname
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
244
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
245 # figure the WHERE clause from the filterspec
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
246 props = self.getprops()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
247 frum = ['_'+cn]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
248 where = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
249 args = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
250 a = self.db.arg
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
251 for k, v in filterspec.items():
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
252 propclass = props[k]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
253 if isinstance(propclass, Multilink):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
254 tn = '%s_%s'%(cn, k)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
255 frum.append(tn)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
256 if isinstance(v, type([])):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
257 s = ','.join([a for x in v])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
258 where.append('id=%s.nodeid and %s.linkid in (%s)'%(tn,tn,s))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
259 args = args + v
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
260 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
261 where.append('id=%s.nodeid and %s.linkid = %s'%(tn, tn, a))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
262 args.append(v)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
263 elif isinstance(propclass, Date):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
264 if isinstance(v, type([])):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
265 s = ','.join([a for x in v])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
266 where.append('_%s in (%s)'%(k, s))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
267 args = args + [date.Date(x).serialise() for x in v]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
268 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
269 where.append('_%s=%s'%(k, a))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
270 args.append(date.Date(v).serialise())
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
271 elif isinstance(propclass, Interval):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
272 if isinstance(v, type([])):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
273 s = ','.join([a for x in v])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
274 where.append('_%s in (%s)'%(k, s))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
275 args = args + [date.Interval(x).serialise() for x in v]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
276 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
277 where.append('_%s=%s'%(k, a))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
278 args.append(date.Interval(v).serialise())
1366
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
279 elif k == 'id':
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
280 if isinstance(v, type([])):
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
281 s = ','.join([a for x in v])
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
282 where.append('%s in (%s)'%(k, s))
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
283 args = args + v
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
284 else:
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
285 where.append('%s=%s'%(k, a))
1cc9c6bc17bd merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents: 1356
diff changeset
286 args.append(v)
1356
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
287 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
288 if isinstance(v, type([])):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
289 s = ','.join([a for x in v])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
290 where.append('_%s in (%s)'%(k, s))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
291 args = args + v
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
292 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
293 where.append('_%s=%s'%(k, a))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
294 args.append(v)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
295
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
296 # add results of full text search
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
297 if search_matches is not None:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
298 v = search_matches.keys()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
299 s = ','.join([a for x in v])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
300 where.append('id in (%s)'%s)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
301 args = args + v
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
302
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
303 # "grouping" is just the first-order sorting in the SQL fetch
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
304 # can modify it...)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
305 orderby = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
306 ordercols = []
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
307 if group[0] is not None and group[1] is not None:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
308 if group[0] != '-':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
309 orderby.append('_'+group[1])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
310 ordercols.append('_'+group[1])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
311 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
312 orderby.append('_'+group[1]+' desc')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
313 ordercols.append('_'+group[1])
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
314
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
315 # now add in the sorting
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
316 group = ''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
317 if sort[0] is not None and sort[1] is not None:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
318 direction, colname = sort
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
319 if direction != '-':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
320 if colname == 'id':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
321 orderby.append(colname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
322 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
323 orderby.append('_'+colname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
324 ordercols.append('_'+colname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
325 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
326 if colname == 'id':
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
327 orderby.append(colname+' desc')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
328 ordercols.append(colname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
329 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
330 orderby.append('_'+colname+' desc')
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
331 ordercols.append('_'+colname)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
332
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
333 # construct the SQL
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
334 frum = ','.join(frum)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
335 if where:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
336 where = ' where ' + (' and '.join(where))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
337 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
338 where = ''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
339 cols = ['id']
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
340 if orderby:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
341 cols = cols + ordercols
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
342 order = ' order by %s'%(','.join(orderby))
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
343 else:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
344 order = ''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
345 cols = ','.join(cols)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
346 sql = 'select %s from %s %s%s%s'%(cols, frum, where, group, order)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
347 args = tuple(args)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
348 if __debug__:
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
349 print >>hyperdb.DEBUG, 'filter', (self, sql, args)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
350 self.db.cursor.execute(sql, args)
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
351 l = self.db.cursor.fetchall()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
352
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
353 # return the IDs
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
354 return [row[0] for row in l]
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
355
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
356 def find(self, **propspec):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
357 ''' Overload to filter out duplicates in the result
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
358 '''
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
359 d = {}
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
360 for k in rdbms_common.Class.find(self, **propspec):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
361 d[k] = 1
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
362 return d.keys()
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
363
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
364 class Class(GadflyClass, rdbms_common.Class):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
365 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
366 class IssueClass(GadflyClass, rdbms_common.IssueClass):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
367 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
368 class FileClass(GadflyClass, rdbms_common.FileClass):
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
369 pass
83f33642d220 [[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
370

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