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
Click here to get your copy of REALbasic
Comments
38 Responses to “REALbasic Database Tutorial”
Leave a Reply
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.
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
Hello Jay,
what a truly excellent screencast.
Keep it up!
Lucas
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
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
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
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 -^
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
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 ?
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.
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).
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.
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
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.
:/ 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…
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…
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.
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
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
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 -^
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
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?
Sorry for the double post… Didn’t know I hit submit before I typed the last question…
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
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…
I too am having troubles getting it to run on vista.
Same issues as above.
Does realbasic work ?
Thanks
Terence
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
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?
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
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!
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?
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?
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.
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.
Thanks for this tutorial
it’s a great way to learn the *ยง$1@# of Database, finally i understand thanks to you
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
Good job !
Nico
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
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
Cool, thanks for the quick reply.
Eddi