Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Testing the BWDB interface in the sandbox

From: iOS SDK and SQLite: Building Data-Driven Apps

Video: Testing the BWDB interface in the sandbox

At this point we have started to incorporate BWDB in the Testbed code for testing. We've set up the SQLite 3 Framework in Xcode, and we've imported the BWDB Library into our Testbed app. Now, it's time to test the library in the testbed. So, you're going to take the results from your last exercise or if you prefer, you can use Testbed-02-done, which is my version. And I'm going to make a working copy of this. And I'm just going to call it Testbed-03-working, and so this way we can pick up where we left off at the end of the last movie.

Testing the BWDB interface in the sandbox

At this point we have started to incorporate BWDB in the Testbed code for testing. We've set up the SQLite 3 Framework in Xcode, and we've imported the BWDB Library into our Testbed app. Now, it's time to test the library in the testbed. So, you're going to take the results from your last exercise or if you prefer, you can use Testbed-02-done, which is my version. And I'm going to make a working copy of this. And I'm just going to call it Testbed-03-working, and so this way we can pick up where we left off at the end of the last movie.

And I'm going to double-click on the Testbed. xcodeproject inside of that folder to open the project in Xcode. So, we have our BWDB Library, there is the m file, and there is the h file. I'm just going to close that up for now, we go to our BWUtilities. And I'm going to come over here to the TestbedViewController.m file, and up here at the top I'm going to import the BWDB header. And I'm going to come back out here into our finder, and I'm going to take this BWDB testbed code and open that up in my text editor. And we've got a couple of methods here.

I'm just going to copy these and paste them into my m file. So, Command+C to copy, coming back here into Xcode, and down here in the implementation I'm going to paste those in, and there they are. And you see that our method here is called testDatabase. And so, I'm just going to come down here in viewDidLoad and instead of runTest, I'm just going to type in testDatabase like that.

And so runTest here is actually often we can leave it there, or you can delete it, it's up to you. So, let's just go ahead here and run this and then we'll come back, and we'll look at the code. Make sure you select the iPhone Simulator and press the Run button, Build Succeeded, that's always a good sign. And so there is the Simulator, we see we have our BWDB version, SQLite version, create table, and all of these database operations happening successfully.

So, let's take to look at the code. So, there's a table name and a file name. And there is an actual BWDB object being declared. And here we have our alloc init pattern, and we're initializing with the file name and the table name. And we call getVersion to display the version, and there is our version there. And SQLite version is value from query select sqlite_version, so there is the sql query to get the SQLite version, and that's getting displayed here.

So, that actually tells us that a lot of stuff is working here. Our interface to the SQLite Framework is working and the interface to BWDB is working. So, we're actually able to send an SQL query and get a value from that, and that's a really good sign. So now, we come out here, and we create a table. You notice I have this message call to create--to display the create table string. And doQuery is the version of the query code, and if we come in here to the BWDB header and SQL query's doQuery simply returns a number of rows that were affected, if any.

So, it's typically called without testing the return value. And we come back down here, and we can see doQuery here has been called without testing the return value. Drop table if exists and then CREATE TABLE. We're creating a table with an id column, INTEGER PRIMARY KEY that's SQLite for an auto incremented integer key. SQLite allows you to create columns without a type because it's really a very loosely typed thing anyway.

And stamp is TEXT DEFAULT CURRENT_TIMESTAMP and so it will always put a timestamp on every single row. And so, now we're going to go ahead and insert a row, and we insert into BW table, so we're using doQuery for this insert, and we return the lastInsertId, and we see that we get one for that. And then using CRUD to insert with insertRow, and these are literal NSDictionary types.

So, we have key value, key value, key value, that's a new feature in Objective-C, and it's much more convenient than the old way. So, I tend to use these literal values a lot. So, you see I'm using some different types here, I've got the literal floating point, I've got literal integers and here is a literal string. So, NSNumber doubles, integers and Mixed. And you see, when we look at these values, we get the return values based on the way that SQLite handles these sorts of things.

