Skip to content

Commit b79ea45

Browse files
author
Richard Jones
committed
fixed rdbms searching by ID [SF#666615]
detect corrupted index and raise semi-useful exception [SF#666767] also some mysql support (in tests)
1 parent 66afe64 commit b79ea45

File tree

8 files changed

+79
-13
lines changed

8 files changed

+79
-13
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ are given with the most recent entry first.
1111
- applied patch for nicer history display (sf feature 638280)
1212

1313

14+
2003-??-?? 0.5.5
15+
- fixed rdbms searching by ID (sf bug 666615)
16+
- detect corrupted index and raise semi-useful exception (sf bug 666767)
17+
18+
1419
2003-01-10 0.5.4
1520
- key the templates cache off full path, not filename
1621
- implemented whole-database locking

TODO.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ pending web multilink item removal action with retirement
5858
pending web implement a python dict version of the form values
5959
pending web implement the request.url attribute?
6060
pending web UNIX init.d script for roundup-server
61+
62+
bug hyperdb need unit tests for firing of auditors and reactors
6163
======= ========= =============================================================
6264

doc/customizing.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.69 $
5+
:Version: $Revision: 1.70 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -999,7 +999,7 @@ forms:
999999
in place if the "foo" form variable doesn't exist.
10001000

10011001
**String Expressions** - eg. ``string:hello ${user/name}``
1002-
These expressions are simple string interpolations (though they can be just
1002+
These expressions are simple string interpolations - though they can be just
10031003
plain strings with no interpolation if you want. The expression in the
10041004
``${ ... }`` is just a path expression as above.
10051005

roundup/backends/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: __init__.py,v 1.20 2002-10-07 00:52:51 richard Exp $
18+
# $Id: __init__.py,v 1.21 2003-01-12 23:53:19 richard Exp $
1919

2020
''' Container for the hyperdb storage backend implementations.
2121
@@ -56,6 +56,15 @@
5656
gadfly = back_gadfly
5757
__all__.append('gadfly')
5858

59+
try:
60+
import MySQLdb
61+
except ImportError, message:
62+
if str(message) != 'No module named MySQLdb': raise
63+
else:
64+
import back_mysql
65+
mysql = back_mysql
66+
__all__.append('mysql')
67+
5968
try:
6069
import sqlite
6170
except ImportError, message:

roundup/backends/back_gadfly.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_gadfly.py,v 1.31 2003-01-08 05:39:40 richard Exp $
1+
# $Id: back_gadfly.py,v 1.32 2003-01-12 23:53:20 richard Exp $
22
''' Gadlfy relational database hypderb backend.
33
44
About Gadfly
@@ -185,6 +185,14 @@ def filter(self, search_matches, filterspec, sort=(None,None),
185185
else:
186186
where.append('_%s=%s'%(k, a))
187187
args.append(date.Interval(v).serialise())
188+
elif k == 'id':
189+
if isinstance(v, type([])):
190+
s = ','.join([a for x in v])
191+
where.append('%s in (%s)'%(k, s))
192+
args = args + v
193+
else:
194+
where.append('%s=%s'%(k, a))
195+
args.append(v)
188196
else:
189197
if isinstance(v, type([])):
190198
s = ','.join([a for x in v])

roundup/backends/rdbms_common.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.27 2003-01-08 05:39:40 richard Exp $
1+
# $Id: rdbms_common.py,v 1.28 2003-01-12 23:53:20 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1762,6 +1762,14 @@ def filter(self, search_matches, filterspec, sort=(None,None),
17621762
else:
17631763
where.append('id=%s.nodeid and %s.linkid = %s'%(tn, tn, a))
17641764
args.append(v)
1765+
elif k == 'id':
1766+
if isinstance(v, type([])):
1767+
s = ','.join([a for x in v])
1768+
where.append('%s in (%s)'%(k, s))
1769+
args = args + v
1770+
else:
1771+
where.append('%s=%s'%(k, a))
1772+
args.append(v)
17651773
elif isinstance(propclass, String):
17661774
if not isinstance(v, type([])):
17671775
v = [v]

roundup/indexer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# that promote freedom, but obviously am giving up any rights
1515
# to compel such.
1616
#
17-
#$Id: indexer.py,v 1.14 2002-09-25 05:06:14 richard Exp $
17+
#$Id: indexer.py,v 1.15 2003-01-12 23:53:19 richard Exp $
1818
'''
1919
This module provides an indexer class, RoundupIndexer, that stores text
2020
indices in a roundup instance. This class makes searching the content of
@@ -214,13 +214,15 @@ def find(self, wordlist):
214214
# word outside the bounds of what we index - ignore
215215
continue
216216
word = word.upper()
217-
entry = self.words.get(word) # For each word, get index
218-
entries[word] = entry # of matching files
219-
if not entry: # Nothing for this one word (fail)
217+
entry = self.words[word] # For each word, get index
218+
entries[word] = entry # of matching files
219+
if not entry: # Nothing for this one word (fail)
220220
return {}
221221
if hits is None:
222222
hits = {}
223223
for k in entry.keys():
224+
if not self.fileids.has_key(k):
225+
raise ValueError, 'Index is corrupted: re-generate it'
224226
hits[k] = self.fileids[k]
225227
else:
226228
# Eliminate hits for every non-match

test/test_db.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.64 2003-01-12 00:43:43 richard Exp $
18+
# $Id: test_db.py,v 1.65 2003-01-12 23:53:20 richard Exp $
1919

2020
import unittest, os, shutil, time
2121

@@ -570,6 +570,10 @@ def filteringSetup(self):
570570
self.db.commit()
571571
return self.assertEqual, self.db.issue.filter
572572

573+
def testFilteringID(self):
574+
ae, filt = self.filteringSetup()
575+
ae(filt(None, {'id': '1'}, ('+','id'), (None,None)), ['1'])
576+
573577
def testFilteringString(self):
574578
ae, filt = self.filteringSetup()
575579
ae(filt(None, {'title': 'issue one'}, ('+','id'), (None,None)), ['1'])
@@ -698,6 +702,32 @@ def setUp(self):
698702
setupSchema(self.db, 0, gadfly)
699703

700704

705+
class mysqlDBTestCase(anydbmDBTestCase):
706+
def setUp(self):
707+
from roundup.backends import mysql
708+
# remove previous test, ignore errors
709+
if os.path.exists(config.DATABASE):
710+
shutil.rmtree(config.DATABASE)
711+
config.MYSQL_DATABASE='mysql@localhost root rootpasswd'.split()
712+
os.makedirs(config.DATABASE + '/files')
713+
self.db = mysql.Database(config, 'admin')
714+
setupSchema(self.db, 1, mysql)
715+
716+
class mysqlReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
717+
def setUp(self):
718+
from roundup.backends import mysql
719+
# remove previous test, ignore errors
720+
if os.path.exists(config.DATABASE):
721+
shutil.rmtree(config.DATABASE)
722+
config.MYSQL_DATABASE='mysql@localhost root rootpasswd'.split()
723+
os.makedirs(config.DATABASE + '/files')
724+
db = mysql.Database(config, 'admin')
725+
setupSchema(db, 1, mysql)
726+
db.close()
727+
self.db = sqlite.Database(config)
728+
setupSchema(self.db, 0, mysql)
729+
730+
701731
class sqliteDBTestCase(anydbmDBTestCase):
702732
def setUp(self):
703733
from roundup.backends import sqlite
@@ -708,9 +738,6 @@ def setUp(self):
708738
self.db = sqlite.Database(config, 'admin')
709739
setupSchema(self.db, 1, sqlite)
710740

711-
def testIDGeneration(self):
712-
pass
713-
714741
class sqliteReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
715742
def setUp(self):
716743
from roundup.backends import sqlite
@@ -791,6 +818,11 @@ def suite():
791818
# return unittest.TestSuite(l)
792819

793820
from roundup import backends
821+
# if hasattr(backends, 'mysql'):
822+
# l.append(unittest.makeSuite(mysqlDBTestCase, 'test'))
823+
# l.append(unittest.makeSuite(mysqlReadOnlyDBTestCase, 'test'))
824+
# return unittest.TestSuite(l)
825+
794826
if hasattr(backends, 'gadfly'):
795827
l.append(unittest.makeSuite(gadflyDBTestCase, 'test'))
796828
l.append(unittest.makeSuite(gadflyReadOnlyDBTestCase, 'test'))

0 commit comments

Comments
 (0)