- [Instructor] Now that we've created our databaseand successfully added a few records,I want to show you how you can inspect its contentsfrom the command line.Let's go ahead and open up our Terminal.You will need to have Android Debug Bridge or ADBavailable on your class Pad.ADB is included in the Android SDK Platform Tools Package.If you have Android Studio running,then you will have ADB available.You can double check that it's on your Padby typing which adb.

Let's do that now, which adb.This will give you the location of adb on your machine.If you don't see the location,please refer to the sample bash profilethat I've included in the exercise files for this video.The next thing we'll do is connect to our running emulator.Make sure you only have one device connectedto follow this command exactly.I'm going to type adb shell.

Notice how the prompt changed in front of the pound sign.We now have access to the database stored on the device.We're going to use the SQLite 3 command line toolin order to inspect our database.The SQLite command line uses simple commandsthat begin with a dot, like .help or .tables.To see a full listing of the available commandsI like the reference provided by tutorialspoint.Along the left hand side,they have examples of each commandthat is available to you.

It shows the syntax and the output.If we look at the Select Query,right over here, I'll choose Select Query.If we scroll down some on the Select Query page,we can see the examples as well as the various optionsthat are available, like .header and .mode,to display the output in a more readable format.I encourage you to bookmark this site as a referencewhen using the SQLite 3 command line tool.

For now, let's go back to our Terminaland look at our topsy turvey database and its recipe table.To open the database on an emulator,we will use the SQLite 3 commandand supply the path to our database.The format is the following,sqlite3 then a space,and you begin to type the path to the database.The database on the emulator is storedin /data, /data again,and then, a forward slash followed by the package name.

In this case, it's info.adavis.topsy.turvey.That's the package name that we chose for our application.Next, we put another forward slash and the word databases.Finally, we have a forward slashand the name that we chose when we created our databasewith SQLite.That was topsy_turvey.db.

Once we click Enter,notice that we're now in the SQLite 3 prompt.This is where we will start to use those dot commandsthat we spoke about earlier.If you ever get lostor a command does not seem to be working,check the spelling and compare against the options availablewhen you type .help.Let's do that now, .help.You will see a full list of all of the available commands.

Now, the first thing we want to do is inspect the tables.For that, we will use the .tables command.We'll type .tables and then Enter.Notice that we have three tables in our database,android_metadata, recipe, and recipe_step.The android_metadata table was created automatically for youby the Android system.The other two tables were createdby using our SQLiteOpenHelper implementation.

We can confirm that by looking at the schema for the tables.Let's look at the schema for the recipe table.We're going to use the .schema command,followed by the table name, recipe.Here we can see the command we suppliedto our create method.The final thing we want to dois view the records that we've inserted so far.This is going to require a simple SQL query.

We want to retrieve all the records from the recipe table,so we'll use a select statement.SELECT * FROM recipe.But since this is an SQL query,we need to end this statement with a semicolon.Now, we'll type Enter.Now we can see the recipe informationprinted out to our screens.Why don't you try using the command linewith the SQLite 3 tool before moving on to the next video.

Resume Transcript Auto-Scroll

Author

Updated

5/24/2018

Released

5/5/2017

By persisting your data, you can provide users with a more seamless experience with your app—even when they go offline. If you're an Android app developer, you have many data persistence options to choose from. In this course, learn about various options for storing your app's data in a database.

To begin, Annyce Davis reviews using the de facto data persistence solution available on Android: SQLite. She takes you through basic SQLite concepts—such as how to create a database wrapper and insert data into a table—as well as a few more advanced topics. Next, she covers working with Cupboard, an open-source project dedicated to simplifying your SQLite interactions. To wrap up, she dives into working with Realm, an object database solution designed with mobile devices in mind. Throughout the course, Annyce discusses establishing relationships between database tables, creating and running queries, as well as performing data migrations.