sqlobject-cvs Mailing List for SQLObject (Page 164)
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
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <sub...@co...> - 2005-07-21 06:02:17
|
Author: ianb Date: 2005-07-21 06:02:09 +0000 (Thu, 21 Jul 2005) New Revision: 847 Modified: trunk/SQLObject/sqlobject/main.py Log: Moved _fromDatabase into sqlmeta Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2005-07-21 05:56:44 UTC (rev 846) +++ trunk/SQLObject/sqlobject/main.py 2005-07-21 06:02:09 UTC (rev 847) @@ -159,6 +159,7 @@ defaultOrder = None cacheValues = True registry = None + fromDatabase = False __metaclass__ = declarative.DeclarativeMeta @@ -283,8 +284,6 @@ _indexes = [] - _fromDatabase = False - # Default is false, but we set it to true for the *instance* # when necessary: (bad clever? maybe) _expired = False @@ -463,7 +462,7 @@ for column in cls._columns: cls.addColumn(column) - if cls._fromDatabase: + if cls.sqlmeta.fromDatabase: cls.addColumnsFromDatabase() ######################################## @@ -506,10 +505,12 @@ _cacheValues = _sqlmeta_attr('cacheValues', 2) _registry = _sqlmeta_attr('registry', 2) _idType = _sqlmeta_attr('idType', 2) + _fromDatabase = _sqlmeta_attr('fromDatabase', 2) def _cleanDeprecatedAttrs(cls, new_attrs): for attr in ['_table', '_lazyUpdate', '_style', '_idName', - '_defaultOrder', '_cacheValues', '_registry']: + '_defaultOrder', '_cacheValues', '_registry', + '_idType', '_fromDatabase']: if new_attrs.has_key(attr): new_name = attr[1:] deprecated("'%s' is deprecated; please set the '%s' " |
From: <sub...@co...> - 2005-07-21 05:56:57
|
Author: ianb Date: 2005-07-21 05:56:44 +0000 (Thu, 21 Jul 2005) New Revision: 846 Modified: trunk/SQLObject/sqlobject/main.py Log: Moved idType to sqlmeta Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2005-07-20 15:00:52 UTC (rev 845) +++ trunk/SQLObject/sqlobject/main.py 2005-07-21 05:56:44 UTC (rev 846) @@ -150,6 +150,10 @@ table = None idName = None + # This function is used to coerce IDs into the proper format, + # so you should replace it with str, or another function, if you + # aren't using integer IDs + idType = int style = None lazyUpdate = False defaultOrder = None @@ -285,11 +289,6 @@ # when necessary: (bad clever? maybe) _expired = False - # This function is used to coerce IDs into the proper format, - # so you should replace it with str, or another function, if you - # aren't using integer IDs - _idType = int - sqlmeta = sqlmeta #DSM: The _inheritable attribute controls wheter the class can by @@ -506,6 +505,7 @@ _defaultOrder = _sqlmeta_attr('defaultOrder', 2) _cacheValues = _sqlmeta_attr('cacheValues', 2) _registry = _sqlmeta_attr('registry', 2) + _idType = _sqlmeta_attr('idType', 2) def _cleanDeprecatedAttrs(cls, new_attrs): for attr in ['_table', '_lazyUpdate', '_style', '_idName', @@ -525,7 +525,7 @@ assert id is not None, 'None is not a possible id for %s' % cls.__name__ - id = cls._idType(id) + id = cls.sqlmeta.idType(id) if connection is None: cache = cls._connection.cache @@ -1059,7 +1059,7 @@ self._SO_writeLock = threading.Lock() if kw.has_key('id'): - id = self._idType(kw['id']) + id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None @@ -1356,7 +1356,7 @@ if isinstance(value, cls): return value.id else: - return cls._idType(value) + return cls.sqlmeta.idType(value) coerceID = classmethod(coerceID) |
From: <sub...@co...> - 2005-07-20 15:00:59
|
Author: phd Date: 2005-07-20 15:00:52 +0000 (Wed, 20 Jul 2005) New Revision: 845 Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py Log: Applied the patch N 1239578. Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py =================================================================== --- trunk/SQLObject/sqlobject/postgres/pgconnection.py 2005-07-20 14:55:52 UTC (rev 844) +++ trunk/SQLObject/sqlobject/postgres/pgconnection.py 2005-07-20 15:00:52 UTC (rev 845) @@ -205,9 +205,12 @@ continue colClass, kw = self.guessClass(t) kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field) + kw['dbName'] = field kw['notNone'] = notnull if defaultstr is not None: - kw['default'] = getattr(sqlbuilder.const, defaultstr) + kw['default'] = self.defaultFromSchema(colClass, defaultstr) + elif not notnull: + kw['default'] = None if keymap.has_key(field): kw['foreignKey'] = keymap[field] results.append(colClass(**kw)) @@ -232,6 +235,18 @@ else: return col.Col, {} + def defaultFromSchema(self, colClass, defaultstr): + """ + If the default can be converted to a python constant, convert it. + Otherwise return is as a sqlbuilder constant. + """ + if colClass == col.BoolCol: + if defaultstr == 'false': + return False + elif defaultstr == 'true': + return True + return getattr(sqlbuilder.const, defaultstr) + def server_version(self): if self._server_version is None: # The result is something like |
From: <sub...@co...> - 2005-07-20 14:55:59
|
Author: phd Date: 2005-07-20 14:55:52 +0000 (Wed, 20 Jul 2005) New Revision: 844 Modified: trunk/SQLObject/sqlobject/joins.py Log: Fixed a bug N 1238458. Modified: trunk/SQLObject/sqlobject/joins.py =================================================================== --- trunk/SQLObject/sqlobject/joins.py 2005-07-20 13:28:39 UTC (rev 843) +++ trunk/SQLObject/sqlobject/joins.py 2005-07-20 14:55:52 UTC (rev 844) @@ -10,7 +10,7 @@ try: return obj.id except AttributeError: - return int(id) + return int(obj) class Join(object): |
From: <sub...@co...> - 2005-07-20 13:28:57
|
Author: phd Date: 2005-07-20 13:28:39 +0000 (Wed, 20 Jul 2005) New Revision: 843 Modified: trunk/SQLObject/sqlobject/sqlbuilder.py Log: Fixed a minor bug in INSubquery - added components(). Modified: trunk/SQLObject/sqlobject/sqlbuilder.py =================================================================== --- trunk/SQLObject/sqlobject/sqlbuilder.py 2005-07-19 09:21:52 UTC (rev 842) +++ trunk/SQLObject/sqlobject/sqlbuilder.py 2005-07-20 13:28:39 UTC (rev 843) @@ -892,6 +892,8 @@ def __init__(self, item, subquery): self.item = item self.subquery = subquery + def components(self): + return [self.item] def __sqlrepr__(self, db): return "%s %s (%s)" % (sqlrepr(self.item, db), self.op, sqlrepr(self.subquery, db)) |
From: <sub...@co...> - 2005-07-19 09:21:59
|
Author: phd Date: 2005-07-19 09:21:52 +0000 (Tue, 19 Jul 2005) New Revision: 842 Modified: trunk/SQLObject/sqlobject/main.py Log: Corrected a number of minor grammar errors in comments from DSM. Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2005-07-15 18:03:44 UTC (rev 841) +++ trunk/SQLObject/sqlobject/main.py 2005-07-19 09:21:52 UTC (rev 842) @@ -293,11 +293,11 @@ sqlmeta = sqlmeta #DSM: The _inheritable attribute controls wheter the class can by - #DSM: inherited 'logically' with a foreignKey and back reference. - _inheritable = False # Does this class is inheritable + #DSM: inherited 'logically' with a foreignKey and a back reference. + _inheritable = False # Is this class inheritable? _parentClass = None # A reference to the parent class _parent = None # A reference to the parent instance - _childClasses = {} # Reference to child classes + _childClasses = {} # References to child classes childName = None # Children name (to be able to get a subclass) # The law of Demeter: the class should not call another classes by name @@ -407,25 +407,25 @@ _cls._childClasses[cls.__name__] = cls #DSM: If this class is a child of a parent class, we need to do some - #DSM: attribute check and a a foreign key to the parent. + #DSM: attribute check and add a foreign key to the parent. if cls._parentClass: #DSM: First, look for invalid column name: #DSM: reserved ones or same as a parent parentCols = [column.name for column in cls._columns] for column in implicitColumns: cname = column.name - if cname in ['childName']: + if cname == 'childName': raise AttributeError, \ - "The column name '%s' is reserved" % cname + "The column name 'childName' is reserved" if cname in parentCols: raise AttributeError, "The column '%s' is already " \ "defined in an inheritable parent" % cname #DSM: Remove columns if inherited from an inheritable class #DSM: as we don't want them. All we want is a foreign key - #DSM: that will link to our parent + #DSM: that points to our parent cls._columns = [] #DSM: If this is inheritable, add some default columns - # to be able to link to children + #DSM: to be able to link to children if hasattr(cls, '_inheritable') and cls._inheritable and \ cls.__name__ <> "InheritableSQLObject": cls._columns.append( |
From: <sub...@co...> - 2005-07-14 08:37:25
|
Author: phd Date: 2005-07-14 08:37:17 +0000 (Thu, 14 Jul 2005) New Revision: 827 Modified: trunk/SQLObject/sqlobject/dbconnection.py trunk/SQLObject/sqlobject/tests/test_joins_conditional.py Log: Fixed a bug - append a comma after non-empty list of tables; added a test. Modified: trunk/SQLObject/sqlobject/dbconnection.py =================================================================== --- trunk/SQLObject/sqlobject/dbconnection.py 2005-07-01 22:57:59 UTC (rev 826) +++ trunk/SQLObject/sqlobject/dbconnection.py 2005-07-14 08:37:17 UTC (rev 827) @@ -370,7 +370,9 @@ tables = select.tables q = "SELECT %s" % ", ".join([str(expression) for expression in expressions]) q += " FROM %s" % ", ".join(tables) - if join: q += self._addJoins(select) + if join: + if tables: q += ',' + q += self._addJoins(select) q += " WHERE" q = self._addWhereClause(select, q, limit=0, order=0) val = self.queryOne(q) @@ -406,7 +408,9 @@ (cls.sqlmeta.table, cls.sqlmeta.idName, ", ".join(tables)) - if join: q += self._addJoins(select) + if join: + if tables: q += ',' + q += self._addJoins(select) q += " WHERE" return self._addWhereClause(select, q) Modified: trunk/SQLObject/sqlobject/tests/test_joins_conditional.py =================================================================== --- trunk/SQLObject/sqlobject/tests/test_joins_conditional.py 2005-07-01 22:57:59 UTC (rev 826) +++ trunk/SQLObject/sqlobject/tests/test_joins_conditional.py 2005-07-14 08:37:17 UTC (rev 827) @@ -12,6 +12,9 @@ class TestJoin2(SQLObject): col2 = StringCol() +class TestJoin3(SQLObject): + col3 = StringCol() + def setup(): setupClass(TestJoin1) setupClass(TestJoin2) @@ -46,3 +49,13 @@ join=LEFTJOINOn(None, TestJoin2, TestJoin1.q.col1 == TestJoin2.q.col2) ) assert select.count() == 3 + +def test_4join_3tables_syntax(): + setup() + setupClass(TestJoin3) + + select = TestJoin1.select( + join=LEFTJOIN(TestJoin2, TestJoin3) + ) + assert str(select) == \ + "SELECT test_join1.id, test_join1.col1 FROM test_join1, test_join2 LEFT JOIN test_join3 WHERE 1 = 1" |
From: <sub...@co...> - 2005-06-29 15:58:30
|
Author: phd Date: 2005-06-29 15:58:25 +0000 (Wed, 29 Jun 2005) New Revision: 825 Modified: trunk/SQLObject/sqlobject/sresults.py Log: Added _getConnection() that gets a connection from self.ops and if it is not there gets it from soClass. Previous code does this not lazily, always asking soClass for _connection regardless of whether there is a connection in self.ops. Modified: trunk/SQLObject/sqlobject/sresults.py =================================================================== --- trunk/SQLObject/sqlobject/sresults.py 2005-06-29 06:01:51 UTC (rev 824) +++ trunk/SQLObject/sqlobject/sresults.py 2005-06-29 15:58:25 UTC (rev 825) @@ -34,8 +34,11 @@ def __repr__(self): return "<%s at %x>" % (self.__class__.__name__, id(self)) + def _getConnection(self): + return self.ops.get('connection') or self.sourceClass._connection + def __str__(self): - conn = self.ops.get('connection', self.sourceClass._connection) + conn = self._getConnection() return conn.queryForSelect(self) def _mungeOrderBy(self, orderBy): @@ -140,10 +143,7 @@ return list(self.clone(start=start, end=start+1))[0] def __iter__(self): - if self.ops.get('connection'): - conn = self.ops.get('connection') - else: - conn = self.sourceClass._connection + conn = self._getConnection() return conn.iterSelect(self) def accumulate(self, *expressions): @@ -152,7 +152,7 @@ connection. Return the accumulate result """ - conn = self.ops.get('connection', self.sourceClass._connection) + conn = self._getConnection() return conn.accumulateSelect(self, *expressions) def count(self): |
From: <sub...@co...> - 2005-06-29 06:01:54
|
Author: phd Date: 2005-06-29 06:01:51 +0000 (Wed, 29 Jun 2005) New Revision: 824 Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py Log: Applied patch N 1226541. Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py =================================================================== --- trunk/SQLObject/sqlobject/postgres/pgconnection.py 2005-06-29 05:43:45 UTC (rev 823) +++ trunk/SQLObject/sqlobject/postgres/pgconnection.py 2005-06-29 06:01:51 UTC (rev 824) @@ -35,19 +35,31 @@ self.db = db self.password = passwd if dsn is None: - dsn = [] - if db: - dsn.append('dbname=%s' % db) - if user: - dsn.append('user=%s' % user) - if passwd: - dsn.append('password=%s' % passwd) - if host: - # @@: right format? - dsn.append('host=%s' % host) - if port: - dsn.append('port=%s' % port) - dsn = ' '.join(dsn) + if usePygresql: + dsn = '' + if host: + dsn += host + dsn += ':' + if db: + dsn += db + dsn += ':' + if user: + dsn += user + dsn += ':' + if passwd: + dsn += passwd + else: + dsn = [] + if db: + dsn.append('dbname=%s' % db) + if user: + dsn.append('user=%s' % user) + if passwd: + dsn.append('password=%s' % passwd) + if host: + # @@: right format? + dsn.append('host=%s' % host) + dsn = ' '.join(dsn) self.dsn = dsn DBAPI.__init__(self, **kw) |
From: <sub...@co...> - 2005-06-29 05:43:48
|
Author: phd Date: 2005-06-29 05:43:45 +0000 (Wed, 29 Jun 2005) New Revision: 823 Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py Log: Aplied autoCommit and queryIns patch from Kevin Dangoor <da...@gm...>. Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py =================================================================== --- trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2005-06-29 05:03:31 UTC (rev 822) +++ trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2005-06-29 05:43:45 UTC (rev 823) @@ -46,6 +46,8 @@ connectionFromURI = classmethod(connectionFromURI) def _runWithConnection(self, meth, *args): + if not self.autoCommit: + return DBAPI._runWithConnection(self, meth, args) conn = self.getConnection() # @@: Horrible auto-commit implementation. Just horrible! try: @@ -89,16 +91,17 @@ idName = soInstance.sqlmeta.idName sequenceName = getattr(soInstance, '_idSequence', 'GEN_%s' % table) + c = conn.cursor() if id is None: - row = self.queryOne('SELECT gen_id(%s,1) FROM rdb$database' + c.execute('SELECT gen_id(%s,1) FROM rdb$database' % sequenceName) - id = row[0] + id = c.fetchone()[0] names = [idName] + names values = [id] + values q = self._insertSQL(table, names, values) if self.debug: self.printDebug(conn, q, 'QueryIns') - self.query(q) + c.execute(q) if self.debugOutput: self.printDebug(conn, id, 'QueryIns', 'result') return id |
From: <sub...@co...> - 2005-06-29 05:03:39
|
Author: phd Date: 2005-06-29 05:03:31 +0000 (Wed, 29 Jun 2005) New Revision: 822 Modified: trunk/SQLObject/sqlobject/dbconnection.py Log: Changed assert error messages for Transaction. Code cleanup - tabs to spaces. Modified: trunk/SQLObject/sqlobject/dbconnection.py =================================================================== --- trunk/SQLObject/sqlobject/dbconnection.py 2005-06-20 11:38:19 UTC (rev 821) +++ trunk/SQLObject/sqlobject/dbconnection.py 2005-06-29 05:03:31 UTC (rev 822) @@ -616,19 +616,19 @@ def _SO_columnClause(self, soClass, kw): ops = {None: "IS"} - data = {} - if 'id' in kw: - data[soClass.sqlmeta.idName] = kw['id'] - else: - for key, col in soClass.sqlmeta._columnDict.items(): - if key in kw: - data[col.dbName] = kw[key] - elif col.foreignName in kw: - obj = kw[col.foreignName] - if obj is None: - data[col.dbName] = None - else: - data[col.dbName] = obj.id + data = {} + if 'id' in kw: + data[soClass.sqlmeta.idName] = kw['id'] + else: + for key, col in soClass.sqlmeta._columnDict.items(): + if key in kw: + data[col.dbName] = kw[key] + elif col.foreignName in kw: + obj = kw[col.foreignName] + if obj is None: + data[col.dbName] = None + else: + data[col.dbName] = obj.id return ' AND '.join( ['%s %s %s' % (dbName, ops.get(value, "="), self.sqlrepr(value)) @@ -683,8 +683,8 @@ if result is None: self._cleanup() raise StopIteration - if result[0] is None: - return None + if result[0] is None: + return None if self.select.ops.get('lazyColumns', 0): obj = self.select.sourceClass.get(result[0], connection=self.dbconn) return obj @@ -714,7 +714,7 @@ self._obsolete = False def assertActive(self): - assert not self._obsolete, "This transaction has already gone through COMMIT/ROLLBACK; create another transaction" + assert not self._obsolete, "This transaction has already gone through ROLLBACK; begin another transaction" def query(self, s): self.assertActive() @@ -795,7 +795,7 @@ def begin(self): # @@: Should we do this, or should begin() be a no-op when we're # not already obsolete? - assert self._obsolete, "You cannot begin a new transaction session without committing or rolling back the transaction" + assert self._obsolete, "You cannot begin a new transaction session without rolling back this one" self._obsolete = False self._connection = self._dbConnection.getConnection() |
From: <sub...@co...> - 2005-06-20 11:38:23
|
Author: phd Date: 2005-06-20 11:38:19 +0000 (Mon, 20 Jun 2005) New Revision: 821 Modified: trunk/SQLObject/sqlobject/col.py Log: Split SOStringCol into SOStringLikeCol; used SOStringLikeCol as a common ancestor for SOUncideCol; this is to allow UnicodeCol avoid having StringValidator in its validators list. Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-06-20 11:07:50 UTC (rev 820) +++ trunk/SQLObject/sqlobject/col.py 2005-06-20 11:38:19 UTC (rev 821) @@ -374,28 +374,9 @@ def withClass(self, soClass): return self.baseClass(soClass=soClass, name=self._name, **self.kw) -class StringValidator(validators.Validator): - def toPython(self, value, state): - if value is None: - return None - if isinstance(value, unicode): - return value.encode("ascii") - return value - - def fromPython(self, value, state): - if value is None: - return None - if isinstance(value, str): - return value - if isinstance(value, unicode): - return value.encode("ascii") - return value - -class SOStringCol(SOCol): - - # 3-03 @@: What about BLOB? - +class SOStringLikeCol(SOCol): + """A common ancestor for SOStringCol and SOUnicodeCol""" def __init__(self, **kw): self.length = popKey(kw, 'length') self.varchar = popKey(kw, 'varchar', 'auto') @@ -409,10 +390,6 @@ SOCol.__init__(self, **kw) - def createValidators(self): - return [StringValidator()] + \ - super(SOStringCol, self).createValidators() - def autoConstraints(self): constraints = [consts.isString] if self.length is not None: @@ -441,11 +418,11 @@ def _postgresType(self): self._check_case_sensitive("PostgreSQL") - return super(SOStringCol, self)._postgresType() + return super(SOStringLikeCol, self)._postgresType() def _sqliteType(self): self._check_case_sensitive("SQLite") - return super(SOStringCol, self)._sqliteType() + return super(SOStringLikeCol, self)._sqliteType() def _sybaseType(self): self._check_case_sensitive("SYBASE") @@ -468,6 +445,31 @@ else: return self._sqlType() + +class StringValidator(validators.Validator): + + def toPython(self, value, state): + if value is None: + return None + if isinstance(value, unicode): + return value.encode("ascii") + return value + + def fromPython(self, value, state): + if value is None: + return None + if isinstance(value, str): + return value + if isinstance(value, unicode): + return value.encode("ascii") + return value + +class SOStringCol(SOStringLikeCol): + + def createValidators(self): + return [StringValidator()] + \ + super(SOStringCol, self).createValidators() + class StringCol(Col): baseClass = SOStringCol @@ -487,10 +489,10 @@ return value return value.encode(self.db_encoding) -class SOUnicodeCol(SOStringCol): +class SOUnicodeCol(SOStringLikeCol): def __init__(self, **kw): self.dbEncoding = popKey(kw, 'dbEncoding', 'UTF-8') - SOStringCol.__init__(self, **kw) + super(SOUnicodeCol, self).__init__(**kw) def createValidators(self): return [UnicodeStringValidator(db_encoding=self.dbEncoding)] + \ |
From: <sub...@co...> - 2005-06-20 11:07:58
|
Author: phd Date: 2005-06-20 11:07:50 +0000 (Mon, 20 Jun 2005) New Revision: 820 Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py Log: Removed ancient kw['pool']. Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py =================================================================== --- trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2005-06-16 18:02:42 UTC (rev 819) +++ trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2005-06-20 11:07:50 UTC (rev 820) @@ -19,10 +19,6 @@ self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE) - if not autoCommit and not kw.has_key('pool'): - # Pooling doesn't work with transactions... - kw['pool'] = 0 - self.host = host self.db = db self.user = user Modified: trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py =================================================================== --- trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py 2005-06-16 18:02:42 UTC (rev 819) +++ trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py 2005-06-20 11:07:50 UTC (rev 820) @@ -21,9 +21,6 @@ using_sqlite2 = False self.module = sqlite self.filename = filename # full path to sqlite-db-file - if not autoCommit and not kw.has_key('pool'): - # Pooling doesn't work with transactions... - kw['pool'] = 0 # connection options opts = {} if using_sqlite2: |
From: <sub...@co...> - 2005-06-16 18:02:55
|
Author: phd Date: 2005-06-16 18:02:42 +0000 (Thu, 16 Jun 2005) New Revision: 819 Modified: trunk/SQLObject/examples/codebits.py Log: Fixed a misspelled variable name. Modified: trunk/SQLObject/examples/codebits.py =================================================================== --- trunk/SQLObject/examples/codebits.py 2005-06-14 18:12:42 UTC (rev 818) +++ trunk/SQLObject/examples/codebits.py 2005-06-16 18:02:42 UTC (rev 819) @@ -76,7 +76,7 @@ ## Snippet "transactions2" class Person(SQLObject): - _cacheValue = False + _cacheValues = False # ... ## end snippet |
From: <sub...@co...> - 2005-06-14 13:50:26
|
Author: phd Date: 2005-06-14 13:50:19 +0000 (Tue, 14 Jun 2005) New Revision: 817 Modified: trunk/SQLObject/sqlobject/col.py Log: Convert from MySQLdb.Binary() that is array.array('c', '...') to string. Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-06-14 13:04:22 UTC (rev 816) +++ trunk/SQLObject/sqlobject/col.py 2005-06-14 13:50:19 UTC (rev 817) @@ -29,6 +29,7 @@ import constraints as consts from include import validators from classregistry import findClass +from converters import array_type NoDefault = sqlbuilder.NoDefault True, False = 1==1, 0==1 @@ -972,7 +973,9 @@ if isinstance(value, state.soObject._connection._binaryType): if hasattr(self, "_binaryValue") and (value == self._binaryValue): return self._origValue - return str(value) + if isinstance(value, array_type): # MySQL + return value.tostring() + return str(value) # buffer => string raise validators.InvalidField("expected a string in the BLOBCol '%s', got %s instead" % \ (self.name, type(value)), value, state) |
From: <sub...@co...> - 2005-06-14 13:04:28
|
Author: phd Date: 2005-06-14 13:04:22 +0000 (Tue, 14 Jun 2005) New Revision: 816 Modified: trunk/SQLObject/sqlobject/sqlbuilder.py Log: Fixed a very subtle bug - self.items is being appended. Modified: trunk/SQLObject/sqlobject/sqlbuilder.py =================================================================== --- trunk/SQLObject/sqlobject/sqlbuilder.py 2005-06-14 11:13:08 UTC (rev 815) +++ trunk/SQLObject/sqlobject/sqlbuilder.py 2005-06-14 13:04:22 UTC (rev 816) @@ -445,7 +445,7 @@ select = "SELECT %s" % ", ".join([sqlrepr(v, db) for v in self.items]) tables = {} - things = self.items + things = self.items[:] if self.whereClause is not NoDefault: things.append(self.whereClause) for thing in things: |
From: <sub...@co...> - 2005-06-14 11:13:15
|
Author: phd Date: 2005-06-14 11:13:08 +0000 (Tue, 14 Jun 2005) New Revision: 815 Modified: trunk/SQLObject/sqlobject/col.py trunk/SQLObject/sqlobject/converters.py trunk/SQLObject/sqlobject/dbconnection.py trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py trunk/SQLObject/sqlobject/tests/test_indexes.py Log: Added a patch for PySQLite2 made by Kevin Dangoor <da...@gm...> and a lot of tweaks for it. Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-06-10 13:23:37 UTC (rev 814) +++ trunk/SQLObject/sqlobject/col.py 2005-06-14 11:13:08 UTC (rev 815) @@ -373,6 +373,24 @@ def withClass(self, soClass): return self.baseClass(soClass=soClass, name=self._name, **self.kw) +class StringValidator(validators.Validator): + + def toPython(self, value, state): + if value is None: + return None + if isinstance(value, unicode): + return value.encode("ascii") + return value + + def fromPython(self, value, state): + if value is None: + return None + if isinstance(value, str): + return value + if isinstance(value, unicode): + return value.encode("ascii") + return value + class SOStringCol(SOCol): # 3-03 @@: What about BLOB? @@ -390,6 +408,10 @@ SOCol.__init__(self, **kw) + def createValidators(self): + return [StringValidator()] + \ + super(SOStringCol, self).createValidators() + def autoConstraints(self): constraints = [consts.isString] if self.length is not None: @@ -851,6 +873,17 @@ % DATETIME_IMPLEMENTATION) now = staticmethod(now) + +if datetime_available: + class DateValidator(DateTimeValidator): + def toPython(self, value, state): + value = super(DateValidator, self).toPython(value, state) + if isinstance(value, datetime.datetime): + value = datetime.date(value.year, value.month, value.day) + return value + + fromPython = toPython + class SODateCol(SOCol): dateFormat = '%Y-%m-%d' @@ -863,7 +896,7 @@ """Create a validator for the column. Can be overriden in descendants.""" _validators = super(SODateCol, self).createValidators() if default_datetime_implementation == DATETIME_IMPLEMENTATION: - validatorClass = DateTimeValidator + validatorClass = DateValidator elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION: validatorClass = MXDateTimeValidator if default_datetime_implementation: @@ -937,7 +970,9 @@ value = module.decode(value) return value if isinstance(value, state.soObject._connection._binaryType): - return self._origValue + if hasattr(self, "_binaryValue") and (value == self._binaryValue): + return self._origValue + return str(value) raise validators.InvalidField("expected a string in the BLOBCol '%s', got %s instead" % \ (self.name, type(value)), value, state) @@ -945,7 +980,8 @@ if value is None: return None self._origValue = value # store the original value - return state.soObject._connection.createBinary(value) + self._binaryValue = state.soObject._connection.createBinary(value) + return self._binaryValue class SOBLOBCol(SOStringCol): def createValidators(self): @@ -983,6 +1019,8 @@ def toPython(self, value, state): if value is None: return None + if isinstance(value, unicode): + value = value.encode("ascii") if isinstance(value, str): return pickle.loads(value) raise validators.InvalidField("expected a pickle string in the PickleCol '%s', got %s instead" % \ Modified: trunk/SQLObject/sqlobject/converters.py =================================================================== --- trunk/SQLObject/sqlobject/converters.py 2005-06-10 13:23:37 UTC (rev 814) +++ trunk/SQLObject/sqlobject/converters.py 2005-06-14 11:13:08 UTC (rev 815) @@ -1,5 +1,4 @@ import array -array_type = type(array.array('c', '')) # In Python 2.2 array.array is a function try: import mx.DateTime.ISO @@ -91,12 +90,17 @@ registerConverter = converters.registerConverter lookupConverter = converters.lookupConverter +array_type = type(array.array('c', '')) # In Python 2.2 array.array and buffer +buffer_type = type(buffer('')) # are functions, not classes + def StringLikeConverter(value, db): if isinstance(value, array_type): try: value = value.tounicode() except ValueError: value = value.tostring() + elif isinstance(value, buffer_type): + value = str(value) if db in ('mysql', 'postgres'): for orig, repl in sqlStringReplace: @@ -110,6 +114,7 @@ registerConverter(type(""), StringLikeConverter) registerConverter(type(u""), StringLikeConverter) registerConverter(array_type, StringLikeConverter) +registerConverter(buffer_type, StringLikeConverter) def IntConverter(value, db): return repr(int(value)) Modified: trunk/SQLObject/sqlobject/dbconnection.py =================================================================== --- trunk/SQLObject/sqlobject/dbconnection.py 2005-06-10 13:23:37 UTC (rev 814) +++ trunk/SQLObject/sqlobject/dbconnection.py 2005-06-14 11:13:08 UTC (rev 815) @@ -510,7 +510,7 @@ self.query(self.createTableSQL(soClass)) def createTableSQL(self, soClass): - return ('CREATE TABLE %s (\n%s\n)' % + return ('CREATE TABLE %s (\n%s\n)' % (soClass.sqlmeta.table, self.createColumns(soClass))) def createColumns(self, soClass): @@ -822,7 +822,7 @@ _connection = hub hub.threadConnection = connectionFromURI('...') - + """ def __init__(self): Modified: trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py =================================================================== --- trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py 2005-06-10 13:23:37 UTC (rev 814) +++ trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py 2005-06-14 11:13:08 UTC (rev 815) @@ -1,6 +1,7 @@ from sqlobject.dbconnection import DBAPI from sqlobject.col import popKey sqlite = None +using_sqlite2 = False class SQLiteConnection(DBAPI): @@ -10,19 +11,33 @@ def __init__(self, filename, autoCommit=1, **kw): global sqlite + global using_sqlite2 if sqlite is None: - import sqlite + try: + from pysqlite2 import dbapi2 as sqlite + using_sqlite2 = True + except ImportError: + import sqlite + using_sqlite2 = False self.module = sqlite self.filename = filename # full path to sqlite-db-file if not autoCommit and not kw.has_key('pool'): # Pooling doesn't work with transactions... kw['pool'] = 0 # connection options - opts = {'autocommit': autoCommit} - if 'encoding' in kw: - opts['encoding'] = popKey(kw, 'encoding') - if 'mode' in kw: - opts['mode'] = int(popKey(kw, 'mode'), 0) + opts = {} + if using_sqlite2: + if autoCommit: + opts["isolation_level"] = None + if 'encoding' in kw: + import warnings + warnings.warn(DeprecationWarning("pysqlite2 does not support the encoding option")) + else: + opts['autocommit'] = autoCommit + if 'encoding' in kw: + opts['encoding'] = popKey(kw, 'encoding') + if 'mode' in kw: + opts['mode'] = int(popKey(kw, 'mode'), 0) if 'timeout' in kw: opts['timeout'] = float(popKey(kw, 'timeout')) # use only one connection for sqlite - supports multiple) @@ -46,8 +61,19 @@ return 'sqlite:///%s' % self.filename def _setAutoCommit(self, conn, auto): - conn.autocommit = auto + if using_sqlite2: + if auto: + conn.isolation_level = None + else: + conn.isolation_level = "" + else: + conn.autocommit = auto + def _setIsolationLevel(self, conn, level): + if not using_sqlite2: + return + conn.isolation_level = level + def makeConnection(self): return self._conn Modified: trunk/SQLObject/sqlobject/tests/test_indexes.py =================================================================== --- trunk/SQLObject/sqlobject/tests/test_indexes.py 2005-06-10 13:23:37 UTC (rev 814) +++ trunk/SQLObject/sqlobject/tests/test_indexes.py 2005-06-14 11:13:08 UTC (rev 815) @@ -29,12 +29,12 @@ mod = SOIndex1._connection.module try: SOIndex1(name='blah', number=0) - except (mod.ProgrammingError, mod.IntegrityError): + except (mod.ProgrammingError, mod.IntegrityError, mod.OperationalError): # expected pass else: assert 0, "Exception expected." - + def test_2(): if not supports('expressionIndex'): return |
From: <sub...@co...> - 2005-06-10 13:23:46
|
Author: phd Date: 2005-06-10 13:23:37 +0000 (Fri, 10 Jun 2005) New Revision: 814 Modified: trunk/SQLObject/sqlobject/converters.py Log: Minor fix for Python 2.2: array.array is a function in 2.2, not a class. Modified: trunk/SQLObject/sqlobject/converters.py =================================================================== --- trunk/SQLObject/sqlobject/converters.py 2005-06-10 12:48:30 UTC (rev 813) +++ trunk/SQLObject/sqlobject/converters.py 2005-06-10 13:23:37 UTC (rev 814) @@ -1,4 +1,5 @@ import array +array_type = type(array.array('c', '')) # In Python 2.2 array.array is a function try: import mx.DateTime.ISO @@ -91,7 +92,7 @@ lookupConverter = converters.lookupConverter def StringLikeConverter(value, db): - if isinstance(value, array.array): + if isinstance(value, array_type): try: value = value.tounicode() except ValueError: @@ -108,7 +109,7 @@ registerConverter(type(""), StringLikeConverter) registerConverter(type(u""), StringLikeConverter) -registerConverter(array.array, StringLikeConverter) +registerConverter(array_type, StringLikeConverter) def IntConverter(value, db): return repr(int(value)) |
From: <sub...@co...> - 2005-06-10 12:48:35
|
Author: phd Date: 2005-06-10 12:48:30 +0000 (Fri, 10 Jun 2005) New Revision: 813 Modified: trunk/SQLObject/sqlobject/col.py trunk/SQLObject/sqlobject/dbconnection.py Log: Save the original value in BinaryValidator.fromPython() and return it in toPython(). Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-06-10 10:22:44 UTC (rev 812) +++ trunk/SQLObject/sqlobject/col.py 2005-06-10 12:48:30 UTC (rev 813) @@ -936,12 +936,15 @@ if module.__name__ == "sqlite": value = module.decode(value) return value + if isinstance(value, state.soObject._connection._binaryType): + return self._origValue raise validators.InvalidField("expected a string in the BLOBCol '%s', got %s instead" % \ (self.name, type(value)), value, state) def fromPython(self, value, state): if value is None: return None + self._origValue = value # store the original value return state.soObject._connection.createBinary(value) class SOBLOBCol(SOStringCol): Modified: trunk/SQLObject/sqlobject/dbconnection.py =================================================================== --- trunk/SQLObject/sqlobject/dbconnection.py 2005-06-10 10:22:44 UTC (rev 812) +++ trunk/SQLObject/sqlobject/dbconnection.py 2005-06-10 12:48:30 UTC (rev 813) @@ -209,6 +209,7 @@ self._pool = [] self._poolLock = threading.Lock() DBConnection.__init__(self, **kw) + self._binaryType = type(self.module.Binary('')) def _runWithConnection(self, meth, *args): conn = self.getConnection() |
From: <sub...@co...> - 2005-06-10 10:22:55
|
Author: phd Date: 2005-06-10 10:22:44 +0000 (Fri, 10 Jun 2005) New Revision: 812 Modified: trunk/SQLObject/sqlobject/col.py Log: Changed the concept of createValidator() - they have been renamed to createValidators(), and now they return a list of validators: the validator for the column and all validators from the parent classes. Added SQLValidator that inherits validators.All, but runs its validators in different order depending of whether it is convertin toPython or fromPython. Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-06-03 21:53:30 UTC (rev 811) +++ trunk/SQLObject/sqlobject/col.py 2005-06-10 10:22:44 UTC (rev 812) @@ -73,6 +73,21 @@ if mxdatetime_available: __all__.append("MXDATETIME_IMPLEMENTATION") + +class SQLValidator(validators.All): + def attemptConvert(self, value, state, validate): + if validate is validators.toPython: + vlist = list(self.validators[:]) + vlist.reverse() + elif validate is validators.fromPython: + vlist = self.validators + else: + raise RuntimeError + for validator in vlist: + value = validate(validator, value, state) + return value + + ######################################## ## Columns ######################################## @@ -180,7 +195,12 @@ else: self.unique = unique - self.validator = validator + _validators = self.createValidators() + if _validators: + if validator: _validators.append(validator) + self.validator = SQLValidator.join(_validators[0], *_validators[1:]) + else: + self.validator = validator self.noCache = noCache self.lazy = lazy # this is in case of ForeignKey, where we rename the column @@ -201,6 +221,10 @@ validator = property(_get_validator, _set_validator) + def createValidators(self): + """Create a list of validators for the column.""" + return [] + def autoConstraints(self): return [] @@ -426,8 +450,12 @@ class UnicodeStringValidator(validators.Validator): - def __init__(self, db_encoding='UTF-8'): - self.db_encoding = db_encoding + def toPython(self, value, state): + if value is None: + return None + if isinstance(value, unicode): + return value + return unicode(value, self.db_encoding) def fromPython(self, value, state): if value is None: @@ -436,24 +464,14 @@ return value return value.encode(self.db_encoding) - def toPython(self, value, state): - if value is None: - return None - if isinstance(value, unicode): - return value - return unicode(value, self.db_encoding) - class SOUnicodeCol(SOStringCol): - validatorClass = UnicodeStringValidator # can be overriden in descendants - def __init__(self, **kw): self.dbEncoding = popKey(kw, 'dbEncoding', 'UTF-8') SOStringCol.__init__(self, **kw) - self.validator = validators.All.join(self.createValidator(), self.validator) - def createValidator(self): - """Create a validator for the column. Can be overriden in descendants.""" - return self.validatorClass(self.dbEncoding) + def createValidators(self): + return [UnicodeStringValidator(db_encoding=self.dbEncoding)] + \ + super(SOUnicodeCol, self).createValidators() class UnicodeCol(Col): baseClass = SOUnicodeCol @@ -461,14 +479,6 @@ class IntValidator(validators.Validator): - def fromPython(self, value, state): - if value is None: - return None - if not isinstance(value, (int, long, sqlbuilder.SQLExpression)): - raise validators.InvalidField("expected an int in the IntCol '%s', got %s instead" % \ - (self.name, type(value)), value, state) - return value - def toPython(self, value, state): if value is None: return None @@ -483,21 +493,23 @@ raise validators.InvalidField("expected an int in the IntCol '%s', got %s instead" % \ (self.name, type(value)), value, state) + def fromPython(self, value, state): + if value is None: + return None + if not isinstance(value, (int, long, sqlbuilder.SQLExpression)): + raise validators.InvalidField("expected an int in the IntCol '%s', got %s instead" % \ + (self.name, type(value)), value, state) + return value + class SOIntCol(SOCol): - validatorClass = IntValidator # can be overriden in descendants - # 3-03 @@: support precision, maybe max and min directly - def __init__(self, **kw): - SOCol.__init__(self, **kw) - self.validator = validators.All.join(self.createValidator(), self.validator) - def autoConstraints(self): return [consts.isInt] - def createValidator(self): - """Create a validator for the column. Can be overriden in descendants.""" - return self.validatorClass(name=self.name) + def createValidators(self): + return [IntValidator(name=self.name)] + \ + super(SOIntCol, self).createValidators() def _sqlType(self): return 'INT' @@ -507,6 +519,14 @@ class BoolValidator(validators.Validator): + def toPython(self, value, state): + if value is None: + return None + elif not value: + return sqlbuilder.FALSE + else: + return sqlbuilder.TRUE + def fromPython(self, value, state): if value is None: return None @@ -515,27 +535,13 @@ else: return sqlbuilder.FALSE - def toPython(self, value, state): - if value is None: - return None - elif not value: - return sqlbuilder.FALSE - else: - return sqlbuilder.TRUE - class SOBoolCol(SOCol): - validatorClass = BoolValidator # can be overriden in descendants - - def __init__(self, **kw): - SOCol.__init__(self, **kw) - self.validator = validators.All.join(self.createValidator(), self.validator) - def autoConstraints(self): return [consts.isBool] - def createValidator(self): - """Create a validator for the column. Can be overriden in descendants.""" - return self.validatorClass() + def createValidators(self): + return [BoolValidator()] + \ + super(SOBoolCol, self).createValidators() def _postgresType(self): return 'BOOL' @@ -561,14 +567,6 @@ class FloatValidator(validators.Validator): - def fromPython(self, value, state): - if value is None: - return None - if not isinstance(value, (int, long, float, sqlbuilder.SQLExpression)): - raise validators.InvalidField("expected a float in the FloatCol '%s', got %s instead" % \ - (self.name, type(value)), value, state) - return value - def toPython(self, value, state): if value is None: return None @@ -580,21 +578,23 @@ raise validators.InvalidField("expected a float in the FloatCol '%s', got %s instead" % \ (self.name, type(value)), value, state) + def fromPython(self, value, state): + if value is None: + return None + if not isinstance(value, (int, long, float, sqlbuilder.SQLExpression)): + raise validators.InvalidField("expected a float in the FloatCol '%s', got %s instead" % \ + (self.name, type(value)), value, state) + return value + class SOFloatCol(SOCol): - validatorClass = FloatValidator # can be overriden in descendants - # 3-03 @@: support precision (e.g., DECIMAL) - def __init__(self, **kw): - SOCol.__init__(self, **kw) - self.validator = validators.All.join(self.createValidator(), self.validator) - def autoConstraints(self): return [consts.isFloat] - def createValidator(self): - """Create a validator for the column. Can be overriden in descendants.""" - return self.validatorClass(name=self.name) + def createValidators(self): + return [FloatValidator(name=self.name)] + \ + super(SOFloatCol, self).createValidators() def _sqlType(self): return 'FLOAT' @@ -689,7 +689,7 @@ sql = ' '.join([fidName, self._maxdbType()]) tName = other.sqlmeta.table idName = other.sqlmeta.idName - sql=sql + ',' + '\n' + sql=sql + ',' + '\n' sql=sql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idName) return sql @@ -742,16 +742,6 @@ if datetime_available: class DateTimeValidator(validators.DateValidator): - def fromPython(self, value, state): - if value is None: - return None - if isinstance(value, (datetime.date, datetime.datetime, sqlbuilder.SQLExpression)): - return value - if hasattr(value, "strftime"): - return value.strftime(self.format) - raise validators.InvalidField("expected a datetime in the DateTimeCol '%s', got %s instead" % \ - (self.name, type(value)), value, state) - def toPython(self, value, state): if value is None: return None @@ -772,18 +762,18 @@ secs = time.mktime(stime) return datetime.datetime.fromtimestamp(secs) -if mxdatetime_available: - class MXDateTimeValidator(validators.DateValidator): def fromPython(self, value, state): if value is None: return None - if isinstance(value, (DateTimeType, sqlbuilder.SQLExpression)): + if isinstance(value, (datetime.date, datetime.datetime, sqlbuilder.SQLExpression)): return value if hasattr(value, "strftime"): return value.strftime(self.format) - raise validators.InvalidField("expected a mxDateTime in the DateTimeCol '%s', got %s instead" % \ + raise validators.InvalidField("expected a datetime in the DateTimeCol '%s', got %s instead" % \ (self.name, type(value)), value, state) +if mxdatetime_available: + class MXDateTimeValidator(validators.DateValidator): def toPython(self, value, state): if value is None: return None @@ -802,6 +792,16 @@ (self.format, self.name, type(value)), value, state) return DateTime.mktime(stime) + def fromPython(self, value, state): + if value is None: + return None + if isinstance(value, (DateTimeType, sqlbuilder.SQLExpression)): + return value + if hasattr(value, "strftime"): + return value.strftime(self.format) + raise validators.InvalidField("expected a mxDateTime in the DateTimeCol '%s', got %s instead" % \ + (self.name, type(value)), value, state) + class SODateTimeCol(SOCol): datetimeFormat = '%Y-%m-%d %H:%M:%S' @@ -809,16 +809,16 @@ datetimeFormat = popKey(kw, 'datetimeFormat') if datetimeFormat: self.datetimeFormat = datetimeFormat SOCol.__init__(self, **kw) - if default_datetime_implementation: - self.validator = validators.All.join(self.createValidator(), self.validator) - def createValidator(self): - """Create a validator for the column. Can be overriden in descendants.""" + def createValidators(self): + _validators = super(SODateTimeCol, self).createValidators() if default_datetime_implementation == DATETIME_IMPLEMENTATION: validatorClass = DateTimeValidator elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION: validatorClass = MXDateTimeValidator - return validatorClass(name=self.name, format=self.datetimeFormat) + if default_datetime_implementation: + _validators.insert(0, validatorClass(name=self.name, format=self.datetimeFormat)) + return _validators def _mysqlType(self): return 'DATETIME' @@ -841,9 +841,9 @@ class DateTimeCol(Col): baseClass = SODateTimeCol def now(): - if DATETIME_IMPLEMENTATION == 'datetime': + if default_datetime_implementation == DATETIME_IMPLEMENTATION: return datetime.datetime.now() - elif DATETIME_IMPLEMENTATION == 'mxdatetime': + elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION: return DateTime.now() else: assert 0, ("No datetime implementation available " @@ -858,16 +858,17 @@ dateFormat = popKey(kw, 'dateFormat') if dateFormat: self.dateFormat = dateFormat SOCol.__init__(self, **kw) - if default_datetime_implementation: - self.validator = validators.All.join(self.createValidator(), self.validator) - def createValidator(self): + def createValidators(self): """Create a validator for the column. Can be overriden in descendants.""" + _validators = super(SODateCol, self).createValidators() if default_datetime_implementation == DATETIME_IMPLEMENTATION: validatorClass = DateTimeValidator elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION: validatorClass = MXDateTimeValidator - return validatorClass(name=self.name, format=self.dateFormat) + if default_datetime_implementation: + _validators.insert(0, validatorClass(name=self.name, format=self.dateFormat)) + return _validators def _mysqlType(self): return 'DATE' @@ -927,21 +928,27 @@ of wrapper type for binary conversion. """ + def toPython(self, value, state): + if value is None: + return None + if isinstance(value, str): + module = state.soObject._connection.module + if module.__name__ == "sqlite": + value = module.decode(value) + return value + raise validators.InvalidField("expected a string in the BLOBCol '%s', got %s instead" % \ + (self.name, type(value)), value, state) + def fromPython(self, value, state): if value is None: return None return state.soObject._connection.createBinary(value) class SOBLOBCol(SOStringCol): - validatorClass = BinaryValidator # can be overriden in descendants + def createValidators(self): + return [BinaryValidator(name=self.name)] + \ + super(SOBLOBCol, self).createValidators() - def __init__(self, **kw): - SOStringCol.__init__(self, **kw) - self.validator = validators.All.join(self.createValidator(), self.validator) - - def createValidator(self): - return self.validatorClass() - def _mysqlType(self): length = self.length varchar = self.varchar @@ -984,15 +991,13 @@ return pickle.dumps(value) class SOPickleCol(SOBLOBCol): - validatorClass = PickleValidator # can be overriden in descendants - def __init__(self, **kw): self.pickleProtocol = popKey(kw, 'pickleProtocol', 1) SOBLOBCol.__init__(self, **kw) - def createValidator(self): - """Create a validator for the column. Can be overriden in descendants.""" - return self.validatorClass(name=self.name, pickleProtocol=self.pickleProtocol) + def createValidators(self): + return [PickleValidator(name=self.name, pickleProtocol=self.pickleProtocol)] + \ + super(SOPickleCol, self).createValidators() class PickleCol(BLOBCol): baseClass = SOPickleCol |
From: <sub...@co...> - 2005-06-03 21:53:39
|
Author: ianb Date: 2005-06-03 21:53:30 +0000 (Fri, 03 Jun 2005) New Revision: 811 Modified: trunk/SQLObject/sqlobject/manager/command.py Log: Note failing upgrade script filename Modified: trunk/SQLObject/sqlobject/manager/command.py =================================================================== --- trunk/SQLObject/sqlobject/manager/command.py 2005-06-03 16:13:48 UTC (rev 810) +++ trunk/SQLObject/sqlobject/manager/command.py 2005-06-03 21:53:30 UTC (rev 811) @@ -910,7 +910,11 @@ print sql print '-'*60 if not sim: - conn.query(sql) + try: + conn.query(sql) + except: + print "Error in script: %s" % upgrader + raise self.update_db(next_version, conn) print 'Done.' |
From: <sub...@co...> - 2005-06-03 16:13:57
|
Author: phd Date: 2005-06-03 16:13:48 +0000 (Fri, 03 Jun 2005) New Revision: 810 Added: trunk/SQLObject/sqlobject/inheritance/tests/test_inherited_foreignKey.py Modified: trunk/SQLObject/sqlobject/inheritance/__init__.py trunk/SQLObject/sqlobject/main.py Log: Added a class method _notifyFinishClassCreation(). The method is used in InheritableSQLObject to propagate columns and joins from parent classes to children if it hasn't been done already. Added a test for that propagation. Modified: trunk/SQLObject/sqlobject/inheritance/__init__.py =================================================================== --- trunk/SQLObject/sqlobject/inheritance/__init__.py 2005-06-01 13:48:41 UTC (rev 809) +++ trunk/SQLObject/sqlobject/inheritance/__init__.py 2005-06-03 16:13:48 UTC (rev 810) @@ -108,7 +108,8 @@ makeProperties(cls) return - super(InheritableSQLObject, cls).addColumn(columnDef, changeSchema, connection) + if columnDef: + super(InheritableSQLObject, cls).addColumn(columnDef, changeSchema, connection) #DSM: Update each child class if needed and existing (only for new #DSM: dynamic column as no child classes exists at object creation) @@ -148,7 +149,8 @@ makeProperties(cls) return - super(InheritableSQLObject, cls).addJoin(joinDef) + if joinDef: + super(InheritableSQLObject, cls).addJoin(joinDef) #DSM: Update each child class if needed and existing (only for new #DSM: dynamic join as no child classes exists at object creation) @@ -167,6 +169,17 @@ delJoin = classmethod(delJoin) + def _notifyFinishClassCreation(cls): + if not cls._columns: + # There are no columns - call addColumn to propagate columns + # from parent classes to children + cls.addColumn(None) + if not cls._joins: + # There are no joins - call addJoin to propagate joins + # from parent classes to children + cls.addJoin(None) + _notifyFinishClassCreation = classmethod(_notifyFinishClassCreation) + def _create(self, id, **kw): #DSM: If we were called by a children class, Added: trunk/SQLObject/sqlobject/inheritance/tests/test_inherited_foreignKey.py =================================================================== --- trunk/SQLObject/sqlobject/inheritance/tests/test_inherited_foreignKey.py 2005-06-01 13:48:41 UTC (rev 809) +++ trunk/SQLObject/sqlobject/inheritance/tests/test_inherited_foreignKey.py 2005-06-03 16:13:48 UTC (rev 810) @@ -0,0 +1,37 @@ +from sqlobject import * +from sqlobject.tests.dbtest import * +from sqlobject.inheritance import InheritableSQLObject + + +class Note(SQLObject): + text = StringCol() + +class PersonWithNotes(InheritableSQLObject): + firstName = StringCol() + lastName = StringCol() + note = ForeignKey("Note", default=None) + +class EmployeeWithNotes(PersonWithNotes): + _inheritable = False + +def setup(): + setupClass(Note) + setupClass(PersonWithNotes) + setupClass(EmployeeWithNotes) + + note = Note(text="person") + PersonWithNotes(firstName='Oneof', lastName='Authors', note=note) + note = Note(text="employee") + EmployeeWithNotes(firstName='Project', lastName='Leader', note=note) + + +def test_inheritance(): + setup() + + person = PersonWithNotes.get(1) + assert isinstance(person, PersonWithNotes) and not isinstance(person, EmployeeWithNotes) + assert person.note.text == "person" + + employee = EmployeeWithNotes.get(2) + assert isinstance(employee, EmployeeWithNotes) + assert employee.note.text == "employee" Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2005-06-01 13:48:41 UTC (rev 809) +++ trunk/SQLObject/sqlobject/main.py 2005-06-03 16:13:48 UTC (rev 810) @@ -475,6 +475,7 @@ # We don't setup the properties until we're finished with the # batch adding of all the columns... + cls._notifyFinishClassCreation() cls._SO_finishedClassCreation = True makeProperties(cls) @@ -796,6 +797,10 @@ delJoin = classmethod(delJoin) + def _notifyFinishClassCreation(cls): + pass + _notifyFinishClassCreation = classmethod(_notifyFinishClassCreation) + def _init(self, id, connection=None, selectResults=None): assert id is not None # This function gets called only when the object is |
From: <sub...@co...> - 2005-06-01 13:48:47
|
Author: phd Date: 2005-06-01 13:48:41 +0000 (Wed, 01 Jun 2005) New Revision: 809 Added: trunk/SQLObject/sqlobject/tests/test_SingleJoin.py Modified: trunk/SQLObject/docs/SQLObjectRelationships.txt trunk/SQLObject/sqlobject/joins.py Log: Added SingleJoin. Thanks to michelts <mic...@gm...>. Modified: trunk/SQLObject/docs/SQLObjectRelationships.txt =================================================================== --- trunk/SQLObject/docs/SQLObjectRelationships.txt 2005-05-30 17:08:10 UTC (rev 808) +++ trunk/SQLObject/docs/SQLObjectRelationships.txt 2005-06-01 13:48:41 UTC (rev 809) @@ -9,7 +9,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~ See `One-to-Many Relationships`_ for an example of one-to-many -relationships. +relationships. Several keyword arguments are allowed to the `MultipleJoin` constructor: @@ -77,3 +77,8 @@ name = StringCol(length=50, alternateID=True) roles = RelatedJoin('Person', joinColumn='role', otherColumn='person', intermediateTable='assigned_roles') + +SingleJoin: One-to-One +~~~~~~~~~~~~~~~~~~~~~~~~~ + +Similar to `MultipleJoin`, but returns just one object, not a list. Modified: trunk/SQLObject/sqlobject/joins.py =================================================================== --- trunk/SQLObject/sqlobject/joins.py 2005-05-30 17:08:10 UTC (rev 808) +++ trunk/SQLObject/sqlobject/joins.py 2005-06-01 13:48:41 UTC (rev 809) @@ -4,7 +4,7 @@ import classregistry from col import popKey -__all__ = ['MultipleJoin', 'SQLMultipleJoin', 'RelatedJoin', 'SQLRelatedJoin'] +__all__ = ['MultipleJoin', 'SQLMultipleJoin', 'RelatedJoin', 'SQLRelatedJoin', 'SingleJoin'] def getID(obj): try: @@ -133,17 +133,17 @@ conn = None return self._applyOrderBy([self.otherClass.get(id, conn) for (id,) in ids if id is not None], self.otherClass) +class MultipleJoin(Join): + baseClass = SOMultipleJoin + class SOSQLMultipleJoin(SOMultipleJoin): def performJoin(self, inst): - results=self.otherClass.select(getattr(self.otherClass.q, self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn))==inst.id) + results = self.otherClass.select(getattr(self.otherClass.q, self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)) == inst.id) if self.orderBy is NoDefault: self.orderBy = self.otherClass.sqlmeta.defaultOrder return results.orderBy(self.orderBy) -class MultipleJoin(Join): - baseClass = SOMultipleJoin - class SQLMultipleJoin(Join): baseClass = SOSQLMultipleJoin @@ -202,6 +202,9 @@ self.otherColumn, getID(other)) +class RelatedJoin(MultipleJoin): + baseClass = SORelatedJoin + class SOSQLRelatedJoin(SORelatedJoin): def performJoin(self, inst): options={ @@ -225,11 +228,33 @@ # TODO (michelts), apply order by on the selection return results -class RelatedJoin(MultipleJoin): - baseClass = SORelatedJoin - class SQLRelatedJoin(RelatedJoin): baseClass = SOSQLRelatedJoin def capitalize(name): return name[0].capitalize() + name[1:] + +class SOSingleJoin(SOMultipleJoin): + + def __init__(self, makeDefault=False, **kw): + SOMultipleJoin.__init__(self, **kw) + self.makeDefault = makeDefault + + def performJoin(self, inst): + pythonColumn = self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn) + results = self.otherClass.select(getattr(self.otherClass.q, pythonColumn) == inst.id) + if results.count() == 0: + if not self.makeDefault: + return None + else: + kw = {pythonColumn[:-2]: inst} # skipping the ID (from foreignkeyID) + return self.otherClass(**kw) # instanciating the otherClass with all + # values to their defaults, except the foreign key + # TODO I don't think this is the best way to know the column as foreignKey + # reather than foreignKeyID, but I don't found a sqlmeta.style function + # to do the work, if there isn't such function, I must create it. + else: + return results[0] + +class SingleJoin(Join): + baseClass = SOSingleJoin Added: trunk/SQLObject/sqlobject/tests/test_SingleJoin.py =================================================================== --- trunk/SQLObject/sqlobject/tests/test_SingleJoin.py 2005-05-30 17:08:10 UTC (rev 808) +++ trunk/SQLObject/sqlobject/tests/test_SingleJoin.py 2005-06-01 13:48:41 UTC (rev 809) @@ -0,0 +1,25 @@ +from sqlobject import * +from sqlobject.tests.dbtest import * + +class PersonWithAlbum(SQLObject): + name = StringCol() + # albumNone returns the album or none + albumNone = SingleJoin('PhotoAlbum', joinColumn='person_id') + # albumInstance returns the album or an default album instance + albumInstance = SingleJoin('PhotoAlbum', makeDefault=True, joinColumn='person_id') + +class PhotoAlbum(SQLObject): + color = StringCol(default='red') + person = ForeignKey('PersonWithAlbum') + +def test_1(): + setupClass([PersonWithAlbum, PhotoAlbum]) + + person = PersonWithAlbum(name='Gokou (Kakarouto)') + assert not person.albumNone # I don't created an album, this way it returns None + assert isinstance(person.albumInstance, PhotoAlbum) + + album = PhotoAlbum(person=person) + assert person.albumNone + assert isinstance(person.albumNone, PhotoAlbum) + assert isinstance(person.albumInstance, PhotoAlbum) |
From: <sub...@co...> - 2005-05-26 22:22:47
|
Author: ianb Date: 2005-05-26 22:22:34 +0000 (Thu, 26 May 2005) New Revision: 807 Modified: trunk/SQLObject/sqlobject/col.py trunk/SQLObject/sqlobject/main.py trunk/SQLObject/sqlobject/tests/test_basic.py Log: Fixed cascade='null', which was cascading deletes, instead of setting columns to null Modified: trunk/SQLObject/sqlobject/col.py =================================================================== --- trunk/SQLObject/sqlobject/col.py 2005-05-26 13:59:05 UTC (rev 806) +++ trunk/SQLObject/sqlobject/col.py 2005-05-26 22:22:34 UTC (rev 807) @@ -122,6 +122,10 @@ # None: no constraint is generated # True: a CASCADE constraint is generated # False: a RESTRICT constraint is generated + # 'null': a SET NULL trigger is generated + if isinstance(cascade, str): + assert cascade == 'null', ( + "The only string value allowed for cascade is 'null' (you gave: %r)" % cascade) self.cascade = cascade if type(constraints) not in (type([]), type(())): Modified: trunk/SQLObject/sqlobject/main.py =================================================================== --- trunk/SQLObject/sqlobject/main.py 2005-05-26 13:59:05 UTC (rev 806) +++ trunk/SQLObject/sqlobject/main.py 2005-05-26 22:22:34 UTC (rev 807) @@ -1205,19 +1205,22 @@ connection=conn) createTable = classmethod(createTable) - def createTableSQL(cls, createJoinTables=True, connection=None): + def createTableSQL(cls, createJoinTables=True, connection=None, + createIndexes=True): conn = connection or cls._connection sql = conn.createTableSQL(cls) if createJoinTables: sql += '\n' + cls.createJoinTablesSQL(connection=conn) + if createIndexes: + sql += '\n' + cls.createIndexesSQL(connection=conn) return sql createTableSQL = classmethod(createTableSQL) def createJoinTables(cls, ifNotExists=False, connection=None): conn = connection or cls._connection for join in cls._getJoinsToCreate(): - if ifNotExists and \ - conn.tableExists(join.intermediateTable): + if (ifNotExists and + conn.tableExists(join.intermediateTable)): continue conn._SO_createJoinTable(join) createJoinTables = classmethod(createJoinTables) @@ -1238,6 +1241,16 @@ conn._SO_createIndex(cls, index) createIndexes = classmethod(createIndexes) + def createIndexesSQL(cls, connection=None): + conn = connection or cls._connection + sql = [] + for index in cls.sqlmeta._indexList: + if not index: + continue + sql.append(conn.createIndexSQL(cls, index)) + return '\n'.join(sql) + createIndexesSQL = classmethod(createIndexesSQL) + def _getJoinsToCreate(cls): joins = [] for join in cls.sqlmeta._joinList: @@ -1282,23 +1295,37 @@ for k in depends: cols = findDependantColumns(klass.__name__, k) query = [] - restrict = False + delete = setnull = restrict = False for col in cols: if col.cascade == False: # Found a restriction restrict = True query.append("%s = %s" % (col.dbName, self.id)) + if col.cascade == 'null': + setnull = col.name + elif col.cascade: + delete = True + assert delete or setnull or restrict, ( + "Class %s depends on %s accoriding to " + "findDependantColumns, but this seems inaccurate" + % (k, klass)) query = ' OR '.join(query) results = k.select(query, connection=self._connection) - if restrict and results.count(): - # Restrictions only apply if there are - # matching records on the related table - raise SQLObjectIntegrityError, ( - "Tried to delete %s::%s but " - "table %s has a restriction against it" % - (klass.__name__, self.id, k.__name__)) - for row in results: - row.destroySelf() + if restrict: + if results.count(): + # Restrictions only apply if there are + # matching records on the related table + raise SQLObjectIntegrityError, ( + "Tried to delete %s::%s but " + "table %s has a restriction against it" % + (klass.__name__, self.id, k.__name__)) + else: + for row in results: + if delete: + row.destroySelf() + else: + row.set(**{setnull: None}) + self.sqlmeta._obsolete = True self._connection._SO_delete(self) self._connection.cache.expire(self.id, self.__class__) Modified: trunk/SQLObject/sqlobject/tests/test_basic.py =================================================================== --- trunk/SQLObject/sqlobject/tests/test_basic.py 2005-05-26 13:59:05 UTC (rev 806) +++ trunk/SQLObject/sqlobject/tests/test_basic.py 2005-05-26 22:22:34 UTC (rev 807) @@ -120,7 +120,6 @@ assert TestSO3.selectBy(otherID=tc4.id)[0] == tc3 assert list(TestSO3.selectBy(otherID=tc4.id)[:10]) == [tc3] assert list(TestSO3.selectBy(other=tc4)[:10]) == [tc3] - assert 0 class TestSO5(SQLObject): name = StringCol(length=10, dbName='name_col') @@ -242,3 +241,27 @@ tc9a.destroySelf() assert TestSO8.select().count() == 0 assert TestSO9.select().count() == 0 + +class TestSO10(SQLObject): + name = StringCol() + +class TestSO11(SQLObject): + name = StringCol() + other = ForeignKey('TestSO10', default=None, cascade='null') + +def testForeignKeySetNull(): + setupClass([TestSO10, TestSO11]) + obj1 = TestSO10(name='foo') + obj2 = TestSO10(name='bar') + dep1 = TestSO11(name='xxx', other=obj1) + dep2 = TestSO11(name='yyy', other=obj1) + dep3 = TestSO11(name='zzz', other=obj2) + for name in 'xxx', 'yyy', 'zzz': + assert len(list(TestSO11.selectBy(name=name))) == 1 + obj1.destroySelf() + for name in 'xxx', 'yyy', 'zzz': + assert len(list(TestSO11.selectBy(name=name))) == 1 + assert dep1.other is None + assert dep2.other is None + assert dep3.other is obj2 + |
From: <sub...@co...> - 2005-05-26 13:59:14
|
Author: phd Date: 2005-05-26 13:59:05 +0000 (Thu, 26 May 2005) New Revision: 806 Modified: trunk/SQLObject/sqlobject/include/validators.py Log: Applied the patch https://sourceforge.net/tracker/index.php?func=detail&aid=1198775&group_id=74338&atid=540674 . Modified: trunk/SQLObject/sqlobject/include/validators.py =================================================================== --- trunk/SQLObject/sqlobject/include/validators.py 2005-05-25 15:42:17 UTC (rev 805) +++ trunk/SQLObject/sqlobject/include/validators.py 2005-05-26 13:59:05 UTC (rev 806) @@ -994,7 +994,7 @@ except ValueError: return {self._ccNumberField: self.message('invalidNumber', "Please enter only the number, no other characters")} - assert _cardInfo.has_key(ccType), "I can't validate that type of credit card" + assert self._cardInfo.has_key(ccType), "I can't validate that type of credit card" foundValid = False validLength = False for prefix, length in self._cardInfo[ccType]: @@ -1009,7 +1009,7 @@ if not foundValid: return {self._ccNumberField: self.message('invalidNumber', "That number is not valid")} - if not _validateMod10(number): + if not self._validateMod10(number): return {self._ccNumberField: self.message('invalidNumber', "That number is not valid")} return None |