Just to make even clearer what Quincey has said;

For NSTableView you MUST follow Quincey's conventions for the data representation. If you do not then simply the NSTableView control will not work. This is due to some very specific restrictions and limitations in the NSTableView Cocoa class. Its worthwhile to notice because otherwise you may have found necessary to rewrite some extensive amount of code for your data logic / or simply found this particular class unusable.

If sure that you dont need to see a TableView representation of the data (perhaps you have your mind set upon to use a different control such as NSOutlineView / or other ones ) then its probably be worth asking about those too. Certainly its going along the right lines to be asking about using an array or dictionary. Those representation will enable you to utilize some helper classes such as NSArrayController (and NSSortDescriptors for sorting) and perhaps certain parts of the Bindings / KVC will become relevant to you.

The following libraries are for executing basic SQL query from within the Cocoa environment and conveniently they can provide data into the NSArray etc;

Quicklite -             http://www.webbotech.com/

FMDB -                  http://flycode.googlecode.com/svn/trunk/fmdb/
                                
http://code.google.com/p/flycode/source/browse/#svn/trunk/fmdb

PLDatabase -    http://code.google.com/p/pldatabase/
(repackage of FMDB)


On 9 Nov 2008, at 17:47, Quincey Morris wrote:

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 (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/dreamcat7%40googlemail.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to