PDA

View Full Version : Xcode and databases




Nermal
Jul 21, 2004, 04:39 AM
This isn't related to Tiger, but we don't have a development forum, however any Tiger users in this forum must be developers, so...

I'm attempting to port an app across from VB.net. It currently stores all its data in an .mdb file. Basically, I'm looking for an equivalent way to use a database (any format) in Xcode - just something simple where I can execute SQL queries and process the results.

I'd preferably like to end up using a cross-platform format, so that I can update the Windows version later, to use the same data format as the Mac version.

Edit: I forgot to mention that I'm new to Xcode. This is my first "real" Mac app (I've made a few little dumb apps just for learning), but I've been developing for Windows for years (mainly VB but some Pascal/Delphi and C++).



robbieduncan
Jul 21, 2004, 05:25 AM
You don't say what language you are using!

If you are using Carbon then I really can't help you, sorry.

If you are using Cocoa/Java (or just pure Java) then you have a real easy solution: use JDBC to connect to just about any relational database you like! If it's going to be a local one (i.e. on the same box) then MySQL is free and easy to use.

If you are in Cocoa/ObcJ you have a few more issues as there is no built in data access framework (anymoree, there was one in NeXT as part of EOF). You could write some of your app in Java to using the ObjC/Java bridge and use JDBC as above. You might want to use this Cocoa wrapper (http://mysql-cocoa.sourceforge.net/) to access MySQL.

Given that you want platform independance I think that you could do a lot worse than MySQL!

Nermal
Jul 21, 2004, 06:01 AM
Oops, I did say I was new at it :o I'm using Cocoa/Obj-C.

I had considered MySQL, but if at all possible I don't want the end-user to have to install anything. Presumably if I were to use MySQL then the user would need to have MySQL on their system? The reason I'm using .mdb on Windows is because it "just works" (that and I already know how to use it :)).

robbieduncan
Jul 21, 2004, 06:20 AM
Oops, I did say I was new at it :o I'm using Cocoa/Obj-C.

I had considered MySQL, but if at all possible I don't want the end-user to have to install anything. Presumably if I were to use MySQL then the user would need to have MySQL on their system? The reason I'm using .mdb on Windows is because it "just works" (that and I already know how to use it :)).

I thought .mdb was an Access format so they required Access on their system? Anyway you could package MySQL within your .app bundle and start it when your app starts as a child process. Beyond that you would probably be on your own writing a load of code!

MisterMe
Jul 21, 2004, 08:06 AM
This isn't related to Tiger, but we don't have a development forum, however any Tiger users in this forum must be developers, so...

I'm attempting to port an app across from VB.net. It currently stores all its data in an .mdb file. Basically, I'm looking for an equivalent way to use a database (any format) in Xcode - just something simple where I can execute SQL queries and process the results.

I'd preferably like to end up using a cross-platform format, so that I can update the Windows version later, to use the same data format as the Mac version.

Edit: I forgot to mention that I'm new to Xcode. This is my first "real" Mac app (I've made a few little dumb apps just for learning), but I've been developing for Windows for years (mainly VB but some Pascal/Delphi and C++).I believe that REALbasic (http://www.realsoftware.com/realbasic/guides/portingvisualbasic/) just came to your rescue.

