sqlobject-cvs Mailing List for SQLObject (Page 137)
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: SourceForge.net <no...@so...> - 2006-02-11 10:40:17
|
Patches item #1423272, was opened at 2006-02-03 05:00 Message generated for change (Comment added) made by ianbicking You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423272&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: Closed >Resolution: Accepted Priority: 5 Submitted By: Rick Richardson (rovar) Assigned to: Nobody/Anonymous (nobody) Summary: Events RowCreateSignal not really useful, added post-create Initial Comment: The RoWCreateSignal suffers from two drawbacks based on the fact that it fires before a row is created. First, it can't give a reference to the created row (which is what i would picture a large percentage of users would want it for) Secondly, it fires whether the row was successfully created or not. In the case of the auditing system that i'm writing. I desperately need these two features. So I added a RowCreatedSignal and then added the code to invoke it in the _SO_finishCreate function and it passes the created ID and the class to the callback. I've tested it. seems to work alright. Attached is the patch if you wish to use it. Rick ---------------------------------------------------------------------- >Comment By: Ian Bicking (ianbicking) Date: 2006-02-11 04:40 Message: Logged In: YES user_id=210337 Applied in r1596. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423272&group_id=74338 |
|
From: <sub...@co...> - 2006-02-11 10:40:05
|
Author: ianb
Date: 2006-02-11 03:39:57 -0700 (Sat, 11 Feb 2006)
New Revision: 1596
Modified:
SQLObject/trunk/sqlobject/events.py
SQLObject/trunk/sqlobject/main.py
Log:
Applied SF [ 1423272 ] Events RowCreateSignal not really useful, added post-create from Rick Richardson
Modified: SQLObject/trunk/sqlobject/events.py
===================================================================
--- SQLObject/trunk/sqlobject/events.py 2006-02-11 10:37:34 UTC (rev 1595)
+++ SQLObject/trunk/sqlobject/events.py 2006-02-11 10:39:57 UTC (rev 1596)
@@ -79,7 +79,18 @@
Note: this is not called when an instance is created from an
existing database row.
"""
+class RowCreatedSignal(Signal):
+ """
+ Called after an instance is created, with the class as the
+ sender. Called with the arguments ``(kwargs, post_funcs)``.
+ There may be a ``connection`` argument. ``kwargs``may be usefully
+ modified. ``post_funcs`` is a list of callbacks, intended to have
+ functions appended to it, and are called with the arguments
+ ``(new_instance)``.
+ Note: this is not called when an instance is created from an
+ existing database row.
+ """
# @@: An event for getting a row? But for each row, when doing a
# select? For .sync, .syncUpdate, .expire?
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2006-02-11 10:37:34 UTC (rev 1595)
+++ SQLObject/trunk/sqlobject/main.py 2006-02-11 10:39:57 UTC (rev 1596)
@@ -1273,7 +1273,11 @@
cache = self._connection.cache
cache.created(id, self.__class__, self)
self._init(id)
+ post_funcs = []
+ kw = dict([('class',self.__class__),('id',id)])
+ self.sqlmeta.send(events.RowCreatedSignal, kw, post_funcs)
+
def _SO_getID(self, obj):
return getID(obj)
|
|
From: SourceForge.net <no...@so...> - 2006-02-11 10:38:17
|
Patches item #1423877, was opened at 2006-02-03 21:19 Message generated for change (Comment added) made by ianbicking You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423877&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: Closed >Resolution: Accepted Priority: 5 Submitted By: Rick Richardson (rovar) Assigned to: Nobody/Anonymous (nobody) Summary: createTable broken for mysql in 0.8dev Initial Comment: There was no mysqlCreateReferenceConstraint so it was referring to the base class which threw a horrible assert. I have created the constraint stuff in the style of the pg version. NOTE: The PG version could easily create constraint name duplicates. This is a nono in mysql and other databases. I have modified the naming convention so that they're far less likely to clash. patch included. ---------------------------------------------------------------------- >Comment By: Ian Bicking (ianbicking) Date: 2006-02-11 04:38 Message: Logged In: YES user_id=210337 Applied in r1595. ---------------------------------------------------------------------- Comment By: Rick Richardson (rovar) Date: 2006-02-09 11:27 Message: Logged In: YES user_id=1443006 Kay.. here is the patch that mods mysqlCreateReferenceConstraint function with the alternate naming convention. (hopefully) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 10:31 Message: Logged In: YES user_id=4799 No, it's not included! Please attach the patch and don't forget to check the checkbox! (-: ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423877&group_id=74338 |
|
From: <sub...@co...> - 2006-02-11 10:37:45
|
Author: ianb
Date: 2006-02-11 03:37:34 -0700 (Sat, 11 Feb 2006)
New Revision: 1595
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
Log:
Applied SF [ 1423877 ] createTable broken for mysql in 0.8dev from Rick Richardson
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2006-02-11 10:33:06 UTC (rev 1594)
+++ SQLObject/trunk/sqlobject/col.py 2006-02-11 10:37:34 UTC (rev 1595)
@@ -777,9 +777,33 @@
'sTName': sTName})
return constraint
+ def mysqlCreateReferenceConstraint(self):
+ sTName = self.soClass.sqlmeta.table
+ other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
+ tName = other.sqlmeta.table
+ idName = other.sqlmeta.idName
+ if self.cascade is not None:
+ if self.cascade == 'null':
+ action = 'ON DELETE SET NULL'
+ elif self.cascade:
+ action = 'ON DELETE CASCADE'
+ else:
+ action = 'ON DELETE RESTRICT'
+ else:
+ action = ''
+ constraint = ('ALTER TABLE %(sTName)s ADD CONSTRAINT %(sTName)s_%(colName)s_to_%(tName)s '
+ 'FOREIGN KEY (%(colName)s) '
+ 'REFERENCES %(tName)s (%(idName)s) '
+ '%(action)s' %
+ {'tName': tName,
+ 'colName': self.dbName,
+ 'idName': idName,
+ 'action': action,
+ 'sTName': sTName})
+ return constraint
+
def mysqlCreateSQL(self):
- sql = SOKeyCol.mysqlCreateSQL(self)
- return sql
+ return SOKeyCol.mysqlCreateSQL(self)
def mysqlCreateReferenceConstraint(self):
return None
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-11 10:33:06 UTC (rev 1594)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-11 10:37:34 UTC (rev 1595)
@@ -110,6 +110,9 @@
def createIndexSQL(self, soClass, index):
return index.mysqlCreateIndexSQL(soClass)
+ def createReferenceConstraint(self, soClass, col):
+ return col.mysqlCreateReferenceConstraint()
+
def createIDColumn(self, soClass):
if soClass.sqlmeta.idType == str:
return '%s TEXT PRIMARY KEY' % soClass.sqlmeta.idName
|
|
From: SourceForge.net <no...@so...> - 2006-02-11 10:33:26
|
Patches item #1421263, was opened at 2006-02-01 02:39 Message generated for change (Comment added) made by ianbicking You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1421263&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: Closed >Resolution: Accepted Priority: 5 Submitted By: Maxim F. Ischenko (mfi) Assigned to: Nobody/Anonymous (nobody) Summary: configurable client character set (encoding) for MySQL Initial Comment: This patch adds 'client_encoding' parameter to MySQLConnection class which is used to configure MySQL connection with "SET NAMES" command. This is the only way for MySQL 4.x on Windows to configure client encoding and is crucial for non-ascii databases. ---------------------------------------------------------------------- >Comment By: Ian Bicking (ianbicking) Date: 2006-02-11 04:33 Message: Logged In: YES user_id=210337 Applied in r1594. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-03 13:02 Message: Logged In: YES user_id=4799 At least add docs, please. ---------------------------------------------------------------------- Comment By: Maxim F. Ischenko (mfi) Date: 2006-02-03 10:53 Message: Logged In: YES user_id=113894 I can add the docs but not the tests, sorry (see my other comment). If you won't accept the patch without tests please let me know. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-03 10:28 Message: Logged In: YES user_id=4799 Patch, documentation and, if possible, tests. Thank you in advance! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1421263&group_id=74338 |
|
From: <sub...@co...> - 2006-02-11 10:33:09
|
Author: ianb
Date: 2006-02-11 03:33:06 -0700 (Sat, 11 Feb 2006)
New Revision: 1594
Modified:
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
Log:
Applied SF [ 1421263 ] configurable client character set (encoding) for MySQL from Maxim F. Ischenko
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-11 10:30:03 UTC (rev 1593)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-11 10:33:06 UTC (rev 1594)
@@ -18,6 +18,10 @@
self.db = db
self.user = user
self.password = password
+ if kw.has_key('client_encoding'):
+ self.client_encoding = col.popKey(kw, 'client_encoding')
+ else:
+ self.client_encoding = None
self.kw = {}
for key in ("unix_socket", "named_pipe", "init_command",
"read_default_file", "read_default_group"):
@@ -47,6 +51,8 @@
if hasattr(conn, 'autocommit'):
conn.autocommit(bool(self.autoCommit))
+ if self.client_encoding:
+ conn.query('SET NAMES ' + self.client_encoding)
return conn
|
|
From: SourceForge.net <no...@so...> - 2006-02-11 10:30:20
|
Patches item #1417936, was opened at 2006-01-29 06:45 Message generated for change (Settings changed) made by ianbicking You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1417936&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: Closed >Resolution: Accepted Priority: 5 Submitted By: Maxim F. Ischenko (mfi) Assigned to: Nobody/Anonymous (nobody) Summary: user unfriendly error message in manager.command Initial Comment: Description and patch (just a few lines) available at http://trac.turbogears.org/turbogears/ticket/459#preview ---------------------------------------------------------------------- >Comment By: Ian Bicking (ianbicking) Date: 2006-02-11 04:30 Message: Logged In: YES user_id=210337 Applied in r1593. ---------------------------------------------------------------------- Comment By: Maxim F. Ischenko (mfi) Date: 2006-02-02 02:28 Message: Logged In: YES user_id=113894 Would you mind to write whether you're going to accept or decline the patch? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1417936&group_id=74338 |
|
From: <sub...@co...> - 2006-02-11 10:30:09
|
Author: ianb
Date: 2006-02-11 03:30:03 -0700 (Sat, 11 Feb 2006)
New Revision: 1593
Modified:
SQLObject/trunk/sqlobject/manager/command.py
Log:
Applied SF [ 1417936 ] user unfriendly error message in manager.command / TG #459 from Maxim F. Ischenko
Modified: SQLObject/trunk/sqlobject/manager/command.py
===================================================================
--- SQLObject/trunk/sqlobject/manager/command.py 2006-02-11 10:27:10 UTC (rev 1592)
+++ SQLObject/trunk/sqlobject/manager/command.py 2006-02-11 10:30:03 UTC (rev 1593)
@@ -1073,7 +1073,11 @@
if self.options.upgrade_to:
version_to = self.options.upgrade_to
else:
- version_to = os.path.basename(self.find_last_version())
+ fname = self.find_last_version()
+ if fname is None:
+ print "No version exists, use 'record' command to create one"
+ return
+ version_to = os.path.basename(fname)
current = self.current_version()
if v:
print 'Current version: %s' % current
|
|
From: SourceForge.net <no...@so...> - 2006-02-11 10:27:40
|
Patches item #1385854, was opened at 2005-12-19 23:37 Message generated for change (Comment added) made by ianbicking You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1385854&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: Closed >Resolution: Accepted Priority: 5 Submitted By: Matthias Urlichs (smurf) Assigned to: Nobody/Anonymous (nobody) Summary: Fix myql support for foreign keys Initial Comment: This change restores proper support for foreign keys when using the mysql backend. (It does not force tables to InnoDB.) ---------------------------------------------------------------------- >Comment By: Ian Bicking (ianbicking) Date: 2006-02-11 04:27 Message: Logged In: YES user_id=210337 Applied in r1592. ---------------------------------------------------------------------- Comment By: Matthias Urlichs (smurf) Date: 2006-02-07 12:59 Message: Logged In: YES user_id=10327 sorry about the missing patch. Attached now. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-11 10:27 Message: Logged In: YES user_id=4799 What change?! You've forgotten to check the checkbox before uploading a file! ;) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1385854&group_id=74338 |
|
From: <sub...@co...> - 2006-02-11 10:27:14
|
Author: ianb
Date: 2006-02-11 03:27:10 -0700 (Sat, 11 Feb 2006)
New Revision: 1592
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
SQLObject/trunk/sqlobject/tests/test_SQLMultipleJoin.py
SQLObject/trunk/sqlobject/tests/test_cache.py
SQLObject/trunk/sqlobject/tests/test_string_id.py
Log:
Applied SF [ 1385854 ] Fix myql support for foreign keys from Matthias Urlichs; plus some fixes for MySQL tests (but still have some test problems)
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2006-02-11 09:51:51 UTC (rev 1591)
+++ SQLObject/trunk/sqlobject/col.py 2006-02-11 10:27:10 UTC (rev 1592)
@@ -752,8 +752,8 @@
'sTName': sTName})
return constraint
- def mysqlCreateSQL(self):
- sql = SOKeyCol.mysqlCreateSQL(self)
+ def mysqlCreateReferenceConstraint(self):
+ sTName = self.soClass.sqlmeta.table
other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
tName = other.sqlmeta.table
idName = other.sqlmeta.idName
@@ -766,15 +766,19 @@
action = 'ON DELETE RESTRICT'
else:
action = ''
- constraint = ('CONSTRAINT %(colName)s_exists '
+ constraint = ('ALTER TABLE %(sTName)s ADD CONSTRAINT %(sTName)s_%(colName)s_exists '
'FOREIGN KEY (%(colName)s) '
'REFERENCES %(tName)s (%(idName)s) '
'%(action)s' %
{'tName': tName,
'colName': self.dbName,
'idName': idName,
- 'action': action})
- sql = ', '.join([sql, constraint])
+ 'action': action,
+ 'sTName': sTName})
+ return constraint
+
+ def mysqlCreateSQL(self):
+ sql = SOKeyCol.mysqlCreateSQL(self)
return sql
def mysqlCreateReferenceConstraint(self):
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-11 09:51:51 UTC (rev 1591)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-11 10:27:10 UTC (rev 1592)
@@ -98,6 +98,9 @@
def createColumn(self, soClass, col):
return col.mysqlCreateSQL()
+ def createReferenceConstraint(self, soClass, col):
+ return col.mysqlCreateReferenceConstraint()
+
def createIndexSQL(self, soClass, index):
return index.mysqlCreateIndexSQL(soClass)
Modified: SQLObject/trunk/sqlobject/tests/test_SQLMultipleJoin.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_SQLMultipleJoin.py 2006-02-11 09:51:51 UTC (rev 1591)
+++ SQLObject/trunk/sqlobject/tests/test_SQLMultipleJoin.py 2006-02-11 10:27:10 UTC (rev 1592)
@@ -40,4 +40,4 @@
assert saiyajin.fightersAsSResult.max('power') == 10
assert trunks in hibrid.fightersAsSResult
assert picollo not in hibrid.fightersAsSResult
- assert hibrid.fightersAsSResult.sum('power') == 23
+ assert str(hibrid.fightersAsSResult.sum('power')) == '23'
Modified: SQLObject/trunk/sqlobject/tests/test_cache.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_cache.py 2006-02-11 09:51:51 UTC (rev 1591)
+++ SQLObject/trunk/sqlobject/tests/test_cache.py 2006-02-11 10:27:10 UTC (rev 1592)
@@ -24,7 +24,7 @@
class CacheTest(SQLObject):
- name = StringCol(alternateID=True)
+ name = StringCol(alternateID=True, length=100)
def test_cache():
setupClass(CacheTest)
Modified: SQLObject/trunk/sqlobject/tests/test_string_id.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_string_id.py 2006-02-11 09:51:51 UTC (rev 1591)
+++ SQLObject/trunk/sqlobject/tests/test_string_id.py 2006-02-11 10:27:10 UTC (rev 1592)
@@ -5,7 +5,7 @@
class sqlmeta(sqlmeta):
idType = str
idName = 'test_id_here'
- name = StringCol()
+ name = StringCol(length=100)
def test_string_id():
conn = getConnection()
|
|
From: <sub...@co...> - 2006-02-11 09:52:04
|
Author: ianb
Date: 2006-02-11 02:51:51 -0700 (Sat, 11 Feb 2006)
New Revision: 1591
Added:
MetaSQLObject/trunk/metasqlobject/classinst.py
MetaSQLObject/trunk/metasqlobject/events.py
MetaSQLObject/trunk/sqlobject/
MetaSQLObject/trunk/sqlobject/__init__.py
MetaSQLObject/trunk/sqlobject/col.py
MetaSQLObject/trunk/sqlobject/events.py
MetaSQLObject/trunk/sqlobject/main.py
MetaSQLObject/trunk/tests/
MetaSQLObject/trunk/tests/conftest.py
MetaSQLObject/trunk/tests/so/
Modified:
MetaSQLObject/trunk/metasqlobject/declarative.py
MetaSQLObject/trunk/setup.cfg
MetaSQLObject/trunk/setup.py
MetaSQLObject/trunk/tests/so/dbtest.py
MetaSQLObject/trunk/tests/so/test_auto.py
MetaSQLObject/trunk/tests/so/test_auto_old.py
MetaSQLObject/trunk/tests/so/test_create_drop.py
MetaSQLObject/trunk/tests/so/test_cyclic_reference.py
MetaSQLObject/trunk/tests/so/test_datetime.py
MetaSQLObject/trunk/tests/so/test_joins_conditional.py
MetaSQLObject/trunk/tests/so/test_paste.py
MetaSQLObject/trunk/tests/so/test_string_id.py
Log:
Intermediate commit while stuff is getting moved around
Added: MetaSQLObject/trunk/metasqlobject/classinst.py
===================================================================
--- MetaSQLObject/trunk/metasqlobject/classinst.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/metasqlobject/classinst.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1,37 @@
+__all__ = ['classinstancemethod']
+
+class classinstancemethod(object):
+ """
+ Acts like a class method when called from a class, like an
+ instance method when called by an instance. The method should
+ take two arguments, 'self' and 'cls'; one of these will be None
+ depending on how the method was called.
+ """
+
+ def __init__(self, func):
+ self.func = func
+
+ def __get__(self, obj, type=None):
+ return _methodwrapper(self.func, obj=obj, type=type)
+
+class _methodwrapper(object):
+
+ def __init__(self, func, obj, type):
+ self.func = func
+ self.obj = obj
+ self.type = type
+
+ def __call__(self, *args, **kw):
+ assert not kw.has_key('self') and not kw.has_key('cls'), (
+ "You cannot use 'self' or 'cls' arguments to a "
+ "classinstancemethod")
+ return self.func(*((self.obj, self.type) + args), **kw)
+
+ def __repr__(self):
+ if self.obj is None:
+ return ('<bound class method %s.%s>'
+ % (self.type.__name__, self.func.func_name))
+ else:
+ return ('<bound method %s.%s of %r>'
+ % (self.type.__name__, self.func.func_name,
+ self.obj))
Property changes on: MetaSQLObject/trunk/metasqlobject/classinst.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: MetaSQLObject/trunk/metasqlobject/declarative.py
===================================================================
--- MetaSQLObject/trunk/metasqlobject/declarative.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/metasqlobject/declarative.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -7,39 +7,36 @@
(So if a class is received, we'll simply instantiate an instance with
no arguments).
-You can provide a variable __unpackargs__ (a list of strings), and if
-the constructor is called with non-keyword arguments they will be
-interpreted as the given keyword arguments.
+You can provide a class variable ``__unpackargs__`` (a list of
+strings), and if the constructor is called with non-keyword arguments
+they will be interpreted as the given keyword arguments.
-If __unpackargs__ is ('*', name), then all the arguments will be put
-in a variable by that name.
+If ``__unpackargs__`` is ``('*', name)``, then all the arguments will
+be put in a variable by that name.
-You can define a __classinit__(cls, new_attrs) method, which will be
-called when the class is created (including subclasses). Note: you
-can't use super() in __classinit__ because the class isn't bound to a
-name. As an analog to __classinit__, Declarative adds
-__instanceinit__ which is called with the same argument (new_attrs).
-This is like __init__, but after __unpackargs__ and other factors have
-been taken into account.
+You can define a ``__classinit__(cls, new_attrs)`` method, which will
+be called when the class is created (including subclasses). Note: you
+can't use ``super()`` in ``__classinit__`` because the class isn't
+bound to a name. As an analog to ``__classinit__``, ``Declarative``
+adds ``__instanceinit__`` which is called with the same argument
+(``new_attrs``). This is like ``__init__``, but applied after
+``__unpackargs__`` and other factors have been taken into account.
-If __mutableattributes__ is defined as a sequence of strings, these
-attributes will not be shared between superclasses and their
+If ``__mutableattributes__`` is defined as a sequence of strings,
+these attributes will not be shared between superclasses and their
subclasses. E.g., if you have a class variable that contains a list
and you append to that list, changes to subclasses will effect
-superclasses unless you add the attribute here.
-
-Also defines classinstancemethod, which acts as either a class method
-or an instance method depending on where it is called.
+superclasses unless you add the attribute here. So any variables
+listed there will be copied (shallowly).
"""
from __future__ import generators
import threading
-import events
-
-__all__ = ('classinstancemethod', 'DeclarativeMeta', 'Declarative')
-
import copy
+from classinst import classinstancemethod
+__all__ = ('DeclarativeMeta', 'Declarative')
+
try:
import itertools
counter = itertools.count()
@@ -51,55 +48,6 @@
yield i
counter = _counter()
-class classinstancemethod(object):
- """
- Acts like a class method when called from a class, like an
- instance method when called by an instance. The method should
- take two arguments, 'self' and 'cls'; one of these will be None
- depending on how the method was called.
- """
-
- def __init__(self, func):
- self.func = func
-
- def __get__(self, obj, type=None):
- return _methodwrapper(self.func, obj=obj, type=type)
-
-class _methodwrapper(object):
-
- def __init__(self, func, obj, type):
- self.func = func
- self.obj = obj
- self.type = type
-
- def __call__(self, *args, **kw):
- assert not kw.has_key('self') and not kw.has_key('cls'), (
- "You cannot use 'self' or 'cls' arguments to a "
- "classinstancemethod")
- return self.func(*((self.obj, self.type) + args), **kw)
-
- def __repr__(self):
- if self.obj is None:
- return ('<bound class method %s.%s>'
- % (self.type.__name__, self.func.func_name))
- else:
- return ('<bound method %s.%s of %r>'
- % (self.type.__name__, self.func.func_name, self.obj))
-
-def threadSafeMethod(lock):
- def decorator(fn):
- def _wrapper(self, *args, **kwargs):
- lock.acquire()
- return_value = fn(self, *args, **kwargs)
- lock.release()
- return return_value
- try:
- _wrapper.func_name = fn.func_name
- except TypeError:
- pass
- return _wrapper
- return decorator
-
class DeclarativeMeta(type):
def __new__(meta, class_name, bases, new_attrs):
Copied: MetaSQLObject/trunk/metasqlobject/events.py (from rev 1562, SQLObject/trunk/sqlobject/events.py)
===================================================================
--- SQLObject/trunk/sqlobject/events.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/metasqlobject/events.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1,44 @@
+from weakref import ref
+from UserDict import DictMixin
+
+__all__ = ['EventHub', 'Signal']
+
+class EventHub(DictMixin):
+
+ def __init__(self):
+ self._events = {}
+
+ def copy(self):
+ new = self.__class__()
+ new._events = self._events.copy()
+ return new
+
+ def listen(self, signal, listener, weak=True):
+ if weak:
+ listener = ref(listener)
+ else:
+ listener = lambda l=listener: l
+ self._events.setdefault(signal, []).append(listener)
+
+ def send(self, signal, **kw):
+ for listener in self._events.get(signal, ()):
+ listener(**kw)
+
+class _Signal(object):
+ """
+ Base event for all SQLObject events.
+
+ In general the sender for these methods is the class, not the
+ instance.
+ """
+
+ def __init__(self, class_name, bases, attrs):
+ self.name = self.__name__ = class_name
+ for name, value in attrs.items():
+ setattr(self, name, value)
+
+ def __repr__(self):
+ return '<Signal:%s>' % (self.name)
+
+Signal = _Signal('Signal', (), {})
+
Modified: MetaSQLObject/trunk/setup.cfg
===================================================================
--- MetaSQLObject/trunk/setup.cfg 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/setup.cfg 2006-02-11 09:51:51 UTC (rev 1591)
@@ -7,7 +7,7 @@
docs = docs/index.txt
doc_base = docs/
dest = docs/html
-modules = metasqlobject
+modules = metasqlobject sqlobject
title = Meta SQLObject
mailing_list_url = http://sqlobject.org/community.html
settings = normal_link_color=#039
Modified: MetaSQLObject/trunk/setup.py
===================================================================
--- MetaSQLObject/trunk/setup.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/setup.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -17,7 +17,7 @@
include_package_data=True,
zip_safe=False,
install_requires=[
- # -*- Extra requirements: -*-
+ 'Louie',
],
entry_points="""
# -*- Entry points: -*-
Added: MetaSQLObject/trunk/sqlobject/__init__.py
===================================================================
--- MetaSQLObject/trunk/sqlobject/__init__.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/sqlobject/__init__.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1 @@
+#
Property changes on: MetaSQLObject/trunk/sqlobject/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: MetaSQLObject/trunk/sqlobject/col.py
===================================================================
--- MetaSQLObject/trunk/sqlobject/col.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/sqlobject/col.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1,28 @@
+from metasqlobject.declarative import Declarative
+
+class Col(Declarative):
+
+ standard_sql_type = None
+ sql_type_parameters = {}
+
+ def _add_sql_type_param(self, **params):
+ if self.sql_type_parameters is self.__class__.sql_type_parameters:
+ self.sql_type_parameters = self.sql_type_parameters.copy()
+ self.sql_type_parameters.update(params)
+
+class StringCol(Col):
+
+ standard_sql_type = 'TEXT'
+
+ def __init__(self, length=None):
+ if length is not None:
+ self._add_sql_type_param(length=length)
+
+class IntCol(Col):
+
+ standard_sql_type = 'INT'
+
+class FloatCol(Col):
+
+ standard_sql_type = 'FLOAT'
+
Property changes on: MetaSQLObject/trunk/sqlobject/col.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: MetaSQLObject/trunk/sqlobject/events.py
===================================================================
--- MetaSQLObject/trunk/sqlobject/events.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/sqlobject/events.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1,114 @@
+from metasqlobject.eventhub import Signal
+
+class ClassCreateSignal(Signal):
+ """
+ Signal raised after class creation. The sender is the superclass
+ (in case of multiple superclasses, the first superclass). The
+ arguments are ``(new_class_name, bases, new_attrs, post_funcs,
+ early_funcs)``. ``new_attrs`` is a dictionary and may be modified
+ (but ``new_class_name`` and ``bases`` are immutable).
+ ``post_funcs`` is an initially-empty list that can have callbacks
+ appended to it.
+
+ Note: at the time this event is called, the new class has not yet
+ been created. The functions in ``post_funcs`` will be called
+ after the class is created, with the single arguments of
+ ``(new_class)``. Also, ``early_funcs`` will be called at the
+ soonest possible time after class creation (``post_funcs`` is
+ called after the class's ``__classinit__``).
+ """
+
+# @@: Should there be a class reload event? This would allow modules
+# to be reloaded, possibly. Or it could even be folded into
+# ClassCreateSignal, since anything that listens to that needs to pay
+# attention to reloads (or else it is probably buggy).
+
+class RowCreateSignal(Signal):
+ """
+ Called before an instance is created, with the class as the
+ sender. Called with the arguments ``(kwargs, post_funcs)``.
+ There may be a ``connection`` argument. ``kwargs``may be usefully
+ modified. ``post_funcs`` is a list of callbacks, intended to have
+ functions appended to it, and are called with the arguments
+ ``(new_instance)``.
+
+ Note: this is not called when an instance is created from an
+ existing database row.
+ """
+
+# @@: An event for getting a row? But for each row, when doing a
+# select? For .sync, .syncUpdate, .expire?
+
+class RowDestroySignal(Signal):
+ """
+ Called before an instance is deleted. Sender is the instance's
+ class. Arguments are ``(instance)``. You cannot cancel the delete,
+ but you can raise an exception (which will probably cancel the
+ delete, but also cause an uncaught exception if not expected).
+
+ Note: this is not called when an instance is destroyed through
+ garbage collection.
+
+ @@: Should this allow ``instance`` to be a primary key, so that a
+ row can be deleted without first fetching it?
+ """
+
+class RowUpdateSignal(Signal):
+ """
+ Called when an instance is updated through a call to ``.set()``.
+ The arguments are ``(instance, kwargs)``. ``kwargs`` can be
+ modified. This is run *before* the instance is updated; if you
+ want to look at the current values, simply look at ``instance``.
+ """
+
+class AddColumnSignal(Signal):
+ """
+ Called when a column is added to a class, with arguments ``(cls,
+ connection, column_name, column_definition, changeSchema,
+ post_funcs)``. This is called *after* the column has been added,
+ and is called for each column after class creation.
+
+ post_funcs are called with ``(cls, so_column_obj)``
+ """
+
+class DeleteColumnSignal(Signal):
+ """
+ Called when a column is removed from a class, with the arguments
+ ``(cls, connection, column_name, so_column_obj, post_funcs)``.
+ Like ``AddColumnSignal`` this is called after the action has been
+ performed, and is called for subclassing (when a column is
+ implicitly removed by setting it to ``None``).
+
+ post_funcs are called with ``(cls, so_column_obj)``
+ """
+
+# @@: Signals for indexes and joins? These are mostly event consumers,
+# though.
+
+class CreateTableSignal(Signal):
+ """
+ Called when a table is created. If ``ifNotExists==True`` and the
+ table exists, this event is not called.
+
+ Called with ``(cls, connection, extra_sql, post_funcs)``.
+ ``extra_sql`` is a list (which can be appended to) of extra SQL
+ statements to be run after the table is created. ``post_funcs``
+ functions are called with ``(cls, connection)`` after the table
+ has been created. Those functions are *not* called simply when
+ constructing the SQL.
+ """
+
+class DropTableSignal(Signal):
+ """
+ Called when a table is dropped. If ``ifExists==True`` and the
+ table doesn't exist, this event is not called.
+
+ Called with ``(cls, connection, extra_sql, post_funcs)``.
+ ``post_funcs`` functions are called with ``(cls, connection)``
+ after the table has been dropped.
+ """
+
+__all__ = []
+for name, value in globals().items():
+ if isinstance(value, type) and issubclass(value, Signal):
+ __all__.append(name)
Property changes on: MetaSQLObject/trunk/sqlobject/events.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: MetaSQLObject/trunk/sqlobject/main.py
===================================================================
--- MetaSQLObject/trunk/sqlobject/main.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/sqlobject/main.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1,49 @@
+from metasqlobject.declarative import Declarative
+from sqlapi import sql
+
+class sqlmeta(object):
+
+ _creating = False
+
+ lazy = False
+
+ def __init__(self, instance):
+ self.instance = instance
+
+ #@classmethod
+ def _set_soclass(cls, soclass):
+ cls.soclass = soclass
+
+ _set_soclass = classmethod(_set_soclass)
+
+ def create(self):
+ conn = self.connection
+ sql = sql.Insert(self._values, self.table)
+
+
+
+class SQLObject(Declarative):
+
+ def __classinit__(cls, new_attrs):
+ if not isinstance(cls.sqlmeta, sqlmeta):
+ new_sqlmeta = type(sqlmeta, (cls.__bases__[0].sqlmeta,),
+ cls.sqlmeta.__dict__)
+ cls.sqlmeta = new_sqlmeta
+ cls.sqlmeta._set_soclass(cls)
+
+ def __init__(self, **kw):
+ self.sqlmeta = self.sqlmeta(self)
+ self.sqlmeta._creating = True
+ self.sqlmeta._values = {}
+ for name, value in kw:
+ if hasattr(self, name):
+ setattr(self, name, value)
+ else:
+ raise TypeError(
+ "%s() called with unknown keyword %s"
+ % (self.__class__.__name__, name))
+
+ if not self.sqlmeta.lazy:
+ self.sqlmeta.create()
+
+
Property changes on: MetaSQLObject/trunk/sqlobject/main.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: MetaSQLObject/trunk/tests/conftest.py
===================================================================
--- MetaSQLObject/trunk/tests/conftest.py 2006-02-10 21:04:09 UTC (rev 1590)
+++ MetaSQLObject/trunk/tests/conftest.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -0,0 +1,4 @@
+import sys, os
+sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
+import pkg_resources
+pkg_resources.require('MetaSQLObject')
Property changes on: MetaSQLObject/trunk/tests/conftest.py
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: MetaSQLObject/trunk/tests/so (from rev 1562, SQLObject/trunk/sqlobject/tests)
Modified: MetaSQLObject/trunk/tests/so/dbtest.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/dbtest.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/dbtest.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -43,169 +43,20 @@
'-limitSelect' : 'mssql'
}
+def setConnection(conn):
+ if isinstance(conn, basestring):
+ conn = sqlobject.connectionForURI(conn)
+ sqlobject.sqlhub.processConnection = conn
-def setupClass(soClasses, force=False):
- """
- Makes sure the classes have a corresponding and correct table.
- This won't recreate the table if it already exists. It will check
- that the table is properly defined (in case you change your table
- definition).
-
- You can provide a single class or a list of classes; if a list
- then classes will be created in the order you provide, and
- destroyed in the opposite order. So if class A depends on class
- B, then do setupClass([B, A]) and B won't be destroyed or cleared
- until after A is destroyed or cleared.
-
- If force is true, then the database will be recreated no matter
- what.
- """
- global hub
+def setupClass(soClasses):
if not isinstance(soClasses, (list, tuple)):
soClasses = [soClasses]
- connection = getConnection()
- for soClass in soClasses:
- ## This would be an alternate way to register connections...
- #try:
- # hub
- #except NameError:
- # hub = sqlobject.dbconnection.ConnectionHub()
- #soClass._connection = hub
- #hub.threadConnection = connection
- #hub.processConnection = connection
- soClass._connection = connection
- installOrClear(soClasses, force=force)
- return soClasses
+ reversed = soClasses[:]
+ for class_ in reversed:
+ class_.dropTable(ifExists=True, cascade=True)
+ for class_ in soClasses:
+ class_.createTable()
-installedDBFilename = os.path.join(getcwd(), 'dbs_data.tmp')
-
-installedDBTracker = sqlobject.connectionForURI(
- 'sqlite:///' + installedDBFilename)
-
-def getConnection(**kw):
- name = getConnectionURI()
- conn = sqlobject.connectionForURI(name, **kw)
- if conftest.option.show_sql:
- conn.debug = True
- if conftest.option.show_sql_output:
- conn.debugOutput = True
- return conn
-
-def getConnectionURI():
- name = conftest.option.Database
- if conftest.connectionShortcuts.has_key(name):
- name = conftest.connectionShortcuts[name]
- return name
-
-try:
- connection = getConnection()
-except Exception, e:
- # At least this module should be importable...
- print >> sys.stderr, (
- "Could not open database: %s" % e)
-
-
-class InstalledTestDatabase(sqlobject.SQLObject):
- """
- This table is set up in SQLite (always, regardless of --Database) and
- tracks what tables have been set up in the 'real' database. This
- way we don't keep recreating the tables over and over when there
- are multiple tests that use a table.
- """
-
- _connection = installedDBTracker
- tableName = sqlobject.StringCol(notNull=True)
- createSQL = sqlobject.StringCol(notNull=True)
- connectionURI = sqlobject.StringCol(notNull=True)
-
- def installOrClear(cls, soClasses, force=False):
- cls.setup()
- reversed = list(soClasses)[:]
- reversed.reverse()
- # If anything needs to be dropped, they all must be dropped
- # But if we're forcing it, then we'll always drop
- if force:
- any_drops = True
- else:
- any_drops = False
- for soClass in reversed:
- table = soClass.sqlmeta.table
- if not soClass._connection.tableExists(table):
- continue
- items = list(cls.selectBy(
- tableName=table,
- connectionURI=soClass._connection.uri()))
- if items:
- instance = items[0]
- sql = instance.createSQL
- else:
- sql = None
- newSQL, constraints = soClass.createTableSQL()
- if sql != newSQL:
- if sql is not None:
- instance.destroySelf()
- any_drops = True
- break
- for soClass in reversed:
- if soClass._connection.tableExists(soClass.sqlmeta.table):
- if any_drops:
- cls.drop(soClass)
- else:
- cls.clear(soClass)
- for soClass in soClasses:
- table = soClass.sqlmeta.table
- if not soClass._connection.tableExists(table):
- cls.install(soClass)
- installOrClear = classmethod(installOrClear)
-
- def install(cls, soClass):
- """
- Creates the given table in its database.
- """
- sql = getattr(soClass, soClass._connection.dbName + 'Create',
- None)
- all_extra = []
- if sql:
- soClass._connection.query(sql)
- else:
- sql, extra_sql = soClass.createTableSQL()
- soClass.createTable(applyConstraints=False)
- 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):
- """
- Drops a the given table from its database
- """
- sql = getattr(soClass, soClass._connection.dbName + 'Drop', None)
- if sql:
- soClass._connection.query(sql)
- else:
- soClass.dropTable()
- drop = classmethod(drop)
-
- def clear(cls, soClass):
- """
- Removes all the rows from a table.
- """
- soClass.clearTable()
- clear = classmethod(clear)
-
- def setup(cls):
- """
- This sets up *this* table.
- """
- if not cls._connection.tableExists(cls.sqlmeta.table):
- cls.createTable()
- setup = classmethod(setup)
-
-installOrClear = InstalledTestDatabase.installOrClear
-
class Dummy(object):
"""
@@ -255,7 +106,7 @@
return results
def supports(feature):
- dbName = connection.dbName
+ dbName = sqlobject.sqlhub.getConnection().dbName
support = supportsMatrix.get('+' + feature, None)
notSupport = supportsMatrix.get('-' + feature, None)
if support is not None and dbName in support.split():
@@ -294,6 +145,6 @@
sqlobject.main.warnings_level = None
sqlobject.main.exception_level = 0
-__all__ = ['getConnection', 'getConnectionURI', 'setupClass', 'Dummy', 'raises',
+__all__ = ['setupClass', 'Dummy', 'raises',
'd', 'inserts', 'supports', 'deprecated_module',
'setup_module', 'teardown_module']
Modified: MetaSQLObject/trunk/tests/so/test_auto.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_auto.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_auto.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -135,14 +135,16 @@
mssqlDrop = sybaseDrop
def setup_method(self, meth):
- conn = getConnection()
+ conn = sqlhub.getConnection()
+ if conn.tableExists('auto_test'):
+ conn.dropTable('auto_test')
dbName = conn.dbName
creator = getattr(self, dbName + 'Create', None)
if creator:
conn.query(creator)
def teardown_method(self, meth):
- conn = getConnection()
+ conn = sqlhub.getConnection()
dbName = conn.dbName
dropper = getattr(self, dbName + 'Drop', None)
if dropper:
@@ -152,7 +154,7 @@
if not supports('fromDatabase'):
return
class AutoTest(SQLObject):
- _connection = getConnection()
+ _connection = sqlhub.getConnection()
class sqlmeta(sqlmeta):
idName = 'auto_id'
fromDatabase = True
Modified: MetaSQLObject/trunk/tests/so/test_auto_old.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_auto_old.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_auto_old.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -28,8 +28,7 @@
class TestPeople:
def setup_method(self, meth):
- setupClass(OldPerson, force=True)
- setupClass(OldPhone, force=True)
+ setupClass([OldPerson, OldPhone])
for n in ['jane', 'tim', 'bob', 'jake']:
OldPerson(name=n)
for p in ['555-555-5555', '555-394-2930',
@@ -137,14 +136,14 @@
DROP TABLE old_auto_test
"""
def setup_method(self, meth):
- conn = getConnection()
+ conn = sqlhub.getConnection()
dbName = conn.dbName
creator = getattr(self, dbName + 'Create', None)
if creator:
conn.query(creator)
def teardown_method(self, meth):
- conn = getConnection()
+ conn = sqlhub.getConnection()
dbName = conn.dbName
dropper = getattr(self, dbName + 'Drop', None)
if dropper:
@@ -154,7 +153,7 @@
if not supports('fromDatabase'):
return
class OldAutoTest(SQLObject):
- _connection = getConnection()
+ _connection = sqlhub.getConnection()
class sqlmeta(sqlmeta):
idName = 'auto_id'
fromDatabase = True
Modified: MetaSQLObject/trunk/tests/so/test_create_drop.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_create_drop.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_create_drop.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -12,7 +12,7 @@
blobcol = BLOBCol()
def test_create_drop():
- conn = getConnection()
+ conn = sqlhub.getConnection()
TestCreateDrop.setConnection(conn)
TestCreateDrop.dropTable(ifExists=True)
assert not conn.tableExists(TestCreateDrop.sqlmeta.table)
Modified: MetaSQLObject/trunk/tests/so/test_cyclic_reference.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_cyclic_reference.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_cyclic_reference.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -24,7 +24,7 @@
fkeya = ForeignKey('TestCyclicReferenceA')
def test_cyclic_reference():
- conn = getConnection()
+ conn = sqlhub.getConnection()
TestCyclicReferenceA.setConnection(conn)
TestCyclicReferenceB.setConnection(conn)
TestCyclicReferenceA.dropTable(ifExists=True, cascade=True)
Modified: MetaSQLObject/trunk/tests/so/test_datetime.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_datetime.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_datetime.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -44,7 +44,7 @@
from mx.DateTime import now, Time
dateFormat = None # use default
- if getConnection().dbName == "sqlite":
+ if sqlhub.getConnection().dbName == "sqlite":
from sqlobject.sqlite.sqliteconnection import using_sqlite2
if using_sqlite2: # PySQLite2 returns full date/time for a date
dateFormat = "%Y-%m-%d %H:%M:%S"
Modified: MetaSQLObject/trunk/tests/so/test_joins_conditional.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_joins_conditional.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_joins_conditional.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -26,7 +26,7 @@
join = LEFTJOIN("table1", "table2")
assert str(join) == "table1 LEFT JOIN table2"
join = LEFTJOINOn("table1", "table2", "tabl1.col1 = table2.col2")
- assert getConnection().sqlrepr(join) == "table1 LEFT JOIN table2 ON tabl1.col1 = table2.col2"
+ assert sqlhub.getConnection().sqlrepr(join) == "table1 LEFT JOIN table2 ON tabl1.col1 = table2.col2"
def test_2select_syntax():
setup()
Modified: MetaSQLObject/trunk/tests/so/test_paste.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_paste.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_paste.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -26,7 +26,7 @@
def makestack(abort=False, begin=False, fail=False, **kw):
app = makeapp(abort=abort, begin=begin, fail=fail)
- app = make_middleware(app, {}, database=getConnectionURI(), **kw)
+ app = make_middleware(app, {}, database=sqlhub.getConnection(), **kw)
return app
def runapp(**kw):
@@ -43,11 +43,11 @@
def setup():
setupClass(NameOnly)
- getConnection().query('DELETE FROM name_only')
+ sqlhub.getConnection().query('DELETE FROM name_only')
NameOnly._connection = sqlhub
def names():
- names = [n.name for n in NameOnly.select(connection=getConnection())]
+ names = [n.name for n in NameOnly.select(connection=sqlhub.getConnection())]
names.sort()
return names
Modified: MetaSQLObject/trunk/tests/so/test_string_id.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_string_id.py 2006-02-03 19:08:46 UTC (rev 1562)
+++ MetaSQLObject/trunk/tests/so/test_string_id.py 2006-02-11 09:51:51 UTC (rev 1591)
@@ -8,7 +8,7 @@
name = StringCol()
def test_string_id():
- conn = getConnection()
+ conn = sqlhub.getConnection()
TestStringID.setConnection(conn)
TestStringID.dropTable(ifExists=True)
assert not conn.tableExists(TestStringID.sqlmeta.table)
|
|
From: <sub...@co...> - 2006-02-10 21:04:33
|
Author: ianb Date: 2006-02-10 14:04:09 -0700 (Fri, 10 Feb 2006) New Revision: 1590 Modified: SQLObject/docs/index.comments.txt Log: in page: http://pythonpaste.org/ Modified: SQLObject/docs/index.comments.txt =================================================================== --- SQLObject/docs/index.comments.txt 2006-02-10 14:55:44 UTC (rev 1589) +++ SQLObject/docs/index.comments.txt 2006-02-10 21:04:09 UTC (rev 1590) @@ -5,7 +5,7 @@ ip: 84.190.227.75 username: MB -Hier kann man Kommentare eingeben +Hier kann man Kommentare eingeben ==== $(example) c ---------------------------------------- date: 2006-01-31T06:42:16 |
|
From: SourceForge.net <no...@so...> - 2006-02-10 17:01:02
|
Bugs item #1429248, was opened at 2006-02-10 17:00 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=1429248&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: Postgres Group: None Status: Open Resolution: None Priority: 5 Submitted By: Hootbah (hootbah) Assigned to: Nobody/Anonymous (nobody) Summary: tableExists query issues with uper case table names Initial Comment: Its is possible for the tableExists query not to find a table when it does actually exist. When using uppercase names e.g. class sqlmeta: table = 'MYTABLE' The tableExists query becomes: SELECT COUNT(relname) FROM pg_class WHERE relname = 'MYTABLE' This fails to find the table as the table names stored within pg_class are all lower case. I propose to change the query to be: SELECT COUNT(relname) FROM pg_class WHERE relname = lower('MYTABLE') This would mean a change to pgconnection.py: result = self.queryOne("SELECT COUNT(relname) FROM pg_class WHERE relname = lower(%s)" % self.sqlrepr(tableName)) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1429248&group_id=74338 |
|
From: <sub...@co...> - 2006-02-10 14:55:52
|
Author: phd
Date: 2006-02-10 07:55:44 -0700 (Fri, 10 Feb 2006)
New Revision: 1589
Modified:
home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py
Log:
Merged patches from the revisions 1586:1588 from the trunk: applied the patch 1410527: allow the use of foreign keys in selects; added a test.
Modified: home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2006-02-10 14:54:29 UTC (rev 1588)
+++ home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2006-02-10 14:55:44 UTC (rev 1589)
@@ -17,6 +17,7 @@
from cache import CacheSet
import col
popKey = col.popKey
+import main
from joins import sorter
from converters import sqlrepr
import classregistry
@@ -702,10 +703,10 @@
data[col.dbName] = popKey(kw, key)
elif col.foreignName in kw:
obj = popKey(kw, col.foreignName)
- if obj is None:
- data[col.dbName] = None
+ if isinstance(obj, main.SQLObject):
+ data[col.dbName] = obj.id
else:
- data[col.dbName] = obj.id
+ data[col.dbName] = obj
if kw:
# pick the first key from kw to use to raise the error,
raise TypeError, "got an unexpected keyword argument(s): %r" % kw.keys()
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py 2006-02-10 14:54:29 UTC (rev 1588)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py 2006-02-10 14:55:44 UTC (rev 1589)
@@ -24,6 +24,9 @@
# Select by usual way
s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9')
assert s[0]==w1
+ # selectBy object.id
+ s = TestWorkKey.selectBy(composer=c.id, title='Symphony No. 9')
+ assert s[0]==w1
# selectBy object
s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9')
assert s[0]==w1
|
|
From: SourceForge.net <no...@so...> - 2006-02-10 14:55:02
|
Patches item #1410527, was opened at 2006-01-20 10:42 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&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: Closed >Resolution: Accepted Priority: 5 Submitted By: Pau Aliagas (linux4u) >Assigned to: Oleg Broytmann (phd) Summary: allow the use of foreign keys in selects (small jewel) Initial Comment: Many times you need to make a query that needs to filter using the foreign key. This should be trivial to do: just adding the foreign table or foreign table SHOULD work. But it does not. Better see the example: class handset_brand(SQLObject): brand = StringCol(alternateID = True, length = 50) handsets = SQLMultipleJoin('handset') class handset(SQLObject): handset_brand = ForeignKey('handset_brand') handset_made_in = ForeignKey('country') model = StringCol(alternateID = True, length = 25) class country(SQLObject): name StringCol(alternateID = True, length = 50) isocode StringCol(alternateID = True, length = 3) Query 1 ------- I want to query the handsets of one concrete brand. * solution 1 ---------- Now the best way to do it would be: handset_brands.get(4).handsets.filter(handset.q.model == "mymodel") but you NEED to define the MultipleJoin. * solution 2 ---------- You can use the dotq syntax: handset.select(handset.q.handset_brandID==4) For me the main problem is the you have to use the foreign key name defined in Style, so if you change the Style it would stop working. That's bad. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4) or b = brand.get(4) handset.select(brand = b) One of both would be GREAT, but both would be AWSOME. This is the natural way of thinking. Query 2 ------- What if if want to filter using two foreign keys? For instance to query the handsets of one concrete brand made in one country. * solution 1 ---------- It would NOT work, you cannot query directly using both foreign tables. * solution 2 ---------- You can use the dotq syntax: handset.select(AND(handset.q.handset_brandID==4, handset.q.countryID==1)) Again, you have to use the foreign key name defined in Style. I try to avoid it, it feels like there SHOULD be a better way. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4, countrID = 1) or b = brand.get(4) c = country.get(1) handset.select(brand = b, country = c) One of both, depending on the occasion, sometimes it would be better to use one way, sometimes the other one. In fact this is the way "INSERT" works!! Why not SELECT? The good news is that this small patch (3 lines) add this powerful features :) It really was trivial to do thanks to the well-designed code. Thanks very much for the hard work. As expected, it passes all the tests. ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-10 17:54 Message: Logged In: YES user_id=4799 Applied at the revision 1587 to the trunk, 1588 to the 0.7-branch. I have slightly modified the patch and added a test. Please take a look. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 21:28 Message: Logged In: YES user_id=140558 I also want to do: s = TestWorkKey.selectBy(composer=c.id, title='Symphony No. 9') This way I can just use the more convenient value without changing the code. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 20:16 Message: Logged In: YES user_id=4799 I understand it. But I think s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') does what you want, doesn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 20:00 Message: Logged In: YES user_id=140558 What I want is to use the object or the field name seemlessly, so that I don't need to use the foreign key name that depends on the Stlye. I'd always use the object name like this. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 18:20 Message: Logged In: YES user_id=4799 This works in the trunk. Look at http://svn.colorstudy.com/SQLObject/trunk/sqlobject/tests/test_foreignKey.py: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') assert s[0]==w1 # selectBy object s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') assert s[0]==w1 Isn't it what you want? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-20 10:51 Message: Logged In: YES user_id=140558 There is a little mistake in the example: s/select/selectBy where it says: handset.select(brand = b, country = c) it should say: handset.selectBy(brand = b, country = c) This is how it really works (select always uses the dotq syntax). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&group_id=74338 |
|
From: <sub...@co...> - 2006-02-10 14:54:37
|
Author: phd
Date: 2006-02-10 07:54:29 -0700 (Fri, 10 Feb 2006)
New Revision: 1588
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_foreignKey.py
Log:
Applied the patch 1410527: allow the use of foreign keys in selects; added a test.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py 2006-02-10 14:53:09 UTC (rev 1587)
+++ SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py 2006-02-10 14:54:29 UTC (rev 1588)
@@ -17,6 +17,7 @@
from cache import CacheSet
import col
popKey = col.popKey
+import main
from joins import sorter
from converters import sqlrepr
import classregistry
@@ -637,10 +638,10 @@
data[col.dbName] = popKey(kw, key)
elif col.foreignName in kw:
obj = popKey(kw, col.foreignName)
- if obj is None:
- data[col.dbName] = None
+ if isinstance(obj, main.SQLObject):
+ data[col.dbName] = obj.id
else:
- data[col.dbName] = obj.id
+ data[col.dbName] = obj
if kw:
# pick the first key from kw to use to raise the error,
raise TypeError, "got an unexpected keyword argument(s): %r" % kw.keys()
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_foreignKey.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_foreignKey.py 2006-02-10 14:53:09 UTC (rev 1587)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_foreignKey.py 2006-02-10 14:54:29 UTC (rev 1588)
@@ -25,6 +25,9 @@
# Select by usual way
s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9')
assert s[0]==w1
+ # selectBy object.id
+ s = TestWorkKey.selectBy(composer=c.id, title='Symphony No. 9')
+ assert s[0]==w1
# selectBy object
s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9')
assert s[0]==w1
|
|
From: <sub...@co...> - 2006-02-10 14:53:22
|
Author: phd
Date: 2006-02-10 07:53:09 -0700 (Fri, 10 Feb 2006)
New Revision: 1587
Modified:
SQLObject/trunk/sqlobject/dbconnection.py
SQLObject/trunk/sqlobject/tests/test_foreignKey.py
Log:
Applied the patch 1410527: allow the use of foreign keys in selects; added a test.
Modified: SQLObject/trunk/sqlobject/dbconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/dbconnection.py 2006-02-07 17:13:06 UTC (rev 1586)
+++ SQLObject/trunk/sqlobject/dbconnection.py 2006-02-10 14:53:09 UTC (rev 1587)
@@ -17,6 +17,7 @@
from cache import CacheSet
import col
popKey = col.popKey
+import main
from joins import sorter
from converters import sqlrepr
import classregistry
@@ -689,10 +690,10 @@
data[col.dbName] = popKey(kw, key)
elif col.foreignName in kw:
obj = popKey(kw, col.foreignName)
- if obj is None:
- data[col.dbName] = None
+ if isinstance(obj, main.SQLObject):
+ data[col.dbName] = obj.id
else:
- data[col.dbName] = obj.id
+ data[col.dbName] = obj
if kw:
# pick the first key from kw to use to raise the error,
raise TypeError, "got an unexpected keyword argument(s): %r" % kw.keys()
Modified: SQLObject/trunk/sqlobject/tests/test_foreignKey.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_foreignKey.py 2006-02-07 17:13:06 UTC (rev 1586)
+++ SQLObject/trunk/sqlobject/tests/test_foreignKey.py 2006-02-10 14:53:09 UTC (rev 1587)
@@ -24,6 +24,9 @@
# Select by usual way
s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9')
assert s[0]==w1
+ # selectBy object.id
+ s = TestWorkKey.selectBy(composer=c.id, title='Symphony No. 9')
+ assert s[0]==w1
# selectBy object
s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9')
assert s[0]==w1
|
|
From: SourceForge.net <no...@so...> - 2006-02-09 18:28:17
|
Patches item #1410527, was opened at 2006-01-20 08:42 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&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: Pau Aliagas (linux4u) Assigned to: Nobody/Anonymous (nobody) Summary: allow the use of foreign keys in selects (small jewel) Initial Comment: Many times you need to make a query that needs to filter using the foreign key. This should be trivial to do: just adding the foreign table or foreign table SHOULD work. But it does not. Better see the example: class handset_brand(SQLObject): brand = StringCol(alternateID = True, length = 50) handsets = SQLMultipleJoin('handset') class handset(SQLObject): handset_brand = ForeignKey('handset_brand') handset_made_in = ForeignKey('country') model = StringCol(alternateID = True, length = 25) class country(SQLObject): name StringCol(alternateID = True, length = 50) isocode StringCol(alternateID = True, length = 3) Query 1 ------- I want to query the handsets of one concrete brand. * solution 1 ---------- Now the best way to do it would be: handset_brands.get(4).handsets.filter(handset.q.model == "mymodel") but you NEED to define the MultipleJoin. * solution 2 ---------- You can use the dotq syntax: handset.select(handset.q.handset_brandID==4) For me the main problem is the you have to use the foreign key name defined in Style, so if you change the Style it would stop working. That's bad. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4) or b = brand.get(4) handset.select(brand = b) One of both would be GREAT, but both would be AWSOME. This is the natural way of thinking. Query 2 ------- What if if want to filter using two foreign keys? For instance to query the handsets of one concrete brand made in one country. * solution 1 ---------- It would NOT work, you cannot query directly using both foreign tables. * solution 2 ---------- You can use the dotq syntax: handset.select(AND(handset.q.handset_brandID==4, handset.q.countryID==1)) Again, you have to use the foreign key name defined in Style. I try to avoid it, it feels like there SHOULD be a better way. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4, countrID = 1) or b = brand.get(4) c = country.get(1) handset.select(brand = b, country = c) One of both, depending on the occasion, sometimes it would be better to use one way, sometimes the other one. In fact this is the way "INSERT" works!! Why not SELECT? The good news is that this small patch (3 lines) add this powerful features :) It really was trivial to do thanks to the well-designed code. Thanks very much for the hard work. As expected, it passes all the tests. ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:28 Message: Logged In: YES user_id=140558 I also want to do: s = TestWorkKey.selectBy(composer=c.id, title='Symphony No. 9') This way I can just use the more convenient value without changing the code. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 18:16 Message: Logged In: YES user_id=4799 I understand it. But I think s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') does what you want, doesn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 18:00 Message: Logged In: YES user_id=140558 What I want is to use the object or the field name seemlessly, so that I don't need to use the foreign key name that depends on the Stlye. I'd always use the object name like this. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 16:20 Message: Logged In: YES user_id=4799 This works in the trunk. Look at http://svn.colorstudy.com/SQLObject/trunk/sqlobject/tests/test_foreignKey.py: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') assert s[0]==w1 # selectBy object s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') assert s[0]==w1 Isn't it what you want? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-20 08:51 Message: Logged In: YES user_id=140558 There is a little mistake in the example: s/select/selectBy where it says: handset.select(brand = b, country = c) it should say: handset.selectBy(brand = b, country = c) This is how it really works (select always uses the dotq syntax). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 17:27:52
|
Patches item #1423877, was opened at 2006-02-04 03:19 Message generated for change (Comment added) made by rovar You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423877&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: Rick Richardson (rovar) Assigned to: Nobody/Anonymous (nobody) Summary: createTable broken for mysql in 0.8dev Initial Comment: There was no mysqlCreateReferenceConstraint so it was referring to the base class which threw a horrible assert. I have created the constraint stuff in the style of the pg version. NOTE: The PG version could easily create constraint name duplicates. This is a nono in mysql and other databases. I have modified the naming convention so that they're far less likely to clash. patch included. ---------------------------------------------------------------------- >Comment By: Rick Richardson (rovar) Date: 2006-02-09 17:27 Message: Logged In: YES user_id=1443006 Kay.. here is the patch that mods mysqlCreateReferenceConstraint function with the alternate naming convention. (hopefully) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 16:31 Message: Logged In: YES user_id=4799 No, it's not included! Please attach the patch and don't forget to check the checkbox! (-: ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423877&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 17:16:40
|
Patches item #1410527, was opened at 2006-01-20 10:42 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&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: Pau Aliagas (linux4u) Assigned to: Nobody/Anonymous (nobody) Summary: allow the use of foreign keys in selects (small jewel) Initial Comment: Many times you need to make a query that needs to filter using the foreign key. This should be trivial to do: just adding the foreign table or foreign table SHOULD work. But it does not. Better see the example: class handset_brand(SQLObject): brand = StringCol(alternateID = True, length = 50) handsets = SQLMultipleJoin('handset') class handset(SQLObject): handset_brand = ForeignKey('handset_brand') handset_made_in = ForeignKey('country') model = StringCol(alternateID = True, length = 25) class country(SQLObject): name StringCol(alternateID = True, length = 50) isocode StringCol(alternateID = True, length = 3) Query 1 ------- I want to query the handsets of one concrete brand. * solution 1 ---------- Now the best way to do it would be: handset_brands.get(4).handsets.filter(handset.q.model == "mymodel") but you NEED to define the MultipleJoin. * solution 2 ---------- You can use the dotq syntax: handset.select(handset.q.handset_brandID==4) For me the main problem is the you have to use the foreign key name defined in Style, so if you change the Style it would stop working. That's bad. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4) or b = brand.get(4) handset.select(brand = b) One of both would be GREAT, but both would be AWSOME. This is the natural way of thinking. Query 2 ------- What if if want to filter using two foreign keys? For instance to query the handsets of one concrete brand made in one country. * solution 1 ---------- It would NOT work, you cannot query directly using both foreign tables. * solution 2 ---------- You can use the dotq syntax: handset.select(AND(handset.q.handset_brandID==4, handset.q.countryID==1)) Again, you have to use the foreign key name defined in Style. I try to avoid it, it feels like there SHOULD be a better way. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4, countrID = 1) or b = brand.get(4) c = country.get(1) handset.select(brand = b, country = c) One of both, depending on the occasion, sometimes it would be better to use one way, sometimes the other one. In fact this is the way "INSERT" works!! Why not SELECT? The good news is that this small patch (3 lines) add this powerful features :) It really was trivial to do thanks to the well-designed code. Thanks very much for the hard work. As expected, it passes all the tests. ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-09 20:16 Message: Logged In: YES user_id=4799 I understand it. But I think s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') does what you want, doesn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 20:00 Message: Logged In: YES user_id=140558 What I want is to use the object or the field name seemlessly, so that I don't need to use the foreign key name that depends on the Stlye. I'd always use the object name like this. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 18:20 Message: Logged In: YES user_id=4799 This works in the trunk. Look at http://svn.colorstudy.com/SQLObject/trunk/sqlobject/tests/test_foreignKey.py: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') assert s[0]==w1 # selectBy object s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') assert s[0]==w1 Isn't it what you want? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-20 10:51 Message: Logged In: YES user_id=140558 There is a little mistake in the example: s/select/selectBy where it says: handset.select(brand = b, country = c) it should say: handset.selectBy(brand = b, country = c) This is how it really works (select always uses the dotq syntax). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 17:00:14
|
Patches item #1410527, was opened at 2006-01-20 08:42 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&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: Pau Aliagas (linux4u) Assigned to: Nobody/Anonymous (nobody) Summary: allow the use of foreign keys in selects (small jewel) Initial Comment: Many times you need to make a query that needs to filter using the foreign key. This should be trivial to do: just adding the foreign table or foreign table SHOULD work. But it does not. Better see the example: class handset_brand(SQLObject): brand = StringCol(alternateID = True, length = 50) handsets = SQLMultipleJoin('handset') class handset(SQLObject): handset_brand = ForeignKey('handset_brand') handset_made_in = ForeignKey('country') model = StringCol(alternateID = True, length = 25) class country(SQLObject): name StringCol(alternateID = True, length = 50) isocode StringCol(alternateID = True, length = 3) Query 1 ------- I want to query the handsets of one concrete brand. * solution 1 ---------- Now the best way to do it would be: handset_brands.get(4).handsets.filter(handset.q.model == "mymodel") but you NEED to define the MultipleJoin. * solution 2 ---------- You can use the dotq syntax: handset.select(handset.q.handset_brandID==4) For me the main problem is the you have to use the foreign key name defined in Style, so if you change the Style it would stop working. That's bad. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4) or b = brand.get(4) handset.select(brand = b) One of both would be GREAT, but both would be AWSOME. This is the natural way of thinking. Query 2 ------- What if if want to filter using two foreign keys? For instance to query the handsets of one concrete brand made in one country. * solution 1 ---------- It would NOT work, you cannot query directly using both foreign tables. * solution 2 ---------- You can use the dotq syntax: handset.select(AND(handset.q.handset_brandID==4, handset.q.countryID==1)) Again, you have to use the foreign key name defined in Style. I try to avoid it, it feels like there SHOULD be a better way. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4, countrID = 1) or b = brand.get(4) c = country.get(1) handset.select(brand = b, country = c) One of both, depending on the occasion, sometimes it would be better to use one way, sometimes the other one. In fact this is the way "INSERT" works!! Why not SELECT? The good news is that this small patch (3 lines) add this powerful features :) It really was trivial to do thanks to the well-designed code. Thanks very much for the hard work. As expected, it passes all the tests. ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 18:00 Message: Logged In: YES user_id=140558 What I want is to use the object or the field name seemlessly, so that I don't need to use the foreign key name that depends on the Stlye. I'd always use the object name like this. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 16:20 Message: Logged In: YES user_id=4799 This works in the trunk. Look at http://svn.colorstudy.com/SQLObject/trunk/sqlobject/tests/test_foreignKey.py: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') assert s[0]==w1 # selectBy object s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') assert s[0]==w1 Isn't it what you want? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-20 08:51 Message: Logged In: YES user_id=140558 There is a little mistake in the example: s/select/selectBy where it says: handset.select(brand = b, country = c) it should say: handset.selectBy(brand = b, country = c) This is how it really works (select always uses the dotq syntax). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 16:42:17
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&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: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 16:31:49
|
Patches item #1423877, was opened at 2006-02-04 06:19 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423877&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: Rick Richardson (rovar) Assigned to: Nobody/Anonymous (nobody) Summary: createTable broken for mysql in 0.8dev Initial Comment: There was no mysqlCreateReferenceConstraint so it was referring to the base class which threw a horrible assert. I have created the constraint stuff in the style of the pg version. NOTE: The PG version could easily create constraint name duplicates. This is a nono in mysql and other databases. I have modified the naming convention so that they're far less likely to clash. patch included. ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:31 Message: Logged In: YES user_id=4799 No, it's not included! Please attach the patch and don't forget to check the checkbox! (-: ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1423877&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 16:18:17
|
Patches item #1416838, was opened at 2006-01-27 22:52 Message generated for change (Settings changed) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1416838&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: Closed Resolution: Rejected Priority: 5 Submitted By: Gabriel Reid (gab_reid) Assigned to: Nobody/Anonymous (nobody) Summary: Fix for styles.py for uppercase column names Initial Comment: If a database column name is in all uppercase, with words separated by undscores (as is the case with column names when fetched from the data dictionary in Firebird), the conversion from database column name to Python attribute name and back does not work correctly, as shown below. This is due to the fact that the style expects a lowercase column name, which will not be the case with Firebird connections. Example: >>> >>> from sqlobject import styles >>> style = styles.DefaultStyle() >>> style.pythonAttrToDBColumn(style.dbColumnToPythonAttr('START_DATE')) 'startdat_e' >>> style.pythonAttrToDBColumn(style.dbColumnToPythonAttr('start_date')) 'start_date' The attached patch simply converts the column name to lowercase before performing the conversion on it in underToMixed. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 19:14 Message: Logged In: YES user_id=4799 The patch is too simple, it breaks many things. For example, test_SQLMultipleJoin.py: return self.FieldClass(self.tableName, E self.soClass.sqlmeta.columns[attr].dbName, > KeyError: 'raceid' [sqlobject/sqlbuilder.py:365] test_SingleJoin.py: return self.FieldClass(self.tableName, E self.soClass.sqlmeta.columns[attr].dbName, > KeyError: 'personid' ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1416838&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-09 16:11:35
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&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: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |