the first thing I’ve spotted in code above - you cannot directly use date as string to filter on field with Date datatype. Instead you need to use NSDate instance.
So you’ll need to change your code something like this:
When you will provide NSDate instances in your predicate, this predicate will be converted into proper DynamicWhere XML, with the same constant node but of DataTime type. Something like
1392160000
The reason you need to provide NSDate instances is that your string date can be written in dozen different formats, and system will not be able to transform it into proper NSDate value. It’s up to you to convert human-readable date strings to exact NSDate.
Now the predicate is (when printed) out, like this:
NSPredicate BookingProgressStatus == 3 AND bBookingIsComplete == 0 AND (dDate >= CAST(382117080.596557, "NSDate") AND dDate <= CAST(387301080.596572, "NSDate"))
Note that the original behaviour I commented on is still present. The dates are being completely ignored (they should all be within 30 days +/- of todays date, but the entire database row set is being returned for all date values, ignoring the date condition completely.
Note that XML inside PRE html tags is still mangled by your blog engine. The XML can’t be pasted into your blog commenting system. You can see the xml here:
Also note that when I put parenthesis around predicates, Apple’s code removes them, thus the NSPredicate prints field1 == 3 and field2 == 0 even though I included parenthesis. (field1 == 3) AND (field2 == 0)
I debugged into uDAEngine.pas and I see that the breakage is happening inside uDAEngine at the stage where the XMLWhere stuff is resolved into real SQL. The breakage may be specific to only MS SQL.
You can see my XML where condition which has 4 AND boolean conditions,
and the short circuited SQL result that clearly only has 2 SQL AND conditions
in its where clause here:
The difference between XML that works, and XML that doesn’t work is that the RemObjects “XML Where” syntax GENERATOR from XCODE CLIENTS generates more than 2 conditions under a single AND binaryoperation but the Data Abstract Server code on Delphi only processes the first two of them.
If you write the following in Pascal in Delphi and andcond is an array of 5 or 6 elements, the binary-expression-expansion of the TDAWhereExpressions is done in a way that results in the XML conditions NOT including more than 2 AND conditions in a row.
wb.NewBinaryExpressionList(andcond,dboAnd)
The logic in the RemObjects DA code for XCode that expands NSPredicates with more than two sub-conditions does NOT expand it properly.
Instead it passes back a single AND outer XML tag, containing 5 XML sub-elements, and the DA engine (uDAEngine.pas) only evaluates 2 of them, and silently IGNORES the others.
I consider this wrong on several levels. First, to have an engine based on XML that silently ignores data that is sent to it if more than 2 inputs are processed is wrong.
Secondly, to have generated uDAENgine so that “BinaryExpression” MUST contain exactly 2 conditions inside, but then not have the same thing be true on the XCode side is really really bad.
I can probably work around this on the XCOde side by making my own function that will, given a list of boolean predicates, construct a correct list of NSPRedicates, two by two, that will then result in a predicate set that will actually function on the uDAEngine side. But the thought of this makes me sick. Surely this could be more simply and easily fixed if the uDAEngine.pas engine did not silently ignore XML nodes passed to it as XMLWhere clauses, and just did the right thing. Please fix this.
I’ve raised an issue 61333 to fix that.
As a temporary solution please use NSCompoundPredicates with not more than 2 sub-predicates inside. Something like: