Re: How to manage (My)SQL data in Cocoa
Re: How to manage (My)SQL data in Cocoa
- Subject: Re: How to manage (My)SQL data in Cocoa
- From: Quincey Morris <email@hidden>
- Date: Sun, 9 Nov 2008 09:47:49 -0800
On Nov 9, 2008, at 09:16, Michele Barboni wrote:
Currently I'm querying the database for a column at once, building
an NSArray of them and add all NSArrays (the columns) in a
NSMutableArray ("the table").
For editing I'm doing queries in the NSTableView controller (and I
really don't like this).
So, I was wondering if there's a "standard" way for storing sql data
(not sqlite and core data of course..) with Cocoa collections.
For example, I have thought to a NSDictionary with id integers as
key and NSArrays with the rest of the *row* as values, sounds better
but since I'm not an experienced programmer I'm asking..
If you're intending to read the entire database into memory, then the
most natural "fit" with a NSTableView would probably be an array of
dictionaries. The arrays would be rows, and each dictionary would
contain the database column values for each row, keyed by a database
column name. Then you could connect the table view columns to the
dictionary with bindings, or use a data source where (say) the table
column identifier was the dictionary key.
Or, instead of one dictionary per row, create a data model class that
has a property (i.e. a setter and a getter, backed by a suitable
instance variable) for each database column, and one object of this
class per row. That would use slightly less memory than dictionaries,
and allow you to customize the logic of data access. (The objects
could keep track of what was changed, too, so that you could avoid
queries at NSTableView editing time.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden