Re: Problem with NSPredicate in core data fetch request

2011-03-14 Thread Gideon King
Thanks for that information - that's an important distinction to understand. I 
guess that may be something to do with what I'm observing, but am not sure 
exactly how.

In my case, I am using an NSAtomicStore subclass. The actual storage behind the 
scenes maps that attribute to an "id" attribute in an XML file, but that should 
all be completely hidden from the layers that actually do the fetch. Anything 
working with the atomic store cache node would be reading and writing it as 
nmObjectId - String, mandatory, no value transformer

Regards

Gideon

On 14/03/2011, at 11:47 PM, Andreas Grosam wrote:

> 
> On Mar 13, 2011, at 3:08 PM, Gideon King wrote:
> 
>> I'm seeing a strange thing with a predicate. When I apply the predicate to a 
>> fetch request, it doesn't return any results, but when I do the fetch 
>> without the predicate and then use filteredArrayUsingPredicate to filter the 
>> results, it has the matching row that I expect.
> ...
>> I am really mystified by this - I can't understand why it would not work 
>> when applied to a fetch request, but would work when applied to the array of 
>> results.
>> 
>> Any suggestions?
> 
> 
> 
> Well, in general, sending executeFetchRequest to the context and performing a 
> predicate upon a result set, behaves not (always) the same, respectively 
> certain requirements must be met. 
> 
> In case of SQLite as the datastore, if you sent executeFetchRequest to the 
> context, the context constructs corresponding SQL Select commands which are 
> sent to SQLite and performed by SQLite itself. First of all, fetch request 
> including the predicate must be convertible to equivalent SQL statements. 
> Then, the SQL statements must be valid of course, and this requires (for 
> instance) that all attributes within the predicate exist as fields in the 
> corresponding table in the database.
> 
> 
> 
> Do you use a SQLite data store and is the attribute transient or is there a 
> value transformer attached to it?

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Problem with NSPredicate in core data fetch request

2011-03-14 Thread Andreas Grosam

On Mar 13, 2011, at 3:08 PM, Gideon King wrote:

> I'm seeing a strange thing with a predicate. When I apply the predicate to a 
> fetch request, it doesn't return any results, but when I do the fetch without 
> the predicate and then use filteredArrayUsingPredicate to filter the results, 
> it has the matching row that I expect.
...
> I am really mystified by this - I can't understand why it would not work when 
> applied to a fetch request, but would work when applied to the array of 
> results.
> 
> Any suggestions?



Well, in general, sending executeFetchRequest to the context and performing a 
predicate upon a result set, behaves not (always) the same, respectively 
certain requirements must be met. 

In case of SQLite as the datastore, if you sent executeFetchRequest to the 
context, the context constructs corresponding SQL Select commands which are 
sent to SQLite and performed by SQLite itself. First of all, fetch request 
including the predicate must be convertible to equivalent SQL statements. Then, 
the SQL statements must be valid of course, and this requires (for instance) 
that all attributes within the predicate exist as fields in the corresponding 
table in the database.



Do you use a SQLite data store and is the attribute transient or is there a 
value transformer attached to it?



Regards
Andreas

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Problem with NSPredicate in core data fetch request

2011-03-13 Thread Gideon King
I'm seeing a strange thing with a predicate. When I apply the predicate to a 
fetch request, it doesn't return any results, but when I do the fetch without 
the predicate and then use filteredArrayUsingPredicate to filter the results, 
it has the matching row that I expect.

Here are the results of a query without any predicate:

(gdb) po [[topic managedObjectContext] executeFetchRequest:request error:&error]
(
 (entity: Attachment; id: 0x1e095f40 

 ; data: {
displayName = "Import test map (picture)";
fileName = "Import test map.png";
nmObjectId = "72172A92-408D-41FA-AAB6-2132C4641AA5";
resource = "0x1e06b400 
";
topic = "0x1e0953b0 
";
}),
 (entity: Attachment; id: 0x1e08ee10 

 ; data: {
displayName = "example RSS feed opml";
fileName = "rss_sharpreader.opml";
nmObjectId = "DAC4868B-C8BA-41DB-9CC1-6F85193EC7B5";
resource = "0x36f98c0 
";
topic = "0x1e08dbd0 
";
}),
 (entity: Attachment; id: 0x1e091ee0 

 ; data: {
displayName = nil;
fileName = "import test mind map(novamind).png";
nmObjectId = "784A6E81-2EEF-42F5-8D08-05F6B58A8B55";
resource = "0x1e0fa240 
";
topic = "0x1e08d830 
";
})
)


And here's my predicate: 

(gdb) po predicate
nmObjectId == "784A6E81-2EEF-42F5-8D08-05F6B58A8B55"



If I apply that predicate to the results of my fetch request:

(gdb) po [results filteredArrayUsingPredicate:predicate]
(
 (entity: Attachment; id: 0x1e091ee0 

 ; data: {
displayName = nil;
fileName = "import test mind map(novamind).png";
nmObjectId = "784A6E81-2EEF-42F5-8D08-05F6B58A8B55";
resource = "0x1e0fa240 
";
topic = "0x1e08d830 
";
})
)


So all that's as expected, but if I set exactly that predicate on my fetch 
request, no results match:

(gdb) call (void)[request setPredicate:predicate]
(gdb) po [[topic managedObjectContext] executeFetchRequest:request error:&error]
(
)


I am really mystified by this - I can't understand why it would not work when 
applied to a fetch request, but would work when applied to the array of results.

Any suggestions?


Here's my code which returns 0 rows:

NSString *attachmentID = [[url path] lastPathComponent];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSError *error = nil;
NSEntityDescription *entity = [NSEntityDescription 
entityForName:kNMAttachmentEntityKey inManagedObjectContext:[topic 
managedObjectContext]];

[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nmObjectId 
== %@", attachmentID];
[request setPredicate:predicate];

NSArray *results = [[topic managedObjectContext] 
executeFetchRequest:request error:&error];
[request release];






Regards

Gideon






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com