sqlobject-cvs Mailing List for SQLObject (Page 151)
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...> - 2005-12-05 19:35:18
|
Author: phd
Date: 2005-12-05 19:35:11 +0000 (Mon, 05 Dec 2005)
New Revision: 1347
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/joins.py
Log:
Merged revs 1345:1346 from the trunk: a patch by "j.kartnaller" <j.k...@ro...> to pass connection if there is no one.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/joins.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/joins.py 2005-12-05 19:34:14 UTC (rev 1346)
+++ SQLObject/branches/0.7-bugfix/sqlobject/joins.py 2005-12-05 19:35:11 UTC (rev 1347)
@@ -246,8 +246,15 @@
SOMultipleJoin.__init__(self, **kw)
def performJoin(self, inst):
+ if inst.sqlmeta._perConnection:
+ conn = inst._connection
+ else:
+ conn = None
pythonColumn = self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)
- results = self.otherClass.select(getattr(self.otherClass.q, pythonColumn) == inst.id)
+ results = self.otherClass.select(
+ getattr(self.otherClass.q, pythonColumn) == inst.id,
+ connection=conn
+ )
if results.count() == 0:
if not self.makeDefault:
return None
|
|
From: <sub...@co...> - 2005-12-05 19:34:22
|
Author: phd
Date: 2005-12-05 19:34:14 +0000 (Mon, 05 Dec 2005)
New Revision: 1346
Modified:
SQLObject/trunk/sqlobject/joins.py
Log:
A patch by "j.kartnaller" <j.k...@ro...> to pass connection if there is no one.
Modified: SQLObject/trunk/sqlobject/joins.py
===================================================================
--- SQLObject/trunk/sqlobject/joins.py 2005-12-05 19:25:09 UTC (rev 1345)
+++ SQLObject/trunk/sqlobject/joins.py 2005-12-05 19:34:14 UTC (rev 1346)
@@ -248,8 +248,15 @@
SOMultipleJoin.__init__(self, **kw)
def performJoin(self, inst):
+ if inst.sqlmeta._perConnection:
+ conn = inst._connection
+ else:
+ conn = None
pythonColumn = self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)
- results = self.otherClass.select(getattr(self.otherClass.q, pythonColumn) == inst.id)
+ results = self.otherClass.select(
+ getattr(self.otherClass.q, pythonColumn) == inst.id,
+ connection=conn
+ )
if results.count() == 0:
if not self.makeDefault:
return None
|
|
From: <sub...@co...> - 2005-12-05 19:25:20
|
Author: phd
Date: 2005-12-05 19:25:09 +0000 (Mon, 05 Dec 2005)
New Revision: 1345
Modified:
SQLObject/trunk/sqlobject/tests/test_csvexport.py
Log:
Renamed tables so they do not conflict with tables from test_combining_joins.py.
Modified: SQLObject/trunk/sqlobject/tests/test_csvexport.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_csvexport.py 2005-12-05 17:59:09 UTC (rev 1344)
+++ SQLObject/trunk/sqlobject/tests/test_csvexport.py 2005-12-05 19:25:09 UTC (rev 1345)
@@ -16,7 +16,7 @@
print s
assert result.strip() == s.strip()
-class Simple(SQLObject):
+class SimpleCSV(SQLObject):
name = StringCol()
address = StringCol()
@@ -24,8 +24,8 @@
hidden = StringCol()
hidden.noCSV = True
-class Complex(SQLObject):
-
+class ComplexCSV(SQLObject):
+
fname = StringCol()
lname = StringCol()
age = IntCol()
@@ -36,55 +36,55 @@
return self.fname + ' ' + self.lname
def _get_initials(self):
return self.fname[0] + self.lname[0]
-
+
def test_simple():
- setupClass(Simple)
- Simple(name='Bob', address='432W', hidden='boo')
- Simple(name='Joe', address='123W', hidden='arg')
+ setupClass(SimpleCSV)
+ SimpleCSV(name='Bob', address='432W', hidden='boo')
+ SimpleCSV(name='Joe', address='123W', hidden='arg')
assert_export("""\
name,Street Address
Bob,432W
Joe,123W
-""", Simple, orderBy='name')
+""", SimpleCSV, orderBy='name')
assert_export("""\
name,Street Address
Joe,123W
Bob,432W
-""", Simple, orderBy='address')
+""", SimpleCSV, orderBy='address')
assert_export("""\
name,Street Address
Joe,123W
-""", Simple.selectBy(name='Joe'))
-
+""", SimpleCSV.selectBy(name='Joe'))
+
def test_complex():
- setupClass(Complex)
- Complex(fname='John', lname='Doe', age=40)
- Complex(fname='Bob', lname='Dylan', age=60)
- Complex(fname='Harriet', lname='Tubman', age=160)
+ setupClass(ComplexCSV)
+ ComplexCSV(fname='John', lname='Doe', age=40)
+ ComplexCSV(fname='Bob', lname='Dylan', age=60)
+ ComplexCSV(fname='Harriet', lname='Tubman', age=160)
assert_export("""\
Full Name,fname,lname,age,initials
John Doe,John,Doe,40,JD
Bob Dylan,Bob,Dylan,60,BD
Harriet Tubman,Harriet,Tubman,160,HT
-""", Complex, orderBy='lname')
+""", ComplexCSV, orderBy='lname')
assert_export("""\
Full Name,fname,lname,age,initials
Bob Dylan,Bob,Dylan,60,BD
John Doe,John,Doe,40,JD
-""", Complex.select(Complex.q.lname.startswith('D'), orderBy='fname'))
+""", ComplexCSV.select(ComplexCSV.q.lname.startswith('D'), orderBy='fname'))
def test_zip():
# Just exercise tests, doesn't actually test results
- setupClass(Simple)
- Simple(name='Bob', address='432W', hidden='boo')
- Simple(name='Joe', address='123W', hidden='arg')
-
- setupClass(Complex)
- Complex(fname='John', lname='Doe', age=40)
- Complex(fname='Bob', lname='Dylan', age=60)
- Complex(fname='Harriet', lname='Tubman', age=160)
- s = export_csv_zip([Simple, Complex])
+ setupClass(SimpleCSV)
+ SimpleCSV(name='Bob', address='432W', hidden='boo')
+ SimpleCSV(name='Joe', address='123W', hidden='arg')
+
+ setupClass(ComplexCSV)
+ ComplexCSV(fname='John', lname='Doe', age=40)
+ ComplexCSV(fname='Bob', lname='Dylan', age=60)
+ ComplexCSV(fname='Harriet', lname='Tubman', age=160)
+ s = export_csv_zip([SimpleCSV, ComplexCSV])
assert isinstance(s, str) and s
- s = export_csv_zip([Simple.selectBy(name='Bob'),
- (Complex, list(Complex.selectBy(fname='John')))])
-
+ s = export_csv_zip([SimpleCSV.selectBy(name='Bob'),
+ (ComplexCSV, list(ComplexCSV.selectBy(fname='John')))])
+
|
|
From: SourceForge.net <no...@so...> - 2005-12-05 19:09:12
|
Bugs item #1373755, was opened at 2005-12-05 11:09 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1373755&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: new link: reddit.com runs on sqlobject Initial Comment: for http://sqlobject.org/links.html reddit: what's new online http://reddit.com/ ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1373755&group_id=74338 |
|
From: <sub...@co...> - 2005-12-05 17:13:34
|
Author: phd Date: 2005-12-05 17:13:28 +0000 (Mon, 05 Dec 2005) New Revision: 1343 Added: home/phd/SQLObject/paramstyles/sqlobject/tests/test_setters.py Log: Merged patches from the revisions 1340:1342 from the trunk: merged the test by Luke Opperman <lu...@me...> for plain/non-plain setters. Copied: home/phd/SQLObject/paramstyles/sqlobject/tests/test_setters.py (from rev 1342, SQLObject/trunk/sqlobject/tests/test_setters.py) |
|
From: <sub...@co...> - 2005-12-05 17:11:39
|
Author: phd Date: 2005-12-05 17:11:30 +0000 (Mon, 05 Dec 2005) New Revision: 1342 Added: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_setters.py Log: Merged rev 1340:1341 from the trunk: the test by Luke Opperman <lu...@me...> for plain/non-plain setters. Copied: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_setters.py (from rev 1341, SQLObject/trunk/sqlobject/tests/test_setters.py) |
|
From: <sub...@co...> - 2005-12-05 17:09:54
|
Author: phd Date: 2005-12-05 17:09:45 +0000 (Mon, 05 Dec 2005) New Revision: 1341 Added: SQLObject/trunk/sqlobject/tests/test_setters.py Log: Added the test by Luke Opperman <lu...@me...> for plain/non-plain setters. Added: SQLObject/trunk/sqlobject/tests/test_setters.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_setters.py 2005-12-05 17:02:18 UTC (rev 1340) +++ SQLObject/trunk/sqlobject/tests/test_setters.py 2005-12-05 17:09:45 UTC (rev 1341) @@ -0,0 +1,21 @@ +from sqlobject import * +from sqlobject.tests.dbtest import * + +class TestPlainAndNonPlainSetter(SQLObject): + firstName = StringCol(length=50, dbName='fname_col', default=None) + lastName = StringCol(length=50, dbName='lname_col', default=None) + + def _set_name(self, v): + firstName, lastName = v.split() + self.firstName = firstName + self.lastName = lastName + + def _get_name(self): + return "%s %s" % (self.firstName, self.lastName) + +def test_create(): + setupClass(TestPlainAndNonPlainSetter) + t = TestPlainAndNonPlainSetter(name='John Doe') + assert t.firstName == 'John' + assert t.lastName == 'Doe' + assert t.name == 'John Doe' \ No newline at end of file |
|
From: <sub...@co...> - 2005-12-05 17:02:26
|
Author: phd
Date: 2005-12-05 17:02:18 +0000 (Mon, 05 Dec 2005)
New Revision: 1340
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/main.py
Log:
Merged rev 1338:1339 from the trunk: a patch by Luke Opperman <lu...@me...> for plain/non-plain setters.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/main.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/main.py 2005-12-05 16:52:31 UTC (rev 1339)
+++ SQLObject/branches/0.7-bugfix/sqlobject/main.py 2005-12-05 17:02:18 UTC (rev 1340)
@@ -1072,6 +1072,9 @@
if to_python:
value = to_python(dbValue, self._SO_validatorState)
setattr(self, instanceName(name), value)
+
+ self._SO_createValues.update(kw)
+
for name, value in extra.items():
try:
getattr(self.__class__, name)
@@ -1083,7 +1086,6 @@
except AttributeError, e:
raise AttributeError, '%s (with attribute %r)' % (e, name)
- self._SO_createValues.update(kw)
self.dirty = True
return
|
|
From: <sub...@co...> - 2005-12-05 16:52:39
|
Author: phd
Date: 2005-12-05 16:52:31 +0000 (Mon, 05 Dec 2005)
New Revision: 1339
Modified:
home/phd/SQLObject/paramstyles/sqlobject/main.py
Log:
Merged patches from the revisions 1337:1338 from the trunk: a patch by Luke Opperman <lu...@me...> for plain/non-plain setters.
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-05 16:51:05 UTC (rev 1338)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-05 16:52:31 UTC (rev 1339)
@@ -1131,6 +1131,9 @@
if to_python:
value = to_python(dbValue, self._SO_validatorState)
setattr(self, instanceName(name), value)
+
+ self._SO_createValues.update(kw)
+
for name, value in extra.items():
try:
getattr(self.__class__, name)
@@ -1142,7 +1145,6 @@
except AttributeError, e:
raise AttributeError, '%s (with attribute %r)' % (e, name)
- self._SO_createValues.update(kw)
self.dirty = True
return
|
|
From: <sub...@co...> - 2005-12-05 16:51:18
|
Author: phd
Date: 2005-12-05 16:51:05 +0000 (Mon, 05 Dec 2005)
New Revision: 1338
Modified:
SQLObject/trunk/sqlobject/main.py
Log:
A patch by Luke Opperman <lu...@me...> for plain/non-plain setters.
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-12-05 16:24:30 UTC (rev 1337)
+++ SQLObject/trunk/sqlobject/main.py 2005-12-05 16:51:05 UTC (rev 1338)
@@ -1131,6 +1131,9 @@
if to_python:
value = to_python(dbValue, self._SO_validatorState)
setattr(self, instanceName(name), value)
+
+ self._SO_createValues.update(kw)
+
for name, value in extra.items():
try:
getattr(self.__class__, name)
@@ -1142,7 +1145,6 @@
except AttributeError, e:
raise AttributeError, '%s (with attribute %r)' % (e, name)
- self._SO_createValues.update(kw)
self.dirty = True
return
|
|
From: <sub...@co...> - 2005-12-05 16:24:47
|
Author: phd
Date: 2005-12-05 16:24:30 +0000 (Mon, 05 Dec 2005)
New Revision: 1337
Modified:
home/phd/SQLObject/paramstyles/sqlobject/cache.py
Log:
Merged patches from the revisions 1334:1336 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/cache.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/cache.py 2005-12-04 21:50:47 UTC (rev 1336)
+++ home/phd/SQLObject/paramstyles/sqlobject/cache.py 2005-12-05 16:24:30 UTC (rev 1337)
@@ -306,7 +306,7 @@
def tryGet(self, id, cls):
try:
- self.caches[cls.__name__].tryGet(id)
+ return self.caches[cls.__name__].tryGet(id)
except KeyError:
return None
|
|
From: <sub...@co...> - 2005-12-04 21:50:50
|
Author: ianb
Date: 2005-12-04 21:50:47 +0000 (Sun, 04 Dec 2005)
New Revision: 1336
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/cache.py
Log:
Merged r1334:1335
Modified: SQLObject/branches/0.7-bugfix/sqlobject/cache.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/cache.py 2005-12-04 21:49:08 UTC (rev 1335)
+++ SQLObject/branches/0.7-bugfix/sqlobject/cache.py 2005-12-04 21:50:47 UTC (rev 1336)
@@ -293,7 +293,7 @@
def tryGet(self, id, cls):
try:
- self.caches[cls.__name__].tryGet(id)
+ return self.caches[cls.__name__].tryGet(id)
except KeyError:
return None
|
|
From: <sub...@co...> - 2005-12-04 21:49:19
|
Author: ianb
Date: 2005-12-04 21:49:08 +0000 (Sun, 04 Dec 2005)
New Revision: 1335
Modified:
SQLObject/trunk/sqlobject/cache.py
Log:
Missed return in tryGet
Modified: SQLObject/trunk/sqlobject/cache.py
===================================================================
--- SQLObject/trunk/sqlobject/cache.py 2005-12-04 01:10:26 UTC (rev 1334)
+++ SQLObject/trunk/sqlobject/cache.py 2005-12-04 21:49:08 UTC (rev 1335)
@@ -306,7 +306,7 @@
def tryGet(self, id, cls):
try:
- self.caches[cls.__name__].tryGet(id)
+ return self.caches[cls.__name__].tryGet(id)
except KeyError:
return None
|
|
From: SourceForge.net <no...@so...> - 2005-12-04 17:35:20
|
Bugs item #1334786, was opened at 2005-10-22 17:30 Message generated for change (Comment added) made by haitong You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1334786&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: M. Dietrich (mdt) Assigned to: Nobody/Anonymous (nobody) Summary: infinitiv recursion in Transaction.__del__ Initial Comment: using ThreadConnections i get a Exception exceptions.RuntimeError: 'maximum recursion depth exceeded' in <bound method Transaction.__del__ of <sqlobject.dbconnection.Transaction object at 0xaedb714c>> ignored , commenting __del__() works in the first place. can't figure out what this __del__ is for... ---------------------------------------------------------------------- Comment By: xiao hai tong (haitong) Date: 2005-12-05 01:35 Message: Logged In: YES user_id=146934 I encount it too. once is too many connection crash my pgsql server on windows, then may of such exceptions reported. other time: a multi thread test program. I want to retry my transaction when excecption occured during commit, I commet the threadConnection.rollback(), just set threadConnection = g_conn.transaction(), and redo the transaction after seconds, such exceptions occurred. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2005-10-26 00:12 Message: Logged In: YES user_id=4799 Can you make a little test program that demonstrates the problem? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1334786&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-12-02 12:50:48
|
Patches item #1371678, was opened at 2005-12-02 13:50 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1371678&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Alan (alanfranz) Assigned to: Nobody/Anonymous (nobody) Summary: Docs update Initial Comment: Some update to the docs, both sqlobject.txt and inheritance.txt. This patch applies against the 0.7bugfix branch. It contains both some clarifications and some corrections. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1371678&group_id=74338 |
|
From: <sub...@co...> - 2005-12-01 17:20:22
|
Author: phd
Date: 2005-12-01 17:20:06 +0000 (Thu, 01 Dec 2005)
New Revision: 1332
Modified:
home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
Log:
Converted _SO_update().
Modified: home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2005-11-30 18:40:48 UTC (rev 1331)
+++ home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2005-12-01 17:20:06 UTC (rev 1332)
@@ -299,18 +299,15 @@
threadName = ''
print '%(n)2i%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' % locals()
- def _convertQuery(self, query):
- paramstyle = self.module.paramstyle
- converter = getattr(DBSingleStyle, "to_" + paramstyle)
- return converter(query.query_list)
-
def _executeRetry(self, conn, cursor, query):
if isinstance(query, str):
if self.debug:
self.printDebug(conn, query, 'QueryR')
return cursor.execute(query)
elif isinstance(query, sqlbuilder.SQLList):
- query_string, params = self._convertQuery(query)
+ paramstyle = self.module.paramstyle
+ converter = getattr(DBSingleStyle, "to_" + paramstyle)
+ query_string, params = converter(query.query_list)
if self.debug:
self.printDebug(conn, query_string, 'QueryString')
self.printDebug(conn, params, 'QueryParams')
@@ -616,12 +613,14 @@
# in the SQLObject class.
def _SO_update(self, so, values):
- self.query("UPDATE %s SET %s WHERE %s = %s" %
- (so.sqlmeta.table,
- ", ".join(["%s = %s" % (dbName, self.sqlrepr(value))
- for dbName, value in values]),
- so.sqlmeta.idName,
- self.sqlrepr(so.id)))
+ query_list = ["UPDATE %s SET " % so.sqlmeta.table]
+ for dbName, value in values:
+ query_list.append("%s=" % dbName)
+ query_list.append(DBSingleStyle.Param(value))
+ query_list.append(" WHERE ")
+ query_list.append("%s=" % so.sqlmeta.idName)
+ query_list.append(DBSingleStyle.Param(so.id))
+ self.query(sqlbuilder.SQLList(query_list))
def _SO_selectOne(self, so, columnNames):
columns = ", ".join(columnNames)
|
|
From: <sub...@co...> - 2005-11-30 18:40:56
|
Author: phd
Date: 2005-11-30 18:40:48 +0000 (Wed, 30 Nov 2005)
New Revision: 1331
Modified:
home/phd/SQLObject/paramstyles/sqlobject/col.py
home/phd/SQLObject/paramstyles/sqlobject/events.py
home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py
Log:
Merged patches from the revisions 1327:1330 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/col.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/col.py 2005-11-30 18:39:28 UTC (rev 1330)
+++ home/phd/SQLObject/paramstyles/sqlobject/col.py 2005-11-30 18:40:48 UTC (rev 1331)
@@ -1204,7 +1204,7 @@
return None
if isinstance(value, str):
module = state.soObject._connection.module
- if module.__name__ == "sqlite":
+ if module.__name__ in ("sqlite", "pysqlite2.dbapi2"):
value = module.decode(value)
return value
if isinstance(value, (buffer_type, state.soObject._connection._binaryType)):
Modified: home/phd/SQLObject/paramstyles/sqlobject/events.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/events.py 2005-11-30 18:39:28 UTC (rev 1330)
+++ home/phd/SQLObject/paramstyles/sqlobject/events.py 2005-11-30 18:40:48 UTC (rev 1331)
@@ -269,6 +269,24 @@
else:
return repr(v)
+try:
+ sorted
+except NameError:
+ # For Python 2.2 and 2.3:
+ def sorted(lst, cmp=None, key=None, reverse=False):
+ if key:
+ lst = [(key(i), i) for i in lst]
+ lst = lst[:]
+ if cmp:
+ lst.sort(cmp)
+ else:
+ lst.sort()
+ if key:
+ lst = [i for k, i in lst]
+ if reverse:
+ lst.reverse()
+ return lst
+
__all__ = ['listen', 'send']
for name, value in globals().items():
if isinstance(value, type) and issubclass(value, Signal):
Modified: home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:39:28 UTC (rev 1330)
+++ home/phd/SQLObject/paramstyles/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:40:48 UTC (rev 1331)
@@ -3,6 +3,7 @@
sqlite = None
using_sqlite2 = False
+sqlite2_Binary = None
class SQLiteConnection(DBAPI):
@@ -34,6 +35,19 @@
for col_type in "text", "char", "varchar":
sqlite.register_converter(col_type, stop_pysqlite2_converting_strings_to_unicode)
sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings_to_unicode)
+ try:
+ from sqlite import encode, decode
+ except ImportError:
+ import base64
+ sqlite.encode = base64.encodestring
+ sqlite.decode = base64.decodestring
+ else:
+ sqlite.encode = encode
+ sqlite.decode = decode
+ global sqlite2_Binary
+ if sqlite2_Binary is None:
+ sqlite2_Binary = sqlite.Binary
+ sqlite.Binary = lambda s: sqlite2_Binary(sqlite.encode(s))
else:
opts['autocommit'] = autoCommit
if 'encoding' in kw:
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py 2005-11-30 18:39:28 UTC (rev 1330)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py 2005-11-30 18:40:48 UTC (rev 1331)
@@ -3,24 +3,6 @@
from sqlobject import events
import sys
-try:
- sorted
-except NameError:
- # For Python 2.3 and under:
- def sorted(lst, cmp=None, key=None, reverse=False):
- if key:
- lst = [(key(i), i) for i in lst]
- lst = lst[:]
- if cmp:
- lst.sort(cmp)
- else:
- lst.sort()
- if key:
- lst = [i for k, i in lst]
- if reverse:
- lst.reverse()
- return lst
-
class EventTester(SQLObject):
name = StringCol()
|
|
From: <sub...@co...> - 2005-11-30 18:39:44
|
Author: phd
Date: 2005-11-30 18:39:28 +0000 (Wed, 30 Nov 2005)
New Revision: 1330
Added:
SQLObject/branches/0.7-bugfix/sqlobject/mssql/
SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py
SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py
Modified:
SQLObject/branches/0.7-bugfix/setup.py
SQLObject/branches/0.7-bugfix/sqlobject/__init__.py
SQLObject/branches/0.7-bugfix/sqlobject/col.py
SQLObject/branches/0.7-bugfix/sqlobject/conftest.py
SQLObject/branches/0.7-bugfix/sqlobject/converters.py
SQLObject/branches/0.7-bugfix/sqlobject/index.py
SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py
Log:
Merged MSSQL support.
For BLOBCol use encode()/decode() from PySQLite1 if available; else use base64.
Modified: SQLObject/branches/0.7-bugfix/setup.py
===================================================================
--- SQLObject/branches/0.7-bugfix/setup.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/setup.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -8,7 +8,8 @@
from distutils.core import setup
subpackages = ['firebird', 'inheritance', 'mysql', 'postgres',
- 'sqlite', 'sybase', 'maxdb', 'util', 'manager']
+ 'sqlite', 'sybase', 'maxdb', 'util', 'manager',
+ 'mssql']
import sys
# patch distutils if it can't cope with the "classifiers" keyword
Modified: SQLObject/branches/0.7-bugfix/sqlobject/__init__.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/__init__.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/__init__.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -42,3 +42,8 @@
def MaxdbConnection(*args, **kw):
_warn('MaxdbConnection is deprecated; use connectionForURI("maxdb://...") or "from sqlobject.maxdb import builder; MaxdbConnection = builder()"')
return _maxdb.builder()(*args, **kw)
+
+import mssql as _mssql
+def MSSQLConnection(*args, **kw):
+ _warn('MssqlConnection is deprecated; use connectionForURI("mssql://...") or "from sqlobject.mssql import builder; MSSQLConnection = builder()"')
+ return _mssql.builder()(*args, **kw)
Modified: SQLObject/branches/0.7-bugfix/sqlobject/col.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/col.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/col.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -311,6 +311,9 @@
def _sybaseType(self):
return self._sqlType()
+ def _mssqlType(self):
+ return self._sqlType()
+
def _firebirdType(self):
return self._sqlType()
@@ -329,6 +332,9 @@
def sybaseCreateSQL(self):
return ' '.join([self.dbName, self._sybaseType()] + self._extraSQL())
+ def mssqlCreateSQL(self):
+ return ' '.join([self.dbName, self._mssqlType()] + self._extraSQL())
+
def firebirdCreateSQL(self):
# Ian Sparks pointed out that fb is picky about the order
# of the NOT NULL clause in a create statement. So, we handle
@@ -466,6 +472,17 @@
type += ' NULL'
return type
+ def _mssqlType(self):
+ if not self.length:
+ type = 'varchar(4000)'
+ elif self.varchar:
+ type = 'VARCHAR(%i)' % self.length
+ else:
+ type = 'CHAR(%i)' % self.length
+ if not self.notNone and not self.alternateID:
+ type += ' NULL'
+ return type
+
def _firebirdType(self):
self._check_case_sensitive("FireBird")
if not self.length:
@@ -612,6 +629,9 @@
def _sybaseType(self):
return "BIT"
+ def _mssqlType(self):
+ return "BIT"
+
def _firebirdType(self):
return 'INT'
@@ -682,6 +702,9 @@
def _sybaseType(self):
return 'NUMERIC(18,0) NULL'
+
+ def _mssqlType(self):
+ return 'INT NULL'
def _firebirdType(self):
return 'INT'
@@ -742,6 +765,17 @@
sql = ' '.join([sql, reference])
return sql
+ def mssqlCreateSQL(self):
+ sql = SOKeyCol.mssqlCreateSQL(self)
+ other = findClass(self.foreignKey)
+ tName = other.sqlmeta.table
+ idName = other.sqlmeta.idName
+ reference = ('REFERENCES %(tName)s(%(idName)s) ' %
+ {'tName':tName,
+ 'idName':idName})
+ sql = ' '.join([sql, reference])
+ return sql
+
def maxdbCreateSQL(self):
other = findClass(self.foreignKey)
fidName = self.dbName
@@ -790,6 +824,9 @@
def _sybaseType(self):
return self._postgresType()
+ def _mssqlType(self):
+ return self._postgresType()
+
def _firebirdType(self):
length = max(map(self._getlength, self.enumValues))
enumValues = ', '.join([sqlbuilder.sqlrepr(v, 'firebird') for v in self.enumValues])
@@ -923,6 +960,9 @@
def _sybaseType(self):
return 'DATETIME'
+ def _mssqlType(self):
+ return 'DATETIME'
+
def _sqliteType(self):
return 'TIMESTAMP'
@@ -985,6 +1025,12 @@
def _sybaseType(self):
return self._postgresType()
+
+ def _mssqlType(self):
+ """
+ SQL Server doesn't have a DATE data type, to emulate we use a vc(10)
+ """
+ return 'VARCHAR(10)'
def _firebirdType(self):
return 'DATE'
@@ -1093,7 +1139,7 @@
return None
if isinstance(value, str):
module = state.soObject._connection.module
- if module.__name__ == "sqlite":
+ if module.__name__ in ("sqlite", "pysqlite2.dbapi2"):
value = module.decode(value)
return value
if isinstance(value, (buffer_type, state.soObject._connection._binaryType)):
@@ -1132,6 +1178,9 @@
def _postgresType(self):
return 'BYTEA'
+ def _mssqlType(self):
+ return "IMAGE"
+
class BLOBCol(StringCol):
baseClass = SOBLOBCol
Modified: SQLObject/branches/0.7-bugfix/sqlobject/conftest.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/conftest.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/conftest.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -20,6 +20,7 @@
'sqlite': 'sqlite:///%s/data/sqlite.data' % os.getcwd(),
'sybase': 'sybase://test:test123@sybase/test?autoCommit=0',
'firebird': 'firebird://sysdba:masterkey@localhost/var/lib/firebird/data/test.gdb',
+ 'mssql': 'mssql://sa:@127.0.0.1/test'
}
Option = py.test.Config.Option
Modified: SQLObject/branches/0.7-bugfix/sqlobject/converters.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/converters.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/converters.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -112,7 +112,7 @@
if db in ('mysql', 'postgres'):
for orig, repl in sqlStringReplace:
value = value.replace(orig, repl)
- elif db in ('sqlite', 'firebird', 'sybase', 'maxdb'):
+ elif db in ('sqlite', 'firebird', 'sybase', 'maxdb', 'mssql'):
value = value.replace("'", "''")
else:
assert 0, "Database %s unknown" % db
Modified: SQLObject/branches/0.7-bugfix/sqlobject/index.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/index.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/index.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -77,8 +77,7 @@
', '.join(spec))
return ret
- postgresCreateIndexSQL = maxdbCreateIndexSQL = sybaseCreateIndexSQL = firebirdCreateIndexSQL = sqliteCreateIndexSQL
-
+ postgresCreateIndexSQL = maxdbCreateIndexSQL = mssqlCreateIndexSQL = sybaseCreateIndexSQL = firebirdCreateIndexSQL = sqliteCreateIndexSQL
def mysqlCreateIndexSQL(self, soClass):
if self.unique:
uniqueOrIndex = 'UNIQUE'
Added: SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -0,0 +1,17 @@
+from sqlobject.dbconnection import registerConnection
+
+def builder():
+ import mssqlconnection
+ return mssqlconnection.MSSQLConnection
+
+def isSupported(cls):
+ try:
+ import pymssql
+ except ImportError:
+ try:
+ import adodbapi
+ except ImportError:
+ return False
+ return True
+
+registerConnection(['mssql'], builder, isSupported)
Added: SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -0,0 +1,258 @@
+from sqlobject.dbconnection import DBAPI
+from sqlobject import col
+import re
+
+sqlmodule = None
+
+class MSSQLConnection(DBAPI):
+
+ supportTransactions = True
+ dbName = 'mssql'
+ schemes = [dbName]
+
+ def __init__(self, db, user, password='', host='localhost',
+ autoCommit=0, **kw):
+ global sqlmodule
+ if not sqlmodule:
+ try:
+ import adodbapi as sqlmodule
+ self.dbconnection = sqlmodule.connect
+ # ADO uses unicode only (AFAIK)
+ self.usingUnicodeStrings = True
+ # MSDE does not allow SQL server login
+ if "sspi" in kw and kw["sspi"]:
+ self.make_conn_str = lambda keys: \
+ ["Provider=SQLOLEDB;Data Source=%s;Initial Catalog=%s;Integrated Security=SSPI;Persist Security Info=False" % (
+ keys.host, keys.db)]
+ del kw["sspi"]
+ else:
+ self.make_conn_str = lambda keys: \
+ ["Provider=SQLOLEDB;Data Source=%s;User Id=%s;Password=%s;Initial Catalog=%s" % (
+ keys.host, keys.user, keys.password, keys.db)]
+ except ImportError: # raise the exceptions other than ImportError for adodbapi absence
+ import pymssql as sqlmodule
+ self.dbconnection = sqlmodule.connect
+ sqlmodule.Binary = lambda st: str(st)
+ # don't know whether pymssql uses unicode
+ self.usingUnicodeStrings = False
+ self.make_conn_str = lambda keys: \
+ ["", keys.user, keys.password, keys.host, keys.db]
+ self.autoCommit=autoCommit
+ self.host = host
+ self.db = db
+ self.user = user
+ self.password = password
+ self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
+ self.password = password
+ self.module = sqlmodule
+ DBAPI.__init__(self, **kw)
+
+ def connectionFromURI(cls, uri):
+ user, password, host, port, path, args = cls._parseURI(uri)
+ path = path.strip('/')
+ return cls(user=user, password=password, host=host or 'localhost',
+ db=path, **args)
+ connectionFromURI = classmethod(connectionFromURI)
+
+ def insert_id(self, conn):
+ """
+ insert_id method.
+ """
+ c = conn.cursor()
+ # converting the identity to an int is ugly, but it gets returned
+ # as a decimal otherwise :S
+ c.execute('SELECT CONVERT(INT, @@IDENTITY)')
+ return c.fetchone()[0]
+
+ def makeConnection(self):
+ con = self.dbconnection( *self.make_conn_str(self) )
+ cur = con.cursor()
+ cur.execute('SET ANSI_NULLS ON')
+ cur.close()
+ return con
+
+ HAS_IDENTITY = """
+ SELECT col.name, col.status, obj.name
+ FROM syscolumns col
+ JOIN sysobjects obj
+ ON obj.id = col.id
+ WHERE obj.name = '%s'
+ and col.autoval is not null
+
+ """
+ def _hasIdentity(self, conn, table):
+ query = self.HAS_IDENTITY % table
+ c = conn.cursor()
+ c.execute(query)
+ r = c.fetchone()
+ return r is not None
+
+ def _queryInsertID(self, conn, soInstance, id, names, values):
+ """
+ Insert the Initial with names and values, using id.
+ """
+ table = soInstance.sqlmeta.table
+ idName = soInstance.sqlmeta.idName
+ c = conn.cursor()
+ has_identity = self._hasIdentity(conn, table)
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
+ elif has_identity and idName in names:
+ try:
+ i = names.index( idName )
+ if i:
+ del names[i]
+ del values[i]
+ except ValueError:
+ pass
+
+ if has_identity:
+ if id is not None:
+ c.execute('SET IDENTITY_INSERT %s ON' % table)
+ else:
+ c.execute('SET IDENTITY_INSERT %s OFF' % table)
+
+ q = self._insertSQL(table, names, values)
+ if self.debug:
+ print 'QueryIns: %s' % q
+ c.execute(q)
+ if has_identity:
+ c.execute('SET IDENTITY_INSERT %s OFF' % table)
+
+ if id is None:
+ id = self.insert_id(conn)
+ if self.debugOutput:
+ self.printDebug(conn, id, 'QueryIns', 'result')
+ return id
+
+ def _queryAddLimitOffset(self, query, start, end):
+ if end and not start:
+ limit_str = "SELECT TOP %i" % end
+
+ match = self.limit_re.match(query)
+ if match and len(match.groups()) == 2:
+ return ' '.join([limit_str, match.group(2)])
+ else:
+ return query
+
+ def createColumn(self, soClass, col):
+ return col.mssqlCreateSQL()
+
+ def createIDColumn(self, soClass):
+ key_type = {int: "INT", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s IDENTITY UNIQUE' % (soClass.sqlmeta.idName, key_type)
+
+ def createIndexSQL(self, soClass, index):
+ return index.mssqlCreateIndexSQL(soClass)
+
+ def joinSQLType(self, join):
+ return 'INT NOT NULL'
+
+ SHOW_TABLES="SELECT name FROM sysobjects WHERE type='U'"
+ def tableExists(self, tableName):
+ for (table,) in self.queryAll(self.SHOW_TABLES):
+ if table.lower() == tableName.lower():
+ return True
+ return False
+
+ def addColumn(self, tableName, column):
+ self.query('ALTER TABLE %s ADD %s' %
+ (tableName,
+ column.mssqlCreateSQL()))
+
+ def delColumn(self, tableName, column):
+ self.query('ALTER TABLE %s DROP COLUMN %s' %
+ (tableName,
+ column.dbName))
+
+ # precision and scale is gotten from column table so that we can create
+ # decimal columns if needed
+ SHOW_COLUMNS = """
+ select
+ name,
+ length,
+ ( select name
+ from systypes
+ where cast(xusertype as int)= cast(sc.xtype as int)
+ ) datatype,
+ prec,
+ scale,
+ isnullable,
+ cdefault,
+ m.text default_text,
+ isnull(len(autoval),0) is_identity
+ from syscolumns sc
+ LEFT OUTER JOIN syscomments m on sc.cdefault = m.id
+ AND m.colid = 1
+ where
+ sc.id in (select id
+ from sysobjects
+ where name = '%s')
+ order by
+ colorder"""
+
+ def columnsFromSchema(self, tableName, soClass):
+ colData = self.queryAll(self.SHOW_COLUMNS
+ % tableName)
+ results = []
+ for field, size, t, precision, scale, nullAllowed, default, defaultText, is_identity in colData:
+ # Seems strange to skip the pk column? What if it's not 'id'?
+ if field == 'id':
+ continue
+ # precision is needed for decimal columns
+ colClass, kw = self.guessClass(t, size, precision, scale)
+ kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field)
+ kw['notNone'] = not nullAllowed
+ if (defaultText):
+ # Strip ( and )
+ defaultText = defaultText[1:-1]
+ if defaultText[0] == "'":
+ defaultText = defaultText[1:-1]
+ else:
+ if t == "int" : defaultText = int(defaultText)
+ if t == "float" : defaultText = float(defaultText)
+ if t == "numeric": defaultText = float(defaultText)
+ # TODO need to access the "column" to_python method here--but the object doesn't exists yet
+
+ # @@ skip key...
+ kw['default'] = defaultText
+
+ results.append(colClass(**kw))
+ return results
+
+ def _setAutoCommit(self, conn, auto):
+ #raise Exception(repr(auto))
+ return
+ #conn.auto_commit = auto
+ option = "ON"
+ if auto == 0:
+ option = "OFF"
+ c = conn.cursor()
+ c.execute("SET AUTOCOMMIT " + option)
+ conn.setconnectoption(SQL.AUTOCOMMIT, option)
+
+ # precision and scale is needed for decimal columns
+ def guessClass(self, t, size, precision, scale):
+ """
+ Here we take raw values coming out of syscolumns and map to SQLObject class types.
+ """
+ if t.startswith('int'):
+ return col.IntCol, {}
+ elif t.startswith('varchar'):
+ if self.usingUnicodeStrings:
+ return col.UnicodeCol, {'length': size}
+ return col.StringCol, {'length': size}
+ elif t.startswith('char'):
+ if self.usingUnicodeStrings:
+ return col.UnicodeCol, {'length': size,
+ 'varchar': False}
+ return col.StringCol, {'length': size,
+ 'varchar': False}
+ elif t.startswith('datetime'):
+ return col.DateTimeCol, {}
+ elif t.startswith('decimal'):
+ return col.DecimalCol, {'size': precision, # be careful for awkward naming
+ 'precision': scale}
+ else:
+ return col.Col, {}
Modified: SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -3,6 +3,7 @@
sqlite = None
using_sqlite2 = False
+sqlite2_Binary = None
class SQLiteConnection(DBAPI):
@@ -34,6 +35,19 @@
for col_type in "text", "char", "varchar":
sqlite.register_converter(col_type, stop_pysqlite2_converting_strings_to_unicode)
sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings_to_unicode)
+ try:
+ from sqlite import encode, decode
+ except ImportError:
+ import base64
+ sqlite.encode = base64.encodestring
+ sqlite.decode = base64.decodestring
+ else:
+ sqlite.encode = encode
+ sqlite.decode = decode
+ global sqlite2_Binary
+ if sqlite2_Binary is None:
+ sqlite2_Binary = sqlite.Binary
+ sqlite.Binary = lambda s: sqlite2_Binary(sqlite.encode(s))
else:
opts['autocommit'] = autoCommit
if 'encoding' in kw:
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -34,10 +34,14 @@
supportsMatrix = {
'+restrictedEnum': 'postgres',
'-transactions': 'mysql',
- '-dropTableCascade': 'sybase',
+ '-dropTableCascade': 'sybase mssql',
'-dynamicColumn': 'sqlite sybase',
'-fromDatabase': 'sqlite sybase firebird',
- '-expressionIndex': 'mysql sqlite firebird',
+ '-expressionIndex': 'mysql sqlite firebird mssql',
+ '-blobData': 'mssql',
+ '-decimalColumn': 'mssql',
+ '-emptyTable': 'mssql',
+ '-limitSelect' : 'mssql'
}
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -106,10 +106,24 @@
age INT DEFAULT 0,
created VARCHAR(40) NOT NULL,
happy char(1) DEFAULT 'Y' NOT NULL,
- long_field TEXT
+ long_field TEXT,
+ wannahavefun BIT default(0) NOT NULL
)
"""
+ mssqlCreate = """
+ CREATE TABLE auto_test (
+ auto_id int identity(1,1),
+ first_name VARCHAR(100),
+ last_name VARCHAR(200) NOT NULL,
+ age INT DEFAULT 0,
+ created VARCHAR(40) NOT NULL,
+ happy char(1) DEFAULT 'Y' NOT NULL,
+ long_field TEXT,
+ wannahavefun BIT default(0) NOT NULL
+ )
+ """
+
mysqlDrop = """
DROP TABLE IF EXISTS auto_test
"""
@@ -122,6 +136,8 @@
DROP TABLE auto_test
"""
+ mssqlDrop = sybaseDrop
+
def setup_method(self, meth):
conn = getConnection()
dbName = conn.dbName
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -112,6 +112,19 @@
)
"""
+ mssqlCreate = """
+ CREATE TABLE old_auto_test (
+ auto_id int IDENTITY(1,1) primary key,
+ first_name VARCHAR(100),
+ last_name VARCHAR(200) NOT NULL,
+ age INT DEFAULT 0,
+ created VARCHAR(40) NOT NULL,
+ happy char(1) DEFAULT 'Y' NOT NULL,
+ long_field TEXT,
+ wannahavefun BIT default(0) NOT NULL
+ )
+ """
+
mysqlDrop = """
DROP TABLE IF EXISTS old_auto_test
"""
@@ -124,6 +137,9 @@
DROP TABLE old_auto_test
"""
+ mssqlDrop = """
+ DROP TABLE old_auto_test
+ """
def setup_method(self, meth):
conn = getConnection()
dbName = conn.dbName
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -9,6 +9,8 @@
image = BLOBCol(default='emptydata', length=65535)
def test_BLOBCol():
+ if not supports('blobData'):
+ return
setupClass(ImageData)
data = ''.join([chr(x) for x in range(256)])
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -7,18 +7,20 @@
Decimal = None
########################################
-## Deciaml columns
+## Decimal columns
########################################
class DecimalTable(SQLObject):
col1 = DecimalCol(size=6, precision=4)
def test_1decimal():
+ if not supports('decimalColumn'):
+ return
setupClass(DecimalTable)
d = DecimalTable(col1=21.12)
assert d.col1 == 21.12
-if Decimal:
+if Decimal and supports('decimalColumn'):
def test_2Decimal():
setupClass(DecimalTable)
d = DecimalTable(col1=Decimal("21.12"))
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -6,6 +6,8 @@
pass
def test_empty():
+ if not supports('emptyTable'):
+ return
setupClass(EmptyClass)
e1 = EmptyClass()
e2 = EmptyClass()
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -29,7 +29,7 @@
mod = SOIndex1._connection.module
try:
SOIndex1(name='blah', number=0)
- except (mod.ProgrammingError, mod.IntegrityError, mod.OperationalError):
+ except (mod.ProgrammingError, mod.IntegrityError, mod.OperationalError, mod.DatabaseError):
# expected
pass
else:
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -56,6 +56,8 @@
assert count == len(names)
def test_04_indexed_ended_by_exception():
+ if not supports('limitSelect'):
+ return
all = IterTest.select()
count = 0
try:
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -17,6 +17,8 @@
Counter(number=i)
def counterEqual(self, counters, value):
+ if not supports('limitSelect'):
+ return
assert [c.number for c in counters] == value
def test_1(self):
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -9,7 +9,7 @@
class sqlmeta(sqlmeta):
table = 'so_string_id'
- _idType = str
+ idType = str
val = StringCol(alternateID=True)
mysqlCreate = """
@@ -40,6 +40,13 @@
)
"""
+ mssqlCreate = """
+ CREATE TABLE so_string_id (
+ id VARCHAR(50) PRIMARY KEY,
+ val varchar(4000)
+ )
+ """
+
sqliteCreate = postgresCreate
mysqlDrop = """
@@ -52,8 +59,8 @@
sqliteDrop = postgresDrop
firebirdDrop = postgresDrop
+ mssqlDrop = postgresDrop
-
def test_stringID():
setupClass(SOStringID)
t = SOStringID(id='hey', val='whatever')
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -34,6 +34,13 @@
)
"""
+ mssqlCreate = """
+ CREATE TABLE so_string_id (
+ id VARCHAR(50) primary key,
+ val VARCHAR(50) NULL
+ )
+ """
+
firebirdCreate = """
CREATE TABLE so_string_id (
id VARCHAR(50) NOT NULL PRIMARY KEY,
@@ -53,6 +60,7 @@
sqliteDrop = postgresDrop
firebirdDrop = postgresDrop
+ mssqlDrop = postgresDrop
def test_stringID():
|
|
From: <sub...@co...> - 2005-11-30 18:36:03
|
Author: phd
Date: 2005-11-30 18:35:57 +0000 (Wed, 30 Nov 2005)
New Revision: 1329
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
Log:
For BLOBCol use encode()/decode() from PySQLite1 if available; else use base64.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2005-11-30 18:02:37 UTC (rev 1328)
+++ SQLObject/trunk/sqlobject/col.py 2005-11-30 18:35:57 UTC (rev 1329)
@@ -1204,7 +1204,7 @@
return None
if isinstance(value, str):
module = state.soObject._connection.module
- if module.__name__ == "sqlite":
+ if module.__name__ in ("sqlite", "pysqlite2.dbapi2"):
value = module.decode(value)
return value
if isinstance(value, (buffer_type, state.soObject._connection._binaryType)):
Modified: SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:02:37 UTC (rev 1328)
+++ SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:35:57 UTC (rev 1329)
@@ -3,6 +3,7 @@
sqlite = None
using_sqlite2 = False
+sqlite2_Binary = None
class SQLiteConnection(DBAPI):
@@ -34,6 +35,19 @@
for col_type in "text", "char", "varchar":
sqlite.register_converter(col_type, stop_pysqlite2_converting_strings_to_unicode)
sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings_to_unicode)
+ try:
+ from sqlite import encode, decode
+ except ImportError:
+ import base64
+ sqlite.encode = base64.encodestring
+ sqlite.decode = base64.decodestring
+ else:
+ sqlite.encode = encode
+ sqlite.decode = decode
+ global sqlite2_Binary
+ if sqlite2_Binary is None:
+ sqlite2_Binary = sqlite.Binary
+ sqlite.Binary = lambda s: sqlite2_Binary(sqlite.encode(s))
else:
opts['autocommit'] = autoCommit
if 'encoding' in kw:
|
|
From: SourceForge.net <no...@so...> - 2005-11-30 18:32:57
|
Patches item #1370278, was opened at 2005-11-30 12:32 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1370278&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Luke Opperman (luke_opperman) Assigned to: Nobody/Anonymous (nobody) Summary: Synchronize main connection cache during transaction commit Initial Comment: See this thread: http://pythonpaste.org/archives/message/20051129.172427.0ec7941f.en.html And this earlier one: http://sourceforge.net/mailarchive/message.php?msg_id=11354123 This fix deals with something not mentioned in the latter message, objects deleted as part of the transaction. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1370278&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-11-30 18:13:28
|
Patches item #1370261, was opened at 2005-11-30 12:13 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1370261&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Luke Opperman (luke_opperman) Assigned to: Nobody/Anonymous (nobody) Summary: Fix for plain/nonplain setters during create Initial Comment: Using rev 1326 (probably long before this, found it during attempting to migrate an 0.5-based app to svn version). I've attached a simple test case, the problem is in main.SQLObject.set. Flow: 1. set plain setters 2. set nonplain setters (in this case, a non-db column) 2a. in the problem scenario, these then set some db columns 2b. which in _SO_setValue add their correct values to _SO_createValues 3. set then updates _SO_createValues with the original dict, which has the default values for the db columns set by the nonplain. Not sure if there's an intentional reason to delay populating _SO_createValues, by moving self._SO_createValues.update(kw) between steps 1 and 2 the tests pass for me. This is that simple patch and the associated test. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1370261&group_id=74338 |
|
From: <sub...@co...> - 2005-11-30 18:02:48
|
Author: phd
Date: 2005-11-30 18:02:37 +0000 (Wed, 30 Nov 2005)
New Revision: 1328
Modified:
SQLObject/trunk/sqlobject/events.py
SQLObject/trunk/sqlobject/tests/test_events.py
Log:
Moved sorted() from tests/test_events.py to events.py.
Modified: SQLObject/trunk/sqlobject/events.py
===================================================================
--- SQLObject/trunk/sqlobject/events.py 2005-11-29 23:04:57 UTC (rev 1327)
+++ SQLObject/trunk/sqlobject/events.py 2005-11-30 18:02:37 UTC (rev 1328)
@@ -269,6 +269,24 @@
else:
return repr(v)
+try:
+ sorted
+except NameError:
+ # For Python 2.2 and 2.3:
+ def sorted(lst, cmp=None, key=None, reverse=False):
+ if key:
+ lst = [(key(i), i) for i in lst]
+ lst = lst[:]
+ if cmp:
+ lst.sort(cmp)
+ else:
+ lst.sort()
+ if key:
+ lst = [i for k, i in lst]
+ if reverse:
+ lst.reverse()
+ return lst
+
__all__ = ['listen', 'send']
for name, value in globals().items():
if isinstance(value, type) and issubclass(value, Signal):
Modified: SQLObject/trunk/sqlobject/tests/test_events.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_events.py 2005-11-29 23:04:57 UTC (rev 1327)
+++ SQLObject/trunk/sqlobject/tests/test_events.py 2005-11-30 18:02:37 UTC (rev 1328)
@@ -3,24 +3,6 @@
from sqlobject import events
import sys
-try:
- sorted
-except NameError:
- # For Python 2.3 and under:
- def sorted(lst, cmp=None, key=None, reverse=False):
- if key:
- lst = [(key(i), i) for i in lst]
- lst = lst[:]
- if cmp:
- lst.sort(cmp)
- else:
- lst.sort()
- if key:
- lst = [i for k, i in lst]
- if reverse:
- lst.reverse()
- return lst
-
class EventTester(SQLObject):
name = StringCol()
|
|
From: SourceForge.net <no...@so...> - 2005-11-30 09:20:40
|
Bugs item #1369871, was opened at 2005-11-30 01:20 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1369871&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: SQLObject release (specify) Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: v0.6: dropTable can not drop CASCADEing Initial Comment: Traceback (most recent call last): File "./cdb.py", line 1403, in ? main() File "./cdb.py", line 1399, in main m = mutateDb() File "./cdb.py", line 523, in __init__ self.cdb = clusterDb() File "/home/ramon/src/lisa/rc_db_utils/so_redesign/cluster_database.py", line 93, in __init__ table.dropTable( ifExists = True, dropJoinTables = True ) File "/usr/lib/python2.3/site-packages/sqlobject/main.py", line 967, in dropTable cls._connection.dropTable(cls._table, cascade) File "/usr/lib/python2.3/site-packages/sqlobject/postgres/pgconnection.py", line 93, in dropTable self.query("DROP TABLE %s %s" % (tableName, File "/usr/lib/python2.3/site-packages/sqlobject/dbconnection.py", line 196, in query return self._runWithConnection(self._query, s) File "/usr/lib/python2.3/site-packages/sqlobject/dbconnection.py", line 117, in _runWithConnection val = meth(conn, *args) File "/usr/lib/python2.3/site-packages/sqlobject/dbconnection.py", line 193, in _query self._executeRetry(conn, conn.cursor(), s) File "/usr/lib/python2.3/site-packages/sqlobject/dbconnection.py", line 188, in _executeRetry return cursor.execute(query) psycopg.ProgrammingError: ERROR: cannot drop table network because other objects depend on it HINT: Use DROP ... CASCADE to drop the dependent objects too. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1369871&group_id=74338 |
|
From: <sub...@co...> - 2005-11-28 09:17:02
|
Author: phd
Date: 2005-11-28 09:16:53 +0000 (Mon, 28 Nov 2005)
New Revision: 1326
Added:
home/phd/SQLObject/paramstyles/sqlobject/tests/test_combining_joins.py
Modified:
home/phd/SQLObject/paramstyles/sqlobject/boundattributes.py
home/phd/SQLObject/paramstyles/sqlobject/declarative.py
home/phd/SQLObject/paramstyles/sqlobject/joins.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py
Log:
Merged patches from the revisions 1314:1325 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/boundattributes.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/boundattributes.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/boundattributes.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -27,6 +27,7 @@
'bind_attributes_local']
import declarative
+import events
class BoundAttribute(declarative.Declarative):
@@ -41,6 +42,8 @@
name, **attrs)`` and maybe ``set_object(added_class, name,
**attrs)`` (the default implementation of ``set_object``
just resets the attribute to whatever ``make_object`` returned).
+
+ Also see ``BoundFactory``.
"""
_private_variables = (
@@ -51,9 +54,11 @@
'_add_attrs',
'set_object',
'make_object',
+ 'clone_in_subclass',
)
_all_attrs = ()
+ clone_for_subclass = True
def __classinit__(cls, new_attrs):
declarative.Declarative.__classinit__(cls, new_attrs)
@@ -61,7 +66,7 @@
def __instanceinit__(self, new_attrs):
declarative.Declarative.__instanceinit__(self, new_attrs)
- self._all_attrs = self._add_attrs(self, new_attrs)
+ self.__dict__['_all_attrs'] = self._add_attrs(self, new_attrs)
def _add_attrs(this_object, new_attrs):
private = this_object._private_variables
@@ -82,6 +87,18 @@
attrs['added_class'] = added_class
attrs['attr_name'] = attr_name
obj = me.make_object(**attrs)
+
+ if self.clone_for_subclass:
+ def on_rebind(new_class_name, bases, new_attrs,
+ post_funcs, early_funcs):
+ def rebind(new_class):
+ me.set_object(
+ new_class, attr_name,
+ me.make_object(**attrs))
+ post_funcs.append(rebind)
+ events.listen(receiver=on_rebind, soClass=added_class,
+ signal=events.ClassCreateSignal, weak=False)
+
me.set_object(added_class, attr_name, obj)
__addtoclass__ = declarative.classinstancemethod(__addtoclass__)
@@ -96,29 +113,24 @@
make_object = classmethod(make_object)
+ def __setattr__(self, name, value):
+ self.__dict__['_all_attrs'] = self._add_attrs(self, {name: value})
+ self.__dict__[name] = value
+
class BoundFactory(BoundAttribute):
+ """
+ This will bind the attribute to whatever is given by
+ ``factory_class``. This factory should be a callable with the
+ signature ``factory_class(added_class, attr_name, *args, **kw)``.
+
+ The factory will be reinvoked (and the attribute rebound) for
+ every subclassing.
+ """
+
factory_class = None
+ _private_variables = (
+ BoundAttribute._private_variables + ('factory_class',))
def make_object(cls, added_class, attr_name, *args, **kw):
return cls.factory_class(added_class, attr_name, *args, **kw)
-
-def bind_attributes(cls, new_attrs):
- for name, value in new_attrs.items():
- if hasattr(value, '__addtoclass__'):
- value.__addtoclass__(cls, name)
-
-def bind_attributes_local(cls, new_attrs):
- new_bound_attributes = {}
- for name, value in getattr(cls, '__bound_attributes__', {}).items():
- if new_attrs.has_key(name):
- # The attribute is being REbound, so don't try to bind it
- # again.
- continue
- value.__addtoclass__(cls, name)
- new_bound_attributes[name] = value
- for name, value in new_attrs.items():
- if hasattr(value, '__addtoclass__'):
- value.__addtoclass__(cls, name)
- new_bound_attributes[name] = value
- cls.__bound_attributes__ = new_bound_attributes
Modified: home/phd/SQLObject/paramstyles/sqlobject/declarative.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/declarative.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/declarative.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -112,6 +112,8 @@
__metaclass__ = DeclarativeMeta
+ __restrict_attributes__ = None
+
def __classinit__(cls, new_attrs):
cls.declarative_count = counter.next()
for name in cls.__mutableattributes__:
@@ -119,6 +121,12 @@
setattr(cls, copy.copy(getattr(cls, name)))
def __instanceinit__(self, new_attrs):
+ if self.__restrict_attributes__ is not None:
+ for name in new_attrs:
+ if name not in self.__restrict_attributes__:
+ raise TypeError(
+ '%s() got an unexpected keyword argument %r'
+ % (self.__class__.__name__, name))
for name, value in new_attrs.items():
setattr(self, name, value)
if not new_attrs.has_key('declarative_count'):
Modified: home/phd/SQLObject/paramstyles/sqlobject/joins.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/joins.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/joins.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -268,43 +268,24 @@
+import boundattributes
-class ManyToMany(object):
-
- def __init__(self, otherClassName,
- intermediateTable=None,
- joinColumn=None,
- otherColumn=None,
- createJoinTable=True):
- self.otherClassName = otherClassName
- self.intermediateTable = intermediateTable
- self.joinColumn = joinColumn
- self.otherColumn = otherColumn
- self.createJoinTable = createJoinTable
-
- def __addtoclass__(self, soClass, name):
- setattr(soClass, name,
- SOManyToMany(soClass, name=name,
- otherClassName=self.otherClassName,
- intermediateTable=self.intermediateTable,
- joinColumn=self.joinColumn,
- otherColumn=self.otherColumn,
- createJoinTable=self.createJoinTable))
-
class SOManyToMany(object):
- def __init__(self, soClass, name, otherClassName,
+ def __init__(self, soClass, name, join,
intermediateTable, joinColumn, otherColumn,
- createJoinTable):
+ createJoinTable, **attrs):
self.name = name
self.intermediateTable = intermediateTable
self.joinColumn = joinColumn
self.otherColumn = otherColumn
self.createJoinTable = createJoinTable
self.soClass = self.otherClass = None
+ for name, value in attrs.items():
+ setattr(self, name, value)
classregistry.registry(
soClass.sqlmeta.registry).addClassCallback(
- otherClassName, self._setOtherClass)
+ join, self._setOtherClass)
classregistry.registry(
soClass.sqlmeta.registry).addClassCallback(
soClass.__name__, self._setThisClass)
@@ -335,6 +316,11 @@
self.soClass, events.CreateTableSignal)
events.listen(self.event_CreateTableSignal,
self.otherClass, events.CreateTableSignal)
+ self.clause = (
+ (self.otherClass.q.id ==
+ sqlbuilder.Field(self.intermediateTable, self.otherColumn))
+ & (sqlbuilder.Field(self.intermediateTable, self.joinColumn)
+ == self.soClass.q.id))
def __get__(self, obj, type):
if obj is None:
@@ -345,10 +331,7 @@
& (sqlbuilder.Field(self.intermediateTable, self.joinColumn)
== obj.id))
select = self.otherClass.select(query)
- return _ManyToManySelectWrapper(obj, self, select)
-
- def __sqlrepr__(self, dbname):
- return self.query.__sqlrepr__(self, dbname)
+ return _ManyToManySelectWrapper(obj, self, select)
def event_CreateTableSignal(self, soClass, connection, extra_sql,
post_funcs):
@@ -359,6 +342,19 @@
if connection.tableExists(self.intermediateTable):
return
connection._SO_createJoinTable(self)
+
+class ManyToMany(boundattributes.BoundFactory):
+ factory_class = SOManyToMany
+ __restrict_attributes__ = (
+ 'join', 'intermediateTable',
+ 'joinColumn', 'otherColumn', 'createJoinTable')
+ __unpackargs__ = ('join',)
+
+ # Default values:
+ intermediateTable = None
+ joinColumn = None
+ otherColumn = None
+ createJoinTable = True
class _ManyToManySelectWrapper(object):
@@ -370,7 +366,7 @@
def __getattr__(self, attr):
# @@: This passes through private variable access too... should it?
# Also magic methods, like __str__
- return getattr(self.select, attr)
+ return getattr(self, select, attr)
def __repr__(self):
return '<%s for: %s>' % (self.__class__.__name__, repr(self.select))
@@ -385,7 +381,6 @@
return self.select[key]
def add(self, obj):
- print "Add", obj, "to", self.forObject
obj._connection._SO_intermediateInsert(
self.join.intermediateTable,
self.join.joinColumn,
@@ -405,34 +400,27 @@
obj = self.join.otherClass(**kw)
self.add(obj)
return obj
-
-class OneToMany(object):
-
- def __init__(self, otherClassName, joinColumn=None):
- self.otherClassName = otherClassName
- self.joinColumn = joinColumn
-
- def __addtoclass__(self, soClass, name):
- setattr(soClass, name,
- SOOneToMany(soClass, name=name,
- otherClassName=self.otherClassName,
- joinColumn=self.joinColumn))
class SOOneToMany(object):
- def __init__(self, soClass, name, otherClassName, joinColumn):
+ def __init__(self, soClass, name, join, joinColumn, **attrs):
self.soClass = soClass
self.name = name
self.joinColumn = joinColumn
+ for name, value in attrs.items():
+ setattr(self, name, value)
classregistry.registry(
soClass.sqlmeta.registry).addClassCallback(
- otherClassName, self._setOtherClass)
+ join, self._setOtherClass)
def _setOtherClass(self, otherClass):
self.otherClass = otherClass
if not self.joinColumn:
self.joinColumn = styles.getStyle(
self.soClass).tableReference(self.soClass.sqlmeta.table)
+ self.clause = (
+ sqlbuilder.Field(self.otherClass.sqlmeta.table, self.joinColumn)
+ == self.soClass.q.id)
def __get__(self, obj, type):
if obj is None:
@@ -443,6 +431,15 @@
select = self.otherClass.select(query)
return _OneToManySelectWrapper(obj, self, select)
+class OneToMany(boundattributes.BoundFactory):
+ factory_class = SOOneToMany
+ __restrict_attributes__ = (
+ 'join', 'joinColumn')
+ __unpackargs__ = ('join',)
+
+ # Default values:
+ joinColumn = None
+
class _OneToManySelectWrapper(object):
def __init__(self, forObject, join, select):
@@ -453,7 +450,7 @@
def __getattr__(self, attr):
# @@: This passes through private variable access too... should it?
# Also magic methods, like __str__
- return getattr(self, select, attr)
+ return getattr(self.select, attr)
def __repr__(self):
return '<%s for: %s>' % (self.__class__.__name__, repr(self.select))
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -701,8 +701,6 @@
def __classinit__(cls, new_attrs):
- declarative.setup_attributes(cls, new_attrs)
-
# This is true if we're initializing the SQLObject class,
# instead of a subclass:
is_base = cls.__bases__ == (object,)
@@ -800,6 +798,10 @@
if connection and not hasattr(cls, '_connection'):
cls.setConnection(connection)
+ # Now the class is in an essentially OK-state, so we can
+ # set up any magic attributes:
+ declarative.setup_attributes(cls, new_attrs)
+
# We have to check if there are columns in the inherited
# _columns where the attribute has been set to None in this
# class. If so, then we need to remove that column from
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -161,14 +161,18 @@
"""
sql = getattr(soClass, soClass._connection.dbName + 'Create',
None)
+ all_extra = []
if sql:
soClass._connection.query(sql)
else:
- sql, constraints = soClass.createTableSQL()
+ sql, extra_sql = soClass.createTableSQL()
soClass.createTable()
+ all_extra.extend(extra_sql)
cls(tableName=soClass.sqlmeta.table,
createSQL=sql,
connectionURI=soClass._connection.uri())
+ for extra_sql in all_extra:
+ soClass._connection.query(extra_sql)
install = classmethod(install)
def drop(cls, soClass):
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_basic.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -279,5 +279,6 @@
def testAsDict():
setupGetters(TestSO1)
bob = TestSO1.selectBy(name='bob')[0]
- assert bob.sqlmeta.asDict() == {'passwd': 'tbq', 'name': 'bob'}
+ assert bob.sqlmeta.asDict() == {
+ 'passwd': 'tbq', 'name': 'bob', 'id': bob.id}
Copied: home/phd/SQLObject/paramstyles/sqlobject/tests/test_combining_joins.py (from rev 1325, SQLObject/trunk/sqlobject/tests/test_combining_joins.py)
Property changes on: home/phd/SQLObject/paramstyles/sqlobject/tests/test_combining_joins.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py 2005-11-27 05:54:15 UTC (rev 1325)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_events.py 2005-11-28 09:16:53 UTC (rev 1326)
@@ -3,6 +3,24 @@
from sqlobject import events
import sys
+try:
+ sorted
+except NameError:
+ # For Python 2.3 and under:
+ def sorted(lst, cmp=None, key=None, reverse=False):
+ if key:
+ lst = [(key(i), i) for i in lst]
+ lst = lst[:]
+ if cmp:
+ lst.sort(cmp)
+ else:
+ lst.sort()
+ if key:
+ lst = [i for k, i in lst]
+ if reverse:
+ lst.reverse()
+ return lst
+
class EventTester(SQLObject):
name = StringCol()
|
|
From: SourceForge.net <no...@so...> - 2005-11-28 01:18:59
|
Bugs item #1367868, was opened at 2005-11-27 17:18 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1367868&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: SQLObject release (specify) Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Newlines escaped in PickleCol Initial Comment: Looks like the PickleCol is having its newlines escaped, which seems to ruin the pickle. Using version 0.7b1dev. Here's some example code: """ class Session(SQLObject): data = PickleCol() try: s = Session(data={'one': 1, 'two': range(10)}) except Exception, msg: print msg print msg.state print msg.value """ ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1367868&group_id=74338 |