sqlobject-cvs Mailing List for SQLObject (Page 147)
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...> - 2005-12-29 14:09:44
|
Bugs item #1392862, was opened at 2005-12-29 06:09 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1392862&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: SQLObject release (specify) Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: An SQLObject class can't natively refer to another class in Initial Comment: Submitted by: michele.cella AT gmail DOT com SQLObject 0.8 This was (is) needed by the TurboGears identity system. The only (ugly) solution is to use names like TG_User. Related links: http://groups.google.com/group/turbogears/browse_frm/thread/a9aa7fe3f4e346ef/a782f8a010bcdbde?q=jeff+registry&rnum=1#a782f8a010bcdbde http://nerd.newburyportion.com/2005/11/updated-identity-framework ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1392862&group_id=74338 |
|
From: <sub...@co...> - 2005-12-28 12:15:30
|
Author: ianb Date: 2005-12-28 12:15:26 +0000 (Wed, 28 Dec 2005) New Revision: 1442 Modified: SQLObject/docs/index.comments.txt Log: Web updates Modified: SQLObject/docs/index.comments.txt =================================================================== --- SQLObject/docs/index.comments.txt 2005-12-28 12:10:55 UTC (rev 1441) +++ SQLObject/docs/index.comments.txt 2005-12-28 12:15:26 UTC (rev 1442) @@ -1,9 +0,0 @@ -==== $(start) + ----------------------------------------- -date: 2005-12-28T05:01:53 -email: none -id: 1 -ip: 213.142.200.103 -username: ash - -test comment |
|
From: <sub...@co...> - 2005-12-28 12:11:33
|
Author: ianb Date: 2005-12-28 12:10:55 +0000 (Wed, 28 Dec 2005) New Revision: 1441 Modified: SQLObject/docs/index.comments.txt Log: Web updates Modified: SQLObject/docs/index.comments.txt =================================================================== --- SQLObject/docs/index.comments.txt 2005-12-24 12:02:40 UTC (rev 1440) +++ SQLObject/docs/index.comments.txt 2005-12-28 12:10:55 UTC (rev 1441) @@ -0,0 +1,9 @@ +==== $(start) + +---------------------------------------- +date: 2005-12-28T05:01:53 +email: none +id: 1 +ip: 213.142.200.103 +username: ash + +test comment |
|
From: <sub...@co...> - 2005-12-24 12:02:50
|
Author: phd
Date: 2005-12-24 12:02:40 +0000 (Sat, 24 Dec 2005)
New Revision: 1440
Modified:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
home/phd/SQLObject/paramstyles/sqlobject/inheritance/iteration.py
home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
Log:
A patch for inheritance by alexander smishlajev.
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2005-12-24 12:01:08 UTC (rev 1439)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2005-12-24 12:02:40 UTC (rev 1440)
@@ -16,8 +16,7 @@
class InheritableSelectResults(SelectResults):
IterationClass = iteration.InheritableIteration
- def __init__(self, sourceClass, clause, clauseTables=None,
- **ops):
+ def __init__(self, sourceClass, clause, clauseTables=None, **ops):
if clause is None or isinstance(clause, str) and clause == 'all':
clause = sqlbuilder.SQLTrueClause
tablesDict = sqlbuilder.tablesUsedDict(clause)
@@ -165,6 +164,8 @@
currentClass = cls.sqlmeta.parentClass
while currentClass:
for column in currentClass.sqlmeta.columnDefinitions.values():
+ if column.name == 'childName':
+ continue
if type(column) == col.ForeignKey:
continue
setattr(cls.q, column.name,
@@ -216,10 +217,20 @@
if childUpdate: return val
#DSM: If this class has a child, return the child
if 'childName' in cls.sqlmeta.columns:
- childName = val.childName
- if childName is not None:
- return cls.sqlmeta.childClasses[childName].get(id,
- connection=connection, selectResults=childResults)
+ childName = val.childName
+ if childName is not None:
+ childClass = cls.sqlmeta.childClasses[childName]
+ # If the class has no columns (which sometimes makes sense
+ # and may be true for non-inheritable (leaf) classes only),
+ # shunt the query to avoid almost meaningless SQL
+ # like "SELECT NULL FROM child WHERE id=1".
+ # This is based on assumption that child object exists
+ # if parent object exists. (If it doesn't your database
+ # is broken and that is a job for database maintenance.)
+ if not (childResults or childClass.sqlmeta.columns):
+ childResults = (None,)
+ return childClass.get(id, connection=connection,
+ selectResults=childResults)
#DSM: Now, we know we are alone or the last child in a family...
#DSM: It's time to find our parents
inst = val
@@ -277,12 +288,12 @@
new_kw = {}
parent_kw = {}
for (name, value) in kw.items():
- if hasattr(parentClass, name):
+ if (name != 'childName') and hasattr(parentClass, name):
parent_kw[name] = value
else:
new_kw[name] = value
kw = new_kw
- parent_kw["childName"] = self.sqlmeta.childName
+ parent_kw['childName'] = self.sqlmeta.childName
self._parent = parentClass(kw=parent_kw,
connection=self._connection)
@@ -298,6 +309,69 @@
return [obj.id], obj
_findAlternateID = classmethod(_findAlternateID)
+ def select(cls, clause=None, *args, **kwargs):
+ parentClass = cls.sqlmeta.parentClass
+ childUpdate = kwargs.pop('childUpdate', None)
+ # childUpdate may have one of three values:
+ # True:
+ # select was issued by parent class to create child objects.
+ # Execute select without modifications.
+ # None (default):
+ # select is run by application. If this class is inheritance
+ # child, delegate query to the parent class to utilize
+ # InheritableIteration optimizations. Selected records
+ # are restricted to this (child) class by adding childName
+ # filter to the where clause.
+ # False:
+ # select is delegated from inheritance child which is parent
+ # of another class. Delegate the query to parent if possible,
+ # but don't add childName restriction: selected records
+ # will be filtered by join to the table filtered by childName.
+ if (not childUpdate) and parentClass:
+ if childUpdate is None:
+ # this is the first parent in deep hierarchy
+ addClause = parentClass.q.childName == cls.sqlmeta.childName
+ # if the clause was one of TRUE varians, replace it
+ if (clause is None) or (clause is sqlbuilder.SQLTrueClause) \
+ or (isinstance(clause, basestring) and (clause == 'all')):
+ clause = addClause
+ else:
+ # patch WHERE condition:
+ # change ID field of this class to ID of parent class
+ # XXX the clause is patched in place; it would be better
+ # to build a new one if we have to replace field
+ clsID = cls.q.id
+ parentID = parentClass.q.id
+ def _get_patched(clause):
+ if isinstance(clause, sqlbuilder.SQLOp):
+ _patch_id_clause(clause)
+ return None
+ elif not isinstance(clause, sqlbuilder.Field):
+ return None
+ elif (clause.tableName == clsID.tableName) \
+ and (clause.fieldName == clsID.fieldName):
+ return parentID
+ else:
+ return None
+ def _patch_id_clause(clause):
+ if not isinstance(clause, sqlbuilder.SQLOp):
+ return
+ expr = _get_patched(clause.expr1)
+ if expr:
+ clause.expr1 = expr
+ expr = _get_patched(clause.expr2)
+ if expr:
+ clause.expr2 = expr
+ _patch_id_clause(clause)
+ # add childName filter
+ clause = sqlbuilder.AND(clause, addClause)
+ return parentClass.select(clause, childUpdate=False,
+ *args, **kwargs)
+ else:
+ return super(InheritableSQLObject, cls).select(
+ clause, *args, **kwargs)
+ select = classmethod(select)
+
def selectBy(cls, connection=None, **kw):
clause = []
for name, value in kw.items():
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/iteration.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/iteration.py 2005-12-24 12:01:08 UTC (rev 1439)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/iteration.py 2005-12-24 12:02:40 UTC (rev 1440)
@@ -67,10 +67,25 @@
registry = self.select.sourceClass.sqlmeta.registry
for childName, ids in childIdsNames.items():
klass = findClass(childName, registry)
- select = klass.select(sqlbuilder.IN(sqlbuilder.SQLConstant("id"), ids))
+ if len(ids) == 1:
+ select = klass.select(klass.q.id == ids[0],
+ childUpdate=True)
+ else:
+ select = klass.select(sqlbuilder.IN(klass.q.id, ids),
+ childUpdate=True)
query = dbconn.queryForSelect(select)
if dbconn.debug:
dbconn.printDebug(rawconn, query, 'Select children of the class %s' % childName)
self.dbconn._executeRetry(rawconn, cursor, query)
for result in cursor.fetchall():
- self._childrenResults[result[0]] = result[1:]
+ # Inheritance child classes may have no own columns
+ # (that makes sense when child class has a join
+ # that does not apply to parent class objects).
+ # In such cases result[1:] gives an empty tuple
+ # which is interpreted as "no results fetched" in .get().
+ # So .get() issues another query which is absolutely
+ # meaningless (like "SELECT NULL FROM child WHERE id=1").
+ # In order to avoid this, we replace empty results
+ # with non-empty tuple. Extra values in selectResults
+ # are Ok - they will be ignored by ._SO_selectInit().
+ self._childrenResults[result[0]] = result[1:] or (None,)
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py 2005-12-24 12:01:08 UTC (rev 1439)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_deep_inheritance.py 2005-12-24 12:02:40 UTC (rev 1440)
@@ -19,21 +19,41 @@
subdudes = MultipleJoin("DIPerson", joinColumn="manager_id")
def test_deep_inheritance():
+
+ cache = getConnection().cache
+
setupClass(DIManager)
setupClass(DIEmployee)
setupClass(DIPerson)
manager = DIManager(firstName='Project', lastName='Manager',
position='Project Manager')
- employee = DIEmployee(firstName='Project', lastName='Leader',
- position='Project leader', manager=manager)
- person = DIPerson(firstName='Oneof', lastName='Authors', manager=manager)
+ manager_id = manager.id
+ employee_id = DIEmployee(firstName='Project', lastName='Leader',
+ position='Project leader', manager=manager).id
+ person_id = DIPerson(firstName='Oneof', lastName='Authors',
+ manager=manager).id
+ cache.clear()
managers = list(DIManager.select())
assert len(managers) == 1
+ cache.clear()
employees = list(DIEmployee.select())
assert len(employees) == 2
+ cache.clear()
persons = list(DIPerson.select())
assert len(persons) == 3
+ cache.clear()
+
+ person = DIPerson.get(employee_id)
+ assert isinstance(person, DIEmployee)
+
+ person = DIPerson.get(manager_id)
+ assert isinstance(person, DIEmployee)
+ assert isinstance(person, DIManager)
+ cache.clear()
+
+ person = DIEmployee.get(manager_id)
+ assert isinstance(person, DIManager)
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-24 12:01:08 UTC (rev 1439)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-24 12:02:40 UTC (rev 1440)
@@ -1513,6 +1513,9 @@
delete = classmethod(delete)
def __repr__(self):
+ if not hasattr(self, 'id'):
+ # Object initialization not finished. No attributes can be read.
+ return '<%s (not initialized)>' % self.__class__.__name__
return '<%s %r %s>' \
% (self.__class__.__name__,
self.id,
|
|
From: <sub...@co...> - 2005-12-24 12:01:47
|
Author: phd
Date: 2005-12-24 12:01:08 +0000 (Sat, 24 Dec 2005)
New Revision: 1439
Modified:
SQLObject/trunk/sqlobject/inheritance/__init__.py
SQLObject/trunk/sqlobject/inheritance/iteration.py
SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py
SQLObject/trunk/sqlobject/main.py
Log:
A patch for inheritance by alexander smishlajev.
Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-12-21 18:46:46 UTC (rev 1438)
+++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-12-24 12:01:08 UTC (rev 1439)
@@ -16,8 +16,7 @@
class InheritableSelectResults(SelectResults):
IterationClass = iteration.InheritableIteration
- def __init__(self, sourceClass, clause, clauseTables=None,
- **ops):
+ def __init__(self, sourceClass, clause, clauseTables=None, **ops):
if clause is None or isinstance(clause, str) and clause == 'all':
clause = sqlbuilder.SQLTrueClause
tablesDict = sqlbuilder.tablesUsedDict(clause)
@@ -165,6 +164,8 @@
currentClass = cls.sqlmeta.parentClass
while currentClass:
for column in currentClass.sqlmeta.columnDefinitions.values():
+ if column.name == 'childName':
+ continue
if type(column) == col.ForeignKey:
continue
setattr(cls.q, column.name,
@@ -216,10 +217,20 @@
if childUpdate: return val
#DSM: If this class has a child, return the child
if 'childName' in cls.sqlmeta.columns:
- childName = val.childName
- if childName is not None:
- return cls.sqlmeta.childClasses[childName].get(id,
- connection=connection, selectResults=childResults)
+ childName = val.childName
+ if childName is not None:
+ childClass = cls.sqlmeta.childClasses[childName]
+ # If the class has no columns (which sometimes makes sense
+ # and may be true for non-inheritable (leaf) classes only),
+ # shunt the query to avoid almost meaningless SQL
+ # like "SELECT NULL FROM child WHERE id=1".
+ # This is based on assumption that child object exists
+ # if parent object exists. (If it doesn't your database
+ # is broken and that is a job for database maintenance.)
+ if not (childResults or childClass.sqlmeta.columns):
+ childResults = (None,)
+ return childClass.get(id, connection=connection,
+ selectResults=childResults)
#DSM: Now, we know we are alone or the last child in a family...
#DSM: It's time to find our parents
inst = val
@@ -277,12 +288,12 @@
new_kw = {}
parent_kw = {}
for (name, value) in kw.items():
- if hasattr(parentClass, name):
+ if (name != 'childName') and hasattr(parentClass, name):
parent_kw[name] = value
else:
new_kw[name] = value
kw = new_kw
- parent_kw["childName"] = self.sqlmeta.childName
+ parent_kw['childName'] = self.sqlmeta.childName
self._parent = parentClass(kw=parent_kw,
connection=self._connection)
@@ -298,6 +309,69 @@
return [obj.id], obj
_findAlternateID = classmethod(_findAlternateID)
+ def select(cls, clause=None, *args, **kwargs):
+ parentClass = cls.sqlmeta.parentClass
+ childUpdate = kwargs.pop('childUpdate', None)
+ # childUpdate may have one of three values:
+ # True:
+ # select was issued by parent class to create child objects.
+ # Execute select without modifications.
+ # None (default):
+ # select is run by application. If this class is inheritance
+ # child, delegate query to the parent class to utilize
+ # InheritableIteration optimizations. Selected records
+ # are restricted to this (child) class by adding childName
+ # filter to the where clause.
+ # False:
+ # select is delegated from inheritance child which is parent
+ # of another class. Delegate the query to parent if possible,
+ # but don't add childName restriction: selected records
+ # will be filtered by join to the table filtered by childName.
+ if (not childUpdate) and parentClass:
+ if childUpdate is None:
+ # this is the first parent in deep hierarchy
+ addClause = parentClass.q.childName == cls.sqlmeta.childName
+ # if the clause was one of TRUE varians, replace it
+ if (clause is None) or (clause is sqlbuilder.SQLTrueClause) \
+ or (isinstance(clause, basestring) and (clause == 'all')):
+ clause = addClause
+ else:
+ # patch WHERE condition:
+ # change ID field of this class to ID of parent class
+ # XXX the clause is patched in place; it would be better
+ # to build a new one if we have to replace field
+ clsID = cls.q.id
+ parentID = parentClass.q.id
+ def _get_patched(clause):
+ if isinstance(clause, sqlbuilder.SQLOp):
+ _patch_id_clause(clause)
+ return None
+ elif not isinstance(clause, sqlbuilder.Field):
+ return None
+ elif (clause.tableName == clsID.tableName) \
+ and (clause.fieldName == clsID.fieldName):
+ return parentID
+ else:
+ return None
+ def _patch_id_clause(clause):
+ if not isinstance(clause, sqlbuilder.SQLOp):
+ return
+ expr = _get_patched(clause.expr1)
+ if expr:
+ clause.expr1 = expr
+ expr = _get_patched(clause.expr2)
+ if expr:
+ clause.expr2 = expr
+ _patch_id_clause(clause)
+ # add childName filter
+ clause = sqlbuilder.AND(clause, addClause)
+ return parentClass.select(clause, childUpdate=False,
+ *args, **kwargs)
+ else:
+ return super(InheritableSQLObject, cls).select(
+ clause, *args, **kwargs)
+ select = classmethod(select)
+
def selectBy(cls, connection=None, **kw):
clause = []
for name, value in kw.items():
Modified: SQLObject/trunk/sqlobject/inheritance/iteration.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/iteration.py 2005-12-21 18:46:46 UTC (rev 1438)
+++ SQLObject/trunk/sqlobject/inheritance/iteration.py 2005-12-24 12:01:08 UTC (rev 1439)
@@ -67,10 +67,25 @@
registry = self.select.sourceClass.sqlmeta.registry
for childName, ids in childIdsNames.items():
klass = findClass(childName, registry)
- select = klass.select(sqlbuilder.IN(sqlbuilder.SQLConstant("id"), ids))
+ if len(ids) == 1:
+ select = klass.select(klass.q.id == ids[0],
+ childUpdate=True)
+ else:
+ select = klass.select(sqlbuilder.IN(klass.q.id, ids),
+ childUpdate=True)
query = dbconn.queryForSelect(select)
if dbconn.debug:
dbconn.printDebug(rawconn, query, 'Select children of the class %s' % childName)
self.dbconn._executeRetry(rawconn, cursor, query)
for result in cursor.fetchall():
- self._childrenResults[result[0]] = result[1:]
+ # Inheritance child classes may have no own columns
+ # (that makes sense when child class has a join
+ # that does not apply to parent class objects).
+ # In such cases result[1:] gives an empty tuple
+ # which is interpreted as "no results fetched" in .get().
+ # So .get() issues another query which is absolutely
+ # meaningless (like "SELECT NULL FROM child WHERE id=1").
+ # In order to avoid this, we replace empty results
+ # with non-empty tuple. Extra values in selectResults
+ # are Ok - they will be ignored by ._SO_selectInit().
+ self._childrenResults[result[0]] = result[1:] or (None,)
Modified: SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py 2005-12-21 18:46:46 UTC (rev 1438)
+++ SQLObject/trunk/sqlobject/inheritance/tests/test_deep_inheritance.py 2005-12-24 12:01:08 UTC (rev 1439)
@@ -19,21 +19,41 @@
subdudes = MultipleJoin("DIPerson", joinColumn="manager_id")
def test_deep_inheritance():
+
+ cache = getConnection().cache
+
setupClass(DIManager)
setupClass(DIEmployee)
setupClass(DIPerson)
manager = DIManager(firstName='Project', lastName='Manager',
position='Project Manager')
- employee = DIEmployee(firstName='Project', lastName='Leader',
- position='Project leader', manager=manager)
- person = DIPerson(firstName='Oneof', lastName='Authors', manager=manager)
+ manager_id = manager.id
+ employee_id = DIEmployee(firstName='Project', lastName='Leader',
+ position='Project leader', manager=manager).id
+ person_id = DIPerson(firstName='Oneof', lastName='Authors',
+ manager=manager).id
+ cache.clear()
managers = list(DIManager.select())
assert len(managers) == 1
+ cache.clear()
employees = list(DIEmployee.select())
assert len(employees) == 2
+ cache.clear()
persons = list(DIPerson.select())
assert len(persons) == 3
+ cache.clear()
+
+ person = DIPerson.get(employee_id)
+ assert isinstance(person, DIEmployee)
+
+ person = DIPerson.get(manager_id)
+ assert isinstance(person, DIEmployee)
+ assert isinstance(person, DIManager)
+ cache.clear()
+
+ person = DIEmployee.get(manager_id)
+ assert isinstance(person, DIManager)
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-12-21 18:46:46 UTC (rev 1438)
+++ SQLObject/trunk/sqlobject/main.py 2005-12-24 12:01:08 UTC (rev 1439)
@@ -1513,6 +1513,9 @@
delete = classmethod(delete)
def __repr__(self):
+ if not hasattr(self, 'id'):
+ # Object initialization not finished. No attributes can be read.
+ return '<%s (not initialized)>' % self.__class__.__name__
return '<%s %r %s>' \
% (self.__class__.__name__,
self.id,
|
|
From: SourceForge.net <no...@so...> - 2005-12-24 07:28:23
|
Bugs item #1389410, was opened at 2005-12-23 22:28 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=1389410&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: SQLObject from repository Status: Open Resolution: None Priority: 5 Submitted By: Alvin (alvinwang) Assigned to: Nobody/Anonymous (nobody) Summary: child_name is text Initial Comment: There are performance issues in a number of databases with text fields. I do not think that class names should be an unlimited length. Say 40 characters max and make it a varchar(40). Even 100 characters is okay but there should be a limit. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1389410&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-12-22 01:51:11
|
Bugs item #1387369, was opened at 2005-12-22 04:03 Message generated for change (Comment added) made by jerub You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1387369&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: SQLObject release (specify) Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: tables not created in correct order Initial Comment: When I have this code: class ClassB(SQLObject): ... var1=StringCol() ... class ClassA(SQLObject): ... var2=ForeignKey('ClassB') ... I get an error that relation 'classb' does not exist. So when I execute tg-admin sql create it tries to create the ClassA table first, not checking for the dependencies and create ClassB first. When I created the ClassB table manually (via tg-admin shell), it went all ok. ---------------------------------------------------------------------- Comment By: Stephen Thorne (jerub) Date: 2005-12-22 11:51 Message: Logged In: YES user_id=100823 I have experenced a similar problem in the past with SQLObject based projects. The general solution seems to be, with databases like postgrsql, to create the foreignkeys after all the tables have been created. This is a code snippet that I have used in the past for creating a bunch of tables correctly (used with SQLObject 0.6.0, so don't be surprised if it doesn't work with the latest SQLObject): fkeys = [] tablename = [] pgCSQL = sqlobject.ForeignKey.baseClass.postgresCreateSQL def newfk(c): fkeys.append((tablename[-1], pgCSQL(c).split(',')[1])) return pgCSQL(c).split(',')[0] sqlobject.ForeignKey.baseClass.postgresCreateSQL = newfk import database import views c = database.__connection__ c.autoCommit = True for x in database.__all__: o = getattr(database, x) tablename.append(o._table) o.createTable() for table, key in fkeys: c.query("ALTER TABLE %s ADD %s" % (table, key)) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1387369&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-12-21 18:03:13
|
Bugs item #1387369, was opened at 2005-12-21 10:03 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=1387369&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: SQLObject release (specify) Status: Open Resolution: None Priority: 5 Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: tables not created in correct order Initial Comment: When I have this code: class ClassB(SQLObject): ... var1=StringCol() ... class ClassA(SQLObject): ... var2=ForeignKey('ClassB') ... I get an error that relation 'classb' does not exist. So when I execute tg-admin sql create it tries to create the ClassA table first, not checking for the dependencies and create ClassB first. When I created the ClassB table manually (via tg-admin shell), it went all ok. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1387369&group_id=74338 |
|
From: <sub...@co...> - 2005-12-21 09:54:06
|
Author: phd
Date: 2005-12-21 09:53:59 +0000 (Wed, 21 Dec 2005)
New Revision: 1436
Modified:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
Log:
Merged patches from the revisions 1434:1435 from the trunk: a patch by alexander smishlajev: move inheritance code to InheritableSQLMeta.
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2005-12-21 09:52:41 UTC (rev 1435)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2005-12-21 09:53:59 UTC (rev 1436)
@@ -1,5 +1,6 @@
from sqlobject import sqlbuilder
from sqlobject import classregistry
+from sqlobject import col
from sqlobject.main import sqlmeta, SQLObject, SelectResults, True, False, \
makeProperties, getterName, setterName
import iteration
@@ -40,9 +41,8 @@
tableRegistry[registryClass] = registryClass
for registryClass in allClasses:
if registryClass.sqlmeta.table in tablesDict:
- currentClass = registryClass
- while currentClass._parentClass:
- currentClass = currentClass._parentClass
+ currentClass = registryClass.sqlmeta.parentClass
+ while currentClass:
if tableRegistry.has_key(currentClass):
#DSM: Must keep the last parent needed
#DSM: (to limit the number of join needed)
@@ -50,19 +50,21 @@
#DSM: Remove this class as it is a parent one
#DSM: of a needed children
del tableRegistry[currentClass]
+ currentClass = currentClass.sqlmeta.parentClass
#DSM: Table registry contains only the last children
#DSM: or standalone classes
parentClause = []
for (currentClass, minParentClass) in tableRegistry.items():
- while currentClass != minParentClass and currentClass._parentClass:
- parentClass = currentClass._parentClass
+ while (currentClass != minParentClass) \
+ and currentClass.sqlmeta.parentClass:
+ parentClass = currentClass.sqlmeta.parentClass
parentClause.append(currentClass.q.id == parentClass.q.id)
currentClass = parentClass
tablesDict[currentClass.sqlmeta.table] = 1
clause = reduce(sqlbuilder.AND, parentClause, clause)
- super(InheritableSelectResults, self).__init__(sourceClass, clause, clauseTables,
- **ops)
+ super(InheritableSelectResults, self).__init__(sourceClass,
+ clause, clauseTables, **ops)
class InheritableSQLMeta(sqlmeta):
@@ -71,8 +73,8 @@
#DSM: Try to add parent properties to the current class
#DSM: Only do this once if possible at object creation and once for
#DSM: each new dynamic column to refresh the current class
- if childUpdate or soClass._parentClass:
- for col in soClass._parentClass.sqlmeta.columnList:
+ if sqlmeta.parentClass:
+ for col in sqlmeta.parentClass.sqlmeta.columnList:
cname = col.name
if cname == 'childName': continue
if cname.endswith("ID"): cname = cname[:-2]
@@ -91,7 +93,7 @@
#DSM: Update each child class if needed and existing (only for new
#DSM: dynamic column as no child classes exists at object creation)
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
c.sqlmeta.addColumn(columnDef, connection=connection, childUpdate=True)
addColumn = classmethod(addColumn)
@@ -102,7 +104,7 @@
#DSM: Update each child class if needed
#DSM: and delete properties for this column
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
delattr(c, name)
delColumn = classmethod(delColumn)
@@ -112,8 +114,8 @@
#DSM: Try to add parent properties to the current class
#DSM: Only do this once if possible at object creation and once for
#DSM: each new dynamic join to refresh the current class
- if childUpdate or soClass._parentClass:
- for join in soClass._parentClass.sqlmeta.joins:
+ if sqlmeta.parentClass:
+ for join in sqlmeta.parentClass.sqlmeta.joins:
jname = join.joinMethodName
jarn = join.addRemoveName
setattr(soClass, getterName(jname),
@@ -133,7 +135,7 @@
#DSM: Update each child class if needed and existing (only for new
#DSM: dynamic join as no child classes exists at object creation)
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
c.sqlmeta.addJoin(joinDef, childUpdate=True)
addJoin = classmethod(addJoin)
@@ -144,7 +146,8 @@
#DSM: Update each child class if needed
#DSM: and delete properties for this join
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
+ # FIXME: what is ``meth``?
delattr(c, meth)
delJoin = classmethod(delJoin)
@@ -156,6 +159,55 @@
_inheritable = True
SelectResultsClass = InheritableSelectResults
+ def __classinit__(cls, new_attrs):
+ SQLObject.__classinit__(cls, new_attrs)
+ # if we are a child class, add sqlbuilder fields from parents
+ currentClass = cls.sqlmeta.parentClass
+ while currentClass:
+ for column in currentClass.sqlmeta.columnDefinitions.values():
+ if type(column) == col.ForeignKey:
+ continue
+ setattr(cls.q, column.name,
+ getattr(currentClass.q, column.name))
+ currentClass = currentClass.sqlmeta.parentClass
+
+ # @classmethod
+ def _SO_setupSqlmeta(cls, new_attrs, is_base):
+ # Note: cannot use super(InheritableSQLObject, cls)._SO_setupSqlmeta -
+ # InheritableSQLObject is not defined when it's __classinit__
+ # is run. Cannot use SQLObject._SO_setupSqlmeta, either:
+ # the method would be bound to wrong class.
+ if cls.__name__ == "InheritableSQLObject":
+ call_super = super(cls, cls)
+ else:
+ # InheritableSQLObject must be in globals yet
+ call_super = super(InheritableSQLObject, cls)
+ call_super._SO_setupSqlmeta(new_attrs, is_base)
+ sqlmeta = cls.sqlmeta
+ sqlmeta.childClasses = {}
+ # locate parent class and register this class in it's children
+ sqlmeta.parentClass = None
+ for superclass in cls.__bases__:
+ if getattr(superclass, '_inheritable', False) \
+ and (superclass.__name__ != 'InheritableSQLObject'):
+ if sqlmeta.parentClass:
+ # already have a parent class;
+ # cannot inherit from more than one
+ raise NotImplementedError(
+ "Multiple inheritance is not implemented")
+ sqlmeta.parentClass = superclass
+ superclass.sqlmeta.childClasses[cls.__name__] = cls
+ if sqlmeta.parentClass:
+ # remove inherited column definitions
+ cls.sqlmeta.columns = {}
+ cls.sqlmeta.columnList = []
+ cls.sqlmeta.columnDefinitions = {}
+ # default inheritance child name
+ if not sqlmeta.childName:
+ sqlmeta.childName = cls.__name__
+
+ _SO_setupSqlmeta = classmethod(_SO_setupSqlmeta)
+
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
val = super(InheritableSQLObject, cls).get(id, connection, selectResults)
@@ -166,12 +218,14 @@
if 'childName' in cls.sqlmeta.columns:
childName = val.childName
if childName is not None:
- return val._childClasses[childName].get(id, connection=connection, selectResults=childResults)
+ return cls.sqlmeta.childClasses[childName].get(id,
+ connection=connection, selectResults=childResults)
#DSM: Now, we know we are alone or the last child in a family...
#DSM: It's time to find our parents
inst = val
- while inst._parentClass and not inst._parent:
- inst._parent = inst._parentClass.get(id, connection=connection, childUpdate=True)
+ while inst.sqlmeta.parentClass and not inst._parent:
+ inst._parent = inst.sqlmeta.parentClass.get(id,
+ connection=connection, childUpdate=True)
inst = inst._parent
#DSM: We can now return ourself
return val
@@ -179,14 +233,32 @@
get = classmethod(get)
def _notifyFinishClassCreation(cls):
- if not cls.sqlmeta.columnList:
+ sqlmeta = cls.sqlmeta
+ # verify names of added columns
+ if sqlmeta.parentClass:
+ # FIXME: this does not check for grandparent column overrides
+ parentCols = sqlmeta.parentClass.sqlmeta.columns.keys()
+ for column in sqlmeta.columnList:
+ if column.name == 'childName':
+ raise AttributeError(
+ "The column name 'childName' is reserved")
+ if column.name in parentCols:
+ raise AttributeError("The column '%s' is"
+ " already defined in an inheritable parent"
+ % column.name)
+ # if this class is inheritable, add column for children distinction
+ if cls._inheritable and (cls.__name__ != 'InheritableSQLObject'):
+ sqlmeta.addColumn(col.StringCol(name='childName',
+ # limit string length to get VARCHAR and not CLOB
+ length=255, default=None))
+ if not sqlmeta.columnList:
# There are no columns - call addColumn to propagate columns
# from parent classes to children
- cls.sqlmeta.addColumn(None)
- if not cls.sqlmeta.joins:
+ sqlmeta.addColumn(None)
+ if not sqlmeta.joins:
# There are no joins - call addJoin to propagate joins
# from parent classes to children
- cls.sqlmeta.addJoin(None)
+ sqlmeta.addJoin(None)
_notifyFinishClassCreation = classmethod(_notifyFinishClassCreation)
def _create(self, id, **kw):
@@ -200,8 +272,8 @@
kw = kw['kw']
#DSM: If we are the children of an inheritable class,
#DSM: we must first create our parent
- if self._parentClass:
- parentClass = self._parentClass
+ if self.sqlmeta.parentClass:
+ parentClass = self.sqlmeta.parentClass
new_kw = {}
parent_kw = {}
for (name, value) in kw.items():
@@ -210,8 +282,9 @@
else:
new_kw[name] = value
kw = new_kw
- self._parent = parentClass(kw=parent_kw, connection=self._connection)
- self._parent.childName = self.__class__.__name__
+ parent_kw["childName"] = self.sqlmeta.childName
+ self._parent = parentClass(kw=parent_kw,
+ connection=self._connection)
id = self._parent.id
@@ -244,7 +317,7 @@
def _reprItems(self):
items = super(InheritableSQLObject, self)._reprItems()
# add parent attributes (if any)
- if self._parentClass:
+ if self.sqlmeta.parentClass:
items.extend(self._parent._reprItems())
# filter out our special column
return [item for item in items if item[0] != 'childName']
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-21 09:52:41 UTC (rev 1435)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-21 09:53:59 UTC (rev 1436)
@@ -213,7 +213,7 @@
__metaclass__ = declarative.DeclarativeMeta
# These attributes shouldn't be shared with superclasses:
- _unshared_attributes = ['table', 'idName', 'columns']
+ _unshared_attributes = ['table', 'idName', 'columns', 'childName']
# These are internal bookkeeping attributes; the class-level
# definition is a default for the instances, instances will
@@ -233,6 +233,11 @@
# will be true. It's false by default:
_perConnection = False
+ # Inheritance definitions:
+ parentClass = None # A reference to the parent class
+ childClasses = {} # References to child classes, keyed by childName
+ childName = None # Class name for inheritance child object creation
+
def __classinit__(cls, new_attrs):
for attr in cls._unshared_attributes:
if not new_attrs.has_key(attr):
@@ -691,10 +696,11 @@
#DSM: The _inheritable attribute controls wheter the class can by
#DSM: inherited 'logically' with a foreignKey and a back reference.
_inheritable = False # Is this class inheritable?
- _parentClass = None # A reference to the parent class
_parent = None # A reference to the parent instance
- _childClasses = {} # References to child classes
childName = None # Children name (to be able to get a subclass)
+ # moved to sqlmeta in 0.8:
+ _parentClass = _sqlmeta_attr('parentClass', 2)
+ _childClasses = _sqlmeta_attr('childClasses', 2)
# The law of Demeter: the class should not call another classes by name
SelectResultsClass = SelectResults
@@ -747,44 +753,6 @@
for j in new_attrs['_joins']:
implicitJoins.append(j)
-
- #DSM: Need to know very soon if the class is a child of an
- #DSM: inheritable class. If so, we keep a link to our parent class.
- cls._childClasses = {}
- for superclass in cls.__bases__:
- if hasattr(superclass, '_inheritable') and superclass._inheritable and \
- superclass.__name__ <> "InheritableSQLObject":
- cls._parentClass = superclass
- cls._parent = None
- superclass._childClasses[cls.__name__] = cls
-
- #DSM: If this class is a child of a parent class, we need to do some
- #DSM: attribute check and add a foreign key to the parent.
- if cls._parentClass:
- #DSM: First, look for invalid column name:
- #DSM: reserved ones or same as a parent
- parentCols = cls.sqlmeta.columns.keys()
- for column in implicitColumns:
- cname = column.name
- if cname == 'childName':
- raise AttributeError, \
- "The column name 'childName' is reserved"
- if cname in parentCols:
- raise AttributeError, "The column '%s' is already " \
- "defined in an inheritable parent" % cname
- #DSM: Remove columns if inherited from an inheritable class
- #DSM: as we don't want them. All we want is a foreign key
- #DSM: that points to our parent
- cls.sqlmeta.columns = {}
- cls.sqlmeta.columnList = []
- cls.sqlmeta.columnDefinitions = {}
- #DSM: If this is inheritable, add some default columns
- #DSM: to be able to link to children
- if hasattr(cls, '_inheritable') and cls._inheritable and \
- cls.__name__ <> "InheritableSQLObject":
- cls.sqlmeta.columnDefinitions['childName'] = col.StringCol(
- name='childName', default=None)
-
######################################################
# Set some attributes to their defaults, if necessary.
# First we get the connection:
@@ -837,15 +805,6 @@
if not is_base:
cls.q = sqlbuilder.SQLObjectTable(cls)
- #DSM: If we are a child, get the q magic from the parent
- currentClass = cls
- while currentClass._parentClass:
- currentClass = currentClass._parentClass
- for column in currentClass.sqlmeta.columnDefinitions.values():
- if type(column) == col.ForeignKey: continue
- setattr(cls.q, column.name,
- getattr(currentClass.q, column.name))
-
classregistry.registry(cls.sqlmeta.registry).addClass(cls)
_style = _sqlmeta_attr('style', 2)
|
|
From: <sub...@co...> - 2005-12-21 09:52:53
|
Author: phd
Date: 2005-12-21 09:52:41 +0000 (Wed, 21 Dec 2005)
New Revision: 1435
Modified:
SQLObject/trunk/sqlobject/inheritance/__init__.py
SQLObject/trunk/sqlobject/main.py
Log:
A patch by alexander smishlajev: move inheritance code to InheritableSQLMeta.
Modified: SQLObject/trunk/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-12-20 21:44:56 UTC (rev 1434)
+++ SQLObject/trunk/sqlobject/inheritance/__init__.py 2005-12-21 09:52:41 UTC (rev 1435)
@@ -1,5 +1,6 @@
from sqlobject import sqlbuilder
from sqlobject import classregistry
+from sqlobject import col
from sqlobject.main import sqlmeta, SQLObject, SelectResults, True, False, \
makeProperties, getterName, setterName
import iteration
@@ -40,9 +41,8 @@
tableRegistry[registryClass] = registryClass
for registryClass in allClasses:
if registryClass.sqlmeta.table in tablesDict:
- currentClass = registryClass
- while currentClass._parentClass:
- currentClass = currentClass._parentClass
+ currentClass = registryClass.sqlmeta.parentClass
+ while currentClass:
if tableRegistry.has_key(currentClass):
#DSM: Must keep the last parent needed
#DSM: (to limit the number of join needed)
@@ -50,19 +50,21 @@
#DSM: Remove this class as it is a parent one
#DSM: of a needed children
del tableRegistry[currentClass]
+ currentClass = currentClass.sqlmeta.parentClass
#DSM: Table registry contains only the last children
#DSM: or standalone classes
parentClause = []
for (currentClass, minParentClass) in tableRegistry.items():
- while currentClass != minParentClass and currentClass._parentClass:
- parentClass = currentClass._parentClass
+ while (currentClass != minParentClass) \
+ and currentClass.sqlmeta.parentClass:
+ parentClass = currentClass.sqlmeta.parentClass
parentClause.append(currentClass.q.id == parentClass.q.id)
currentClass = parentClass
tablesDict[currentClass.sqlmeta.table] = 1
clause = reduce(sqlbuilder.AND, parentClause, clause)
- super(InheritableSelectResults, self).__init__(sourceClass, clause, clauseTables,
- **ops)
+ super(InheritableSelectResults, self).__init__(sourceClass,
+ clause, clauseTables, **ops)
class InheritableSQLMeta(sqlmeta):
@@ -71,8 +73,8 @@
#DSM: Try to add parent properties to the current class
#DSM: Only do this once if possible at object creation and once for
#DSM: each new dynamic column to refresh the current class
- if childUpdate or soClass._parentClass:
- for col in soClass._parentClass.sqlmeta.columnList:
+ if sqlmeta.parentClass:
+ for col in sqlmeta.parentClass.sqlmeta.columnList:
cname = col.name
if cname == 'childName': continue
if cname.endswith("ID"): cname = cname[:-2]
@@ -91,7 +93,7 @@
#DSM: Update each child class if needed and existing (only for new
#DSM: dynamic column as no child classes exists at object creation)
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
c.sqlmeta.addColumn(columnDef, connection=connection, childUpdate=True)
addColumn = classmethod(addColumn)
@@ -102,7 +104,7 @@
#DSM: Update each child class if needed
#DSM: and delete properties for this column
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
delattr(c, name)
delColumn = classmethod(delColumn)
@@ -112,8 +114,8 @@
#DSM: Try to add parent properties to the current class
#DSM: Only do this once if possible at object creation and once for
#DSM: each new dynamic join to refresh the current class
- if childUpdate or soClass._parentClass:
- for join in soClass._parentClass.sqlmeta.joins:
+ if sqlmeta.parentClass:
+ for join in sqlmeta.parentClass.sqlmeta.joins:
jname = join.joinMethodName
jarn = join.addRemoveName
setattr(soClass, getterName(jname),
@@ -133,7 +135,7 @@
#DSM: Update each child class if needed and existing (only for new
#DSM: dynamic join as no child classes exists at object creation)
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
c.sqlmeta.addJoin(joinDef, childUpdate=True)
addJoin = classmethod(addJoin)
@@ -144,7 +146,8 @@
#DSM: Update each child class if needed
#DSM: and delete properties for this join
- for c in soClass._childClasses.values():
+ for c in sqlmeta.childClasses.values():
+ # FIXME: what is ``meth``?
delattr(c, meth)
delJoin = classmethod(delJoin)
@@ -156,6 +159,55 @@
_inheritable = True
SelectResultsClass = InheritableSelectResults
+ def __classinit__(cls, new_attrs):
+ SQLObject.__classinit__(cls, new_attrs)
+ # if we are a child class, add sqlbuilder fields from parents
+ currentClass = cls.sqlmeta.parentClass
+ while currentClass:
+ for column in currentClass.sqlmeta.columnDefinitions.values():
+ if type(column) == col.ForeignKey:
+ continue
+ setattr(cls.q, column.name,
+ getattr(currentClass.q, column.name))
+ currentClass = currentClass.sqlmeta.parentClass
+
+ # @classmethod
+ def _SO_setupSqlmeta(cls, new_attrs, is_base):
+ # Note: cannot use super(InheritableSQLObject, cls)._SO_setupSqlmeta -
+ # InheritableSQLObject is not defined when it's __classinit__
+ # is run. Cannot use SQLObject._SO_setupSqlmeta, either:
+ # the method would be bound to wrong class.
+ if cls.__name__ == "InheritableSQLObject":
+ call_super = super(cls, cls)
+ else:
+ # InheritableSQLObject must be in globals yet
+ call_super = super(InheritableSQLObject, cls)
+ call_super._SO_setupSqlmeta(new_attrs, is_base)
+ sqlmeta = cls.sqlmeta
+ sqlmeta.childClasses = {}
+ # locate parent class and register this class in it's children
+ sqlmeta.parentClass = None
+ for superclass in cls.__bases__:
+ if getattr(superclass, '_inheritable', False) \
+ and (superclass.__name__ != 'InheritableSQLObject'):
+ if sqlmeta.parentClass:
+ # already have a parent class;
+ # cannot inherit from more than one
+ raise NotImplementedError(
+ "Multiple inheritance is not implemented")
+ sqlmeta.parentClass = superclass
+ superclass.sqlmeta.childClasses[cls.__name__] = cls
+ if sqlmeta.parentClass:
+ # remove inherited column definitions
+ cls.sqlmeta.columns = {}
+ cls.sqlmeta.columnList = []
+ cls.sqlmeta.columnDefinitions = {}
+ # default inheritance child name
+ if not sqlmeta.childName:
+ sqlmeta.childName = cls.__name__
+
+ _SO_setupSqlmeta = classmethod(_SO_setupSqlmeta)
+
def get(cls, id, connection=None, selectResults=None, childResults=None, childUpdate=False):
val = super(InheritableSQLObject, cls).get(id, connection, selectResults)
@@ -166,12 +218,14 @@
if 'childName' in cls.sqlmeta.columns:
childName = val.childName
if childName is not None:
- return val._childClasses[childName].get(id, connection=connection, selectResults=childResults)
+ return cls.sqlmeta.childClasses[childName].get(id,
+ connection=connection, selectResults=childResults)
#DSM: Now, we know we are alone or the last child in a family...
#DSM: It's time to find our parents
inst = val
- while inst._parentClass and not inst._parent:
- inst._parent = inst._parentClass.get(id, connection=connection, childUpdate=True)
+ while inst.sqlmeta.parentClass and not inst._parent:
+ inst._parent = inst.sqlmeta.parentClass.get(id,
+ connection=connection, childUpdate=True)
inst = inst._parent
#DSM: We can now return ourself
return val
@@ -179,14 +233,32 @@
get = classmethod(get)
def _notifyFinishClassCreation(cls):
- if not cls.sqlmeta.columnList:
+ sqlmeta = cls.sqlmeta
+ # verify names of added columns
+ if sqlmeta.parentClass:
+ # FIXME: this does not check for grandparent column overrides
+ parentCols = sqlmeta.parentClass.sqlmeta.columns.keys()
+ for column in sqlmeta.columnList:
+ if column.name == 'childName':
+ raise AttributeError(
+ "The column name 'childName' is reserved")
+ if column.name in parentCols:
+ raise AttributeError("The column '%s' is"
+ " already defined in an inheritable parent"
+ % column.name)
+ # if this class is inheritable, add column for children distinction
+ if cls._inheritable and (cls.__name__ != 'InheritableSQLObject'):
+ sqlmeta.addColumn(col.StringCol(name='childName',
+ # limit string length to get VARCHAR and not CLOB
+ length=255, default=None))
+ if not sqlmeta.columnList:
# There are no columns - call addColumn to propagate columns
# from parent classes to children
- cls.sqlmeta.addColumn(None)
- if not cls.sqlmeta.joins:
+ sqlmeta.addColumn(None)
+ if not sqlmeta.joins:
# There are no joins - call addJoin to propagate joins
# from parent classes to children
- cls.sqlmeta.addJoin(None)
+ sqlmeta.addJoin(None)
_notifyFinishClassCreation = classmethod(_notifyFinishClassCreation)
def _create(self, id, **kw):
@@ -200,8 +272,8 @@
kw = kw['kw']
#DSM: If we are the children of an inheritable class,
#DSM: we must first create our parent
- if self._parentClass:
- parentClass = self._parentClass
+ if self.sqlmeta.parentClass:
+ parentClass = self.sqlmeta.parentClass
new_kw = {}
parent_kw = {}
for (name, value) in kw.items():
@@ -210,8 +282,9 @@
else:
new_kw[name] = value
kw = new_kw
- self._parent = parentClass(kw=parent_kw, connection=self._connection)
- self._parent.childName = self.__class__.__name__
+ parent_kw["childName"] = self.sqlmeta.childName
+ self._parent = parentClass(kw=parent_kw,
+ connection=self._connection)
id = self._parent.id
@@ -244,7 +317,7 @@
def _reprItems(self):
items = super(InheritableSQLObject, self)._reprItems()
# add parent attributes (if any)
- if self._parentClass:
+ if self.sqlmeta.parentClass:
items.extend(self._parent._reprItems())
# filter out our special column
return [item for item in items if item[0] != 'childName']
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-12-20 21:44:56 UTC (rev 1434)
+++ SQLObject/trunk/sqlobject/main.py 2005-12-21 09:52:41 UTC (rev 1435)
@@ -213,7 +213,7 @@
__metaclass__ = declarative.DeclarativeMeta
# These attributes shouldn't be shared with superclasses:
- _unshared_attributes = ['table', 'idName', 'columns']
+ _unshared_attributes = ['table', 'idName', 'columns', 'childName']
# These are internal bookkeeping attributes; the class-level
# definition is a default for the instances, instances will
@@ -233,6 +233,11 @@
# will be true. It's false by default:
_perConnection = False
+ # Inheritance definitions:
+ parentClass = None # A reference to the parent class
+ childClasses = {} # References to child classes, keyed by childName
+ childName = None # Class name for inheritance child object creation
+
def __classinit__(cls, new_attrs):
for attr in cls._unshared_attributes:
if not new_attrs.has_key(attr):
@@ -691,10 +696,11 @@
#DSM: The _inheritable attribute controls wheter the class can by
#DSM: inherited 'logically' with a foreignKey and a back reference.
_inheritable = False # Is this class inheritable?
- _parentClass = None # A reference to the parent class
_parent = None # A reference to the parent instance
- _childClasses = {} # References to child classes
childName = None # Children name (to be able to get a subclass)
+ # moved to sqlmeta in 0.8:
+ _parentClass = _sqlmeta_attr('parentClass', 2)
+ _childClasses = _sqlmeta_attr('childClasses', 2)
# The law of Demeter: the class should not call another classes by name
SelectResultsClass = SelectResults
@@ -747,44 +753,6 @@
for j in new_attrs['_joins']:
implicitJoins.append(j)
-
- #DSM: Need to know very soon if the class is a child of an
- #DSM: inheritable class. If so, we keep a link to our parent class.
- cls._childClasses = {}
- for superclass in cls.__bases__:
- if hasattr(superclass, '_inheritable') and superclass._inheritable and \
- superclass.__name__ <> "InheritableSQLObject":
- cls._parentClass = superclass
- cls._parent = None
- superclass._childClasses[cls.__name__] = cls
-
- #DSM: If this class is a child of a parent class, we need to do some
- #DSM: attribute check and add a foreign key to the parent.
- if cls._parentClass:
- #DSM: First, look for invalid column name:
- #DSM: reserved ones or same as a parent
- parentCols = cls.sqlmeta.columns.keys()
- for column in implicitColumns:
- cname = column.name
- if cname == 'childName':
- raise AttributeError, \
- "The column name 'childName' is reserved"
- if cname in parentCols:
- raise AttributeError, "The column '%s' is already " \
- "defined in an inheritable parent" % cname
- #DSM: Remove columns if inherited from an inheritable class
- #DSM: as we don't want them. All we want is a foreign key
- #DSM: that points to our parent
- cls.sqlmeta.columns = {}
- cls.sqlmeta.columnList = []
- cls.sqlmeta.columnDefinitions = {}
- #DSM: If this is inheritable, add some default columns
- #DSM: to be able to link to children
- if hasattr(cls, '_inheritable') and cls._inheritable and \
- cls.__name__ <> "InheritableSQLObject":
- cls.sqlmeta.columnDefinitions['childName'] = col.StringCol(
- name='childName', default=None)
-
######################################################
# Set some attributes to their defaults, if necessary.
# First we get the connection:
@@ -837,15 +805,6 @@
if not is_base:
cls.q = sqlbuilder.SQLObjectTable(cls)
- #DSM: If we are a child, get the q magic from the parent
- currentClass = cls
- while currentClass._parentClass:
- currentClass = currentClass._parentClass
- for column in currentClass.sqlmeta.columnDefinitions.values():
- if type(column) == col.ForeignKey: continue
- setattr(cls.q, column.name,
- getattr(currentClass.q, column.name))
-
classregistry.registry(cls.sqlmeta.registry).addClass(cls)
_style = _sqlmeta_attr('style', 2)
|
|
From: SourceForge.net <no...@so...> - 2005-12-20 15:09:31
|
Patches item #1386249, was opened at 2005-12-20 15:09 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1386249&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: Jan-Wijbrand Kolman (j-w) Assigned to: Nobody/Anonymous (nobody) Summary: Date(time) converters cannot handle dates before 1900 Initial Comment: The Date(time) converters rely on Python's datetime.strftime method. This method cannot handle dates with years < 1900. The attached patch uses 'normal' string interpolation to overcome this limitiation. A test for this fix is included in the patch. I hope this patch proofs to be useful and can be applied to the SQLObject codebase. Thx for the great library! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1386249&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-12-20 05:37:07
|
Patches item #1385854, was opened at 2005-12-20 06:37 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=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: Open Resolution: None 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.) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1385854&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-12-18 22:28:56
|
Bugs item #1384706, was opened at 2005-12-18 23:28 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=1384706&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: Matthias Urlichs (smurf) Assigned to: Nobody/Anonymous (nobody) Summary: n:m join of a table with itself overwrites methods Initial Comment: I'm trying to do a n:m join of a table with itself. Unfortunately, the accessor methods are named only by the referenced table and thus get overwritten. The same problem would occur if I had two *different* RelatedJoins between two tables, which is not at all unheard-of. class ACLUser(sql.SQLObject): """\ This class represents a user (or group). Names are not necessarily unique; for the most part, visibility rules control which ACLs anybody can see. """ name = sql.StringCol(length=40, notNone = True) groups = sql.RelatedJoin('ACLUser', joinColumn='user_id', otherColumn='group_id', intermediateTable='acl_roles') members = sql.RelatedJoin('ACLUser', joinColumn='group_id', otherColumn='user_id', intermediateTable='acl_roles', createRelatedTable=False) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1384706&group_id=74338 |
|
From: <sub...@co...> - 2005-12-16 18:05:36
|
Author: test Date: 2005-12-16 18:05:27 +0000 (Fri, 16 Dec 2005) New Revision: 1429 Modified: SQLObject/contrib/ Log: Added my own recipes to ianb/ Property changes on: SQLObject/contrib ___________________________________________________________________ Name: svn:externals + ianb http://svn.colorstudy.com/home/ianb/sqlobject-recipes |
|
From: <sub...@co...> - 2005-12-16 13:58:29
|
Author: phd
Date: 2005-12-16 13:58:24 +0000 (Fri, 16 Dec 2005)
New Revision: 1427
Modified:
home/phd/SQLObject/paramstyles/sqlobject/main.py
Log:
Merged the rev. 1425 from the trunk: a patch by Yuan HOng <hon...@gm...> -
.get() updates the object using passed selectResults.
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-16 13:58:11 UTC (rev 1426)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-16 13:58:24 UTC (rev 1427)
@@ -960,6 +960,13 @@
cache.put(id, cls, val)
finally:
cache.finishPut(cls)
+ elif selectResults and not val.dirty:
+ val._SO_writeLock.acquire()
+ try:
+ val._SO_selectInit(selectResults)
+ val.sqlmeta.expired = False
+ finally:
+ val._SO_writeLock.release()
return val
get = classmethod(get)
|
|
From: <sub...@co...> - 2005-12-16 13:58:20
|
Author: phd
Date: 2005-12-16 13:58:11 +0000 (Fri, 16 Dec 2005)
New Revision: 1426
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/main.py
Log:
Merged the rev. 1425 from the trunk: a patch by Yuan HOng <hon...@gm...> -
.get() updates the object using passed selectResults.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/main.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/main.py 2005-12-16 13:56:56 UTC (rev 1425)
+++ SQLObject/branches/0.7-bugfix/sqlobject/main.py 2005-12-16 13:58:11 UTC (rev 1426)
@@ -909,6 +909,13 @@
cache.put(id, cls, val)
finally:
cache.finishPut(cls)
+ elif selectResults and not val.dirty:
+ val._SO_writeLock.acquire()
+ try:
+ val._SO_selectInit(selectResults)
+ val.sqlmeta.expired = False
+ finally:
+ val._SO_writeLock.release()
return val
get = classmethod(get)
|
|
From: <sub...@co...> - 2005-12-16 13:57:13
|
Author: phd
Date: 2005-12-16 13:56:56 +0000 (Fri, 16 Dec 2005)
New Revision: 1425
Modified:
SQLObject/trunk/sqlobject/main.py
Log:
A patch by Yuan HOng <hon...@gm...> -
.get() updates the object using passed selectResults.
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-12-15 16:56:09 UTC (rev 1424)
+++ SQLObject/trunk/sqlobject/main.py 2005-12-16 13:56:56 UTC (rev 1425)
@@ -960,6 +960,13 @@
cache.put(id, cls, val)
finally:
cache.finishPut(cls)
+ elif selectResults and not val.dirty:
+ val._SO_writeLock.acquire()
+ try:
+ val._SO_selectInit(selectResults)
+ val.sqlmeta.expired = False
+ finally:
+ val._SO_writeLock.release()
return val
get = classmethod(get)
|
|
From: <sub...@co...> - 2005-12-15 16:56:13
|
Author: phd
Date: 2005-12-15 16:56:09 +0000 (Thu, 15 Dec 2005)
New Revision: 1424
Modified:
home/phd/SQLObject/paramstyles/sqlobject/main.py
Log:
Merged from the trunk rev 1422: a patch by Andres Freund <an...@an...> to clear _SO_createValue on .expire().
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-15 16:49:59 UTC (rev 1423)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2005-12-15 16:56:09 UTC (rev 1424)
@@ -1067,6 +1067,7 @@
delattr(self, instanceName(column.name))
self.sqlmeta.expired = True
self._connection.cache.expire(self.id, self.__class__)
+ self._SO_createValues = {}
finally:
self._SO_writeLock.release()
|
|
From: <sub...@co...> - 2005-12-15 16:50:06
|
Author: phd
Date: 2005-12-15 16:49:59 +0000 (Thu, 15 Dec 2005)
New Revision: 1423
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/main.py
Log:
Merged from the trunk rev 1422: a patch by Andres Freund <an...@an...> to clear _SO_createValue on .expire().
Modified: SQLObject/branches/0.7-bugfix/sqlobject/main.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/main.py 2005-12-15 16:49:22 UTC (rev 1422)
+++ SQLObject/branches/0.7-bugfix/sqlobject/main.py 2005-12-15 16:49:59 UTC (rev 1423)
@@ -1016,6 +1016,7 @@
delattr(self, instanceName(column.name))
self.sqlmeta.expired = True
self._connection.cache.expire(self.id, self.__class__)
+ self._SO_createValues = {}
finally:
self._SO_writeLock.release()
|
|
From: <sub...@co...> - 2005-12-15 16:49:28
|
Author: phd
Date: 2005-12-15 16:49:22 +0000 (Thu, 15 Dec 2005)
New Revision: 1422
Modified:
SQLObject/trunk/sqlobject/main.py
Log:
A patch Andres Freund <an...@an...> to clear _SO_createValue on .expire().
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2005-12-14 23:24:40 UTC (rev 1421)
+++ SQLObject/trunk/sqlobject/main.py 2005-12-15 16:49:22 UTC (rev 1422)
@@ -1067,6 +1067,7 @@
delattr(self, instanceName(column.name))
self.sqlmeta.expired = True
self._connection.cache.expire(self.id, self.__class__)
+ self._SO_createValues = {}
finally:
self._SO_writeLock.release()
|
|
From: SourceForge.net <no...@so...> - 2005-12-14 12:51:01
|
Patches item #1380405, was opened at 2005-12-14 13:51 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1380405&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: I*igo Serna (inigoserna) Assigned to: Nobody/Anonymous (nobody) Summary: enable check_same_thread option in SQLiteConnection Initial Comment: Hi there, For a project I'm writing using CherryPy + SQLObject + sqlite3 I need to pass "enable_check_same_thread = False" option to pysqlite2 in SQLiteConnection, but SQLObject 0.7rc1 doesn't allow it, so I've written this simple patch. I know this is an evil option, but I *really* need it in my project (cherrypy app is exposed to apache using mpcp-1.2) or it's the only solution I've found. Default remains safe enable_check_same_thread = True option. Patch is against SQLObject 0.7rc1. Iñigo ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1380405&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2005-12-14 10:18:06
|
Bugs item #1380296, was opened at 2005-12-14 10:17 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=1380296&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: SQLObject from repository Status: Open Resolution: None Priority: 5 Submitted By: TH (therve) Assigned to: Nobody/Anonymous (nobody) Summary: idSequence should be in sqlmeta Initial Comment: All is in title : to be consistent with the move of table, idName etc. in sqlmeta, the idSequence attribute should also be move there. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1380296&group_id=74338 |
|
From: <sub...@co...> - 2005-12-12 16:15:18
|
Author: phd
Date: 2005-12-12 16:15:10 +0000 (Mon, 12 Dec 2005)
New Revision: 1419
Modified:
home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_select.py
Log:
Merged a patch from the revisions 1418:1418 from the trunk: a patch by j.kartnaller <j.k...@ro...> to allow .selectBy() without keywords.
Modified: home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2005-12-12 16:11:04 UTC (rev 1418)
+++ home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2005-12-12 16:15:10 UTC (rev 1419)
@@ -705,6 +705,8 @@
data[col.dbName] = None
else:
data[col.dbName] = obj.id
+ if not data:
+ return None
return ' AND '.join(
['%s %s %s' %
(dbName, ops.get(value, "="), self.sqlrepr(value))
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_select.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_select.py 2005-12-12 16:11:04 UTC (rev 1418)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_select.py 2005-12-12 16:15:10 UTC (rev 1419)
@@ -84,8 +84,12 @@
b2 = IterTest(name='b')
raises(SQLObjectIntegrityError, 'IterTest.selectBy(name="b").getOne()')
raises(SQLObjectIntegrityError, 'IterTest.selectBy(name="b").getOne(None)')
-
+def test_selectBy():
+ setupClass(IterTest)
+ a = IterTest(name='a')
+ b = IterTest(name='b')
+ assert IterTest.selectBy().count() == 2
class Counter2(SQLObject):
|
|
From: <sub...@co...> - 2005-12-12 16:11:16
|
Author: phd
Date: 2005-12-12 16:11:04 +0000 (Mon, 12 Dec 2005)
New Revision: 1418
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py
Log:
Merged the patch from rev 1417 from the trunk:
a patch by "j.kartnaller" <j.k...@ro...> to allow .select() without keywords.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py 2005-12-12 16:10:14 UTC (rev 1417)
+++ SQLObject/branches/0.7-bugfix/sqlobject/dbconnection.py 2005-12-12 16:11:04 UTC (rev 1418)
@@ -640,6 +640,8 @@
data[col.dbName] = None
else:
data[col.dbName] = obj.id
+ if not data:
+ return None
return ' AND '.join(
['%s %s %s' %
(dbName, ops.get(value, "="), self.sqlrepr(value))
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py 2005-12-12 16:10:14 UTC (rev 1417)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py 2005-12-12 16:11:04 UTC (rev 1418)
@@ -71,9 +71,13 @@
pass
assert count == len(names)
+def test_selectBy():
+ setupClass(IterTest)
+ a = IterTest(name='a')
+ b = IterTest(name='b')
+ assert IterTest.selectBy().count() == 2
-
class Counter2(SQLObject):
n1 = IntCol(notNull=True)
|
|
From: <sub...@co...> - 2005-12-12 16:10:23
|
Author: phd
Date: 2005-12-12 16:10:14 +0000 (Mon, 12 Dec 2005)
New Revision: 1417
Modified:
SQLObject/trunk/sqlobject/dbconnection.py
SQLObject/trunk/sqlobject/tests/test_select.py
Log:
A patch by "j.kartnaller" <j.k...@ro...> to allow .select() without keywords.
Modified: SQLObject/trunk/sqlobject/dbconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/dbconnection.py 2005-12-12 08:33:20 UTC (rev 1416)
+++ SQLObject/trunk/sqlobject/dbconnection.py 2005-12-12 16:10:14 UTC (rev 1417)
@@ -692,6 +692,8 @@
data[col.dbName] = None
else:
data[col.dbName] = obj.id
+ if not data:
+ return None
return ' AND '.join(
['%s %s %s' %
(dbName, ops.get(value, "="), self.sqlrepr(value))
Modified: SQLObject/trunk/sqlobject/tests/test_select.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_select.py 2005-12-12 08:33:20 UTC (rev 1416)
+++ SQLObject/trunk/sqlobject/tests/test_select.py 2005-12-12 16:10:14 UTC (rev 1417)
@@ -84,8 +84,12 @@
b2 = IterTest(name='b')
raises(SQLObjectIntegrityError, 'IterTest.selectBy(name="b").getOne()')
raises(SQLObjectIntegrityError, 'IterTest.selectBy(name="b").getOne(None)')
-
+def test_selectBy():
+ setupClass(IterTest)
+ a = IterTest(name='a')
+ b = IterTest(name='b')
+ assert IterTest.selectBy().count() == 2
class Counter2(SQLObject):
|