Xcode and databases

Discussion in 'OS X' started by Nermal, Jul 21, 2004.

  1. Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #1
    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++).
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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 to access MySQL.

    Given that you want platform independance I think that you could do a lot worse than MySQL!
     
  3. thread starter Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #3
    Oops, I did say I was new at it :eek: 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 :)).
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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!
     
  5. macrumors G4

    Joined:
    Jul 17, 2002
    Location:
    USA
    #5
    I believe that REALbasic just came to your rescue.
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    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.
     
  7. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    Futher digging into the RB option reveals this. Looks like .mdb files are simply not supported by RealBasic so you might as well develop a real solution that will be portable.
     
  8. macrumors regular

    Joined:
    Apr 11, 2003
    #8
    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....
     
  9. macrumors regular

    Joined:
    Apr 11, 2003
    #9
    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.
     
  10. jsw
    Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #10
    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 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.
     
  11. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    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.
     
  12. jsw
    Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #12
    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.
     
  13. macrumors 6502a

    Joined:
    May 6, 2004
    Location:
    SC
    #13
    To get somewhat on topic, what exactly does CoreData do for people? Is it a db access framework?
     
  14. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #14
    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 :(
     
  15. macrumors member

    Joined:
    May 28, 2003
    #15
    Yep, it's definitely under NDA.
     
  16. jsw
    Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #16
    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.
     
  17. macrumors 6502a

    Joined:
    May 6, 2004
    Location:
    SC
    #17
    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.
     
  18. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #18
    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 :(
     
  19. macrumors 6502a

    Palad1

    Joined:
    Feb 24, 2004
    Location:
    London, UK
    #19
    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.
     
  20. macrumors 6502a

    Joined:
    May 6, 2004
    Location:
    SC
    #20
    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.
     
  21. thread starter Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #21
    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.
     
  22. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  23. jsw
    Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #23
    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.
     
  24. thread starter Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    Whakatane, New Zealand
    #24
    That looks wonderful :)

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

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #25
    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.
     

Share This Page