[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix GDL2, EOSQLExpression (prepareSelectExpressionWithAttributes)
From: |
Georg Fleischmann |
Subject: |
Fix GDL2, EOSQLExpression (prepareSelectExpressionWithAttributes) |
Date: |
Fri, 24 Jul 2009 15:54:57 +0800 |
here is another fix for [EOSQLExpression -
prepareSelectExpressionWithAttributes:] to make aggregate functions
like "count(*)" and "sum(amount)" work.
These functions are set in an attribute's definition and look like
that in the EOmodeld:
{
definition = "count(*)";
externalType = int4;
isReadOnly = Y;
name = countEntries;
valueClassName = NSNumber;
valueType = i;
},
To make this work I filled a TODO for flattened Attributes (is it
correct that these attributes appear flattened?).
My code adds the definition of the attribute to the listString, but
only if it's not a relationship (= contains a dot).
The second patch in EOExpressionArray changes a hard-coded dot "." to
_infix, so that the functions will not end up like "count.(*)" and
"sum.(.amount.)" in the SELECT.
* EOAccess/EOSQLExpression ([EOSQLExpression -
prepareSelectExpressionWithAttributes:]):
set listString for "flattened attributes" with a definition like count
(*) or sum(amount)
* EOAccess/EOExpressionArray (EOExpressionArray -
valueForSQLExpression:):
use _infix instead of "."
Best wishes,
Georg Fleischmann
*** EOAccess/EOSQLExpression.m.old Wed Jul 22 18:06:02 2009
--- EOAccess/EOSQLExpression.m Thu Jul 23 13:46:37 2009
***************
*** 684,692 ****
{
EOAttribute *attribute = [attributes objectAtIndex: i];
! if ([attribute isFlattened])
! {
! NSEmitTODO(); //TODO???
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"flattened
attribute=%@",
attribute);
}
--- 684,698 ----
{
EOAttribute *attribute = [attributes objectAtIndex: i];
! if ([attribute isFlattened]) // we have to add definitions
that are not relationships
! { NSMutableString *listString = [self listString];
! NSString *definition = [attribute definition];
!
! if ( [definition rangeOfString:@"."].length == 0 ) // arg
! {
! [self appendItem: definition
! toListString: listString];
! }
EOFLOGObjectLevelArgs(@"EOSQLExpression", @"flattened
attribute=%@",
attribute);
}
*** EOAccess/EOExpressionArray.m.old Tue Jan 22 21:57:07 2008
--- EOAccess/EOExpressionArray.m Wed Jul 22 17:52:49 2009
***************
*** 365,372 ****
relValue = [obj valueForSQLExpression: sqlExpression];
! if (i > 0)
! [value appendString: @"."];
[value appendString: relValue];
}
--- 365,372 ----
relValue = [obj valueForSQLExpression: sqlExpression];
! if (i > 0 && _infix)
! [value appendString: _infix];
[value appendString: relValue];
}
- Fix GDL2, EOSQLExpression (prepareSelectExpressionWithAttributes),
Georg Fleischmann <=