sqlobject-cvs Mailing List for SQLObject (Page 180)
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: <sub...@co...> - 2004-05-27 10:04:19
|
Author: ahmedmo Date: 2004-05-27 02:03:30 -0400 (Thu, 27 May 2004) New Revision: 119 Removed: trunk/SQLObject/db/ Log: Removed file/folder created by error by the client tool |
|
From: <sub...@co...> - 2004-05-27 10:04:03
|
Author: ahmedmo Date: 2004-05-27 02:03:14 -0400 (Thu, 27 May 2004) New Revision: 118 Removed: trunk/SQLObject/hooks/ Log: Removed file/folder |
|
From: <sub...@co...> - 2004-05-27 10:03:59
|
Author: ahmedmo Date: 2004-05-27 02:03:02 -0400 (Thu, 27 May 2004) New Revision: 117 Removed: trunk/SQLObject/locks/ Log: Removed file/folder created by error by the client tool |
|
From: <sub...@co...> - 2004-05-27 10:03:34
|
Author: ahmedmo Date: 2004-05-27 02:02:42 -0400 (Thu, 27 May 2004) New Revision: 116 Removed: trunk/SQLObject/SQLOBJECT/ Log: Removed file/folder created by error by the client tool |
|
From: <sub...@co...> - 2004-05-27 10:03:21
|
Author: ahmedmo Date: 2004-05-27 02:02:29 -0400 (Thu, 27 May 2004) New Revision: 115 Removed: trunk/SQLObject/SQLObject/ Log: Removed file/folder created by error by the client tool |
|
From: <sub...@co...> - 2004-05-27 10:00:57
|
Author: ahmedmo Date: 2004-05-27 02:00:07 -0400 (Thu, 27 May 2004) New Revision: 114 Added: trunk/SQLObject/SQLObject/ trunk/SQLObject/SQLObject/sqlobject/ Log: Initial Import |
|
From: <sub...@co...> - 2004-05-27 09:55:29
|
Author: ahmedmo Date: 2004-05-27 01:54:38 -0400 (Thu, 27 May 2004) New Revision: 112 Added: trunk/SQLObject/conf/ trunk/SQLObject/dav/ trunk/SQLObject/db/ trunk/SQLObject/hooks/ trunk/SQLObject/locks/ Log: Initial Import |
|
From: <sub...@co...> - 2004-05-27 09:50:25
|
Author: ahmedmo Date: 2004-05-27 01:49:33 -0400 (Thu, 27 May 2004) New Revision: 109 Added: trunk/SQLObject/SQLOBJECT/ Log: Initial Import |
|
From: <sub...@co...> - 2004-05-26 15:52:39
|
Author: ianb
Date: 2004-05-26 07:51:52 -0400 (Wed, 26 May 2004)
New Revision: 107
Modified:
trunk/SQLObject/sqlobject/firebird/firebirdconnection.py
Log:
Translate '/' in the path in a Firebird connection URI to os.path.sep,
i.e., '\' on Windows, since Firebird doesn't handle /'s appropriately
on that platform.
Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2004-05-25 1=
5:11:52 UTC (rev 106)
+++ trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2004-05-26 1=
1:51:52 UTC (rev 107)
@@ -1,6 +1,7 @@
from sqlobject.dbconnection import DBAPI
kinterbasdb =3D None
import re
+import os
=20
class FirebirdConnection(DBAPI):
=20
@@ -33,6 +34,7 @@
password =3D 'masterkey'
if not auth:
auth=3D'sysdba'
+ path =3D path.replace('/', os.path.sep)
return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **ar=
gs)
connectionFromURI =3D classmethod(connectionFromURI)
=20
|
|
From: <sub...@co...> - 2004-05-25 19:12:36
|
Author: iansparks
Date: 2004-05-25 11:11:52 -0400 (Tue, 25 May 2004)
New Revision: 106
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Added support for firebird for Datetime and Date columns.
Improved firebird support for enum columns.
Modified: trunk/SQLObject/sqlobject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/col.py 2004-04-25 18:02:09 UTC (rev 105)
+++ trunk/SQLObject/sqlobject/col.py 2004-05-25 15:11:52 UTC (rev 106)
@@ -221,8 +221,8 @@
# them differently for Enum columns.
if not isinstance(self, SOEnumCol):
return ' '.join([self.dbName, self._firebirdType()] + self._=
extraSQL())
- else:
- return ' '.join([self.dbName] + self._extraSQL() + [self._fi=
rebirdType()])
+ else:
+ return ' '.join([self.dbName] + [self._firebirdType()[0]] + =
self._extraSQL() + [self._firebirdType()[1]])
=20
def __get__(self, obj, type=3DNone):
if obj is None:
@@ -472,7 +472,11 @@
return self._postgresType()
=20
def _firebirdType(self):
- return self._postgresType()
+ length =3D max(map(len, self.enumValues))
+ enumValues =3D ', '.join([sqlbuilder.sqlrepr(v, 'firebird') for =
v in self.enumValues])
+ checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
+ #NB. Return a tuple, not a string here
+ return "VARCHAR(%i)" % (length), checkConstraint
=20
class EnumCol(Col):
baseClass =3D SOEnumCol
@@ -493,7 +497,10 @@
=20
def _sqliteType(self):
return 'TIMESTAMP'
-
+
+ def _firebirdType(self):
+ return 'TIMESTAMP'
+
class DateTimeCol(Col):
baseClass =3D SODateTimeCol
=20
@@ -510,6 +517,9 @@
=20
def _sybaseType(self):
return self._postgresType()
+
+ def _firebirdType(self):
+ return 'DATE'
=20
class DateCol(Col):
baseClass =3D SODateCol
|
|
From: <sub...@co...> - 2004-04-25 22:00:09
|
Author: sweafty
Date: 2004-04-25 14:02:09 -0400 (Sun, 25 Apr 2004)
New Revision: 105
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Adding SQLite DateTime type support
Modified: trunk/SQLObject/sqlobject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/col.py 2004-04-23 18:04:25 UTC (rev 104)
+++ trunk/SQLObject/sqlobject/col.py 2004-04-25 18:02:09 UTC (rev 105)
@@ -491,6 +491,9 @@
def _sybaseType(self):
return 'DATETIME'
=20
+ def _sqliteType(self):
+ return 'TIMESTAMP'
+
class DateTimeCol(Col):
baseClass =3D SODateTimeCol
=20
|
|
From: <sub...@co...> - 2004-04-23 22:02:09
|
Author: ianb
Date: 2004-04-23 14:04:25 -0400 (Fri, 23 Apr 2004)
New Revision: 104
Modified:
trunk/SQLObject/sqlobject/main.py
trunk/SQLObject/tests/test.py
Log:
Fixed bug related to orderBy=3D'-column_name'
Modified: trunk/SQLObject/sqlobject/main.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/main.py 2004-04-14 16:38:33 UTC (rev 103)
+++ trunk/SQLObject/sqlobject/main.py 2004-04-23 18:04:25 UTC (rev 104)
@@ -1095,6 +1095,7 @@
orderBy =3D map(self._mungeOrderBy, orderBy)
else:
orderBy =3D self._mungeOrderBy(orderBy)
+ print "OUT: %r; in: %r" % (sourceClass.sqlrepr(orderBy), sourceC=
lass.sqlrepr(self.ops['orderBy']))
self.ops['dbOrderBy'] =3D orderBy
if ops.has_key('connection') and ops['connection'] is None:
del ops['connection']
@@ -1105,17 +1106,20 @@
desc =3D True
else:
desc =3D False
- if self.sourceClass._SO_columnDict.has_key(orderBy):
- val =3D self.sourceClass._SO_columnDict[orderBy].dbName
- if desc:
- return '-' + val
+ if isinstance(orderBy, (str, unicode)):
+ if self.sourceClass._SO_columnDict.has_key(orderBy):
+ val =3D self.sourceClass._SO_columnDict[orderBy].dbName
+ if desc:
+ return '-' + val
+ else:
+ return val
else:
- return val
+ if desc:
+ return '-' + orderBy
+ else:
+ return orderBy
else:
- if desc:
- return sqlbuilder.DESC(orderBy)
- else:
- return orderBy
+ return orderBy
=20
def clone(self, **newOps):
ops =3D self.ops.copy()
Modified: trunk/SQLObject/tests/test.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/tests/test.py 2004-04-14 16:38:33 UTC (rev 103)
+++ trunk/SQLObject/tests/test.py 2004-04-23 18:04:25 UTC (rev 104)
@@ -259,33 +259,56 @@
=20
_table =3D 'names_table'
=20
- fname =3D StringCol(length=3D30)
- lname =3D StringCol(length=3D30)
+ firstName =3D StringCol(length=3D30)
+ lastName =3D StringCol(length=3D30)
=20
- _defaultOrder =3D ['lname', 'fname']
+ _defaultOrder =3D ['lastName', 'firstName']
=20
class NamesTest(SQLObjectTest):
=20
classes =3D [Names]
=20
def inserts(self):
- for fname, lname in [('aj', 'baker'), ('joe', 'robbins'),
- ('tim', 'jackson'), ('joe', 'baker'),
- ('zoe', 'robbins')]:
- Names(fname=3Dfname, lname=3Dlname)
+ for firstName, lastName in [('aj', 'baker'), ('joe', 'robbins'),
+ ('tim', 'jackson'), ('joe', 'baker')=
,
+ ('zoe', 'robbins')]:
+ Names(firstName=3DfirstName, lastName=3DlastName)
=20
def testDefaultOrder(self):
- self.assertEqual([(n.fname, n.lname) for n in Names.select()],
+ self.assertEqual([(n.firstName, n.lastName) for n in Names.selec=
t()],
[('aj', 'baker'), ('joe', 'baker'),
('tim', 'jackson'), ('joe', 'robbins'),
('zoe', 'robbins')])
=20
def testOtherOrder(self):
- self.assertEqual([(n.fname, n.lname) for n in Names.select().ord=
erBy(['fname', 'lname'])],
+ self.assertEqual([(n.firstName, n.lastName) for n in Names.selec=
t().orderBy(['firstName', 'lastName'])],
[('aj', 'baker'), ('joe', 'baker'),
('joe', 'robbins'), ('tim', 'jackson'),
('zoe', 'robbins')])
=20
+ def testUntranslatedColumnOrder(self):
+ self.assertEqual([(n.firstName, n.lastName) for n in Names.selec=
t().orderBy(['first_name', 'last_name'])],
+ [('aj', 'baker'), ('joe', 'baker'),
+ ('joe', 'robbins'), ('tim', 'jackson'),
+ ('zoe', 'robbins')])
+
+ def testSingleUntranslatedColumnOrder(self):
+ self.assertEqual([n.firstName for n in
+ Names.select().orderBy('firstName')],
+ ['aj', 'joe', 'joe', 'tim', 'zoe'])
+ self.assertEqual([n.firstName for n in
+ Names.select().orderBy('first_name')],
+ ['aj', 'joe', 'joe', 'tim', 'zoe'])
+ self.assertEqual([n.firstName for n in
+ Names.select().orderBy('-firstName')],
+ ['zoe', 'tim', 'joe', 'joe', 'aj'])
+ self.assertEqual([n.firstName for n in
+ Names.select().orderBy('-first_name')],
+ ['zoe', 'tim', 'joe', 'joe', 'aj'])
+ self.assertEqual([n.firstName for n in
+ Names.select().orderBy(Names.q.firstName)],
+ ['aj', 'joe', 'joe', 'tim', 'zoe'])
+
########################################
## Select results
########################################
|
|
From: <sub...@co...> - 2004-04-14 20:35:22
|
Author: sweafty
Date: 2004-04-14 12:38:33 -0400 (Wed, 14 Apr 2004)
New Revision: 103
Modified:
trunk/SQLObject/sqlobject/dbconnection.py
trunk/SQLObject/sqlobject/main.py
trunk/SQLObject/tests/test.py
Log:
Accumulate functions in SelectResults: sum(), count()
Modified: trunk/SQLObject/sqlobject/dbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/dbconnection.py 2004-04-05 02:41:54 UTC (re=
v 102)
+++ trunk/SQLObject/sqlobject/dbconnection.py 2004-04-14 16:38:33 UTC (re=
v 103)
@@ -236,9 +236,14 @@
return Iteration(self, self.getConnection(),
select, keepConnection=3DFalse)
=20
- def countSelect(self, select):
- q =3D "SELECT COUNT(*) FROM %s WHERE" % \
- ", ".join(select.tables)
+ def accumulateSelect(self, select, expression):
+ """ Apply an accumulate function (like SUM, COUNT, ..)
+ to the select object.
+ Return the value resulting from the SQL accumulate function
+ as an integer.
+ """
+ q =3D "SELECT %s" % expression
+ q +=3D " FROM %s WHERE" % ", ".join(select.tables)
q =3D self._addWhereClause(select, q, limit=3D0, order=3D0)
val =3D int(self.queryOne(q)[0])
return val
Modified: trunk/SQLObject/sqlobject/main.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/main.py 2004-04-05 02:41:54 UTC (rev 102)
+++ trunk/SQLObject/sqlobject/main.py 2004-04-14 16:38:33 UTC (rev 103)
@@ -1191,15 +1191,35 @@
conn =3D self.ops.get('connection', self.sourceClass._connection=
)
return conn.iterSelect(self)
=20
+ def accumulate(self, expression):
+ """ Use an accumulate expression to select result
+ using another SQL select through current
+ connection.
+ Return the accumulate result
+ """
+ conn =3D self.ops.get('connection', self.sourceClass._connection=
)
+ return conn.accumulateSelect(self,expression)
+
def count(self):
- conn =3D self.ops.get('connection', self.sourceClass._connection=
)
- count =3D conn.countSelect(self)
+ """ Counting elements of current select results """
+ count =3D self.accumulate('COUNT(*)')
if self.ops.get('start'):
count -=3D self.ops['start']
if self.ops.get('end'):
count =3D min(self.ops['end'] - self.ops.get('start', 0), co=
unt)
return count
=20
+ def sum(self, attribute):
+ """ Making the sum of a given select result attribute.
+ `attribute` can be a column name (like 'a_column')
+ or a dot-q attribute (like Table.q.aColumn)
+ """
+ if type(attribute) =3D=3D type(''):
+ expression =3D 'SUM(%s)' % attribute
+ else:
+ expression =3D sqlbuilder.func.SUM(attribute)
+ return self.accumulate(expression)
+
class SQLObjectState(object):
=20
def __init__(self, soObject):
Modified: trunk/SQLObject/tests/test.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/tests/test.py 2004-04-05 02:41:54 UTC (rev 102)
+++ trunk/SQLObject/tests/test.py 2004-04-14 16:38:33 UTC (rev 103)
@@ -499,6 +499,17 @@
def counterEqual(self, counters, value):
self.assertEquals([(c.n1, c.n2) for c in counters], value)
=20
+ def accumulateEqual(self, func, counters, value):
+ self.assertEqual(func([ c.n1 for c in counters]), value)
+
+ def test1(self):
+ self.accumulateEqual(sum,Counter2.select('n1', orderBy=3D'n1'),
+ sum(range(10)) * 10)
+
+ def test2(self):
+ self.accumulateEqual(len,Counter2.select('all'), 100)
+
+ =20
########################################
## Dynamic column tests
########################################
|
|
From: <sub...@co...> - 2004-03-31 06:50:28
|
Author: ianb
Date: 2004-03-30 21:55:04 -0500 (Tue, 30 Mar 2004)
New Revision: 84
Modified:
trunk/SQLObject/sqlobject/dbconnection.py
trunk/SQLObject/sqlobject/dbm/dbmconnection.py
trunk/SQLObject/sqlobject/firebird/firebirdconnection.py
trunk/SQLObject/sqlobject/mysql/mysqlconnection.py
trunk/SQLObject/sqlobject/postgres/pgconnection.py
trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py
trunk/SQLObject/sqlobject/sybase/sybaseconnection.py
Log:
* Fixed threading issue with Iterator, to match fix in 0.5
(connections were being released multiple times)
* Expanded URIs to allow keyword (GET) arguments
* Put in (optionally) more thorough debugging output
Modified: trunk/SQLObject/sqlobject/dbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/dbconnection.py 2004-03-31 02:48:02 UTC (re=
v 83)
+++ trunk/SQLObject/sqlobject/dbconnection.py 2004-03-31 02:55:04 UTC (re=
v 84)
@@ -13,6 +13,7 @@
import col
from joins import sorter
from converters import sqlrepr
+import urllib
=20
warnings.filterwarnings("ignore", "DB-API extension cursor.lastrowid use=
d")
=20
@@ -21,10 +22,12 @@
class DBConnection:
=20
def __init__(self, name=3DNone, debug=3DFalse, debugOutput=3DFalse,
- cache=3DTrue, style=3DNone, autoCommit=3DTrue):
+ cache=3DTrue, style=3DNone, autoCommit=3DTrue,
+ debugThreading=3DFalse):
self.name =3D name
self.debug =3D debug
self.debugOutput =3D debugOutput
+ self.debugThreading =3D debugThreading
self.cache =3D CacheSet(cache=3Dcache)
self.doCache =3D cache
self.style =3D style
@@ -81,7 +84,15 @@
else:
user =3D password =3D None
path =3D '/' + rest
- return user, password, host, path
+ args =3D {}
+ if path.find('?') !=3D -1:
+ path, arglist =3D path.split('?', 1)
+ arglist =3D arglist.split('&')
+ for single in arglist:
+ argname, argvalue =3D single.split('=3D', 1)
+ argvalue =3D urllib.unquote(argvalue)
+ args[argname] =3D argvalue
+ return user, password, host, path, args
_parseURI =3D staticmethod(_parseURI)
=20
class DBAPI(DBConnection):
@@ -117,11 +128,26 @@
self._connectionNumbers[id(newConn)] =3D self._connectio=
nCount
self._connectionCount +=3D 1
val =3D self._pool.pop()
+ if self.debug:
+ s =3D 'ACQUIRE'
+ if self._pool is not None:
+ s +=3D ' pool=3D[%s]' % ', '.join([str(self._connect=
ionNumbers[id(v)]) for v in self._pool])
+ self.printDebug(val, s, 'Pool')
return val
finally:
self._poolLock.release()
=20
def releaseConnection(self, conn, explicit=3DFalse):
+ if self.debug:
+ if explicit:
+ s =3D 'RELEASE (explicit)'
+ else:
+ s =3D 'RELEASE (implicit, autocommit=3D%s)' % self.autoC=
ommit
+ if self._pool is None:
+ s +=3D ' no pooling'
+ else:
+ s +=3D ' pool=3D[%s]' % ', '.join([str(self._connectionN=
umbers[id(v)]) for v in self._pool])
+ self.printDebug(conn, s, 'Pool')
if self.supportTransactions:
if self.autoCommit =3D=3D 'exception':
if self.debug:
@@ -137,7 +163,11 @@
self.printDebug(conn, 'auto', 'ROLLBACK')
conn.rollback()
if self._pool is not None:
- self._pool.append(conn)
+ if conn not in self._pool:
+ # @@: We can get duplicate releasing of connections with
+ # the __del__ in Iteration (unfortunately, not sure why
+ # it happens)
+ self._pool.append(conn)
=20
def printDebug(self, conn, s, name, type=3D'query'):
if type =3D=3D 'query':
@@ -147,12 +177,20 @@
s =3D repr(s)
n =3D self._connectionNumbers[id(conn)]
spaces =3D ' '*(8-len(name))
- print '%(n)2i/%(name)s%(spaces)s%(sep)s %(s)s' % locals()
+ if self.debugThreading:
+ threadName =3D threading.currentThread().getName()
+ threadName =3D (':' + threadName + ' '*(8-len(threadName)))
+ else:
+ threadName =3D ''
+ print '%(n)2i%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' % l=
ocals()
=20
+ def _executeRetry(self, conn, cursor, query):
+ return cursor.execute(query)
+
def _query(self, conn, s):
if self.debug:
self.printDebug(conn, s, 'Query')
- conn.cursor().execute(s)
+ self._executeRetry(conn, conn.cursor(), s)
=20
def query(self, s):
return self._runWithConnection(self._query, s)
@@ -161,7 +199,7 @@
if self.debug:
self.printDebug(conn, s, 'QueryAll')
c =3D conn.cursor()
- c.execute(s)
+ self._executeRetry(conn, c, s)
value =3D c.fetchall()
if self.debugOutput:
self.printDebug(conn, value, 'QueryAll', 'result')
@@ -174,7 +212,7 @@
if self.debug:
self.printDebug(conn, s, 'QueryOne')
c =3D conn.cursor()
- c.execute(s)
+ self._executeRetry(conn, c, s)
value =3D c.fetchone()
if self.debugOutput:
self.printDebug(conn, value, 'QueryOne', 'result')
@@ -390,13 +428,12 @@
self.query =3D self.dbconn.queryForSelect(select)
if dbconn.debug:
dbconn.printDebug(rawconn, self.query, 'Select')
- self.cursor.execute(self.query)
+ self.dbconn._executeRetry(self.rawconn, self.cursor, self.query)
=20
def next(self):
result =3D self.cursor.fetchone()
if result is None:
- if not self.keepConnection:
- self.dbconn.releaseConnection(self.rawconn)
+ self._cleanup()
raise StopIteration
if self.select.ops.get('lazyColumns', 0):
obj =3D self.select.sourceClass.get(result[0], connection=3D=
self.dbconn)
@@ -405,11 +442,20 @@
obj =3D self.select.sourceClass.get(result[0], selectResults=
=3Dresult[1:], connection=3Dself.dbconn)
return obj
=20
- def __del__(self):
+ def _cleanup(self):
+ if self.query is None:
+ # already cleaned up
+ return
+ self.query =3D None
if not self.keepConnection:
self.dbconn.releaseConnection(self.rawconn)
+ self.dbconn =3D self.rawconn =3D self.select =3D self.cursor =3D=
None
=20
+ def __del__(self):
+ self._cleanup()
+ =20
=20
+
class Transaction(object):
=20
def __init__(self, dbConnection):
@@ -441,8 +487,13 @@
=20
def iterSelect(self, select):
self.assertActive()
- return Iteration(self, self._connection,
- select, keepConnection=3DTrue)
+ # We can't keep the cursor open with results in a transaction,
+ # because we might want to use the connection while we're
+ # still iterating through the results.
+ # @@: But would it be okay for psycopg, with threadsafety
+ # level 2?
+ return list(Iteration(self, self._connection,
+ select, keepConnection=3DTrue))
=20
def commit(self):
if self._obsolete:
Modified: trunk/SQLObject/sqlobject/dbm/dbmconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/dbm/dbmconnection.py 2004-03-31 02:48:02 UT=
C (rev 83)
+++ trunk/SQLObject/sqlobject/dbm/dbmconnection.py 2004-03-31 02:55:04 UT=
C (rev 84)
@@ -127,12 +127,12 @@
FileConnection.__init__(self, **kw)
=20
def connectionFromURI(cls, uri):
- user, password, host, path =3D self._parseURI(uri, expectHost=3D=
False)
+ user, password, host, path, args =3D self._parseURI(uri, expectH=
ost=3DFalse)
assert host is None
assert user is None and password is None, \
- "SQLite cannot accept usernames or passwords"
+ "DBM cannot accept usernames or passwords"
path =3D '/' + path
- return cls(path)
+ return cls(path, **args)
connectionFromURI =3D classmethod(connectionFromURI)
=20
def _newID(self, table):
Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2004-03-31 0=
2:48:02 UTC (rev 83)
+++ trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2004-03-31 0=
2:55:04 UTC (rev 84)
@@ -28,12 +28,12 @@
DBAPI.__init__(self, **kw)
=20
def connectionFromURI(cls, uri):
- auth, password, host, path =3D cls._parseURI(uri)
+ auth, password, host, path, args =3D cls._parseURI(uri)
if not password:
password =3D 'masterkey'
if not auth:
auth=3D'sysdba'
- return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword)
+ return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **ar=
gs)
connectionFromURI =3D classmethod(connectionFromURI)
=20
def _runWithConnection(self, meth, *args):
Modified: trunk/SQLObject/sqlobject/mysql/mysqlconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/mysql/mysqlconnection.py 2004-03-31 02:48:0=
2 UTC (rev 83)
+++ trunk/SQLObject/sqlobject/mysql/mysqlconnection.py 2004-03-31 02:55:0=
4 UTC (rev 84)
@@ -19,15 +19,27 @@
DBAPI.__init__(self, **kw)
=20
def connectionFromURI(cls, uri):
- user, password, host, path =3D cls._parseURI(uri)
+ user, password, host, path, args =3D cls._parseURI(uri)
return cls(db=3Dpath.strip('/'), user=3Duser or '', passwd=3Dpas=
sword or '',
- host=3Dhost or 'localhost')
+ host=3Dhost or 'localhost', **args)
connectionFromURI =3D classmethod(connectionFromURI)
=20
def makeConnection(self):
return MySQLdb.connect(host=3Dself.host, db=3Dself.db,
user=3Dself.user, passwd=3Dself.passwd)
=20
+ def _executeRetry(self, conn, cursor, query):
+ while 1:
+ try:
+ return cursor.execute(query)
+ except MySQLdb.OperationalError, e:
+ if e.args[0] =3D=3D 2013:
+ # This is a=20
+ if self.debug:
+ self.printDebug(conn, str(e), 'ERROR')
+ else:
+ raise
+
def _queryInsertID(self, conn, table, idName, id, names, values):
c =3D conn.cursor()
if id is not None:
@@ -36,7 +48,7 @@
q =3D self._insertSQL(table, names, values)
if self.debug:
self.printDebug(conn, q, 'QueryIns')
- c.execute(q)
+ self._executeRetry(conn, c, q)
if id is None:
id =3D c.insert_id()
if self.debugOutput:
Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/postgres/pgconnection.py 2004-03-31 02:48:0=
2 UTC (rev 83)
+++ trunk/SQLObject/sqlobject/postgres/pgconnection.py 2004-03-31 02:55:0=
4 UTC (rev 84)
@@ -42,16 +42,15 @@
DBAPI.__init__(self, **kw)
=20
def connectionFromURI(cls, uri):
- user, password, host, path =3D cls._parseURI(uri)
+ user, password, host, path, args =3D cls._parseURI(uri)
path =3D path.strip('/')
- return cls(host=3Dhost, db=3Dpath, user=3Duser, passwd=3Dpasswor=
d)
+ return cls(host=3Dhost, db=3Dpath, user=3Duser, passwd=3Dpasswor=
d, **args)
connectionFromURI =3D classmethod(connectionFromURI)
=20
def _setAutoCommit(self, conn, auto):
conn.autocommit(auto)
=20
def makeConnection(self):
- print 'DSN', self.dsn
conn =3D self.pgmodule.connect(self.dsn)
if self.autoCommit:
conn.autocommit(1)
Modified: trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py 2004-03-31 02:48=
:02 UTC (rev 83)
+++ trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py 2004-03-31 02:55=
:04 UTC (rev 84)
@@ -21,10 +21,10 @@
DBAPI.__init__(self, **kw)
=20
def connectionFromURI(cls, uri):
- user, password, host, path =3D cls._parseURI(uri)
+ user, password, host, path, args =3D cls._parseURI(uri)
assert host is None, "SQLite can only be used locally (with a UR=
I like sqlite:///file or sql:/file, not %r)" % uri
assert user is None and password is None, "You may not provide u=
sernames or passwords for SQLite databases"
- return cls(filename=3D'/' + path)
+ return cls(filename=3D'/' + path, **args)
connectionFromURI =3D classmethod(connectionFromURI)
=20
def _setAutoCommit(self, conn, auto):
Modified: trunk/SQLObject/sqlobject/sybase/sybaseconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/sybase/sybaseconnection.py 2004-03-31 02:48=
:02 UTC (rev 83)
+++ trunk/SQLObject/sqlobject/sybase/sybaseconnection.py 2004-03-31 02:55=
:04 UTC (rev 84)
@@ -26,9 +26,9 @@
DBAPI.__init__(self, **kw)
=20
def connectionFromURI(cls, uri):
- user, password, host, path =3D cls._parseURI(uri)
+ user, password, host, path, args =3D cls._parseURI(uri)
return cls(user=3Duser, passwd=3Dpassword, host=3Dhost or 'local=
host',
- db=3Dpath)
+ db=3Dpath, **args)
connectionFromURI =3D classmethod(connectionFromURI)
=20
def insert_id(self, conn):
|
|
From: <sub...@co...> - 2004-03-31 06:43:27
|
Author: ianb
Date: 2004-03-30 21:48:02 -0500 (Tue, 30 Mar 2004)
New Revision: 83
Modified:
branches/SQLObject/0.5/SQLObject/DBConnection.py
Log:
Fixed another (blech) threading issue with iterators, where a=20
connection could be returned to the pool multiple times, and then
be fetched from the pool by different threads.
Modified: branches/SQLObject/0.5/SQLObject/DBConnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/SQLObject/0.5/SQLObject/DBConnection.py 2004-03-31 02:47:19 =
UTC (rev 82)
+++ branches/SQLObject/0.5/SQLObject/DBConnection.py 2004-03-31 02:48:02 =
UTC (rev 83)
@@ -105,7 +105,11 @@
self.printDebug(conn, 'auto', 'ROLLBACK')
conn.rollback()
if self._pool is not None:
- self._pool.append(conn)
+ if conn not in self._pool:
+ # @@: We can get duplicate releasing of connections with
+ # the __del__ in Iteration (unfortunately, not sure why
+ # it happens)
+ self._pool.append(conn)
=20
def printDebug(self, conn, s, name, type=3D'query'):
if type =3D=3D 'query':
@@ -363,8 +367,7 @@
def next(self):
result =3D self.cursor.fetchone()
if result is None:
- if not self.keepConnection:
- self.dbconn.releaseConnection(self.rawconn)
+ self._cleanup()
raise StopIteration
if self.select.ops.get('lazyColumns', 0):
obj =3D self.select.sourceClass(result[0], connection=3Dself=
.dbconn)
@@ -373,10 +376,18 @@
obj =3D self.select.sourceClass(result[0], selectResults=3Dr=
esult[1:], connection=3Dself.dbconn)
return obj
=20
- def __del__(self):
+ def _cleanup(self):
+ if self.query is None:
+ # already cleaned up
+ return
+ self.query =3D None
if not self.keepConnection:
self.dbconn.releaseConnection(self.rawconn)
+ self.dbconn =3D self.rawconn =3D self.select =3D self.cursor =3D=
None
=20
+ def __del__(self):
+ self._cleanup()
+
class Transaction(object):
=20
def __init__(self, dbConnection):
|
|
From: <sub...@co...> - 2004-03-31 06:42:44
|
Author: ianb Date: 2004-03-30 21:47:19 -0500 (Tue, 30 Mar 2004) New Revision: 82 Modified: branches/SQLObject/0.5/release Log: Simplified Modified: branches/SQLObject/0.5/release =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/SQLObject/0.5/release 2004-03-27 19:44:31 UTC (rev 81) +++ branches/SQLObject/0.5/release 2004-03-31 02:47:19 UTC (rev 82) @@ -1,14 +1,14 @@ #!/bin/sh =20 -echo 'Installing...' -sudo python ./setup.py install -echo 'installation done.' +#echo 'Installing...' +#sudo python ./setup.py install +#echo 'installation done.' =20 -pushd tests > /dev/null -echo 'Testing...' -python ./test.py -echo 'testing done.' -popd +#pushd tests > /dev/null +#echo 'Testing...' +#python ./test.py +#echo 'testing done.' +#popd =20 echo 'Building...' python ./setup.py sdist |
|
From: <sub...@co...> - 2004-03-18 07:48:31
|
Author: ianb
Date: 2004-03-17 22:54:19 -0500 (Wed, 17 Mar 2004)
New Revision: 69
Removed:
trunk/FormEncode/experimental/FormEncodeKit/Examples/address.py
Log:
removed dup file
Deleted: trunk/FormEncode/experimental/FormEncodeKit/Examples/address.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/FormEncode/experimental/FormEncodeKit/Examples/address.py 2004-=
03-18 03:49:45 UTC (rev 68)
+++ trunk/FormEncode/experimental/FormEncodeKit/Examples/address.py 2004-=
03-18 03:54:19 UTC (rev 69)
@@ -1,61 +0,0 @@
-from Component.CPage import CPage
-
-from formencode import validators, htmlview, schema
-from formencode.FormComponent import FormComponent
-
-class Address(CPage):
-
- components =3D [FormComponent()]
-
- class schema(schema.Schema):
-
- firstName =3D validators.String(notEmpty=3DTrue, htmlview=3Dhtml=
view.Text)
- lastName =3D validators.String(notEmpty=3DTrue, htmlview=3Dhtmlv=
iew.Text)
-
- class phone(schema.Schema):
- repeating =3D 1
- number =3D validators.PhoneNumber(ifEmpty=3DNone, htmlview=3D=
htmlview.Text)
- type =3D validators.OneOf(['home', 'work'],
- htmlview=3Dhtmlview.Select(selections=
=3D[('home', 'home'), ('work', 'work')]))
-
- repeats =3D validators.Int(htmlview=3Dhtmlview.Hidden)
-
- submit =3D validators.String(htmlview=3Dhtmlview.SubmitButton(de=
scription=3D''))
-
- def cleanup(cls, value):
- value =3D value.copy()
- value['phone'] =3D [p for p in value['phone'] if p['number']=
is not None]
- return value
- cleanup =3D classmethod(cleanup)
-
- def render(cls, value):
- s =3D 'Name: %s %s<br>\n' % (value.get('firstName'),
- value.get('lastName'))
- if value.get('phone', []):
- s +=3D '<ul>\n'
- for p in value.get('phone'):
- s +=3D '<li>%s: %s\n' % (p['type'], p['number'])
- s +=3D '</ul>\n'
- return s
- render =3D classmethod(render)
-
- def optionsAddRep(cls, value, add=3D1):
- value['repeats'] =3D len(value.get('phone', [])) + add
- return {'phone': {'repetitions': value['repeats']}}
- optionsAddRep =3D classmethod(optionsAddRep)
-
- def writeContent(self):
- ses =3D self.session()
-
- valid, address =3D self.processForm()
- if valid:
- address =3D self.schema.cleanup(address)
- ses.setValue('address', address)
- else:
- address =3D ses.value('address', {})
- self.write('<h1>Address:</h1>\n')
- self.write(self.schema.render(address))
- self.write('<hr noshade>\n')
- options =3D self.schema.optionsAddRep(address)
- self.writeForm(defaults=3Daddress, options=3Doptions)
-
|
|
From: <sub...@co...> - 2004-03-18 07:44:01
|
Author: ianb Date: 2004-03-17 22:49:45 -0500 (Wed, 17 Mar 2004) New Revision: 68 Modified: trunk/FormEncode/experimental/FormEncodeKit/ trunk/FormEncode/experimental/FormEncodeKit/Examples/ Log: Added svn:ignore's Property changes on: trunk/FormEncode/experimental/FormEncodeKit ___________________________________________________________________ Name: svn:ignore + *.pyc Property changes on: trunk/FormEncode/experimental/FormEncodeKit/Examples ___________________________________________________________________ Name: svn:ignore + *.pyc |
|
From: <ian...@us...> - 2004-03-09 07:10:09
|
Update of /cvsroot/sqlobject/SQLObject In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1083 Added Files: DO_NOT_USE_CVS Log Message: Added note about not using CVS --- NEW FILE: DO_NOT_USE_CVS --- Do not use this CVS repository! This CVS repository is defunct! Use the Subversion repository: svn://colorstudy.com/trunk/SQLObject svn://colorstudy.com/branches/SQLObject |
|
From: <bbo...@us...> - 2004-02-11 16:29:54
|
Update of /cvsroot/sqlobject/SQLObject/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20327/tests Modified Files: SQLObjectTest.py test.py Log Message: I wrote a unit test to show that, when using a transaction to create a new object, its ForeignKey objects were not using that same connection (which they should have.) Daniel Savard implemented the fix in SQLObject. I'm also deliberately checking in a broken test that demonstrates how we want instance validation to work (confirmed with Ian), in the hopes that a broken test will annoy someone enough to go in and implement in lieu of me/us having the time to do so. :) Index: SQLObjectTest.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/tests/SQLObjectTest.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** SQLObjectTest.py 4 Dec 2003 16:46:31 -0000 1.21 --- SQLObjectTest.py 11 Feb 2004 16:25:40 -0000 1.22 *************** *** 1,6 **** import unittest from SQLObject import * ! True, False = 1==1, 0==1 def mysqlConnection(): --- 1,8 ---- import unittest + from SQLObject import * ! True = (1 == 1) ! False = (0 == 1) def mysqlConnection(): Index: test.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** test.py 21 Jan 2004 22:21:33 -0000 1.38 --- test.py 11 Feb 2004 16:25:40 -0000 1.39 *************** *** 10,13 **** --- 10,14 ---- import sys + sys.path.insert(0, "..") if '--coverage' in sys.argv: import coverage *************** *** 369,395 **** ######################################## ! class TestSOTrans(SQLObject): ! #_cacheValues = False ! name = StringCol(length=10, alternateID=True, dbName='name_col') _defaultOrderBy = 'name' class TransactionTest(SQLObjectTest): ! classes = [TestSOTrans] def inserts(self): ! TestSOTrans.new(name='bob') ! TestSOTrans.new(name='tim') def testTransaction(self): ! if not self.supportTransactions: return ! trans = TestSOTrans._connection.transaction() try: ! TestSOTrans._connection.autoCommit = 'exception' ! TestSOTrans.new(name='joe', connection=trans) trans.rollback() ! self.assertEqual([n.name for n in TestSOTrans.select(connection=trans)], ! ['bob', 'tim']) ! b = TestSOTrans.byName('bob', connection=trans) b.name = 'robert' trans.commit() --- 370,402 ---- ######################################## ! class Man(SQLObject): ! name = StringCol(length = 10, alternateID = True) ! ! class Dog(SQLObject): _defaultOrderBy = 'name' + name = StringCol(length = 10, alternateID = True, dbName = 'name_col') + ownerID = ForeignKey('Man', notNone = True) class TransactionTest(SQLObjectTest): ! classes = [Man, Dog] def inserts(self): ! bob = Man.new(name = 'bob') ! Dog.new(name = 'fido', ownerID = bob.id) ! Dog.new(name = 'ralph', ownerID = bob.id) def testTransaction(self): ! if not self.supportTransactions: ! return ! ! trans = Man._connection.transaction() try: ! Man._connection.autoCommit = 'exception' ! Man.new(name = 'joe', connection = trans) trans.rollback() ! self.assertEqual([n.name for n in Man.select(connection = trans)], ['bob']) ! ! b = Man.byName('bob', connection = trans) b.name = 'robert' trans.commit() *************** *** 399,403 **** self.assertEqual(b.name, 'robert') finally: ! TestSOTrans._connection.autoCommit = True --- 406,427 ---- self.assertEqual(b.name, 'robert') finally: ! Man._connection.autoCommit = True ! Dog._connection.autoCommit = True ! ! def testForeignKeyObjConnectionWithinTransaction(self): ! if not self.supportTransactions: ! return ! ! trans = Man._connection.transaction() ! try: ! jim = Man.new(name = 'jim') ! jims_id = jim.id ! del jim ! benji = Dog.new(name = 'benji', ownerID = jims_id, connection = trans) ! self.assertEqual(benji._connection, trans) ! self.assertEqual(benji._connection, benji.owner._connection) ! finally: ! Man._connection.autoCommit = True ! Dog._connection.autoCommit = True *************** *** 782,790 **** --- 806,834 ---- ######################################## + class Age2GreaterThanAge1(Validator.FancyValidator): + def validatePython(self, values, state): + cur_obj = state.soObject + if values.has_key('age1'): + age1 = int(values['age1']) + else: + age1 = cur_obj.age1 + + if values.has_key('age2'): + age2 = int(values['age2']) + else: + age2 = cur_obj.age2 + + if not (age2 > age1): + raise Validator.InvalidField( + self.message('badAges', 'Age 2 must be greater than age1'), value, state) + class SOValidation(SQLObject): + _validator = Age2GreaterThanAge1() name = StringCol(validator=Validator.PlainText(), default='x', dbName='name_col') name2 = StringCol(validator=Validator.ConfirmType(str), default='y') name3 = IntCol(validator=Validator.Wrapper(fromPython=int), default=100) + age1 = IntCol(notNone = True, default = 1) + age2 = IntCol(notNone = True, default = 2) class ValidationTest(SQLObjectTest): *************** *** 815,818 **** --- 859,868 ---- self.assertEqual(t.name3, 0) + def testInstanceValidation(self): + obj = SOValidation.new(age1 = 5, age2 = 18) + self.assertRaises(Validator.InvalidField, setattr, obj, 'age2', 4) + self.assertRaises(Validator.InvalidField, obj.set, age1 = 20, age2 = 19) + self.assertRaises(Validator.InvalidField, SOValidation.new, age1 = 7, age2 = 3) + ######################################## |
|
From: <bbo...@us...> - 2004-02-11 16:29:54
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20327/SQLObject Modified Files: SQLObject.py Log Message: I wrote a unit test to show that, when using a transaction to create a new object, its ForeignKey objects were not using that same connection (which they should have.) Daniel Savard implemented the fix in SQLObject. I'm also deliberately checking in a broken test that demonstrates how we want instance validation to work (confirmed with Ian), in the hopes that a broken test will annoy someone enough to go in and implement in lieu of me/us having the time to do so. :) Index: SQLObject.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** SQLObject.py 4 Dec 2003 16:46:31 -0000 1.66 --- SQLObject.py 11 Feb 2004 16:25:38 -0000 1.67 *************** *** 838,843 **** # Passing None for the ID tells __new__ we want to create # a new object. if kw.has_key('connection'): ! inst = cls(CreateNewSQLObject, connection=kw['connection']) del kw['connection'] else: --- 838,845 ---- # Passing None for the ID tells __new__ we want to create # a new object. + connection = None if kw.has_key('connection'): ! connection = kw['connection'] ! inst = cls(CreateNewSQLObject, connection=connection) del kw['connection'] else: *************** *** 895,903 **** # 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 --- 897,905 ---- # Then we finalize the process: ! inst._SO_finishCreate(id, connection=connection) return inst new = classmethod(new) ! def _SO_finishCreate(self, id=None, connection=None): # Here's where an INSERT is finalized. # These are all the column values that were supposed *************** *** 920,924 **** cache = self._connection.cache cache.created(id, self.__class__, self) ! self._init(id) def _SO_getID(self, obj): --- 922,926 ---- cache = self._connection.cache cache.created(id, self.__class__, self) ! self._init(id, connection=connection) def _SO_getID(self, obj): |
|
From: <sub...@co...> - 2004-02-11 05:38:55
|
Author: ianb
Date: Tue Feb 10 20:30:58 2004
New Revision: 14
Modified:
trunk/SQLObject/sqlobject/__init__.py
Log:
Added some backward-compatible *Connection constructors
Modified: trunk/SQLObject/sqlobject/__init__.py
==============================================================================
--- trunk/SQLObject/sqlobject/__init__.py (original)
+++ trunk/SQLObject/sqlobject/__init__.py Tue Feb 10 20:30:58 2004
@@ -7,16 +7,52 @@
from dbconnection import connectionForURI
## Each of these imports allows the driver to install itself
+## Then we set up some backward compatibility
+
+def _warn(msg):
+ import warnings
+ warnings.warn(msg, warnings.DeprecationWarning, stacklevel=2)
import firebird
+_firebird = firebird
del firebird
+def FirebirdConnection(*args, **kw):
+ _warn('FirebirdConnection is deprecated; use connectionForURI("firebird://...") or "from sqlobject.firebird import builder; FirebirdConnection = builder()"')
+ _firebird.builder()(*args, **kw)
+
import mysql
+_mysql = mysql
del mysql
+def MySQLConnection(*args, **kw):
+ _warn('MySQLConnection is deprecated; use connectionForURI("mysql://...") or "from sqlobject.mysql import builder; MySQLConnection = builder()"')
+ _mysql.builder()(*args, **kw)
+
import postgres
+_postgres = postgres
del postgres
+def PostgresConnection(*args, **kw):
+ _warn('PostgresConnection is deprecated; use connectionForURI("postgres://...") or "from sqlobject.postgres import builder; PostgresConnection = builder()"')
+ _postgres.builder()(*args, **kw)
+
import sqlite
+_sqlite = sqlite
del sqlite
+def SQLiteConnection(*args, **kw):
+ _warn('SQLiteConnection is deprecated; use connectionForURI("sqlite://...") or "from sqlobject.sqlite import builder; SQLiteConnection = builder()"')
+ _sqlite.builder()(*args, **kw)
+
import dbm
+_dbm = dbm
del dbm
+def DBMConnection(*args, **kw):
+ _warn('DBMConnection is deprecated; use connectionForURI("dbm://...") or "from sqlobject.dbm import builder; DBMConnection = builder()"')
+ _dbm.builder()(*args, **kw)
+
import sybase
+_sybase = sybase
del sybase
+def SybaseConnection(*args, **kw):
+ _warn('SybaseConnection is deprecated; use connectionForURI("sybase://...") or "from sqlobject.sybase import builder; SybaseConnection = builder()"')
+ _sybase.builder()(*args, **kw)
+
+
|
|
From: <sub...@co...> - 2004-02-11 05:21:17
|
Author: ianb Date: Tue Feb 10 20:13:17 2004 New Revision: 13 Modified: trunk/SQLObject/docs/News.txt trunk/SQLObject/sqlobject/__init__.py trunk/SQLObject/sqlobject/col.py trunk/SQLObject/sqlobject/dbconnection.py trunk/SQLObject/sqlobject/dbm/__init__.py trunk/SQLObject/sqlobject/dbm/dbmconnection.py trunk/SQLObject/sqlobject/firebird/__init__.py trunk/SQLObject/sqlobject/firebird/firebirdconnection.py trunk/SQLObject/sqlobject/main.py trunk/SQLObject/sqlobject/mysql/__init__.py trunk/SQLObject/sqlobject/mysql/mysqlconnection.py trunk/SQLObject/sqlobject/postgres/__init__.py trunk/SQLObject/sqlobject/postgres/pgconnection.py trunk/SQLObject/sqlobject/sqlite/__init__.py trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py trunk/SQLObject/sqlobject/sybase/__init__.py trunk/SQLObject/sqlobject/sybase/sybaseconnection.py trunk/SQLObject/tests/SQLObjectTest.py Log: Bunch of fixes to database refactoring- made database modules load lazily (only when they are used), did actual regression testing on the databases Modified: trunk/SQLObject/docs/News.txt ============================================================================== --- trunk/SQLObject/docs/News.txt (original) +++ trunk/SQLObject/docs/News.txt Tue Feb 10 20:13:17 2004 @@ -18,6 +18,7 @@ ``obj.sync()`` (``sync`` also refetches the data from the database, which ``syncUpdate`` does not do). When enabled, instances have a property ``dirty``, which indicates if they have pending updates. + Inserts are still done immediately. * Separated database drivers (PostgresConnection, MySQLConnection, etc.) into separate packages. You can access the driver through URIs, like ``mysql://user:pass@host/dbname`` -- to set drivers after @@ -32,6 +33,11 @@ * We're now using a Subversion repository instead of CVS. It is located at svn://colorstudy.com/trunk/SQLObject +Bugs +---- + +* SQLite booleans fixed. + SQLObject 0.5.2 =============== Modified: trunk/SQLObject/sqlobject/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/__init__.py (original) +++ trunk/SQLObject/sqlobject/__init__.py Tue Feb 10 20:13:17 2004 @@ -4,9 +4,12 @@ from styles import * from joins import * from include import validators +from dbconnection import connectionForURI ## Each of these imports allows the driver to install itself +import firebird +del firebird import mysql del mysql import postgres Modified: trunk/SQLObject/sqlobject/col.py ============================================================================== --- trunk/SQLObject/sqlobject/col.py (original) +++ trunk/SQLObject/sqlobject/col.py Tue Feb 10 20:13:17 2004 @@ -352,6 +352,9 @@ def _sybaseType(self): return "BIT" + def _firebirdType(self): + return 'INT' + class BoolCol(Col): baseClass = SOBoolCol @@ -405,7 +408,7 @@ SOKeyCol.__init__(self, **kw) def postgresCreateSQL(self): - from SQLObject import findClass + from main import findClass sql = SOKeyCol.postgresCreateSQL(self) if self.cascade is not None: other = findClass(self.foreignKey) Modified: trunk/SQLObject/sqlobject/dbconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/dbconnection.py (original) +++ trunk/SQLObject/sqlobject/dbconnection.py Tue Feb 10 20:13:17 2004 @@ -56,24 +56,30 @@ raise NotImplemented connectionFromURI = classmethod(connectionFromURI) - def _parseURI(uri, expectHost=True): + def _parseURI(uri): schema, rest = uri.split(':', 1) - rest = rest.strip('/') - if expectHost: + assert rest.startswith('/'), "URIs must start with scheme:/ -- you did not include a / (in %r)" % rest + if rest.startswith('/') and not rest.startswith('//'): + host = None + rest = rest[1:] + elif rest.startswith('///'): + host = None + rest = rest[3:] + else: + rest = rest[2:] if rest.find('/') == -1: - host, rest = rest, '' + host = rest + rest = '' else: host, rest = rest.split('/', 1) - if host.find('@') != -1: - user, host = host.split('@', 1) - if user.find(':') != -1: - user, password = user.split(':', 1) - else: - password = None + if host and host.find('@') != -1: + user, host = host.split('@', 1) + if user.find(':') != -1: + user, password = user.split(':', 1) else: - user = password = None + password = None else: - host = user = password = None + user = password = None path = '/' + rest return user, password, host, path _parseURI = staticmethod(_parseURI) @@ -462,18 +468,18 @@ class ConnectionURIOpener(object): def __init__(self): - self.allClasses = [] - self.classSchemes = {} + self.schemeBuilders = {} + self.schemeSupported = {} self.instanceNames = {} + self.cachedURIs = {} - def registerConnectionClass(self, cls): - if cls not in self.allClasses: - self.allClasses.append(cls) - for uriScheme in cls.schemes: - assert not self.classSchemes.has_key(uriScheme) \ - or self.classSchemes[uriScheme] is cls, \ - "A class has already been registered for the URI scheme %s" % uriScheme - self.classSchemes[uriScheme] = cls + def registerConnection(self, schemes, builder, isSupported): + for uriScheme in schemes: + assert not self.schemeBuilders.has_key(uriScheme) \ + or self.schemeBuilders[uriScheme] is builder, \ + "A driver has already been registered for the URI scheme %s" % uriScheme + self.schemeBuilders[uriScheme] = builder + self.schemeSupported = isSupported def registerConnectionInstance(self, inst): if inst.name: @@ -483,20 +489,25 @@ assert inst.name.find(':') == -1, "You cannot include ':' in your class names (%r)" % cls.name self.instanceNames[inst.name] = inst - def openURI(self, uri): + def connectionForURI(self, uri): + if self.cachedURIs.has_key(uri): + return self.cachedURIs[uri] if uri.find(':') != -1: scheme, rest = uri.split(':', 1) - assert self.classSchemes.has_key(scheme), \ + assert self.schemeBuilders.has_key(scheme), \ "No SQLObject driver exists for %s" % scheme - return self.classSchemes[scheme].connectionFromURI(uri) + conn = self.schemeBuilders[scheme]().connectionFromURI(uri) else: # We just have a name, not a URI assert self.instanceNames.has_key(uri), \ "No SQLObject driver exists under the name %s" % uri - return self.instanceNames[uri] + conn = self.instanceNames[uri] + # @@: Do we care if we clobber another connection? + self.cachedURIs[uri] = conn + return conn TheURIOpener = ConnectionURIOpener() -registerConnectionClass = TheURIOpener.registerConnectionClass +registerConnection = TheURIOpener.registerConnection registerConnectionInstance = TheURIOpener.registerConnectionInstance -openURI = TheURIOpener.openURI +connectionForURI = TheURIOpener.connectionForURI Modified: trunk/SQLObject/sqlobject/dbm/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/dbm/__init__.py (original) +++ trunk/SQLObject/sqlobject/dbm/__init__.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,14 @@ -from sqlobject import dbconnection -from dbmconnection import DBMConnection +from sqlobject.dbconnection import registerConnection -dbconnection.registerConnectionClass( - DBMConnection) +def builder(): + import dbmconnection + return dbmconnection.DBMConnection + +def isSupported(): + try: + import anydbm + except ImportError: + return False + return True + +registerConnection(['dbm'], builder, isSupported) Modified: trunk/SQLObject/sqlobject/dbm/dbmconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/dbm/dbmconnection.py (original) +++ trunk/SQLObject/sqlobject/dbm/dbmconnection.py Tue Feb 10 20:13:17 2004 @@ -105,7 +105,6 @@ supportTransactions = False dbName = 'dbm' - schemes = [dbName] def __init__(self, path, **kw): global anydbm, pickle @@ -136,16 +135,6 @@ return cls(path) connectionFromURI = classmethod(connectionFromURI) - def isSupported(cls): - global anydbm - if anydbm is None: - try: - import anydbm - except ImportError: - return False - return True - isSupported = classmethod(isSupported) - def _newID(self, table): id = int(self._meta["%s.id" % table]) + 1 self._meta["%s.id" % table] = str(id) Modified: trunk/SQLObject/sqlobject/firebird/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/firebird/__init__.py (original) +++ trunk/SQLObject/sqlobject/firebird/__init__.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,13 @@ -from sqlobject import dbconnection -from firebirdconnection import FirebirdConnection +from sqlobject.dbconnection import registerConnection -dbconnection.registerConnectionClass( - FirebirdConnection) +def builder(): + import firebirdconnection + return firebirdconnection.FirebirdConnection + +def isSupported(): + try: + import kinterbasdb + except ImportError: + return False + +registerConnection(['firebird', 'interbase'], builder, isSupported) Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/firebird/firebirdconnection.py (original) +++ trunk/SQLObject/sqlobject/firebird/firebirdconnection.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,6 @@ from sqlobject.dbconnection import DBAPI kinterbasdb = None +import re class FirebirdConnection(DBAPI): @@ -27,23 +28,13 @@ DBAPI.__init__(self, **kw) def connectionFromURI(cls, uri): - auth, password, host, path = self._parseURI(url) + auth, password, host, path = cls._parseURI(uri) if not password: password = 'masterkey' if not auth: auth='sysdba' - return cls(host, db=path, user=user, passwd=password) + return cls(host, db=path, user=auth, passwd=password) connectionFromURI = classmethod(connectionFromURI) - - def isSupported(cls): - global kinterbasdb - if kinterbasdb is None: - try: - import kinterbasdb - except ImportError: - return False - return True - isSupported = classmethod(isSupported) def _runWithConnection(self, meth, *args): conn = self.getConnection() Modified: trunk/SQLObject/sqlobject/main.py ============================================================================== --- trunk/SQLObject/sqlobject/main.py (original) +++ trunk/SQLObject/sqlobject/main.py Tue Feb 10 20:13:17 2004 @@ -242,7 +242,7 @@ def findClass(name, registry=None): #assert classRegistry.get(registry, {}).has_key(name), "No class by the name %s found (I have %s)" % (repr(name), ', '.join(map(str, classRegistry.keys()))) - return classRegistry[registry][name] + return classregistry.registry(registry).getClass(name) def findDependencies(name, registry=None): depends = [] @@ -652,7 +652,6 @@ def syncUpdate(self): if not self._SO_createValues: return - print 'UP:', self._SO_createValues self._SO_writeLock.acquire() try: if self._SO_columnDict: @@ -1035,7 +1034,7 @@ def setConnection(cls, value): if isinstance(value, (str, unicode)): - value = dbconnection.openURI(value) + value = dbconnection.connectionForURI(value) cls._connection = value setConnection = classmethod(setConnection) Modified: trunk/SQLObject/sqlobject/mysql/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/mysql/__init__.py (original) +++ trunk/SQLObject/sqlobject/mysql/__init__.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,14 @@ -from sqlobject import dbconnection -from mysqlconnection import MySQLConnection +from sqlobject.dbconnection import registerConnection -dbconnection.registerConnectionClass( - MySQLConnection) +def builder(): + import mysqlconnection + return mysqlconnection.MySQLConnection + +def isSupported(): + try: + import MySQLdb + except ImportError: + return False + return True + +registerConnection(['mysql'], builder, isSupported) Modified: trunk/SQLObject/sqlobject/mysql/mysqlconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/mysql/mysqlconnection.py (original) +++ trunk/SQLObject/sqlobject/mysql/mysqlconnection.py Tue Feb 10 20:13:17 2004 @@ -1,4 +1,5 @@ from sqlobject.dbconnection import DBAPI +from sqlobject import col MySQLdb = None class MySQLConnection(DBAPI): @@ -23,16 +24,6 @@ host=host or 'localhost') connectionFromURI = classmethod(connectionFromURI) - def isSupported(cls): - global MySQLdb - if MySQLdb is None: - try: - import MySQLdb - except ImportError: - return False - return True - isSupported = classmethod(isSupported) - def makeConnection(self): return MySQLdb.connect(host=self.host, db=self.db, user=self.user, passwd=self.passwd) Modified: trunk/SQLObject/sqlobject/postgres/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/postgres/__init__.py (original) +++ trunk/SQLObject/sqlobject/postgres/__init__.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,15 @@ -from sqlobject import dbconnection -from pgconnection import PostgresConnection +from sqlobject.dbconnection import registerConnection -dbconnection.registerConnectionClass( - PostgresConnection) +def builder(): + import pgconnection + return pgconnection.PostgresConnection + +def isSupported(): + try: + import psycopg + except ImportError: + return False + return False + +registerConnection(['postgres', 'postgresql', 'psycopg'], + builder, isSupported) Modified: trunk/SQLObject/sqlobject/postgres/pgconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/postgres/pgconnection.py (original) +++ trunk/SQLObject/sqlobject/postgres/pgconnection.py Tue Feb 10 20:13:17 2004 @@ -1,4 +1,7 @@ from sqlobject.dbconnection import DBAPI +import re +from sqlobject import col +from sqlobject import sqlbuilder psycopg = None pgdb = None @@ -42,24 +45,16 @@ DBAPI.__init__(self, **kw) def connectionFromURI(cls, uri): - user, password, host, path = self._parseURI(uri) + user, password, host, path = cls._parseURI(uri) + path = path.strip('/') return cls(host=host, db=path, user=user, passwd=password) connectionFromURI = classmethod(connectionFromURI) - def isSupported(cls): - global psycopg - if psycopg is None: - try: - import psycopg - except ImportError: - return False - return False - isSupported = classmethod(isSupported) - def _setAutoCommit(self, conn, auto): conn.autocommit(auto) def makeConnection(self): + print 'DSN', self.dsn conn = self.pgmodule.connect(self.dsn) if self.autoCommit: conn.autocommit(1) Modified: trunk/SQLObject/sqlobject/sqlite/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/sqlite/__init__.py (original) +++ trunk/SQLObject/sqlobject/sqlite/__init__.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,14 @@ -from sqlobject import dbconnection -from sqliteconnection import SQLiteConnection +from sqlobject.dbconnection import registerConnection -dbconnection.registerConnectionClass( - SQLiteConnection) +def builder(): + import sqliteconnection + return sqliteconnection.SQLiteConnection + +def isSupported(): + try: + import sqlite + except ImportError: + return False + return True + +registerConnection(['sqlite'], builder, isSupported) Modified: trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py (original) +++ trunk/SQLObject/sqlobject/sqlite/sqliteconnection.py Tue Feb 10 20:13:17 2004 @@ -21,22 +21,12 @@ DBAPI.__init__(self, **kw) def connectionFromURI(cls, uri): - user, password, host, path = cls._parseURI(uri, expectHost=False) - assert host is None + user, password, host, path = cls._parseURI(uri) + assert host is None, "SQLite can only be used locally (with a URI like sqlite:///file or sql:/file, not %r)" % uri assert user is None and password is None, "You may not provide usernames or passwords for SQLite databases" return cls(filename='/' + path) connectionFromURI = classmethod(connectionFromURI) - def isSupported(cls): - global sqlite - if sqlite is None: - try: - import sqlite - except ImportError: - return False - return True - isSupported = classmethod(isSupported) - def _setAutoCommit(self, conn, auto): conn.autocommit = auto Modified: trunk/SQLObject/sqlobject/sybase/__init__.py ============================================================================== --- trunk/SQLObject/sqlobject/sybase/__init__.py (original) +++ trunk/SQLObject/sqlobject/sybase/__init__.py Tue Feb 10 20:13:17 2004 @@ -1,5 +1,14 @@ -from sqlobject import dbconnection -from sybaseconnection import SybaseConnection +from sqlobject.dbconnection import registerConnection -dbconnection.registerConnectionClass( - SybaseConnection) +def builder(): + import sybaseconnection + return sybaseconnection.SybaseConnection + +def isSupported(cls): + try: + import Sybase + except ImportError: + return False + return True + +registerConnection(['sybase'], builder, isSupported) Modified: trunk/SQLObject/sqlobject/sybase/sybaseconnection.py ============================================================================== --- trunk/SQLObject/sqlobject/sybase/sybaseconnection.py (original) +++ trunk/SQLObject/sqlobject/sybase/sybaseconnection.py Tue Feb 10 20:13:17 2004 @@ -31,16 +31,6 @@ db=path) connectionFromURI = classmethod(connectionFromURI) - def isSupported(cls): - global Sybase - if Sybase is None: - try: - import Sybase - except ImportError: - return False - return True - isSupported = classmethod(isSupported) - def insert_id(self, conn): """ Sybase adapter/cursor does not support the Modified: trunk/SQLObject/tests/SQLObjectTest.py ============================================================================== --- trunk/SQLObject/tests/SQLObjectTest.py (original) +++ trunk/SQLObject/tests/SQLObjectTest.py Tue Feb 10 20:13:17 2004 @@ -1,6 +1,5 @@ import unittest from sqlobject import * -from sqlobject.dbconnection import openURI import os True, False = 1==1, 0==1 @@ -27,7 +26,7 @@ SQLObjectTest.supportAuto = True SQLObjectTest.supportRestrictedEnum = True SQLObjectTest.supportTransactions = True - return 'postgres://localhost/test' + return 'postgres:///test' def pygresConnection(): SQLObjectTest.supportDynamic = True @@ -89,7 +88,7 @@ def setUp(self): global __connection__ if isinstance(__connection__, str): - __connection__ = openURI(__connection__) + __connection__ = connectionForURI(__connection__) if self.debugSQL: print print '#' * 70 |
|
From: <sub...@co...> - 2004-02-10 06:05:20
|
Author: ianb
Date: Mon Feb 9 20:57:48 2004
New Revision: 12
Modified:
trunk/SQLObject/tests/test.py
Log:
Added another boolean test
Modified: trunk/SQLObject/tests/test.py
==============================================================================
--- trunk/SQLObject/tests/test.py (original)
+++ trunk/SQLObject/tests/test.py Mon Feb 9 20:57:48 2004
@@ -98,6 +98,8 @@
def testBoolCol(self):
student = Student(is_smart=False)
self.assertEqual(student.is_smart, False)
+ student2 = Student(is_smart='false')
+ self.assertEqual(student2.is_smart, True)
class TestCase34(SQLObjectTest):
|
|
From: <sub...@co...> - 2004-02-10 06:04:38
|
Author: ianb
Date: Mon Feb 9 20:57:09 2004
New Revision: 11
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Fixed converter for BoolValidator, which wasn't working with SQLite
Modified: trunk/SQLObject/sqlobject/col.py
==============================================================================
--- trunk/SQLObject/sqlobject/col.py (original)
+++ trunk/SQLObject/sqlobject/col.py Mon Feb 9 20:57:09 2004
@@ -328,6 +328,12 @@
else:
return sqlbuilder.FALSE
+ def toPython(self, value, state):
+ if int(value):
+ return sqlbuilder.TRUE
+ else:
+ return sqlbuilder.FALSE
+
class SOBoolCol(SOCol):
def __init__(self, **kw):
|