dabo Commit
Revision 6279
Date: 2010-12-24 16:10:04 -0800 (Fri, 24 Dec 2010)
Author: Jacekk
Trac: http://trac.dabodev.com/changeset/6279
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/db/dCursorMixin.py
Log:
It's not the common practice, use of compound keys, but now Dabo allows such
behavior, I hope.
This commit should also fix DBQueryException SQL syntax error near parameter
placeholder '%s' reported by some users.
It's serious change in business and data layer, and although I tested this
changes over the past few months, please report any issue immediately.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2010-12-24 13:41:02 UTC (rev 6278)
+++ trunk/dabo/biz/dBizobj.py 2010-12-25 00:10:04 UTC (rev 6279)
@@ -1042,22 +1042,29 @@
there is no parent record, there cannot be any child records
saved yet,
so an empty query is built.
"""
- # Return a tuple of the params. Default to an empty tuple.
ret = tuple()
if self.DataSource and self.LinkField and self.Parent:
- if self.Parent.RowCount == 0:
- # Parent is new and not yet saved, so we cannot
have child records yet.
-
self._CurrentCursor.setNonMatchChildFilterClause()
+ links = self.LinkField.replace(" ", "").split(",")
+ # It's not necessary to requery if parent has no records
+ # or parent row is new and child is linked with parent
PK.
+ # Use of setNonMatchChildFilterClause is no more
necessary,
+ # and SQL query never changes, but parameters does.
+ if not self.Parent.RowCount or \
+ (self.Parent.IsAdding and not
self.ParentLinkField):
+ ret = tuple((None,)) * len(links)
else:
- val = self.getParentLinkValue()
- linkFieldParts = self.LinkField.split(".")
+ ret = self.getParentLinkValue()
+ linkFields = tuple()
+ for linkField in links:
+ linkFieldParts = linkField.split(".")
if len(linkFieldParts) < 2:
- linkField = self.LinkField
+ linkFields += (linkFieldParts[0],)
else:
# The source table was specified in the
LinkField
- linkField = linkFieldParts[1]
- self._CurrentCursor.setChildFilter(linkField)
- ret = (val, )
+ linkFields += (linkFieldParts[1],)
+ self._CurrentCursor.setChildFilter(linkFields)
+ if not isinstance(ret, tuple):
+ ret = (ret,)
return ret
@@ -1066,17 +1073,22 @@
is the PK of the parent, but can be a non-PK field, if this
bizobj's ParentLinkField is
not empty.
"""
- if not self.Parent:
- return None
- fld = self.ParentLinkField
- try:
- if not fld:
- # Use the PK value
- ret = self.getParentPK()
- else:
- ret = self.Parent.getFieldVal(fld)
- except dException.NoRecordsException:
- ret = NO_RECORDS_PK
+ ret = None
+ if self.Parent:
+ fld = self.ParentLinkField
+ try:
+ if not fld:
+ # Use the PK value
+ ret = self.getParentPK()
+ else:
+ flds = fld.replace(" ", "").split(",")
+ ret = map(self.Parent.getFieldVal,
tuple(flds))
+ if len(ret) == 1:
+ ret = ret[0]
+ else:
+ ret = tuple(ret)
+ except dException.NoRecordsException:
+ ret = NO_RECORDS_PK
return ret
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2010-12-24 13:41:02 UTC (rev 6278)
+++ trunk/dabo/db/dCursorMixin.py 2010-12-25 00:10:04 UTC (rev 6279)
@@ -2273,12 +2273,11 @@
def setChildFilter(self, fld):
- """ This method sets the appropriate WHERE filter for dependent
child queries."""
+ """ This method sets the appropriate filter for dependent child
queries."""
def getTableAlias(fromClause):
if not fromClause.strip():
return None
-
joinStrings = ["left join", "right join", "outer join",
"inner join", "join"]
foundAlias = None
for joinString in joinStrings:
@@ -2295,7 +2294,10 @@
if not alias:
# Use the old way (pre 2180) of using the Table
(DataSource) property.
alias = self.Table
- filtExpr = " %s.%s = %s " % (alias, fld, self.ParamPlaceholder)
+ if not isinstance(fld, (list, tuple)):
+ fld = (fld,)
+ filtExpr = "and".join([" %s.%s = %s " % (alias, fldExpr,
self.ParamPlaceholder)
+ for fldExpr in fld])
self.setChildFilterClause(filtExpr)
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]