robbieduncan
Jul 21, 2004, 08:12 AM
I believe that REALbasic (http://www.realsoftware.com/realbasic/guides/portingvisualbasic/) just came to your rescue.

It says at the botom of the page "Database will require some re-work, but SQL logic is largely compatible." Does it support .mdb on non-windows platforms. If not then we have not advance any and have taken the retrograde step of using a poor quality solution (RealBasic). Every RB app I have ever used annoyed me as it just didn't work as well as "real (Cocoa and Carbon)" apps.

robbieduncan
Jul 21, 2004, 08:14 AM
Futher digging into the RB option reveals this (http://www.realsoftware.com/listarchives/realbasic-nug/1999-03/msg01167.html). Looks like .mdb files are simply not supported by RealBasic so you might as well develop a real solution that will be portable.

Thom_Edwards
Jul 21, 2004, 08:21 AM
It says at the botom of the page "Database will require some re-work, but SQL logic is largely compatible." Does it support .mdb on non-windows platforms. If not then we have not advance any and have taken the retrograde step of using a poor quality solution (RealBasic). Every RB app I have ever used annoyed me as it just didn't work as well as "real (Cocoa and Carbon)" apps.

i understand your argument concerning a lot of REALbasic apps not working like 'real' apps. the thing is that a lot of hobbyists (read non-programmers) use REALbasic and don't really 'get it' when it comes to what it takes to make a 'real' app. if you know what it takes to design a proper gui/user experience, then there is no difference in the final product.

REALbasic supports a LARGE number of databases, plus it has its own cross-platform propietary database. it (being REAL's database) will not be as powerful as some of the more mature db's out there, but it will suit most purposes very well.

i am a Big Fan of REALbasic. Don't let the word basic fool ya--it is a fully oop language. add the ability to compile os x, classic, win32 and many linux flavors and you have a pretty powerful setup. there's more i could go on about, but i won't....

Thom_Edwards
Jul 21, 2004, 08:23 AM
Futher digging into the RB option reveals this (http://www.realsoftware.com/listarchives/realbasic-nug/1999-03/msg01167.html). Looks like .mdb files are simply not supported by RealBasic so you might as well develop a real solution that will be portable.

did you look at the date of that post from the link? in was done in 1999!!! things have changes a lot since then...... :rolleyes:

i will confess i have not used access databases with anything, but there is DEFINITELY an ODBC plug-in (driver) for REALbasic.

jsw
Jul 21, 2004, 08:25 AM
If you intend, as you say, to go back to Windows with this, then I second the suggestion to (if at all possible) use Java and JDBC to get to your data via SQL calls. These calls will work with MySQL on pretty much any platform, and will work with Access on Windows. Cocoa's pretty flexible about using Java and Objective-C together (so I've read - I'm also just in the very beginning of writing my first "real" Mac app after using it to do Java work for quite a while). Using Java to get to a database is easier than any other solution I've seen, and, of course, leaves open the door for a Linux port should you want one on the future.

Having written a few cross-platform apps, my other advise would be to get something working on one of them - working just enough to show results, not polished perfectly - then get it to work on at least one other platform to make sure you're not introducing hidden assumptions about the OS into your work. Java's strength is cross platform work, but even Java can be induced to use platform-specific traits. If you work that way - develop primarily on one platform, and jump to the other occassionally to verify your approach - you'll get it ready for both platformas a [i]lot[/]i quicker than if you either try to do both at once in parallel or, in particular, wait until the very end to do the port.

robbieduncan
Jul 21, 2004, 08:27 AM
did you look at the date of that post from the link? in was done in 1999!!! things have changes a lot since then...... :rolleyes:

i will confess i have not used access databases with anything, but there is DEFINITELY an ODBC plug-in (driver) for REALbasic.

ODBC drivers are not enough. You also need something for the driver to connect to. In this case you need the Jet engine (which is what Access uses). Without it you cannot use .mdb files. The lack of Jet on any non-windows platform is as real today as it was then.

jsw
Jul 21, 2004, 08:27 AM
i am a Big Fan of REALbasic. Don't let the word basic fool ya--it is a fully oop language. add the ability to compile os x, classic, win32 and many linux flavors and you have a pretty powerful setup. there's more i could go on about, but i won't....

Agreed. it's not as powerful as other development approaches, but it is wrong to underestimate it. It's a fantastic tool for developing most apps for most situations. I prefer Java, but, when you've got a hammer, everything looks like a nail - you tend to use what you know. RB is a fine tool, and many of my friends swear by it.

relimw
Jul 21, 2004, 09:48 AM
To get somewhat on topic, what exactly does CoreData do for people? Is it a db access framework?

robbieduncan
Jul 21, 2004, 09:54 AM
To get somewhat on topic, what exactly does CoreData do for people? Is it a db access framework?

I think it's part of WebObjects, a bit like what EOF was. Unfortunatly it's not actually uavailable yet! I think it's still NDAed from WWDC. A search on the ADC site for CoreData returned no documents :(

jcgerm
Jul 21, 2004, 10:12 AM
I think it's part of WebObjects, a bit like what EOF was. Unfortunatly it's not actually uavailable yet! I think it's still NDAed from WWDC. A search on the ADC site for CoreData returned no documents :(

Yep, it's definitely under NDA.

jsw
Jul 21, 2004, 10:16 AM
Yep, it's definitely under NDA.

Hence, not the cross-platform approach that Nermal wants. Does Tiger promote any standards-based data access? NDA's would preclude a specific answer here, maybe, but a "yes" or "no" is probably allowed to such a general question.

relimw
Jul 21, 2004, 10:23 AM
I think it's part of WebObjecthttp://connect.as, a bit like what EOF was. Unfortunatly it's not actually uavailable yet! I think it's still NDAed from WWDC. A search on the ADC site for CoreData returned no documents :(

Ahhh, hmm, why must Apple put everything in .dmg.bin files....sheesh....
(I'm temporarily on my work laptop...win98...joy).

It would seem that the WWDC Tiger docs are posted on http://connect.apple.com/ and Core Data does have some ability to do database stuffs. Tho I couldn't figure out in just an initial read thru, what type/format database it was sending too.

robbieduncan
Jul 21, 2004, 10:31 AM
Ahhh, hmm, why must Apple put everything in .dmg.bin files....sheesh....
(I'm temporarily on my work laptop...win98...joy).

It would seem that the WWDC Tiger docs are posted on http://connect.apple.com/ and Core Data does have some ability to do database stuffs. Tho I couldn't figure out in just an initial read thru, what type/format database it was sending too.

I ran my search on developer.apple.com. I'm logging into connect now (just to check out the docs, I think we all realise that CoreData is not the best solution to this problem)....

Edit: Damn it, I think you have to be a paid up (as opposed to free, web only) member :(

Palad1
Jul 21, 2004, 11:01 AM
What does your app need a database for?


As a way to store data for a single person at a time
As a way to share data with multiple persons at the same time


If your data are accessed by only one person, have you considered ditching databases in favor of XML?

I bet my skin cocoa has a very efficient xml library. Considering the fact that the whole friggin' os uses xml for pretty much anything (prefs, iTunes, i* ...)?

With some planning you can avoid huge XML files and save the parsing time, and using xPath you can recreate select statements.

relimw
Jul 21, 2004, 11:03 AM
I ran my search on developer.apple.com. I'm logging into connect now (just to check out the docs, I think we all realise that CoreData is not the best solution to this problem)....

Edit: Damn it, I think you have to be a paid up (as opposed to free, web only) member :(

Yep, you do.

You're prolly right that Core Data isn't a good solution to his problem, but it would be nice if Apple did provide and end-to-end solution. Seems I saw somewhere, that they were now including MySQL in with the BSD tools install with Tiger.

Nermal
Jul 21, 2004, 06:14 PM
What does your app need a database for?


As a way to store data for a single person at a time
As a way to share data with multiple persons at the same time


If your data are accessed by only one person, have you considered ditching databases in favor of XML?

I bet my skin cocoa has a very efficient xml library. Considering the fact that the whole friggin' os uses xml for pretty much anything (prefs, iTunes, i* ...)?

With some planning you can avoid huge XML files and save the parsing time, and using xPath you can recreate select statements.

I'd never considered XML. It would certainly simplify things since they're just text files. The concern I have with XML is that it might be difficult to do searches on the data. I'm only doing simple queries though ("SELECT * FROM Table WHERE Criteria = Blah" and "UPDATE Table SET Field = Blah WHERE Criteria = Blah"). So I'll take a look at XML, and see what I can find.

And now, a note to the RealBasic fans: :)
I've taken a look at RealBasic, but I'd rather use a "proper" language - I need to practice my C after using VB for so long.

robbieduncan
Jul 22, 2004, 10:57 AM
i just saw this (http://treehouseideas.com/datacrux/) which might do what you want?

jsw
Jul 22, 2004, 11:17 AM
I'd never considered XML. It would certainly simplify things since they're just text files. The concern I have with XML is that it might be difficult to do searches on the data. I'm only doing simple queries though ("SELECT * FROM Table WHERE Criteria = Blah" and "UPDATE Table SET Field = Blah WHERE Criteria = Blah"). So I'll take a look at XML, and see what I can find.

Ah, it is lamentable that you're not using Java. ** sighs ** It makes this stuff (working with databases, working with XML) so easy. (I have a hammer - Java - and, by God, everything looks like a nail to me!)

Anyway: XML is a wonderful format for information exchange. It is also a great format for storing hierarchical data (i.e., things like organizational charts). It's easy to use to store small amounts of data in any format (great for .plist files, for example).

However, it completely and utterly sucks at storing lots of tabular data in an easy-to-search and easy-to-fetch way. XML is a wonderful complement to a relational database, not a replacement for it - nor is an RDB a good XML replacement.

If you can easily hold all your data in memory, and access speeds aren't all that important, then by all means go with XML. It's good to know, in any event. But if you've got lots of data - no matter if it's for one user or many - a database will be better for you.

Nermal
Jul 22, 2004, 05:28 PM
i just saw this (http://treehouseideas.com/datacrux/) which might do what you want?

That looks wonderful :)

Ah, it is lamentable that you're not using Java.

Unfortunately, I don't know anything about Java. I can't even make a "Hello World". :eek:

jsw
Jul 22, 2004, 05:50 PM
Unfortunately, I don't know anything about Java. I can't even make a "Hello World". :eek:

class HelloWorld
{public static void main(String[] args)
{System.out.println("Hello World!");
}

};

Can't seem to get indent to work efficiently. Anyway, if you can do C, and especially if you can do Objective-C, you can easily do Java. It's a very nice, object-oriented language with no need for manual garbage collection. You don't need it, but it might be fun to look into.

Edit: type the above into a file named HelloWorld.java (has to have same name as class inside). Go to Terminal, type 'javac HelloWorld.java' to compile it, then 'java HelloWorld' to run it. Of course, this assumes you actually care to play with it.

crenz
Jul 22, 2004, 06:22 PM
SqLite (http://www.sqlite.org/) is a wonderful open-source database that will store all your data in one file. You can just link the library into your executable. It is cross-platform and cross-language, so it should be rather future proof for your project. Also, it is rather speedy and supports transactions.

No need to use Java, unless you have lots of time on your hands :-).

Palad1
Jul 23, 2004, 02:59 AM
Of course!

I'm stupid not having thought of it first.
Use Berkerley DB !!

It's used by most unix apps on osX

you don't have any server just a lib that groks SQL on a single file, you have to provide a lock mechanism, but for single user it's great...

Too much win2k coding with sql server clouded my judgement :/

Nermal
Jul 24, 2004, 09:55 PM
Of course!

I'm stupid not having thought of it first.
Use Berkerley DB !!

I just took a look at Berkeley DB, and I don't agree with the licence. I can't make my app open-source, and since I couldn't find any commercial pricing information, I assume it's expensive.

Palad1
Jul 25, 2004, 10:33 AM
I just took a look at Berkeley DB, and I don't agree with the licence. I can't make my app open-source, and since I couldn't find any commercial pricing information, I assume it's expensive.

Are you absolutely positive about this?

SubVersion uses Berkley DB and I'm fairly sure it is licensed under the GPL. Now that I come to think of it, Apache seems to use BDB as well (there's a dependency to bdb when you install apache2 using dselect under osX)

Cheers,
Palad1

robbieduncan
Jul 25, 2004, 12:00 PM
Are you absolutely positive about this?

SubVersion uses Berkley DB and I'm fairly sure it is licensed under the GPL. Now that I come to think of it, Apache seems to use BDB as well (there's a dependency to bdb when you install apache2 using dselect under osX)

Cheers,
Palad1

SubVersion and Apache are both Open-Source. Nermal cannot Open-Source his app. Is Berkley DB GPL, LGPL or something else. If it's LGPL you can compile it a stand alone library and link against it without open sourcing your own app.

Nermal
Jul 25, 2004, 05:22 PM
The license for each of these products permits you to use the software at no charge under the condition that if you use them in an application you redistribute, the complete source code for your application must be available and freely redistributable under reasonable conditions. If you do not want to release the source code for an application you redistribute, you may purchase a license from Sleepycat Software.

It says that if I use Berkeley DB in my app then I must open-source it. But maybe you're right about making it separate.

Here's the licence (http://www.sleepycat.com/download/oslicense.html).

robbieduncan
Jul 25, 2004, 05:34 PM
It says that if I use Berkeley DB in my app then I must open-source it. But maybe you're right about making it separate.

Here's the licence (http://www.sleepycat.com/download/oslicense.html).

This is similar to the GPL, not the LGPL. If you link against this (even dynamically) you would have to release the full source to your app if you distribute it (of course if you are writing it for internal use only you can probably get round this as you are not distributing it).

iJed
Jul 25, 2004, 06:48 PM
SqLite (http://www.sqlite.org/) is a wonderful open-source database that will store all your data in one file. You can just link the library into your executable. It is cross-platform and cross-language, so it should be rather future proof for your project. Also, it is rather speedy and supports transactions.

No need to use Java, unless you have lots of time on your hands :-).

I have to agree that SQLite is a very good choice. Its not like your average DBMS which runs as a separate process and is instead a tiny library with easy to use C functions. Its mostly a lot better than the rather poor mysql database since it supports basic features like nested queries (which mysql unbelievably doesn't yet!) SQLite is also included in Tiger but you could easily install it with your app for older OS version should you choose to support them. The biggest limitation for me in SQLite (other than not being able to connect to it via a network) is that it doesn't support "ALTER TABLE".

Another great DBMS is PostgreSQL. This ahead of mysql in almost every respect and is, in my opinion, an all round better solution. It supports just about every feature of modern SQL including PL/SQL. Unfortunately I doubt it supports Java stored procedures but I seriously doubt you will be using them. You could include an installer for this with your application.

Here are the technologies I'd avoid:
1) RealBasic - Expect people to hate you and your application if you use this. I've never found anything I can stand using written in this pile of ****.

2) MySQL - Of all the biggish open-source databases this is probably the weakest. It popular but there are much much better solutions out there. Version 5 is looking promising though (and even 4.1 seems to make some great additions).

Nermal
Jul 27, 2004, 08:40 PM
I'll take a look at SQLite when I get a chance. I've had some other things spring up, so porting the app across is now a low priority.

ibook_g4_user
Aug 11, 2004, 12:43 AM
One of the new features in tiger is direct access to SQLite, its very easy to use.. read more about it on Appleinsider (http://www.appleinsider.com/article.php?id=593)..man.. tiger will make everything much easier for devolopers.

Nermal
Aug 11, 2004, 01:02 AM
Yeah, I saw that. I'm still really busy with other stuff though and haven't even looked at my app for about 2 weeks now :eek: