comparison roundup/backends/rdbms_common.py @ 1951:767ff2a03eee

more unit tests to improve coverage (up from 85% to 88% for anydbm! :)
author Richard Jones <richard@users.sourceforge.net>
date Fri, 05 Dec 2003 09:47:46 +0000
parents 3bdd34547fa7
children 910b39f8c5b8
comparison
equal deleted inserted replaced
1950:1eba6b6ca159 1951:767ff2a03eee
1 # $Id: rdbms_common.py,v 1.71 2003-11-16 18:41:40 jlgijsbers Exp $ 1 # $Id: rdbms_common.py,v 1.72 2003-12-05 09:47:46 richard Exp $
2 ''' Relational database (SQL) backend common code. 2 ''' Relational database (SQL) backend common code.
3 3
4 Basics: 4 Basics:
5 5
6 - map roundup classes to relational tables 6 - map roundup classes to relational tables
153 153
154 # commit 154 # commit
155 self.conn.commit() 155 self.conn.commit()
156 156
157 def refresh_database(self): 157 def refresh_database(self):
158 # now detect changes in the schema 158 self.post_init()
159 for classname, spec in self.classes.items():
160 dbspec = self.database_schema[classname]
161 self.update_class(spec, dbspec, force=1)
162 self.database_schema[classname] = spec.schema()
163 # update the database version of the schema
164 self.sql('delete from schema')
165 self.save_dbschema(self.database_schema)
166 # reindex the db
167 self.reindex()
168 # commit
169 self.conn.commit()
170
171 159
172 def reindex(self): 160 def reindex(self):
173 for klass in self.classes.values(): 161 for klass in self.classes.values():
174 for nodeid in klass.list(): 162 for nodeid in klass.list():
175 klass.index(nodeid) 163 klass.index(nodeid)
1798 prop = props[propname] 1786 prop = props[propname]
1799 if not isinstance(prop, Link) and not isinstance(prop, Multilink): 1787 if not isinstance(prop, Link) and not isinstance(prop, Multilink):
1800 raise TypeError, "'%s' not a Link/Multilink property"%propname 1788 raise TypeError, "'%s' not a Link/Multilink property"%propname
1801 1789
1802 # first, links 1790 # first, links
1803 where = [] 1791 where = ['__retired__ = %s']
1804 allvalues = () 1792 allvalues = (0,)
1805 a = self.db.arg 1793 a = self.db.arg
1806 for prop, values in propspec: 1794 for prop, values in propspec:
1807 if not isinstance(props[prop], hyperdb.Link): 1795 if not isinstance(props[prop], hyperdb.Link):
1808 continue 1796 continue
1809 if type(values) is type({}) and len(values) == 1: 1797 if type(values) is type({}) and len(values) == 1:
1850 ''' 1838 '''
1851 where = [] 1839 where = []
1852 args = [] 1840 args = []
1853 for propname in requirements.keys(): 1841 for propname in requirements.keys():
1854 prop = self.properties[propname] 1842 prop = self.properties[propname]
1855 if isinstance(not prop, String): 1843 if not isinstance(prop, String):
1856 raise TypeError, "'%s' not a String property"%propname 1844 raise TypeError, "'%s' not a String property"%propname
1857 where.append(propname) 1845 where.append(propname)
1858 args.append(requirements[propname].lower()) 1846 args.append(requirements[propname].lower())
1859 1847
1860 # generate the where clause 1848 # generate the where clause
1861 s = ' and '.join(['lower(_%s)=%s'%(col, self.db.arg) for col in where]) 1849 s = ' and '.join(['lower(_%s)=%s'%(col, self.db.arg) for col in where])
1862 sql = 'select id from _%s where %s'%(self.classname, s) 1850 sql = 'select id from _%s where %s and __retired__=%s'%(self.classname,
1851 s, self.db.arg)
1852 args.append(0)
1863 self.db.sql(sql, tuple(args)) 1853 self.db.sql(sql, tuple(args))
1864 l = [x[0] for x in self.db.sql_fetchall()] 1854 l = [x[0] for x in self.db.sql_fetchall()]
1865 if __debug__: 1855 if __debug__:
1866 print >>hyperdb.DEBUG, 'find ... ', l 1856 print >>hyperdb.DEBUG, 'find ... ', l
1867 return l 1857 return l

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