And here I'm reading it back, and that's where it's displayed here using the NSFastEnumeration. And so, I simply pass the query into the db object and for a row in, the value that's returned by that is the actual db object. If we look at the getQuery code over here, we notice that it returns itself. So, that's actually returning the BWDB object. And because of NSFastEnumeration, I'm able to just say for row in that object, and then call display row with that row.

And display row of course is up here, and it's just this simple message with the row. And again, we're using this new subscripting feature that's new in Objective-C. So, we use db countRows here, and there we have count rows 4, and then we delete a row and then we get count rows 3. So here, we delete row three with deleteRow, and we call countRows again we get a different value. And then we look, and we have just row 1, row 2 and row 4, and that again is using the NS enumeration for displaying the rows in the table.

And then we're able to display an individual row using getRow. So, this should make it clear that the value of this wrapper is it makes it easy to work with SQLite in an Objective-C environment. We are using Objective-C paradigms for all of this, rather than having to write C code in the middle of our Objective-C. It makes this all seamlessly integrate with our Objective-C code for iOS. It's also easy as we'll see in another lesson in this chapter to subclass BWDB and create a specific interface for a specific application.

Show transcript

This video is part of

Image for iOS SDK and SQLite: Building Data-Driven Apps
iOS SDK and SQLite: Building Data-Driven Apps

41 video lessons · 6437 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 8m 29s
    1. Welcome
      57s
    2. Exercise files
      2m 17s
    3. Course overview
      3m 4s
    4. Application overview
      2m 11s
  2. 14m 49s
    1. Prototyping in a testbed
      1m 27s
    2. Building the view controller
      3m 45s
    3. Coding the testbed
      7m 56s
    4. Using the testbed
      1m 41s
  3. 37m 49s
    1. Understanding SQLite in iOS
      1m 41s
    2. Creating an Objective-C interface for SQLite
      9m 57s
    3. Testing the BWDB interface in the sandbox
      7m 1s
    4. Designing a database schema
      8m 7s
    5. Supporting the application with a specific interface
      7m 7s
    6. Using C pointers with automatic reference counting (ARC)
      3m 56s
  4. 21m 18s
    1. Understanding the table view
      1m 33s
    2. Creating the view controller
      6m 39s
    3. Reading from the database
      13m 6s
  5. 33m 50s
    1. Understanding the parsing process
      1m 57s
    2. Creating the item view controller
      12m 25s
    3. Reading data from the internet
      5m 30s
    4. Parsing the feed with NSXMLParser
      8m 2s
    5. Updating the item view with the feed items
      5m 56s
  6. 40m 14s
    1. Understanding the modal view
      1m 47s
    2. Constructing the view controller
      15m 5s
    3. Finding a feed link in a web page
      8m 55s
    4. Parsing the feed with NSXMLParser
      5m 4s
    5. Delegating back to the parent view
      6m 11s
    6. Deleting feeds
      3m 12s
  7. 21m 5s
    1. Creating the web view class
      12m 33s
    2. Coding the web view
      5m 25s
    3. Viewing pages in Safari
      3m 7s
  8. 14m 3s
    1. Understanding the iOS preferences system
      1m 23s
    2. Creating the preferences plist in Xcode
      7m 20s
    3. Reading preferences in your application
      5m 20s
  9. 6m 15s
    1. Adding pull-to-refresh functionality
      2m 34s
    2. Implementing the pull-to-refresh gesture for iOS 6
      3m 41s
  10. 27m 1s
    1. Understanding split view
      1m 4s
    2. Coding the table views
      11m 24s
    3. Implementing the iPad detail view
      6m 35s
    4. Implementing the iPad modal view
      7m 58s
  11. 35s
    1. Goodbye
      35s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed iOS SDK and SQLite: Building Data-Driven Apps.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.