Click here to get your copy of REALbasic

REALbasic Database Tutorial

Posted on January 1, 2008 
Filed Under REALbasic Tutorial

Here’s a video tutorial that will walk you through View, Insert, Update, and Delete records in REALbasic using the RealSQL database:

REALbasic Database Video Tutorial

I put this together because the docs about DB use in RB seem to be a little lacking — at least for me.

Jay Jennings

tags technorati :

Click here to get your copy of REALbasic

Comments

38 Responses to “REALbasic Database Tutorial”

  1. Matt Stough on February 16th, 2008 2:32 am

    I’ve longed for some database tutorial. I run RB Pro 2007 Rel 3 (hedging on the $250 dump to get 2008) and many years ago created my first program “Math Wizard Pro,” a math flashcard program for my three kids. I want to add a database that keeps their records after each session, allows them to log-in to use it, etc. Your video tutorials on the basics of database design are EXCELLENT! Any chance your planning an intermediate offering any time soon, covering basic error checking, maybe password entry, etc. Thanks again for providing a MUCH NEEDED service to the RB community.

  2. Alakazam on February 16th, 2008 3:47 am

    Actually, I do have plans to do another DB tutorial covering some of what you mentioned — I’m just not sure of the timeline, yet. =:)

    Jay

  3. Lucas on February 24th, 2008 6:45 pm

    Hello Jay,

    what a truly excellent screencast.

    Keep it up!

    Lucas

  4. Bob on March 20th, 2008 12:42 am

    Hi Jay,

    Loved the tutorial. My only suggestion would be to allow us to download the code so that we can study it a bit.

    Thanks though, great work.

    Bob

  5. Bob on April 5th, 2008 2:35 am

    While I think in general this is exactly what I was looking for as far as content goes, no matter how closely I think I’ve followed it the ‘edit’ and ‘delete’ functions never work (tried it in RB 5.5 AND RB 2006).
    There are a few places where the video just isn’t clear enough for me to make it out, i.e. UpdateRow :
    sql = “Select name, homepage, country from people where name = ” + lstPeople.Cell(lstPeople.ListIndex, 0) + “and homepage = ” + lstPeople.Cell(lstPeople.ListIndex, 1) + ” and country = ” + lstPeople.Cell(lstPeople.ListIndex, 2)

    on editing or deleting turns up a nilexception error. In the video, it almost looks like this part :
    sql = “Select name, homepage, country from people where name = ” + lstPeople.Cell(lstPeople.ListIndex, 0) : contains a quote, then an apostrophe, like this…
    sql = “Select name, homepage, country from people where name = “‘ + lstPeople.Cell( lstPeople …
    but of course that would only comment out the rest of the line. What am I missing here?

    The new record works perfectly, but after running over this 6 times I have to admit I’m getting a tad frustrated with it not working correctly :(

  6. Alakazam on April 5th, 2008 3:16 am

    Bob – I’ve been needing/wanting to update this for a while but have been swamped with other things (things that pay the bills).

    But even if I can’t do a follow-up right now, it would probably help if I posted the sample program so you can look at the actual code. I’ll try and do that this weekend.

    Jay

  7. Bob on April 5th, 2008 6:02 pm

    You know, on re-reading the end of my post, I wish I could have worded it better ;)

    I really do think it was an awesome bit of work, and frankly out of the two DB tut’s I found comes far closer to what I would like to use.

    I well understand the things that pay the bills part, whenever you find the time ( or even if you never do ) is ok, I’m still pounding on it. Eventually I’ll know enough so that I’ll find the soloution on my own, or figure a different way altogether.

    Your tute got me farther than any of my previous attempts, and at the very least I have a foundational understanding of whats going on.

    p.s. blather on, that was some of the most informative stuff IN the video, its not often you get to hear what someone is thinking about WHILE they are pounding out the code -^

  8. Pyraxis on April 13th, 2008 1:53 pm

    I very much enjoyed this tutorial. I’m quite new to the basic scene and was eager to make something I could use. Sadly, not knowing at the time, I did the personal edition trial. This, if I understand correctly, prevents me from using databases in my applications. So I just follow along and make it anyways, hoping to actually build it later this year when I have the money to purchase Pro. But I am still very thankful for your time that you put into making these videos. I look forward to returning to this site when I have Pro to use some more tutorials.

    -Pyraxis

  9. Bob on April 15th, 2008 10:58 pm

    Pyraxis, if by ‘personal edition’ you mean the standard one, you should be able to access databases/use this tutorial.

    I also have the standard version ( both 5.5/2006r3) and haven’t had any trouble following along (except where pointed out). Of course, it could be they’ve changed something in the 2008 vers. that I’m unaware of ?

  10. Pyraxis on April 17th, 2008 2:46 am

    I’m not sure, but if i take out the open script on the listbox (the database access stuff) the program runs normally, but if click a button that has to do with the database or have the listbox load info from the database it crashes the application. Maybe its because I’m using the trial. Thats something I should look into, could save me 400 dollars for now… Most of what I’m doing now is just for a learning experience, though I do plan to eventually market my products. But I’m not sure why it crashes if its not because its standard version or trial version.

  11. Bob on April 18th, 2008 12:15 am

    Well, I sure hope you take this as it is meant, and aren’t insulted by the obvious question, but do you have a database made for the program to access? If there isn’t a database ready, you will get a nil exception crash, or at least I did.

    Also, you might have to slightly modify the line:

    sql=”Select name, homepage, country from people”
    -/ to /->
    sql”Select * from people”

    Although Jay correctly states in the video that using the specific names is preferable, I did notice that on Win2k at least, this also caused the program to crash with a nil exception (no clue why).

  12. Pyraxis on April 18th, 2008 1:48 pm

    Hmmm… does somebody have a rbp file of this tutorial that i could download and try to run? That way i would know for sure if it was my code or not.

  13. Bob on April 18th, 2008 7:03 pm

    Well, I’d send you mine, but of course it still isn’t fully working (can add records ok, but of course edit/delete are flakey at best) .

    If your just looking for a simple test to see if you can access a db or not, try this link (no guarantees it will run, but it does here). Its written in rb5.5, your newer vers. of rb will tell you it will be upgaded, so it should work.

    http://bogess1.googlepages.com/realbasiccodedump

  14. Bob on April 18th, 2008 7:15 pm

    By the way Jay, I notice that the time stamp on top of the posts is ..um…misbehaving :)

    For instance, my post above this was made at 2:31pm, not 7:03 pm. Just figured I’d let you know.

  15. Pyraxis on April 18th, 2008 8:55 pm

    :/ No luck with the testing… The .rb isn’t for my version of REALbasic… And exe doesn’t work for me either as I am a Mac user >.< But that file isn’t as important as the project file… Which for me is a .rbp, though i am thankful you tried. I’ll search their website for any possible hints…

  16. Pyraxis on April 18th, 2008 9:01 pm

    http://www.realsoftware.com/products/realbasic/compare.php

    Personal Edition doesn’t have database connectivity… :(

    As for time stamps, they work fine for me, 5 hours ahead like they should be. The minutes are right on though…

  17. Bob on April 18th, 2008 10:02 pm

    Well, it doesn’t have database ’server’ connectivity anyways. However, it doesn’t say anything about the native db format, I’m downloading the 08 vers to see for myself.

    In the meantime, I updated the link so it points to the newer vers (rb2006r3) of the same file. Its odd you can’t import the 5.5, I’ve done it many times myself with far older ones :( Same going backwards I might add. Sure hope this one works for you, though.

  18. Alakazam on April 18th, 2008 10:49 pm

    The source code for this example is available here:

    http://rbnation.com/files/RBDBTutorial.zip

    This was done back in 2006 when “list bindings” were OK to use — this code may not work in RB2008 unless you delete those bindings.

    Jay Jennings

  19. Alakazam on April 18th, 2008 10:53 pm

    Oh, and about the personal version and databases — the personal version CAN use the REALSQLDatabase (aka Sqlite) — I created that tutorial using the personal version of RB (that’s the only version I have for Windows).

    Jay Jennings

  20. Bob on April 19th, 2008 8:30 am

    To Pyraxis, Yah, confirmed , After dl’ing and running the registration baloney for the trial ‘personal’ edition (apparently they’ve changed the ’standard’ to ‘personal’), you go to the Project menu/Add/Database and select New Real Sql Database, then fill in the tables and columns as shown in the video. Accessing the same worked out just fine, although it did take me 3 times to get the database to work properly (it wouldn’t connect the first 2 times for some reason).

    To Jay, AWESOME and thankyou for posting you source, going to spend the next hour dribbling through it -^

  21. Pyraxis on April 19th, 2008 2:12 pm

    Even the source code doesn’t run. Before I took off the list bindings I got a new error. But after I removed them it went back to its unexpected quitting… Even if I build it I can’t run it… So I have absolutely no idea whats going on… This makes me sad :(

  22. Pyraxis on April 19th, 2008 2:13 pm

    Even the source code doesn’t run. Before I took off the list bindings I got a new error. But after I removed them it went back to its unexpected quitting… Even if I build it I can’t run it… So I have absolutely no idea whats going on… This makes me sad :( Could it have to do with a possible error for Mac users?

  23. Pyraxis on April 19th, 2008 3:13 pm

    Sorry for the double post… Didn’t know I hit submit before I typed the last question…

  24. Bob on April 19th, 2008 10:44 pm

    hm, couldn’t answer that one, I dont have a mac to test on, although my code matches the source Jay posted, I know my program has problems running where as I didn’t have even a tidge running his compiled or stepping through. Wish I could help more, but I’m at a loss to explain the problems I’m seeing, not having a mac I couldn’t begin to say about yours :(

  25. Pyraxis on April 20th, 2008 12:14 am

    This really makes me sad… I might have to install Windows on my mac (Ew, gross) and then buy Visual Basic (Again, ew, gross) if i can’t get this to work… but i really really dont want to have to do either of those things…

  26. Terence Blyth on April 23rd, 2008 7:09 am

    I too am having troubles getting it to run on vista.
    Same issues as above.
    Does realbasic work ?

    Thanks
    Terence

  27. Matt Arnold on May 1st, 2008 12:00 am

    Jay – I’m glad I found your tutorials, they’re very helpful. I downloaded the source (above). I’m running RB 2008 Release 1

    the app crashes on this line in the open event of lstPeople:

    dim rs as RecordSet = tutor.SQLSelect(sql)

    to test it, I created a new (identical) tutor database and saved it, and deleted the bindings in the main window. I found the crash by putting a msgbox before and after this line of code. the app displays the first msgbox before crashing, but never gets to the second one.

    I think a fantastic subject for tutorials is debugging techniques.. ways to track down a bug in your code — lord knows that’s what I spend most of my time doing. ;) most tutorials never have to do this because everything is worked out beforehand.

    I think a few simple videos showing common errors and how to detect them would be very popular. I remember when someone showed me the msgbox technique — it’s like setting breakpoints except you don’t step out of the application. and you can have the msgbox display values of current parameters as well … like

    msgbox “you made it to here! the value of x is now ” + str(x)

    thanks

  28. wjun on May 14th, 2008 1:32 am

    sorry for my bad english. it’s not my native language.
    i downloaed file from rbnation.com/files/RBDBTutorial.zip, but it can’t run in my realbasic 2008r1/r2 linux personal version. When i builed it and run it out of ide, it told me ” nilofobject” and quit right now. To fix the problom it costed me two days.
    The thing i did was to move listpeople.open methond source code to windos.open methond.
    everything is ok. what a beatuiful world!
    tks to Jay Jennings.
    btw: i am not find binding in realbasic 2008r1/r2 linux personal version. anyone could tell me how to bind databasequery and listbox?

  29. Tom on May 17th, 2008 3:07 pm

    Hi Jay,

    Thank you for the tutorial and the code,it work great.
    how about some hints on how to do the search for name.( start search in Name column)
    some code please anyone?

    Many thanks

    Tom

  30. Andreas Thapper on June 21st, 2008 7:29 pm

    If you follow the tutorial and get stuck in the same manner as Bob earlier in the comments – NilObjectException when editing records. You might have missed adding an apostrophe (or single quotation mark “‘”) before/and after some of the regular quotation marks when you generate the sql string. I sure as heck did…

    Thanks for a great video tutorial, Jay!

  31. J. Aarons on September 6th, 2008 3:35 pm

    I have downloaded your tutorial and it runs fine on Mac OS 10 Vers 10.3.9 but always comes up with a NilObjectException whenever the program is trying to attach to the database in OS Vers 10.4.11. This has also happened in other database examples that I have been studying if I alter the database in any way. Does anyone know how to get the connection to the
    databases on OS 10.4.11?

  32. J. Aarons on September 6th, 2008 10:46 pm

    As I replay the program on the Mac OS 10.4.11 it appears that the tutor database cannot be recognized by the application.

    What code could I use to have the program look for the database.

    The nilobjectexception occurs on the line where I want to insert a record:

    Tutor.InsertRecord “People”, dr.

    When I switch over to the project page and double click the Tutor database icon an error message comes up that says

    “Could not connect to the database”.

    So.. it seems that I need to figure out a method that can be used to have the app look for the database.

    Maybe I should use the Attach Database command:

    ATTACH [DATABASE] database-filename AS database-name.

    Should I put this in as a method?

  33. Jamie on September 7th, 2008 9:51 am

    What an excellent tutorial. I have only be using Realbasic for a couple of days and wanted to use it for database applications.

    Not only did the tutorial help me start working on a database application but it gave a great insight into the other techniques you can use with RealBasic such as linking objects together.

  34. Vince on September 8th, 2008 5:01 pm

    Worked Perfectly for me, Thank you so much for posting this. This Gave me a huge insight into Realbasic and helped me understand how to modify it to create a Database For Work.

  35. picsoung on February 1st, 2009 5:21 am

    Thanks for this tutorial :D
    it’s a great way to learn the *ยง$1@# of Database, finally i understand thanks to you :D

    think the next step could be a tuto to improve it, and speak about primary key, condition on database…

    and maybe why databasequery object are useful :P

    Good job !
    Nico

  36. Eddi on December 14th, 2009 8:52 am

    Hello,

    thanks a lot for the tutorial – my version of REALBasic (the latest release for Mac, i.e. REALBasic 2009 Release 5) crashes whenever I attempt to save any changes in a newly created database. Also I cannot run the Database Example.rbp program that came with REALBasic, the error being

    Code, SampleReports.PushButton1.Action, Zeile 28, Parameter sind nicht zu dieser Funktion kompatibel, If rpt.Document <> Nil Then ReportViewer1.SetDocument( rpt.Document )
    (i.e. Line 28, parameters are not compatible with this function)

    I hope you can help? Thanks a lot, best wishes Eddi

  37. Jay on December 14th, 2009 10:30 pm

    They are releasing 2009r5.1 very soon because there’s a bad DB bug in r5 — I expect that’s what you’re running up against.

    Jay

  38. Eddi on December 17th, 2009 5:06 pm

    Cool, thanks for the quick reply.
    Eddi

Leave a Reply