We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
I'm looking at initDB here and what I'm going to do is walk you through the function. It seems to have a lot of code in it, but really isn't very much. Don't worry about it because it does just the initialization of the database and what you can see is it's called, as you remember, it's called form.load and the purpose of this function is to initialize the database and it returns database. So, it is going to fill the database variable with something. It might be no as you see here, but it's going to return something. So, let's take a look at what's happening here and we have here a try block. We are gonna have to look a little bit at PHP code. This is a refresher if you know a bit about PHP and it's been a while. The try block is a section of code that is executed and if a failure occurs, then the catch block down here is executed. It saves using if statements and testing to see if something has worked or not. The try block, as long as you put it within pointed brackets following the word try, then you have catch and then you have the catch code down here, you can - this is the exception that has been raised, you can process it, but for now and in fact many, many people only use this structure with just try block-up code catch and then another block-up code here. So, if anything goes wrong up here, in the try block, we are going to set the database variable to no and it will be returned. If the try block succeeds, the database variable will be set to an open database and you can see that's what's happening up here. We call the open database method of the window because that's where it's located and then we call open database itself. We pass in four parameters to open database. The short name of the database, the version number, the long name and the size, and that's the initial size. When it gets full, the user will be asked to allow the system to enlarge it and that's where the database name and the long name come into play because in a message such as that, it's the long name that is presented to the user, "Do you want to enlarge message database?" rather than the short name, which might be a somewhat cryptic name. In this case, it isn't, but this is the database that's going to be opened here for us and the way in which open database works is it's got these four parameters, the long and the short name, the version number and the size and it tries to open that database and if it can, it creates it. It's got enough information to create the database. Now remember, this database is created just for this user. This not a shareable database so it's located, it's created by the web kit on the user's device. In this case, it would be on the iPhone and you've got a database at that point. Now, if you have the database then we come down here and execute this code. If not, then you'll fail and what we're going to do here is if the database is created, which it should be, then we go into a transaction. Now, transactions in SQL consist of one or more statements that are treated atomically. If a failure occurs in the middle of a transaction, all of the changes are rolled back so you never have a partial transaction. It's all or nothing and this transaction has the executeSql function here and what that does is it executes an Sql query and don't worry, I will go through this several times and after a few times, you'll see that the structure is always the same.
| Course: | Developing iPhone Web Apps |
| Author: | Jesse Feiler |
| SKU: | 34075 |
| ISBN: | 1-935320-89-0 |
| Release Date: | 2009-12-31 |
| Duration: | 8 hrs / 103 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |