ccgus / fmdb

A Cocoa / Objective-C wrapper around SQLite
Other
13.84k stars 2.77k forks source link

FMResult set and Natural Outer Left Join behavior #238

Open ArEnSc opened 10 years ago

ArEnSc commented 10 years ago

So I found an issue In this query

SELECT e.event_id, e.event_name, e.event_description, p.photo_id, p.photo_create_date,p.photo_image_path, v.version_id, v.version_image_path, v.version_create_date, v.photo_id FROM events e INNER JOIN photos p ON p.event_id = 5 AND e.event_id = 5 NATURAL LEFT OUTER JOIN versions v ORDER BY e.event_id DESC, p.photo_create_date DESC,v.version_create_date DESC;

// Since it is a natural join I think FMDB overdoes it and removes the photo_id twice.... The fix. Remove this... v.photo_id

SELECT e.event_id, e.event_name, e.event_description, p.photo_id, p.photo_create_date,p.photo_image_path, v.version_id, v.version_image_path, v.version_create_date FROM events e INNER JOIN photos p ON p.event_id = 5 AND e.event_id = 5 NATURAL LEFT OUTER JOIN versions v ORDER BY e.event_id DESC, p.photo_create_date DESC,v.version_create_date DESC;

Natural join removes one column I believe FMDB does it a second time, resulting in queries that basically return nothing for photo_id ....

Or it could be the fact that if there are two matching columns in a query it does not know which one to map from?

ccgus commented 10 years ago

two matching column names are probably going to mess things up if you're using the ForColumn: methods. Is that what you're doing?

ArEnSc commented 10 years ago

I actually grab the NSDictionary, for the row, and the row result shows up that photo_id returns nothing. I could probably make a small project that could replicate this.