Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv21238/SQLObject
Modified Files:
Col.py Constraints.py Converters.py DBConnection.py
Log Message:
Added BoolCol with tests
Index: Col.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Col.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** Col.py 7 Sep 2003 22:35:09 -0000 1.26
--- Col.py 25 Sep 2003 20:40:25 -0000 1.27
***************
*** 35,39 ****
validator=None,
immutable=False):
!
# This isn't strictly true, since we *could* use backquotes or
# " or something (database-specific) around column names, but
--- 35,39 ----
validator=None,
immutable=False):
!
# This isn't strictly true, since we *could* use backquotes or
# " or something (database-specific) around column names, but
***************
*** 78,82 ****
else:
self.dbName = dbName
!
# alternateID means that this is a unique column that
# can be used to identify rows
--- 78,82 ----
else:
self.dbName = dbName
!
# alternateID means that this is a unique column that
# can be used to identify rows
***************
*** 219,225 ****
elif self.varchar == 'auto':
self.varchar = True
!
SOCol.__init__(self, **kw)
!
def autoConstraints(self):
constraints = [Constraints.isString]
--- 219,225 ----
elif self.varchar == 'auto':
self.varchar = True
!
SOCol.__init__(self, **kw)
!
def autoConstraints(self):
constraints = [Constraints.isString]
***************
*** 238,242 ****
class StringCol(Col):
baseClass = SOStringCol
!
class SOIntCol(SOCol):
--- 238,242 ----
class StringCol(Col):
baseClass = SOStringCol
!
class SOIntCol(SOCol):
***************
*** 252,255 ****
--- 252,266 ----
baseClass = SOIntCol
+ class SOBoolCol(SOCol):
+
+ def autoConstraints(self):
+ return [Constraints.isBool]
+
+ def _sqlType(self):
+ return 'BOOL'
+
+ class BoolCol(Col):
+ baseClass = SOBoolCol
+
class SOFloatCol(SOCol):
***************
*** 283,287 ****
class KeyCol(Col):
!
baseClass = SOKeyCol
--- 294,298 ----
class KeyCol(Col):
!
baseClass = SOKeyCol
Index: Constraints.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Constraints.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Constraints.py 19 Apr 2003 00:58:45 -0000 1.2
--- Constraints.py 25 Sep 2003 20:40:25 -0000 1.3
***************
*** 3,6 ****
--- 3,8 ----
"""
+ True, False = (1==1), (0==1)
+
class BadValue(ValueError):
***************
*** 20,24 ****
if type(value) is not type(""):
raise BadValue("only allows strings", obj, col, value)
!
def notNull(obj, col, value):
if value is None:
--- 22,26 ----
if type(value) is not type(""):
raise BadValue("only allows strings", obj, col, value)
!
def notNull(obj, col, value):
if value is None:
***************
*** 33,38 ****
raise BadValue("only allows floating point numbers", obj, col, value)
class InList:
!
def __init__(self, l):
self.list = l
--- 35,44 ----
raise BadValue("only allows floating point numbers", obj, col, value)
+ def isBool(obj, col, value):
+ if type(value) not in (type(True),):
+ raise BadValue("only allows booleans", obj, col, value)
+
class InList:
!
def __init__(self, l):
self.list = l
***************
*** 53,56 ****
% self.length,
obj, col, value)
!
!
--- 59,62 ----
% self.length,
obj, col, value)
!
!
Index: Converters.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Converters.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Converters.py 7 Sep 2003 07:05:26 -0000 1.4
--- Converters.py 25 Sep 2003 20:40:25 -0000 1.5
***************
*** 16,19 ****
--- 16,22 ----
except ImportError:
datetime = None
+
+ True, False = (1==1), (0==1)
+
from types import InstanceType, ClassType, TypeType
***************
*** 75,78 ****
--- 78,86 ----
registerConverter(type(1), IntConverter)
registerConverter(type(0L), IntConverter)
+
+ def BoolConverter(value):
+ return repr(bool(value))
+
+ registerConverter(type(True), BoolConverter)
def FloatConverter(value):
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** DBConnection.py 7 Sep 2003 23:36:08 -0000 1.47
--- DBConnection.py 25 Sep 2003 20:40:25 -0000 1.48
***************
*** 178,182 ****
return self._runWithConnection(self._iterSelect, select, self,
False)
!
def countSelect(self, select):
q = "SELECT COUNT(*) FROM %s WHERE %s" % \
--- 178,182 ----
return self._runWithConnection(self._iterSelect, select, self,
False)
!
def countSelect(self, select):
q = "SELECT COUNT(*) FROM %s WHERE %s" % \
***************
*** 395,399 ****
subCaches = [(sub, sub.allIDs()) for sub in self.cache.allSubCaches()]
self._connection.rollback()
!
for subCache, ids in subCaches:
for id in ids:
--- 395,399 ----
subCaches = [(sub, sub.allIDs()) for sub in self.cache.allSubCaches()]
self._connection.rollback()
!
for subCache, ids in subCaches:
for id in ids:
***************
*** 512,515 ****
--- 512,517 ----
elif t.startswith('datetime'):
return Col.DateTimeCol, {}
+ elif t.startswith('bool'):
+ return Col.BoolCol, {}
else:
return Col.Col, {}
***************
*** 663,666 ****
--- 665,670 ----
elif t.startswith('datetime'):
return Col.DateTimeCol, {}
+ elif t.startswith('bool'):
+ return Col.BoolCol, {}
else:
return Col.Col, {}
***************
*** 740,744 ****
if kinterbasdb is None:
import kinterbasdb
!
self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
--- 744,748 ----
if kinterbasdb is None:
import kinterbasdb
!
self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
***************
*** 751,755 ****
self.user = user
self.passwd = passwd
!
DBAPI.__init__(self, **kw)
--- 755,759 ----
self.user = user
self.passwd = passwd
!
DBAPI.__init__(self, **kw)
***************
*** 778,782 ****
self.printDebug(conn, id, 'QueryIns', 'result')
return id
!
def _queryAddLimitOffset(self, query, start, end):
"""Firebird slaps the limit and offset (actually 'first' and
--- 782,786 ----
self.printDebug(conn, id, 'QueryIns', 'result')
return id
!
def _queryAddLimitOffset(self, query, start, end):
"""Firebird slaps the limit and offset (actually 'first' and
***************
*** 797,806 ****
def createTable(self, soClass):
self.query('CREATE TABLE %s (\n%s\n)' % \
! (soClass._table, self.createColumns(soClass)))
self.query("CREATE GENERATOR GEN_%s" % soClass._table)
!
def createColumn(self, soClass, col):
return col.firebirdCreateSQL()
!
def createIDColumn(self, soClass):
return '%s INT NOT NULL PRIMARY KEY' % soClass._idName
--- 801,810 ----
def createTable(self, soClass):
self.query('CREATE TABLE %s (\n%s\n)' % \
! (soClass._table, self.createColumns(soClass)))
self.query("CREATE GENERATOR GEN_%s" % soClass._table)
!
def createColumn(self, soClass, col):
return col.firebirdCreateSQL()
!
def createIDColumn(self, soClass):
return '%s INT NOT NULL PRIMARY KEY' % soClass._idName
|