 |
 |
Cocoa Database Options?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: NJ, USA
Status:
Offline
|
|
Hi all! Please forgive me if I'm asking a FAQ. I'm trying to research what options are available for Cocoa database development. I know I can use dictionaries but wonder about the limitations (I'm looking at databases around 5-10,000 records). Are there any third party libraries available? I was originally going to do this app in AppleScript Studio and FileMaker but there are speed issues...Many thanks in advance for any input!
Steve W
|
|
Windows SysAdmin by day, OS X maniac by night...
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jul 2001
Status:
Offline
|
|
If I recall correctly, NSDictionary is implemented as a hash table, so it's probably fast enough for you. Development in NeXTstep never suffered from speed problems as far as I know, so it shouldn't in Cocoa, either.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: NJ, USA
Status:
Offline
|
|
Thanks for the reply Carl. I will put together a sample project and do some testing...
Steve W
|
|
Windows SysAdmin by day, OS X maniac by night...
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status:
Offline
|
|
Originally posted by Carl Norum:
<STRONG>If I recall correctly, NSDictionary is implemented as a hash table, so it's probably fast enough for you. Development in NeXTstep never suffered from speed problems as far as I know, so it shouldn't in Cocoa, either.</STRONG>
Well, NeXTSTEP had EOF, an ObjC-interface for any RDBMS. Apple scrapped it (no one needs databases anyways, right?), but it might come back someday.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: NJ, USA
Status:
Offline
|
|
Hmm, I just had an ugly thought...shared database access. Ugh.
Steve W
|
|
Windows SysAdmin by day, OS X maniac by night...
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: NJ, USA
Status:
Offline
|
|
How about sql? Anybody here worked with it under OS X?
Steve W
|
|
Windows SysAdmin by day, OS X maniac by night...
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status:
Offline
|
|
I would use PostgreSQL, or MySQL. I prefer PG, but many seem to like MySQL.
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Mar 2001
Location: Adelaide, South Australia
Status:
Offline
|
|
So.... making an instance of NSdictionary is easy enough, but how would one go about writing it to disk and then reading it back next time the app is launched? Is this part of that NSArchiver voodoo that I haven't figured out yet? If I have a dictionary that contains 10,000 records and unarchive it from disk, does it eat up a huge amount of memory? (i.e. your app stores the entire thing in RAM?) It would be cool if I could find a sample project that makes a dictionary, and writes/reads it from disk. I've actually just given up on AppleScript Studio due to the difficulty of making/storing large amounts of data for an app I want to create. Oh well, back on the steeper learning curve of Cocoa.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status:
Offline
|
|
I'm not entirely familiar with Cocoa, so I may be wrong, but based on having used Dictionary/hash objects before, I'll try to answer you. You're not going to directly read/write a dictionary object to disk. Dictionary objects have basically two fields, a key and a value. Basically, you just need to write a loop to go through the dictionary object and write it into a text file. Using a CSV format if you want. Write a routine to loop through a text file and read it back into a dictionary object. Reading and writing from a text file is very fast.
Your file should look somewhat like this:
1, Value One
2, Value Two
3, Value Three
This isn't very good if you are going to have many people using this. If you read from the file, and lock it, no one can use it while it's locked. If you don't lock it, you risk corruption if someone else writes back to it before you do.
Using an SQL server might be a good idea for you, especially with 10,000 records. MySQL and PGSQL are very good, and free. If you haven't used SQL before, don't worry - it's easy to pick up.
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Mar 2001
Location: Adelaide, South Australia
Status:
Offline
|
|
Hey, that explanation makes a lot of sense wallinbl! Thanks a lot. About using SQL... wouldn't that mean that my app could only be run on machines with SQL installed? Is that part of the standard OS X install or just with the Dev Tools (or even a separate download). The app I'm thinking of making would be for everyday people usage, not enterprise level database stuff. Thanks again for the nice clear answer. I like that in a discussion thread .

|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status:
Offline
|
|
I was making the assumption that you would have some sort of centralized data storage (on a file server, or whatever). If each user has their own data, then a local file is fine.
If multiple users are using the same data (not copies of the same data, but actually the same file), you should use something with record level locking like SQL. You only have to put SQL on one machine, and then point the other machines to it.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: NJ, USA
Status:
Offline
|
|
Thanks for the replies! I will investigate mySQL and PostGres...I am somwhat familiar with sql so this may be the answer I was looking for. Many thanks!
Steve W
|
|
Windows SysAdmin by day, OS X maniac by night...
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
Here are several non-relational databases. Just pick one you like and link the library into your application.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2001
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
No. You don't have to write any loop to write a NSDictionary / NSMutableDictionary to disk. All you have to do is:
NSMutableDictionary *dict;
dict = [[NSMutableDictionary alloc] initWithCapacity:0];
[dict setObject: YOUR_OBJ_HERE forKey:YOUR_KEY_HERE];
[[NSFileManager defaultManager] createFileAtPath:FILE_PATH contents  NSData*)dict attributes:nil];
To read the file back, you can simply use:
dict = [NSDictionary dictionaryWithContentsOfFile:FILE_PATH];
Isn't that simple and elegant? 
|
|
--
Jack Chang, R&D Supervisor
Specialized in: Embedded System, Storage System, RAID, VHDL, C/C++ Programming
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: NJ, USA
Status:
Offline
|
|
Wow, lots of new replies, thanks to all! I am intriqued at the thought of using NSArray/NSDictionary, but I wonder how I would handle shared access to the data? NSLock whenever the data is to be written back? What are the advantages/disadvantages to using this method vs. some form of sql? Many thanks to all, I appreciate this discussion very much.
Steve W
|
|
Windows SysAdmin by day, OS X maniac by night...
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2000
Location: Oslo, Norway
Status:
Offline
|
|
I think MySQL 4.x.x can be embedded in applications.
Check it out at MySQL
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
It depends on how your data are going to be shared. If your data is only shared by several threads in the same application, the easiest way could be creating an object responsible for data read / write and isolate all other threads from direct data access. You may also implement some kind of semaphore in your object in case of some data can't be altered and must keep accurate during a specific amount of time.
If you're going to, however, share the data between several processes all written by yourself, you may need something more complex. I'm not sure about NSLock for I haven't tried that before. But I'm sure you can use *nix mutex or semaphore, which is fairly easy to use.
If, further, you want to share data between uncertain amount of processes and some of them may not be written by you. You have several choices. You may divide your data into pieces and store in the disk. Every time, then you want to read / write some data you may have to lock the file in filesystem using System Call. Or, the way I prefer, you can create a process responsible for read / write data and listen on local socket or pipe. In this way you're almost implementing a database system.
|
|
--
Jack Chang, R&D Supervisor
Specialized in: Embedded System, Storage System, RAID, VHDL, C/C++ Programming
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|