Mercurial > p > roundup > code
comparison roundup/backends/rdbms_common.py @ 2005:fc52d57c6c3e
documentation cleanup
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 11 Feb 2004 23:55:10 +0000 |
| parents | 5660b89f8903 |
| children | 261c2e6ceb1e |
comparison
equal
deleted
inserted
replaced
| 2004:1782fe36e7b8 | 2005:fc52d57c6c3e |
|---|---|
| 1 # $Id: rdbms_common.py,v 1.74 2004-01-20 05:55:51 richard Exp $ | 1 # $Id: rdbms_common.py,v 1.75 2004-02-11 23:55:09 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 |
| 18 sql_* methods, since everything else should be fairly generic. There's | 18 sql_* methods, since everything else should be fairly generic. There's |
| 19 probably a bit of work to be done if a database is used that actually | 19 probably a bit of work to be done if a database is used that actually |
| 20 honors column typing, since the initial databases don't (sqlite stores | 20 honors column typing, since the initial databases don't (sqlite stores |
| 21 everything as a string.) | 21 everything as a string.) |
| 22 ''' | 22 ''' |
| 23 __docformat__ = 'restructuredtext' | |
| 23 | 24 |
| 24 # standard python modules | 25 # standard python modules |
| 25 import sys, os, time, re, errno, weakref, copy | 26 import sys, os, time, re, errno, weakref, copy |
| 26 | 27 |
| 27 # roundup modules | 28 # roundup modules |
| 488 return self.classes[classname] | 489 return self.classes[classname] |
| 489 except KeyError: | 490 except KeyError: |
| 490 raise KeyError, 'There is no class called "%s"'%classname | 491 raise KeyError, 'There is no class called "%s"'%classname |
| 491 | 492 |
| 492 def clear(self): | 493 def clear(self): |
| 493 ''' Delete all database contents. | 494 '''Delete all database contents. |
| 494 | 495 |
| 495 Note: I don't commit here, which is different behaviour to the | 496 Note: I don't commit here, which is different behaviour to the |
| 496 "nuke from orbit" behaviour in the *dbms. | 497 "nuke from orbit" behaviour in the dbs. |
| 497 ''' | 498 ''' |
| 498 if __debug__: | 499 if __debug__: |
| 499 print >>hyperdb.DEBUG, 'clear', (self,) | 500 print >>hyperdb.DEBUG, 'clear', (self,) |
| 500 for cn in self.classes.keys(): | 501 for cn in self.classes.keys(): |
| 501 sql = 'delete from _%s'%cn | 502 sql = 'delete from _%s'%cn |
| 1647 '''Destroy a node. | 1648 '''Destroy a node. |
| 1648 | 1649 |
| 1649 WARNING: this method should never be used except in extremely rare | 1650 WARNING: this method should never be used except in extremely rare |
| 1650 situations where there could never be links to the node being | 1651 situations where there could never be links to the node being |
| 1651 deleted | 1652 deleted |
| 1653 | |
| 1652 WARNING: use retire() instead | 1654 WARNING: use retire() instead |
| 1655 | |
| 1653 WARNING: the properties of this node will not be available ever again | 1656 WARNING: the properties of this node will not be available ever again |
| 1657 | |
| 1654 WARNING: really, use retire() instead | 1658 WARNING: really, use retire() instead |
| 1655 | 1659 |
| 1656 Well, I think that's enough warnings. This method exists mostly to | 1660 Well, I think that's enough warnings. This method exists mostly to |
| 1657 support the session storage of the cgi interface. | 1661 support the session storage of the cgi interface. |
| 1658 | 1662 |
| 1704 def getkey(self): | 1708 def getkey(self): |
| 1705 '''Return the name of the key property for this class or None.''' | 1709 '''Return the name of the key property for this class or None.''' |
| 1706 return self.key | 1710 return self.key |
| 1707 | 1711 |
| 1708 def labelprop(self, default_to_id=0): | 1712 def labelprop(self, default_to_id=0): |
| 1709 ''' Return the property name for a label for the given node. | 1713 '''Return the property name for a label for the given node. |
| 1710 | 1714 |
| 1711 This method attempts to generate a consistent label for the node. | 1715 This method attempts to generate a consistent label for the node. |
| 1712 It tries the following in order: | 1716 It tries the following in order: |
| 1713 1. key property | 1717 |
| 1714 2. "name" property | 1718 1. key property |
| 1715 3. "title" property | 1719 2. "name" property |
| 1716 4. first property from the sorted property name list | 1720 3. "title" property |
| 1721 4. first property from the sorted property name list | |
| 1717 ''' | 1722 ''' |
| 1718 k = self.getkey() | 1723 k = self.getkey() |
| 1719 if k: | 1724 if k: |
| 1720 return k | 1725 return k |
| 1721 props = self.getprops() | 1726 props = self.getprops() |
| 1895 ids = [x[0] for x in self.db.cursor.fetchall()] | 1900 ids = [x[0] for x in self.db.cursor.fetchall()] |
| 1896 return ids | 1901 return ids |
| 1897 | 1902 |
| 1898 def filter(self, search_matches, filterspec, sort=(None,None), | 1903 def filter(self, search_matches, filterspec, sort=(None,None), |
| 1899 group=(None,None)): | 1904 group=(None,None)): |
| 1900 ''' Return a list of the ids of the active nodes in this class that | 1905 '''Return a list of the ids of the active nodes in this class that |
| 1901 match the 'filter' spec, sorted by the group spec and then the | 1906 match the 'filter' spec, sorted by the group spec and then the |
| 1902 sort spec | 1907 sort spec |
| 1903 | 1908 |
| 1904 "filterspec" is {propname: value(s)} | 1909 "filterspec" is {propname: value(s)} |
| 1905 "sort" and "group" are (dir, prop) where dir is '+', '-' or None | 1910 |
| 1906 and prop is a prop name or None | 1911 "sort" and "group" are (dir, prop) where dir is '+', '-' or None |
| 1907 "search_matches" is {nodeid: marker} | 1912 and prop is a prop name or None |
| 1908 | 1913 |
| 1909 The filter must match all properties specificed - but if the | 1914 "search_matches" is {nodeid: marker} |
| 1910 property value to match is a list, any one of the values in the | 1915 |
| 1911 list may match for that property to match. | 1916 The filter must match all properties specificed - but if the |
| 1917 property value to match is a list, any one of the values in the | |
| 1918 list may match for that property to match. | |
| 1912 ''' | 1919 ''' |
| 1913 # just don't bother if the full-text search matched diddly | 1920 # just don't bother if the full-text search matched diddly |
| 1914 if search_matches == {}: | 1921 if search_matches == {}: |
| 1915 return [] | 1922 return [] |
| 1916 | 1923 |
