sqlobject-cvs Mailing List for SQLObject (Page 184)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
(9) |
Apr
(74) |
May
(29) |
Jun
(16) |
Jul
(28) |
Aug
(10) |
Sep
(57) |
Oct
(9) |
Nov
(29) |
Dec
(12) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(7) |
Feb
(14) |
Mar
(6) |
Apr
(3) |
May
(12) |
Jun
(34) |
Jul
(9) |
Aug
(29) |
Sep
(22) |
Oct
(2) |
Nov
(15) |
Dec
(52) |
| 2005 |
Jan
(47) |
Feb
(78) |
Mar
(14) |
Apr
(35) |
May
(33) |
Jun
(16) |
Jul
(26) |
Aug
(63) |
Sep
(40) |
Oct
(96) |
Nov
(96) |
Dec
(123) |
| 2006 |
Jan
(159) |
Feb
(144) |
Mar
(64) |
Apr
(31) |
May
(88) |
Jun
(48) |
Jul
(16) |
Aug
(64) |
Sep
(87) |
Oct
(92) |
Nov
(56) |
Dec
(76) |
| 2007 |
Jan
(94) |
Feb
(103) |
Mar
(126) |
Apr
(123) |
May
(85) |
Jun
(11) |
Jul
(130) |
Aug
(47) |
Sep
(65) |
Oct
(70) |
Nov
(12) |
Dec
(11) |
| 2008 |
Jan
(30) |
Feb
(55) |
Mar
(88) |
Apr
(20) |
May
(50) |
Jun
|
Jul
(38) |
Aug
(1) |
Sep
(9) |
Oct
(5) |
Nov
(6) |
Dec
(39) |
| 2009 |
Jan
(8) |
Feb
(16) |
Mar
(3) |
Apr
(33) |
May
(44) |
Jun
(1) |
Jul
(10) |
Aug
(33) |
Sep
(74) |
Oct
(22) |
Nov
|
Dec
(15) |
| 2010 |
Jan
(28) |
Feb
(22) |
Mar
(46) |
Apr
(29) |
May
(1) |
Jun
(1) |
Jul
(27) |
Aug
(8) |
Sep
(5) |
Oct
(33) |
Nov
(24) |
Dec
(41) |
| 2011 |
Jan
(4) |
Feb
(12) |
Mar
(35) |
Apr
(29) |
May
(19) |
Jun
(16) |
Jul
(32) |
Aug
(25) |
Sep
(5) |
Oct
(11) |
Nov
(21) |
Dec
(12) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
(20) |
Apr
(4) |
May
(25) |
Jun
(13) |
Jul
|
Aug
|
Sep
(2) |
Oct
(25) |
Nov
(9) |
Dec
(1) |
| 2013 |
Jan
(6) |
Feb
(8) |
Mar
|
Apr
(10) |
May
(31) |
Jun
(7) |
Jul
(18) |
Aug
(33) |
Sep
(4) |
Oct
(16) |
Nov
|
Dec
(27) |
| 2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
(11) |
May
(39) |
Jun
(8) |
Jul
(11) |
Aug
(4) |
Sep
|
Oct
(27) |
Nov
|
Dec
(71) |
| 2015 |
Jan
(17) |
Feb
(47) |
Mar
(33) |
Apr
|
May
|
Jun
(9) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(8) |
| 2016 |
Jan
(4) |
Feb
(4) |
Mar
|
Apr
|
May
(12) |
Jun
(7) |
Jul
(9) |
Aug
(31) |
Sep
(8) |
Oct
(3) |
Nov
(15) |
Dec
(1) |
| 2017 |
Jan
(13) |
Feb
(7) |
Mar
(14) |
Apr
(8) |
May
(10) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(8) |
Nov
(4) |
Dec
(5) |
| 2018 |
Jan
(2) |
Feb
(8) |
Mar
|
Apr
(4) |
May
|
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
(1) |
Feb
(16) |
Mar
(1) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(2) |
| 2021 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
(1) |
Dec
(4) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(4) |
Dec
|
| 2024 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(9) |
| 2025 |
Jan
|
Feb
(4) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(2) |
Dec
(2) |
|
From: <ian...@us...> - 2003-09-26 07:13:05
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv1915/tests
Modified Files:
test.py
Log Message:
* Fixed validation -- fromPython and toPython were mixed up in places.
* Made sure validation/conversion happened everywhere it should.
* Fixed BoolCol to work like it should.
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** test.py 25 Sep 2003 20:40:25 -0000 1.30
--- test.py 26 Sep 2003 07:13:00 -0000 1.31
***************
*** 437,441 ****
created DATETIME NOT NULL,
happy char(1) DEFAULT 'Y' NOT NULL,
! wannahavefun BOOL DEFAULT FALSE NOT NULL
)
"""
--- 437,441 ----
created DATETIME NOT NULL,
happy char(1) DEFAULT 'Y' NOT NULL,
! wannahavefun TINYINT DEFAULT 0 NOT NULL
)
"""
***************
*** 639,643 ****
name = StringCol(validator=Validator.PlainText(), default='x')
name2 = StringCol(validator=Validator.ConfirmType(str), default='y')
! name3 = StringCol(validator=Validator.Wrapper(toPython=int), default=100)
class ValidationTest(SQLObjectTest):
--- 639,643 ----
name = StringCol(validator=Validator.PlainText(), default='x')
name2 = StringCol(validator=Validator.ConfirmType(str), default='y')
! name3 = StringCol(validator=Validator.Wrapper(fromPython=int), default=100)
class ValidationTest(SQLObjectTest):
***************
*** 692,697 ****
"""
! sqliteCreate = mysqlCreate
! firebirdCreate = mysqlCreate
mysqlDrop = """
--- 692,697 ----
"""
! sqliteCreate = postgresCreate
! firebirdCreate = postgresCreate
mysqlDrop = """
|
|
From: <ian...@us...> - 2003-09-26 07:13:04
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv1915/SQLObject
Modified Files:
Col.py Converters.py DBConnection.py SQLObject.py
Log Message:
* Fixed validation -- fromPython and toPython were mixed up in places.
* Made sure validation/conversion happened everywhere it should.
* Fixed BoolCol to work like it should.
Index: Col.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Col.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** Col.py 25 Sep 2003 20:40:25 -0000 1.27
--- Col.py 26 Sep 2003 07:12:59 -0000 1.28
***************
*** 103,113 ****
self.foreignName = None
! if validator:
! self.toPython = validator.toPython
! self.fromPython = validator.fromPython
else:
self.toPython = None
self.fromPython = None
def autoConstraints(self):
return []
--- 103,122 ----
self.foreignName = None
! self.validator = validator
!
! def _set_validator(self, value):
! self._validator = value
! if self._validator:
! self.toPython = self._validator.toPython
! self.fromPython = self._validator.fromPython
else:
self.toPython = None
self.fromPython = None
+ def _get_validator(self):
+ return self._validator
+
+ validator = property(_get_validator, _set_validator)
+
def autoConstraints(self):
return []
***************
*** 252,262 ****
baseClass = SOIntCol
class SOBoolCol(SOCol):
def autoConstraints(self):
return [Constraints.isBool]
! def _sqlType(self):
return 'BOOL'
class BoolCol(Col):
--- 261,286 ----
baseClass = SOIntCol
+ class BoolValidator(Validator.Validator):
+
+ def fromPython(self, value, state):
+ if value:
+ return 't'
+ else:
+ return 'f'
+
class SOBoolCol(SOCol):
+ def __init__(self, **kw):
+ SOCol.__init__(self, **kw)
+ self.validator = Validator.All.join(BoolValidator(), self.validator)
+
def autoConstraints(self):
return [Constraints.isBool]
! def _postgresType(self):
return 'BOOL'
+
+ def _mysqlType(self):
+ return "ENUM('t', 'f')"
class BoolCol(Col):
Index: Converters.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Converters.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Converters.py 25 Sep 2003 20:40:25 -0000 1.5
--- Converters.py 26 Sep 2003 07:12:59 -0000 1.6
***************
*** 80,86 ****
def BoolConverter(value):
! return repr(bool(value))
! registerConverter(type(True), BoolConverter)
def FloatConverter(value):
--- 80,90 ----
def BoolConverter(value):
! if value:
! return '1'
! else:
! return '0'
! if type(True) != type(1):
! registerConverter(type(True), BoolConverter)
def FloatConverter(value):
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** DBConnection.py 25 Sep 2003 20:40:25 -0000 1.48
--- DBConnection.py 26 Sep 2003 07:12:59 -0000 1.49
***************
*** 661,665 ****
return Col.StringCol, {'length': int(t[t.index('(')+1:-1]),
'varchar': False}
! elif t=='text':
return Col.StringCol, {}
elif t.startswith('datetime'):
--- 661,665 ----
return Col.StringCol, {'length': int(t[t.index('(')+1:-1]),
'varchar': False}
! elif t == 'text':
return Col.StringCol, {}
elif t.startswith('datetime'):
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** SQLObject.py 24 Sep 2003 12:18:15 -0000 1.58
--- SQLObject.py 26 Sep 2003 07:12:59 -0000 1.59
***************
*** 380,383 ****
--- 380,384 ----
inst = object.__new__(cls)
inst._SO_creating = True
+ inst._SO_validatorState = SQLObjectState(inst)
# This is a dictionary of column-names to
# column-values for the new row:
***************
*** 403,406 ****
--- 404,408 ----
try:
val = object.__new__(cls)
+ val._SO_validatorState = SQLObjectState(val)
val._init(id, connection, selectResults)
cache.put(id, cls, val)
***************
*** 454,459 ****
if not column.immutable:
# We start by just using the _SO_setValue method
! setter = eval('lambda self, val: self._SO_setValue(%s, val, self.%s)' % (repr(name), '_SO_toPython_%s' % name))
! setattr(cls, '_SO_toPython_%s' % name, column.toPython)
setattr(cls, rawSetterName(name), setter)
# Then do the aliasing
--- 456,461 ----
if not column.immutable:
# We start by just using the _SO_setValue method
! setter = eval('lambda self, val: self._SO_setValue(%s, val, self.%s)' % (repr(name), '_SO_fromPython_%s' % name))
! setattr(cls, '_SO_fromPython_%s' % name, column.fromPython)
setattr(cls, rawSetterName(name), setter)
# Then do the aliasing
***************
*** 661,666 ****
self._SO_perConnection = True
- self._SO_validatorState = SQLObjectState(self)
-
if not selectResults:
dbNames = [col.dbName for col in self._SO_columns]
--- 663,666 ----
***************
*** 721,725 ****
self._SO_writeLock.release()
! def _SO_setValue(self, name, value, toPython):
# This is the place where we actually update the
# database.
--- 721,725 ----
self._SO_writeLock.release()
! def _SO_setValue(self, name, value, fromPython):
# This is the place where we actually update the
# database.
***************
*** 729,734 ****
# the parts are set. So we just keep them in a
# dictionary until later:
! if toPython:
! value = toPython(value, self._SO_validatorState)
if self._SO_creating:
self._SO_createValues[name] = value
--- 729,734 ----
# the parts are set. So we just keep them in a
# dictionary until later:
! if fromPython:
! value = fromPython(value, self._SO_validatorState)
if self._SO_creating:
self._SO_createValues[name] = value
***************
*** 748,751 ****
--- 748,755 ----
# _SO_creating is special, see _SO_setValue
if self._SO_creating:
+ for name, value in kw.items():
+ fromPython = getattr(self, '_SO_fromPython_%s' % name)
+ if fromPython:
+ kw[name] = fromPython(value, self._SO_validatorState)
self._SO_createValues.update(kw)
return
***************
*** 764,767 ****
--- 768,774 ----
for name, value in kw.items():
if self._SO_plainSetters.has_key(name):
+ fromPython = getattr(self, '_SO_fromPython_%s' % name)
+ if fromPython:
+ value = fromPython(value, self._SO_validatorState)
toUpdate[name] = value
if self._cacheValues:
***************
*** 776,781 ****
def _SO_selectInit(self, row):
for col, colValue in zip(self._SO_columns, row):
! if col.fromPython:
! colValue = col.fromPython(colValue, self._SO_validatorState)
setattr(self, instanceName(col.name), colValue)
--- 783,788 ----
def _SO_selectInit(self, row):
for col, colValue in zip(self._SO_columns, row):
! if col.toPython:
! colValue = col.toPython(colValue, self._SO_validatorState)
setattr(self, instanceName(col.name), colValue)
|
|
From: <ian...@us...> - 2003-09-26 07:13:04
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject/include
In directory sc8-pr-cvs1:/tmp/cvs-serv1915/SQLObject/include
Modified Files:
Validator.py
Log Message:
* Fixed validation -- fromPython and toPython were mixed up in places.
* Made sure validation/conversion happened everywhere it should.
* Fixed BoolCol to work like it should.
Index: Validator.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/include/Validator.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Validator.py 24 Sep 2003 12:18:15 -0000 1.2
--- Validator.py 26 Sep 2003 07:12:59 -0000 1.3
***************
*** 282,285 ****
--- 282,289 ----
return first.withValidator(validators)
else:
+ # Get rid of any None values in the list:
+ validators = filter(None, validators)
+ if not validators:
+ return first
return cls(first, *validators)
join = classmethod(join)
***************
*** 345,348 ****
--- 349,353 ----
'subclass': self.subclass},
value, state)
+ return value
def confirmInType(self, value, state):
***************
*** 352,355 ****
--- 357,361 ----
'typeList': ', '.join(map(repr, self.inType))},
value, state)
+ return value
def confirmType(self, value, state):
***************
*** 359,362 ****
--- 365,369 ----
'type': self.type},
value, state)
+ return value
class Wrapper(FancyValidator):
|
|
From: <ian...@us...> - 2003-09-26 07:11:51
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv1794/tests
Modified Files:
SQLObjectTest.py
Log Message:
Added a slightly better error message
Index: SQLObjectTest.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/SQLObjectTest.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** SQLObjectTest.py 7 Sep 2003 23:36:08 -0000 1.15
--- SQLObjectTest.py 26 Sep 2003 07:11:46 -0000 1.16
***************
*** 132,136 ****
def setDatabaseType(t):
global __connection__
! conn = globals()[t + "Connection"]()
SQLObjectTest.databaseName = t
__connection__ = conn
--- 132,139 ----
def setDatabaseType(t):
global __connection__
! try:
! conn = globals()[t + "Connection"]()
! except KeyError:
! raise KeyError, 'No connection by the type %s is known' % t
SQLObjectTest.databaseName = t
__connection__ = conn
|
|
From: <dre...@us...> - 2003-09-25 20:40:29
|
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
|
|
From: <dre...@us...> - 2003-09-25 20:40:29
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv21238/tests
Modified Files:
test.py test_converters.py
Log Message:
Added BoolCol with tests
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** test.py 24 Sep 2003 12:18:16 -0000 1.29
--- test.py 25 Sep 2003 20:40:25 -0000 1.30
***************
*** 436,440 ****
age INT DEFAULT NULL,
created DATETIME NOT NULL,
! happy char(1) DEFAULT 'Y' NOT NULL
)
"""
--- 436,441 ----
age INT DEFAULT NULL,
created DATETIME NOT NULL,
! happy char(1) DEFAULT 'Y' NOT NULL,
! wannahavefun BOOL DEFAULT FALSE NOT NULL
)
"""
***************
*** 447,451 ****
age INT DEFAULT 0,
created VARCHAR(40) NOT NULL,
! happy char(1) DEFAULT 'Y' NOT NULL
)
"""
--- 448,453 ----
age INT DEFAULT 0,
created VARCHAR(40) NOT NULL,
! happy char(1) DEFAULT 'Y' NOT NULL,
! wannahavefun BOOL DEFAULT FALSE NOT NULL
)
"""
***************
*** 468,479 ****
_fromDatabase = True
_connection = connection()
! AutoTest.new(firstName='john',
! lastName='doe',
! age=10,
! created=DateTime.now())
! AutoTest.new(firstName='jane',
! lastName='doe',
! happy='N',
! created=DateTime.now())
reg = sys.modules[SQLObject.__module__].classRegistry[AutoTest._registry]
del reg['AutoTest']
--- 470,485 ----
_fromDatabase = True
_connection = connection()
! john = AutoTest.new(firstName='john',
! lastName='doe',
! age=10,
! created=DateTime.now(),
! wannahavefun=False)
! jane = AutoTest.new(firstName='jane',
! lastName='doe',
! happy='N',
! created=DateTime.now(),
! wannahavefun=True)
! self.failIf(john.wannahavefun)
! self.failUnless(jane.wannahavefun)
reg = sys.modules[SQLObject.__module__].classRegistry[AutoTest._registry]
del reg['AutoTest']
Index: test_converters.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test_converters.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** test_converters.py 31 Jul 2003 14:25:33 -0000 1.3
--- test_converters.py 25 Sep 2003 20:40:25 -0000 1.4
***************
*** 74,77 ****
--- 74,81 ----
self.assertEqual(sqlRepr(('one','two','three')), "('one', 'two', 'three')")
+ def test_bool(self):
+ self.assertEqual(sqlRepr(True), 'True')
+ self.assertEqual(sqlRepr(False), 'False')
+
def test_instance(self):
instance = TestClass()
|
|
From: <dre...@us...> - 2003-09-24 12:18:21
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject/include
In directory sc8-pr-cvs1:/tmp/cvs-serv2752/SQLObject/include
Modified Files:
Validator.py
Log Message:
Mostly whitespace and a fix for postgreSQLCreate
Index: Validator.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/include/Validator.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Validator.py 7 Sep 2003 22:35:09 -0000 1.1
--- Validator.py 24 Sep 2003 12:18:15 -0000 1.2
***************
*** 1,5 ****
## FormEncode, a Form processor
## Copyright (C) 2003, Ian Bicking <ia...@co...>
! ##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
--- 1,5 ----
## FormEncode, a Form processor
## Copyright (C) 2003, Ian Bicking <ia...@co...>
! ##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
***************
*** 71,75 ****
obj = All(*obj)
return obj
!
def _validateToSomething(obj, value, state, finisher):
validator = getValidator(obj)
--- 71,75 ----
obj = All(*obj)
return obj
!
def _validateToSomething(obj, value, state, finisher):
validator = getValidator(obj)
***************
*** 113,117 ****
def message(self, name, default):
! if not self.messages:
return default
return self.messages.get(name, default)
--- 113,117 ----
def message(self, name, default):
! if not self.messages:
return default
return self.messages.get(name, default)
***************
*** 150,154 ****
* .sqlToPython(value, state):
* .pythonToSQL(value, state):
!
Validators should have no internal state besides the
values given at instantiation. They should be reusable and
--- 150,154 ----
* .sqlToPython(value, state):
* .pythonToSQL(value, state):
!
Validators should have no internal state besides the
values given at instantiation. They should be reusable and
***************
*** 293,297 ****
an integer, and then check if each integer is 1, 2, or 3.
"""
!
def attemptConvert(self, value, state, validate):
newList = []
--- 293,297 ----
an integer, and then check if each integer is 1, 2, or 3.
"""
!
def attemptConvert(self, value, state, validate):
newList = []
***************
*** 377,381 ****
except Exception, e:
raise InvalidField(str(e), value, state)
! return result
class Constant(FancyValidator):
--- 377,381 ----
except Exception, e:
raise InvalidField(str(e), value, state)
! return result
class Constant(FancyValidator):
***************
*** 538,542 ****
return i
raise InvalidField("Item %s was not found in the list"
! % repr(value), value, state)
class DateValidator(FancyValidator):
--- 538,542 ----
return i
raise InvalidField("Item %s was not found in the list"
! % repr(value), value, state)
class DateValidator(FancyValidator):
***************
*** 582,586 ****
"""
Converts things to string, but treats empty things as the empty
! string.
"""
--- 582,586 ----
"""
Converts things to string, but treats empty things as the empty
! string.
"""
***************
*** 705,709 ****
self.message('invalid', 'That is not a valid state code'),
value, state)
!
def _toPython(self, value, state):
return string.strip(string.upper(value))
--- 705,709 ----
self.message('invalid', 'That is not a valid state code'),
value, state)
!
def _toPython(self, value, state):
return string.strip(string.upper(value))
***************
*** 803,807 ****
except DateTime.RangeError, v:
raise InvalidField(self.message('invalidDay', 'That is not a valid day') + '(%s)' % v, value, state)
!
def makeMonth(self, value):
try:
--- 803,807 ----
except DateTime.RangeError, v:
raise InvalidField(self.message('invalidDay', 'That is not a valid day') + '(%s)' % v, value, state)
!
def makeMonth(self, value):
try:
***************
*** 844,848 ****
# @@ ib: double-check, improve
return value.strftime("%m/%d/%Y")
!
def unconvertMonth(self, value, state):
# @@ ib: double-check, improve
--- 844,848 ----
# @@ ib: double-check, improve
return value.strftime("%m/%d/%Y")
!
def unconvertMonth(self, value, state):
# @@ ib: double-check, improve
***************
*** 879,883 ****
"""
A FormValidator is something that can be chained with a
! Schema. Unlike normal chaining the FormValidator can
validate forms that aren't entirely valid.
--- 879,883 ----
"""
A FormValidator is something that can be chained with a
! Schema. Unlike normal chaining the FormValidator can
validate forms that aren't entirely valid.
***************
*** 973,977 ****
for name, value in errorList]),
fieldDict, state, errorDict=errors)
!
def _validateReturn(self, fieldDict, state):
ccType = string.lower(string.strip(fieldDict[self._ccTypeField]))
--- 973,977 ----
for name, value in errorList]),
fieldDict, state, errorDict=errors)
!
def _validateReturn(self, fieldDict, state):
ccType = string.lower(string.strip(fieldDict[self._ccTypeField]))
|
|
From: <dre...@us...> - 2003-09-24 12:18:21
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv2752/tests
Modified Files:
test.py
Log Message:
Mostly whitespace and a fix for postgreSQLCreate
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** test.py 7 Sep 2003 23:36:08 -0000 1.28
--- test.py 24 Sep 2003 12:18:16 -0000 1.29
***************
*** 58,62 ****
bob.name = testString
self.assertEqual(bob.name, testString)
!
class TestCaseGetSet(TestCase1):
--- 58,62 ----
bob.name = testString
self.assertEqual(bob.name, testString)
!
class TestCaseGetSet(TestCase1):
***************
*** 67,71 ****
bob.name = 'joe'
self.assertEqual(bob.name, 'joe')
!
class TestSO2(SQLObject):
--- 67,71 ----
bob.name = 'joe'
self.assertEqual(bob.name, 'joe')
!
class TestSO2(SQLObject):
***************
*** 119,124 ****
tcc2 = TestSO3.new(name='c', other=tc4a.id)
self.assertEqual(tcc2.other, tc4a)
!
!
########################################
## Fancy sort
--- 119,124 ----
tcc2 = TestSO3.new(name='c', other=tc4a.id)
self.assertEqual(tcc2.other, tc4a)
!
!
########################################
## Fancy sort
***************
*** 160,164 ****
class IterTest(SQLObject):
name = StringCol()
!
class IterationTestCase(SQLObjectTest):
'''Test basic iteration techniques'''
--- 160,164 ----
class IterTest(SQLObject):
name = StringCol()
!
class IterationTestCase(SQLObjectTest):
'''Test basic iteration techniques'''
***************
*** 268,272 ****
finally:
TestSOTrans._connection.autoCommit = True
!
########################################
--- 268,272 ----
finally:
TestSOTrans._connection.autoCommit = True
!
########################################
***************
*** 316,320 ****
for i in range(100):
Counter.new(number=i)
!
def counterEqual(self, counters, value):
self.assertEquals([c.number for c in counters], value)
--- 316,320 ----
for i in range(100):
Counter.new(number=i)
!
def counterEqual(self, counters, value):
self.assertEquals([c.number for c in counters], value)
***************
*** 418,422 ****
l = [p.phone for p in Person.selectBy(name='tim')[0].phones]
l.sort()
! self.assertEqual(l,
['555-394-2930', '555-555-5555'])
Phone.delColumn(col, changeSchema=True)
--- 418,422 ----
l = [p.phone for p in Person.selectBy(name='tim')[0].phones]
l.sort()
! self.assertEqual(l,
['555-394-2930', '555-555-5555'])
Phone.delColumn(col, changeSchema=True)
***************
*** 517,521 ****
self.assertZipsEqual(b.addressJoiners, ['22222'])
self.assertNamesEqual(z.personJoiners, [])
!
def assertZipsEqual(self, zips, dest):
self.assertEqual([a.zip for a in zips], dest)
--- 517,521 ----
self.assertZipsEqual(b.addressJoiners, ['22222'])
self.assertNamesEqual(z.personJoiners, [])
!
def assertZipsEqual(self, zips, dest):
self.assertEqual([a.zip for a in zips], dest)
***************
*** 547,551 ****
#p1.addAddressJoiner2(a)
AddressJoiner2.new(zip='00000', personJoiner2=p2)
!
def test(self):
bob = PersonJoiner2.byName('bob')
--- 547,551 ----
#p1.addAddressJoiner2(a)
AddressJoiner2.new(zip='00000', personJoiner2=p2)
!
def test(self):
bob = PersonJoiner2.byName('bob')
***************
*** 566,570 ****
self.assertEqual([i.zip for i in p1.addressJoiner2s],
['33333', '22222', '11111'])
!
########################################
--- 566,570 ----
self.assertEqual([i.zip for i in p1.addressJoiner2s],
['33333', '22222', '11111'])
!
########################################
***************
*** 595,599 ****
s3 = Sub(s1.id)
self.assertEqual(s1, s3)
!
########################################
--- 595,599 ----
s3 = Sub(s1.id)
self.assertEqual(s1, s3)
!
########################################
***************
*** 661,665 ****
t.name3 = 0
self.assertEqual(t.name3, 0)
!
########################################
## String ID test
--- 661,666 ----
t.name3 = 0
self.assertEqual(t.name3, 0)
!
!
########################################
## String ID test
***************
*** 678,685 ****
"""
! postgresCreate = mysqlCreate
sqliteCreate = mysqlCreate
firebirdCreate = mysqlCreate
!
mysqlDrop = """
DROP TABLE IF EXISTS so_string_id
--- 679,692 ----
"""
! postgresCreate = """
! CREATE TABLE so_string_id (
! id VARCHAR(50) PRIMARY KEY,
! val TEXT
! )
! """
!
sqliteCreate = mysqlCreate
firebirdCreate = mysqlCreate
!
mysqlDrop = """
DROP TABLE IF EXISTS so_string_id
***************
*** 823,825 ****
coverage.stop()
coverModules()
!
--- 830,832 ----
coverage.stop()
coverModules()
!
|
|
From: <dre...@us...> - 2003-09-24 12:18:21
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject In directory sc8-pr-cvs1:/tmp/cvs-serv2752/SQLObject Modified Files: SQLObject.py __init__.py Log Message: Mostly whitespace and a fix for postgreSQLCreate Index: SQLObject.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** SQLObject.py 7 Sep 2003 23:36:08 -0000 1.57 --- SQLObject.py 24 Sep 2003 12:18:15 -0000 1.58 *************** *** 1175,1179 **** - ######################################## ## Utility functions (for external consumption) --- 1175,1178 ---- Index: __init__.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/__init__.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** __init__.py 26 May 2003 21:48:54 -0000 1.4 --- __init__.py 24 Sep 2003 12:18:15 -0000 1.5 *************** *** 5,6 **** --- 5,7 ---- from Style import * from Join import * + from include import Validator |
|
From: <ian...@us...> - 2003-09-09 04:04:05
|
Update of /cvsroot/sqlobject/SQLObject/docs In directory sc8-pr-cvs1:/tmp/cvs-serv13289/docs Modified Files: FAQ.txt Log Message: Updated FAQ about non-integer IDs Index: FAQ.txt =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/docs/FAQ.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FAQ.txt 7 Sep 2003 19:14:43 -0000 1.3 --- FAQ.txt 9 Sep 2003 04:04:02 -0000 1.4 *************** *** 147,156 **** --------------- ! SQLObject requires that you use an integer primary key, usually ! defined in a specific way (``INT PRIMARY KEY AUTO_INCREMENT`` for ! MySQL, for instance, or ``SERIAL PRIMARY KEY`` for PostgreSQL). You ! cannot use strings or other kinds of values. ! This restriction will probably be removed soon. --- 147,178 ---- --------------- ! Yes, you can use non-integer IDs, but only in CVS_ now. ! .. _CVS: http://sqlobject.org/#anonymous-cvs ! ! If you use non-integer IDs, you will not be able to use automatic ! ``CREATE TABLE`` generation (i.e., ``createTable``). You also will ! have to give your own ID values when creating an object, like:: ! ! color = Something.new(id="blue", r=0, b=100, g=0) ! ! IDs are, and always will in future versions, be considered immutable. ! Right now that is not enforced; you can assign to the ``id`` ! attribute. But if you do you'll just mess everything up. This will ! probably be taken away sometime to avoid possibly confusing bugs ! (actually, assigning to ``id`` is almost certain to cause confusing ! bugs). ! ! If you are concerned about enforcing the type of IDs (which can be a ! problem even with integer IDs) you may want to do this:: ! ! def Color(SQLObject): ! def _init(self, id, connection=None): ! id = str(id) ! SQLObject._init(self, id, connection) ! ! Instead of ``str()`` you may use ``int()`` or whatever else you want. ! This will be resolved in a future version when ID column types can be ! declared like other columns. |
|
From: <ian...@us...> - 2003-09-09 04:03:27
|
Update of /cvsroot/sqlobject/SOWeb/docs In directory sc8-pr-cvs1:/tmp/cvs-serv13162/docs Modified Files: FAQ.html FAQ.txt default.css Log Message: Updated FAQ Index: FAQ.html =================================================================== RCS file: /cvsroot/sqlobject/SOWeb/docs/FAQ.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FAQ.html 7 Sep 2003 19:15:46 -0000 1.3 --- FAQ.html 9 Sep 2003 04:03:23 -0000 1.4 *************** *** 272,280 **** <div class="section" id="non-integer-ids"> <h1><a name="non-integer-ids">Non-Integer IDs</a></h1> ! <p>SQLObject requires that you use an integer primary key, usually ! defined in a specific way (<tt class="literal"><span class="pre">INT</span> <span class="pre">PRIMARY</span> <span class="pre">KEY</span> <span class="pre">AUTO_INCREMENT</span></tt> for ! MySQL, for instance, or <tt class="literal"><span class="pre">SERIAL</span> <span class="pre">PRIMARY</span> <span class="pre">KEY</span></tt> for PostgreSQL). You ! cannot use strings or other kinds of values.</p> ! <p>This restriction will probably be removed soon.</p> </div> <div class="section" id="binary-values"> --- 272,299 ---- <div class="section" id="non-integer-ids"> <h1><a name="non-integer-ids">Non-Integer IDs</a></h1> ! <p>Yes, you can use non-integer IDs, but only in <a class="reference" href="http://sqlobject.org/#anonymous-cvs">CVS</a> now.</p> ! <p>If you use non-integer IDs, you will not be able to use automatic ! <tt class="literal"><span class="pre">CREATE</span> <span class="pre">TABLE</span></tt> generation (i.e., <tt class="literal"><span class="pre">createTable</span></tt>). You also will ! have to give your own ID values when creating an object, like:</p> ! <pre class="literal-block"> ! color = Something.new(id="blue", r=0, b=100, g=0) ! </pre> ! <p>IDs are, and always will in future versions, be considered immutable. ! Right now that is not enforced; you can assign to the <tt class="literal"><span class="pre">id</span></tt> ! attribute. But if you do you'll just mess everything up. This will ! probably be taken away sometime to avoid possibly confusing bugs ! (actually, assigning to <tt class="literal"><span class="pre">id</span></tt> is almost certain to cause confusing ! bugs).</p> ! <p>If you are concerned about enforcing the type of IDs (which can be a ! problem even with integer IDs) you may want to do this:</p> ! <pre class="literal-block"> ! def Color(SQLObject): ! def _init(self, id, connection=None): ! id = str(id) ! SQLObject._init(self, id, connection) ! </pre> ! <p>Instead of <tt class="literal"><span class="pre">str()</span></tt> you may use <tt class="literal"><span class="pre">int()</span></tt> or whatever else you want. ! This will be resolved in a future version when ID column types can be ! declared like other columns.</p> </div> <div class="section" id="binary-values"> Index: FAQ.txt =================================================================== RCS file: /cvsroot/sqlobject/SOWeb/docs/FAQ.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FAQ.txt 7 Sep 2003 19:15:46 -0000 1.3 --- FAQ.txt 9 Sep 2003 04:03:23 -0000 1.4 *************** *** 147,156 **** --------------- ! SQLObject requires that you use an integer primary key, usually ! defined in a specific way (``INT PRIMARY KEY AUTO_INCREMENT`` for ! MySQL, for instance, or ``SERIAL PRIMARY KEY`` for PostgreSQL). You ! cannot use strings or other kinds of values. ! This restriction will probably be removed soon. --- 147,178 ---- --------------- ! Yes, you can use non-integer IDs, but only in CVS_ now. ! .. _CVS: http://sqlobject.org/#anonymous-cvs ! ! If you use non-integer IDs, you will not be able to use automatic ! ``CREATE TABLE`` generation (i.e., ``createTable``). You also will ! have to give your own ID values when creating an object, like:: ! ! color = Something.new(id="blue", r=0, b=100, g=0) ! ! IDs are, and always will in future versions, be considered immutable. ! Right now that is not enforced; you can assign to the ``id`` ! attribute. But if you do you'll just mess everything up. This will ! probably be taken away sometime to avoid possibly confusing bugs ! (actually, assigning to ``id`` is almost certain to cause confusing ! bugs). ! ! If you are concerned about enforcing the type of IDs (which can be a ! problem even with integer IDs) you may want to do this:: ! ! def Color(SQLObject): ! def _init(self, id, connection=None): ! id = str(id) ! SQLObject._init(self, id, connection) ! ! Instead of ``str()`` you may use ``int()`` or whatever else you want. ! This will be resolved in a future version when ID column types can be ! declared like other columns. Index: default.css =================================================================== RCS file: /cvsroot/sqlobject/SOWeb/docs/default.css,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 |
|
From: <ian...@us...> - 2003-09-07 23:37:34
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv14660/SQLObject
Modified Files:
DBConnection.py SQLObject.py
Log Message:
Allow non-integer IDs
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** DBConnection.py 7 Sep 2003 07:25:58 -0000 1.46
--- DBConnection.py 7 Sep 2003 23:36:08 -0000 1.47
***************
*** 152,157 ****
return Transaction(self)
! def queryInsertID(self, table, idName, names, values):
! return self._runWithConnection(self._queryInsertID, table, idName, names, values)
def _iterSelect(self, conn, select, withConnection=None,
--- 152,157 ----
return Transaction(self)
! def queryInsertID(self, table, idName, id, names, values):
! return self._runWithConnection(self._queryInsertID, table, idName, id, names, values)
def _iterSelect(self, conn, select, withConnection=None,
***************
*** 373,379 ****
return self._dbConnection._queryOne(self._connection, s)
! def queryInsertID(self, table, idName, names, values):
return self._dbConnection._queryInsertID(
! self._connection, table, idName, names, values)
def iterSelect(self, select):
--- 373,379 ----
return self._dbConnection._queryOne(self._connection, s)
! def queryInsertID(self, table, idName, id, names, values):
return self._dbConnection._queryInsertID(
! self._connection, table, idName, id, names, values)
def iterSelect(self, select):
***************
*** 439,449 ****
user=self.user, passwd=self.passwd)
! def _queryInsertID(self, conn, table, idName, names, values):
c = conn.cursor()
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! id = c.insert_id()
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
--- 439,453 ----
user=self.user, passwd=self.passwd)
! def _queryInsertID(self, conn, table, idName, id, names, values):
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! if id is None:
! id = c.insert_id()
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
***************
*** 558,570 ****
return conn
! def _queryInsertID(self, conn, table, idName, names, values):
c = conn.cursor()
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! c.execute('SELECT %s FROM %s WHERE oid = %s'
! % (idName, table, c.lastoid()))
! id = c.fetchone()[0]
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
--- 562,578 ----
return conn
! def _queryInsertID(self, conn, table, idName, id, names, values):
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
q = self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
c.execute(q)
! if id is None:
! c.execute('SELECT %s FROM %s WHERE oid = %s'
! % (idName, table, c.lastoid()))
! id = c.fetchone()[0]
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
***************
*** 682,687 ****
return self._conn
! def _queryInsertID(self, conn, table, idName, names, values):
c = conn.cursor()
q = self._insertSQL(table, names, values)
if self.debug:
--- 690,698 ----
return self._conn
! def _queryInsertID(self, conn, table, idName, id, names, values):
c = conn.cursor()
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
q = self._insertSQL(table, names, values)
if self.debug:
***************
*** 689,693 ****
c.execute(q)
# lastrowid is a DB-API extension from "PEP 0249":
! id = int(c.lastrowid)
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
--- 700,705 ----
c.execute(q)
# lastrowid is a DB-API extension from "PEP 0249":
! if id is None:
! id = int(c.lastrowid)
if self.debugOutput:
self.printDebug(conn, id, 'QueryIns', 'result')
***************
*** 748,761 ****
)
! def _queryInsertID(self, conn, table, idName, names, values):
"""Firebird uses 'generators' to create new ids for a table.
The users needs to create a generator named GEN_<tablename>
for each table this method to work."""
! row = self.queryOne('SELECT gen_id(GEN_%s,1) FROM rdb$database'
! % table)
! new_key = row[0]
! names.append('ID')
! values.append(new_key)
qry = self._insertSQL(table, names, values)
if self.debug:
--- 760,774 ----
)
! def _queryInsertID(self, conn, table, idName, id, names, values):
"""Firebird uses 'generators' to create new ids for a table.
The users needs to create a generator named GEN_<tablename>
for each table this method to work."""
! if id is None:
! row = self.queryOne('SELECT gen_id(GEN_%s,1) FROM rdb$database'
! % table)
! id = row[0]
! names = [idName] + names
! values = [id] + values
qry = self._insertSQL(table, names, values)
if self.debug:
***************
*** 763,768 ****
self.query(qry)
if self.debugOutput:
! self.printDebug(conn, new_key, 'QueryIns', 'result')
! return new_key
def _queryAddLimitOffset(self, query, start, end):
--- 776,781 ----
self.query(qry)
if self.debugOutput:
! self.printDebug(conn, id, 'QueryIns', 'result')
! return id
def _queryAddLimitOffset(self, query, start, end):
***************
*** 840,845 ****
"""
! def queryInsertID(self, table, idName, names, values):
! id = self._newID(table)
self._saveDict(table, id, dict(zip(names, values)))
return id
--- 853,859 ----
"""
! def queryInsertID(self, table, idName, id, names, values):
! if id is None:
! id = self._newID(table)
self._saveDict(table, id, dict(zip(names, values)))
return id
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.56
retrieving revision 1.57
diff -C2 -d -r1.56 -r1.57
*** SQLObject.py 7 Sep 2003 22:35:09 -0000 1.56
--- SQLObject.py 7 Sep 2003 23:36:08 -0000 1.57
***************
*** 817,820 ****
--- 817,826 ----
inst = cls(CreateNewSQLObject)
+ if kw.has_key('id'):
+ id = kw['id']
+ del kw['id']
+ else:
+ id = None
+
# First we do a little fix-up on the keywords we were
# passed:
***************
*** 862,870 ****
# Then we finalize the process:
! inst._SO_finishCreate()
return inst
new = classmethod(new)
! def _SO_finishCreate(self):
# Here's where an INSERT is finalized.
# These are all the column values that were supposed
--- 868,876 ----
# Then we finalize the process:
! inst._SO_finishCreate(id)
return inst
new = classmethod(new)
! def _SO_finishCreate(self, id=None):
# Here's where an INSERT is finalized.
# These are all the column values that were supposed
***************
*** 884,888 ****
# non-standard.
id = self._connection.queryInsertID(self._table, self._idName,
! names, values)
cache = self._connection.cache
cache.created(id, self.__class__, self)
--- 890,894 ----
# non-standard.
id = self._connection.queryInsertID(self._table, self._idName,
! id, names, values)
cache = self._connection.cache
cache.created(id, self.__class__, self)
|
|
From: <ian...@us...> - 2003-09-07 23:37:32
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv14660/tests
Modified Files:
SQLObjectTest.py test.py
Log Message:
Allow non-integer IDs
Index: SQLObjectTest.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/SQLObjectTest.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** SQLObjectTest.py 7 Sep 2003 07:05:09 -0000 1.14
--- SQLObjectTest.py 7 Sep 2003 23:36:08 -0000 1.15
***************
*** 95,100 ****
if hasattr(c, '%sDrop' % self.databaseName):
if __connection__.tableExists(c._table):
! __connection__.query(
! getattr(c, '%sDrop' % self.databaseName))
elif hasattr(c, 'drop'):
__connection__.query(c.drop)
--- 95,103 ----
if hasattr(c, '%sDrop' % self.databaseName):
if __connection__.tableExists(c._table):
! sql = getattr(c, '%sDrop' % self.databaseName)
! #if self.debugInserts:
! # print sql
! __connection__.query(sql)
!
elif hasattr(c, 'drop'):
__connection__.query(c.drop)
***************
*** 104,109 ****
if hasattr(c, '%sCreate' % self.databaseName):
if not __connection__.tableExists(c._table):
! __connection__.query(
! getattr(c, '%sCreate' % self.databaseName))
elif hasattr(c, 'create'):
__connection__.query(c.create)
--- 107,115 ----
if hasattr(c, '%sCreate' % self.databaseName):
if not __connection__.tableExists(c._table):
! sql = getattr(c, '%sCreate' % self.databaseName)
! #if self.debugInserts:
! # print sql
! __connection__.query(sql)
!
elif hasattr(c, 'create'):
__connection__.query(c.create)
***************
*** 127,131 ****
global __connection__
conn = globals()[t + "Connection"]()
! SQLObject.databaseName = t
__connection__ = conn
--- 133,137 ----
global __connection__
conn = globals()[t + "Connection"]()
! SQLObjectTest.databaseName = t
__connection__ = conn
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** test.py 7 Sep 2003 22:35:09 -0000 1.27
--- test.py 7 Sep 2003 23:36:08 -0000 1.28
***************
*** 662,665 ****
--- 662,708 ----
self.assertEqual(t.name3, 0)
+ ########################################
+ ## String ID test
+ ########################################
+
+ class SOStringID(SQLObject):
+
+ _table = 'so_string_id'
+ val = StringCol(alternateID=True)
+
+ mysqlCreate = """
+ CREATE TABLE IF NOT EXISTS so_string_id (
+ id VARCHAR(50) PRIMARY KEY,
+ val TEXT
+ )
+ """
+
+ postgresCreate = mysqlCreate
+ sqliteCreate = mysqlCreate
+ firebirdCreate = mysqlCreate
+
+ mysqlDrop = """
+ DROP TABLE IF EXISTS so_string_id
+ """
+
+ postgresDrop = """
+ DROP TABLE so_string_id
+ """
+
+ sqliteDrop = postgresDrop
+ firebirdDrop = postgresDrop
+
+ class StringIDTest(SQLObjectTest):
+
+ classes = [SOStringID]
+
+ def testStringID(self):
+ t = SOStringID.new(id='hey', val='whatever')
+ t2 = SOStringID.byVal('whatever')
+ self.assertEqual(t, t2)
+ t3 = SOStringID.new(id='you', val='nowhere')
+ t4 = SOStringID('you')
+ self.assertEqual(t3, t4)
+
########################################
|
|
From: <ian...@us...> - 2003-09-07 22:35:17
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv5224/SQLObject
Modified Files:
Col.py SQLObject.py
Log Message:
Added conversion/validation to columns
Index: Col.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Col.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** Col.py 6 Sep 2003 02:33:17 -0000 1.25
--- Col.py 7 Sep 2003 22:35:09 -0000 1.26
***************
*** 6,9 ****
--- 6,10 ----
import re
import Constraints
+ from include import Validator
NoDefault = SQLBuilder.NoDefault
***************
*** 31,39 ****
unique=NoDefault,
sqlType=None,
! columnDef=None):
! # This isn't strictly true, since we *could* use backquotes
! # around column names, but why would anyone *want* to
! # use a name like that?
# @@: I suppose we could actually add backquotes to the
# dbName if we needed to...
--- 32,42 ----
unique=NoDefault,
sqlType=None,
! columnDef=None,
! validator=None,
! immutable=False):
! # This isn't strictly true, since we *could* use backquotes or
! # " or something (database-specific) around column names, but
! # why would anyone *want* to use a name like that?
# @@: I suppose we could actually add backquotes to the
# dbName if we needed to...
***************
*** 45,48 ****
--- 48,53 ----
self.columnDef = columnDef
+ self.immutable = immutable
+
if type(constraints) not in (type([]), type(())):
constraints = [constraints]
***************
*** 97,100 ****
--- 102,112 ----
else:
self.foreignName = None
+
+ if validator:
+ self.toPython = validator.toPython
+ self.fromPython = validator.fromPython
+ else:
+ self.toPython = None
+ self.fromPython = None
def autoConstraints(self):
Index: SQLObject.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** SQLObject.py 7 Sep 2003 18:06:21 -0000 1.55
--- SQLObject.py 7 Sep 2003 22:35:09 -0000 1.56
***************
*** 427,434 ****
# no superclass that defines the database access.
if cls._cacheValues:
-
# We create a method here, which is just a function
# that takes "self" as the first argument.
getter = eval('lambda self: self._SO_loadValue(%s)' % repr(instanceName(name)))
else:
# If we aren't caching values, we just call the
--- 427,434 ----
# no superclass that defines the database access.
if cls._cacheValues:
# We create a method here, which is just a function
# that takes "self" as the first argument.
getter = eval('lambda self: self._SO_loadValue(%s)' % repr(instanceName(name)))
+
else:
# If we aren't caching values, we just call the
***************
*** 452,466 ****
# those methods themself.
! # We start by just using the _SO_setValue method
! setter = eval('lambda self, val: self._SO_setValue(%s, val)' % repr(name))
! setattr(cls, rawSetterName(name), setter)
! # Then do the aliasing
! if not hasattr(cls, setterName(name)):
! setattr(cls, setterName(name), setter)
! # We keep track of setters that haven't been
! # overridden, because we can combine these
! # set columns into one SQL UPDATE query.
! cls._SO_plainSetters[name] = 1
!
##################################################
--- 452,467 ----
# those methods themself.
! if not column.immutable:
! # We start by just using the _SO_setValue method
! setter = eval('lambda self, val: self._SO_setValue(%s, val, self.%s)' % (repr(name), '_SO_toPython_%s' % name))
! setattr(cls, '_SO_toPython_%s' % name, column.toPython)
! setattr(cls, rawSetterName(name), setter)
! # Then do the aliasing
! if not hasattr(cls, setterName(name)):
! setattr(cls, setterName(name), setter)
! # We keep track of setters that haven't been
! # overridden, because we can combine these
! # set columns into one SQL UPDATE query.
! cls._SO_plainSetters[name] = 1
##################################################
***************
*** 490,500 ****
cls._SO_plainForeignGetters[name[:-2]] = 1
! # The setter just gets the ID of the object,
! # and then sets the real column.
! setter = eval('lambda self, val: setattr(self, %s, self._SO_getID(val))' % (repr(name)))
! setattr(cls, rawSetterName(name)[:-2], setter)
! if not hasattr(cls, setterName(name)[:-2]):
! setattr(cls, setterName(name)[:-2], setter)
! cls._SO_plainForeignSetters[name[:-2]] = 1
# We'll need to put in a real reference at
--- 491,502 ----
cls._SO_plainForeignGetters[name[:-2]] = 1
! if not column.immutable:
! # The setter just gets the ID of the object,
! # and then sets the real column.
! setter = eval('lambda self, val: setattr(self, %s, self._SO_getID(val))' % (repr(name)))
! setattr(cls, rawSetterName(name)[:-2], setter)
! if not hasattr(cls, setterName(name)[:-2]):
! setattr(cls, setterName(name)[:-2], setter)
! cls._SO_plainForeignSetters[name[:-2]] = 1
# We'll need to put in a real reference at
***************
*** 659,662 ****
--- 661,666 ----
self._SO_perConnection = True
+ self._SO_validatorState = SQLObjectState(self)
+
if not selectResults:
dbNames = [col.dbName for col in self._SO_columns]
***************
*** 717,721 ****
self._SO_writeLock.release()
! def _SO_setValue(self, name, value):
# This is the place where we actually update the
# database.
--- 721,725 ----
self._SO_writeLock.release()
! def _SO_setValue(self, name, value, toPython):
# This is the place where we actually update the
# database.
***************
*** 725,728 ****
--- 729,734 ----
# the parts are set. So we just keep them in a
# dictionary until later:
+ if toPython:
+ value = toPython(value, self._SO_validatorState)
if self._SO_creating:
self._SO_createValues[name] = value
***************
*** 770,773 ****
--- 776,781 ----
def _SO_selectInit(self, row):
for col, colValue in zip(self._SO_columns, row):
+ if col.fromPython:
+ colValue = col.fromPython(colValue, self._SO_validatorState)
setattr(self, instanceName(col.name), colValue)
***************
*** 778,786 ****
# @@: do we really need this lock?
#self._SO_writeLock.acquire()
! results = self._connection._SO_selectOne(self, [self._SO_columnDict[name].dbName])
#self._SO_writeLock.release()
assert results != None, "%s with id %s is not in the database" \
% (self.__class__.__name__, self.id)
! return results[0]
def _SO_foreignKey(self, id, joinClass):
--- 786,798 ----
# @@: do we really need this lock?
#self._SO_writeLock.acquire()
! column = self._SO_columnDict[name]
! results = self._connection._SO_selectOne(self, [column.dbName])
#self._SO_writeLock.release()
assert results != None, "%s with id %s is not in the database" \
% (self.__class__.__name__, self.id)
! value = results[0]
! if column.toPython:
! value = column.toPython(value, self._SO_validatorState)
! return value
def _SO_foreignKey(self, id, joinClass):
***************
*** 1150,1154 ****
--- 1162,1170 ----
return count
+ class SQLObjectState(object):
+ def __init__(self, soObject):
+ self.soObject = soObject
+ self.protocol = 'sql'
|
|
From: <ian...@us...> - 2003-09-07 22:35:17
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject/include
In directory sc8-pr-cvs1:/tmp/cvs-serv5224/SQLObject/include
Added Files:
Validator.py __init__.py
Log Message:
Added conversion/validation to columns
--- NEW FILE: Validator.py ---
## FormEncode, a Form processor
## Copyright (C) 2003, Ian Bicking <ia...@co...>
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public
## License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
## NOTE: In the context of the Python environment, I interpret "dynamic
## linking" as importing -- thus the LGPL applies to the contents of
[...1000 lines suppressed...]
('52', 16),
('53', 16),
('54', 16),
('55', 16)],
"discover": [('6011', 16)],
"amex": [('34', 15),
('37', 15)],
"dinersclub": [('300', 14),
('301', 14),
('302', 14),
('303', 14),
('304', 14),
('305', 14),
('36', 14),
('38', 14)],
"jcb": [('3', 16),
('2131', 15),
('1800', 15)],
}
--- NEW FILE: __init__.py ---
"""
This directory includes third-party software, or software that is
distributed separately, that may not be installed on this computer.
"""
|
|
From: <ian...@us...> - 2003-09-07 22:35:17
|
Update of /cvsroot/sqlobject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv5224
Modified Files:
setup.py
Log Message:
Added conversion/validation to columns
Index: setup.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/setup.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** setup.py 5 Jul 2003 03:55:22 -0000 1.11
--- setup.py 7 Sep 2003 22:35:09 -0000 1.12
***************
*** 31,35 ****
url="http://sqlobject.org",
license="LGPL",
! packages=["SQLObject"],
download_url="http://prdownloads.sourceforge.net/sqlobject/SQLObject-0.4.tar.gz?download")
--- 31,35 ----
url="http://sqlobject.org",
license="LGPL",
! packages=["SQLObject", "SQLObject.include"],
download_url="http://prdownloads.sourceforge.net/sqlobject/SQLObject-0.4.tar.gz?download")
|
|
From: <ian...@us...> - 2003-09-07 22:35:16
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv5224/tests
Modified Files:
test.py
Log Message:
Added conversion/validation to columns
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** test.py 7 Sep 2003 19:14:07 -0000 1.26
--- test.py 7 Sep 2003 22:35:09 -0000 1.27
***************
*** 18,21 ****
--- 18,22 ----
from SQLObjectTest import *
from SQLObject import *
+ from SQLObject.include import Validator
from mx import DateTime
***************
*** 623,626 ****
--- 624,665 ----
b.sync()
self.assertEqual(b.name, 'bobby')
+
+ ########################################
+ ## Validation/conversion
+ ########################################
+
+ class SOValidation(SQLObject):
+
+ name = StringCol(validator=Validator.PlainText(), default='x')
+ name2 = StringCol(validator=Validator.ConfirmType(str), default='y')
+ name3 = StringCol(validator=Validator.Wrapper(toPython=int), default=100)
+
+ class ValidationTest(SQLObjectTest):
+
+ classes = [SOValidation]
+
+ def testValidate(self):
+ t = SOValidation.new(name='hey')
+ self.assertRaises(Validator.InvalidField, setattr, t,
+ 'name', '!!!')
+ t.name = 'you'
+
+ def testConfirmType(self):
+ t = SOValidation.new(name2='hey')
+ self.assertRaises(Validator.InvalidField, setattr, t,
+ 'name2', 1)
+ t.name2 = 'you'
+
+ def testWrapType(self):
+ t = SOValidation.new(name3=1)
+ self.assertRaises(Validator.InvalidField, setattr, t,
+ 'name3', 'x')
+ t.name3 = 1L
+ self.assertEqual(t.name3, 1)
+ t.name3 = '1'
+ self.assertEqual(t.name3, 1)
+ t.name3 = 0
+ self.assertEqual(t.name3, 0)
+
########################################
|
|
From: <ian...@us...> - 2003-09-07 22:34:44
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject/include In directory sc8-pr-cvs1:/tmp/cvs-serv5181/SQLObject/include Log Message: Directory /cvsroot/sqlobject/SQLObject/SQLObject/include added to the repository |
|
From: <ian...@us...> - 2003-09-07 19:15:51
|
Update of /cvsroot/sqlobject/SOWeb/docs In directory sc8-pr-cvs1:/tmp/cvs-serv1774/docs Modified Files: FAQ.html FAQ.txt default.css Log Message: Updated docs Index: FAQ.html =================================================================== RCS file: /cvsroot/sqlobject/SOWeb/docs/FAQ.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FAQ.html 7 Sep 2003 18:21:38 -0000 1.2 --- FAQ.html 7 Sep 2003 19:15:46 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- <li><a class="reference" href="#composite-compound-attributes" id="id5" name="id5">Composite/Compound Attributes</a></li> <li><a class="reference" href="#non-integer-ids" id="id6" name="id6">Non-Integer IDs</a></li> + <li><a class="reference" href="#binary-values" id="id7" name="id7">Binary Values</a></li> </ul> </div> *************** *** 276,279 **** --- 277,316 ---- cannot use strings or other kinds of values.</p> <p>This restriction will probably be removed soon.</p> + </div> + <div class="section" id="binary-values"> + <h1><a name="binary-values">Binary Values</a></h1> + <p>Binary values can be difficult to store in databases, as SQL doesn't + have a widely-implemented way to express binaries as literals, and + there's differing support in database.</p> + <p>A possible way to keep this data in a database is by using encoding. + Base 64 is a good encoding, reasonably compact but also safe. As + an example, imagine you want to store images in the database:</p> + + <pre class="literal-block"><tt><span class="keyword">class</span> <span class="function">Image</span><span class="symbol">(</span><span class="normal">SQLObject</span><span class="symbol">)</span><span class="symbol">:</span> + + <span class="normal">data</span> <span class="symbol">=</span> <span class="function">StringCol</span><span class="symbol">(</span><span class="symbol">)</span> + <span class="normal">height</span> <span class="symbol">=</span> <span class="function">IntCol</span><span class="symbol">(</span><span class="symbol">)</span> + <span class="normal">width</span> <span class="symbol">=</span> <span class="function">IntCol</span><span class="symbol">(</span><span class="symbol">)</span> + + <span class="keyword">def</span> <span class="function">_set_data</span><span class="symbol">(</span><span class="normal">self</span><span class="symbol">,</span> <span class="normal">value</span><span class="symbol">)</span><span class="symbol">:</span> + <span class="normal">self</span><span class="symbol">.</span><span class="function">_SO_set_data</span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">.</span><span class="function">encode</span><span class="symbol">(</span><span class="string">'base64'</span><span class="symbol">)</span><span class="symbol">)</span> + + <span class="keyword">def</span> <span class="function">_get_data</span><span class="symbol">(</span><span class="normal">self</span><span class="symbol">,</span> <span class="normal">value</span><span class="symbol">)</span><span class="symbol">:</span> + <span class="keyword">return</span> <span class="normal">self</span><span class="symbol">.</span><span class="function">_SO_get_data</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">.</span><span class="function">decode</span><span class="symbol">(</span><span class="string">'base64'</span><span class="symbol">)</span> + </tt></pre> + <p>SQLite does not respect backslash quoting, so for instance <tt class="literal"><span class="pre">\n</span></tt> is + not interpreted as a newline. For the moment there's no resolution, + and this will mess up your base64-encoded values. As a workaround:</p> + + <pre class="literal-block"><tt><span class="keyword">class</span> <span class="function">Image</span><span class="symbol">(</span><span class="normal">SQLObject</span><span class="symbol">)</span><span class="symbol">:</span> + <span class="normal">data</span> <span class="symbol">=</span> <span class="function">StringCol</span><span class="symbol">(</span><span class="symbol">)</span> + + <span class="keyword">def</span> <span class="function">_set_data</span><span class="symbol">(</span><span class="normal">self</span><span class="symbol">,</span> <span class="normal">value</span><span class="symbol">)</span><span class="symbol">:</span> + <span class="comment"># base64 just ignores whitespace, so we can get rid of \n's</span> + <span class="normal">self</span><span class="symbol">.</span><span class="function">_SO_set_data</span><span class="symbol">(</span><span class="normal">value</span><span class="symbol">.</span><span class="function">encode</span><span class="symbol">(</span><span class="string">'base64'</span><span class="symbol">)</span><span class="symbol">.</span><span class="function">replace</span><span class="symbol">(</span><span class="string">'\n'</span><span class="symbol">,</span> <span class="string">''</span><span class="symbol">)</span><span class="symbol">)</span> + + <span class="keyword">def</span> <span class="function">_get_data</span><span class="symbol">(</span><span class="normal">self</span><span class="symbol">)</span><span class="symbol">:</span> + <span class="keyword">return</span> <span class="normal">self</span><span class="symbol">.</span><span class="function">_SO_get_data</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">.</span><span class="function">decode</span><span class="symbol">(</span><span class="string">'base64'</span><span class="symbol">)</span> + </tt></pre> </div> </div> Index: FAQ.txt =================================================================== RCS file: /cvsroot/sqlobject/SOWeb/docs/FAQ.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FAQ.txt 7 Sep 2003 18:21:38 -0000 1.2 --- FAQ.txt 7 Sep 2003 19:15:46 -0000 1.3 *************** *** 154,155 **** --- 154,177 ---- This restriction will probably be removed soon. + + Binary Values + ------------- + + Binary values can be difficult to store in databases, as SQL doesn't + have a widely-implemented way to express binaries as literals, and + there's differing support in database. + + A possible way to keep this data in a database is by using encoding. + Base 64 is a good encoding, reasonably compact but also safe. As + an example, imagine you want to store images in the database: + + .. raw:: html + :file: ../examples/snippets/image-binary.html + + SQLite does not respect backslash quoting, so for instance ``\n`` is + not interpreted as a newline. For the moment there's no resolution, + and this will mess up your base64-encoded values. As a workaround: + + .. raw:: html + :file: ../examples/snippets/image-binary-sqlite.html + Index: default.css =================================================================== RCS file: /cvsroot/sqlobject/SOWeb/docs/default.css,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 |
|
From: <ian...@us...> - 2003-09-07 19:14:46
|
Update of /cvsroot/sqlobject/SQLObject/examples
In directory sc8-pr-cvs1:/tmp/cvs-serv1609/examples
Modified Files:
codebits.py
Log Message:
Added FAQ about binary files
Index: codebits.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/examples/codebits.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** codebits.py 21 Aug 2003 05:02:17 -0000 1.2
--- codebits.py 7 Sep 2003 19:14:43 -0000 1.3
***************
*** 221,222 ****
--- 221,248 ----
longitude = property(_get_longitude, set_longitude)
## end snippet
+
+ ## Snippet "image-binary"
+ class Image(SQLObject):
+
+ data = StringCol()
+ height = IntCol()
+ width = IntCol()
+
+ def _set_data(self, value):
+ self._SO_set_data(value.encode('base64'))
+
+ def _get_data(self, value):
+ return self._SO_get_data().decode('base64')
+ ## end snippet
+
+ ## Snippet "image-binary-sqlite"
+ class Image(SQLObject):
+ data = StringCol()
+
+ def _set_data(self, value):
+ # base64 just ignores whitespace, so we can get rid of \n's
+ self._SO_set_data(value.encode('base64').replace('\n', ''))
+
+ def _get_data(self):
+ return self._SO_get_data().decode('base64')
+ ## end snippet
|
|
From: <ian...@us...> - 2003-09-07 19:14:46
|
Update of /cvsroot/sqlobject/SQLObject/docs In directory sc8-pr-cvs1:/tmp/cvs-serv1609/docs Modified Files: FAQ.txt Log Message: Added FAQ about binary files Index: FAQ.txt =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/docs/FAQ.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FAQ.txt 7 Sep 2003 18:19:25 -0000 1.2 --- FAQ.txt 7 Sep 2003 19:14:43 -0000 1.3 *************** *** 154,155 **** --- 154,177 ---- This restriction will probably be removed soon. + + Binary Values + ------------- + + Binary values can be difficult to store in databases, as SQL doesn't + have a widely-implemented way to express binaries as literals, and + there's differing support in database. + + A possible way to keep this data in a database is by using encoding. + Base 64 is a good encoding, reasonably compact but also safe. As + an example, imagine you want to store images in the database: + + .. raw:: html + :file: ../examples/snippets/image-binary.html + + SQLite does not respect backslash quoting, so for instance ``\n`` is + not interpreted as a newline. For the moment there's no resolution, + and this will mess up your base64-encoded values. As a workaround: + + .. raw:: html + :file: ../examples/snippets/image-binary-sqlite.html + |
|
From: <ian...@us...> - 2003-09-07 19:14:11
|
Update of /cvsroot/sqlobject/SQLObject/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv1387/tests
Modified Files:
.cvsignore test.py
Log Message:
Ignore coverage data file. But also delete coverage data file after
generating reports
Index: .cvsignore
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/.cvsignore,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** .cvsignore 7 Sep 2003 19:12:43 -0000 1.2
--- .cvsignore 7 Sep 2003 19:14:07 -0000 1.3
***************
*** 1,2 ****
--- 1,3 ----
*.pyc
*,cover
+ .coverage
Index: test.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** test.py 7 Sep 2003 18:07:11 -0000 1.25
--- test.py 7 Sep 2003 19:14:07 -0000 1.26
***************
*** 644,647 ****
--- 644,648 ----
if modFile.startswith(here) or modFile.startswith(there):
writeCoverage(mod, there, os.path.join(here, 'SQLObject'))
+ coverage.erase()
sys.stdout.write('done.\n')
|
|
From: <ian...@us...> - 2003-09-07 19:12:47
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject In directory sc8-pr-cvs1:/tmp/cvs-serv1139/SQLObject Modified Files: .cvsignore Log Message: Ignore ,cover files Index: .cvsignore =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/.cvsignore,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** .cvsignore 26 Feb 2003 23:59:41 -0000 1.1.1.1 --- .cvsignore 7 Sep 2003 19:12:43 -0000 1.2 *************** *** 1 **** --- 1,2 ---- *.pyc + *,cover |
|
From: <ian...@us...> - 2003-09-07 19:12:47
|
Update of /cvsroot/sqlobject/SQLObject/examples In directory sc8-pr-cvs1:/tmp/cvs-serv1139/examples Modified Files: .cvsignore Log Message: Ignore ,cover files Index: .cvsignore =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/examples/.cvsignore,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** .cvsignore 26 Feb 2003 23:59:43 -0000 1.1.1.1 --- .cvsignore 7 Sep 2003 19:12:43 -0000 1.2 *************** *** 1 **** --- 1,2 ---- *.pyc + *,cover |
|
From: <ian...@us...> - 2003-09-07 19:12:47
|
Update of /cvsroot/sqlobject/SQLObject/tests In directory sc8-pr-cvs1:/tmp/cvs-serv1139/tests Modified Files: .cvsignore Log Message: Ignore ,cover files Index: .cvsignore =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/tests/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 2 Mar 2003 23:11:58 -0000 1.1 --- .cvsignore 7 Sep 2003 19:12:43 -0000 1.2 *************** *** 1 **** --- 1,2 ---- *.pyc + *,cover |