Android 7 Programming Tutorial. adb.exe and SQLite


Uploaded by edu4java on 18.11.2010

Transcript:
Hello, I´m Edu from edu4java and this is Android Tutorial number 7
We are going to see Android Debug Bridge and SQLite
Ok, let´s start
if you remember I installed the SDK, here in the Desktop
I hope you installed it in a better place,
but if you open it you, you can find inside a tool directory
and inside an adb.exe file
I am going to use this Ms-dos command and I´m going to put Android list adb
that list the devices that are defined in my emulator
I´m going to start my emulator, this dev22
I start with emulator at dev22
Start is from Ms-dos to start in another window in another process
Ok, here I have the emulator loaded
I´m going to minimize this for now
and I´m going to use the Android bridge adb shell
this is a Linux command shell inside the phone
in this case is the emulator
Here in the emulator I already worked with Contacts and wrote two contacts
one with Edu as a name and 4java as the last name
Phone 555-555 email
and as a company name I wrote edu4java.com
And here I wrote another; Eli 4java and the phone is 444-444
Ok, now this is setup
we can go and try to see what we can do in the Linux shell
In this Linux shell we are inside the Android phone emulator
but if we put a real phone in an usb connection
we can do the same in a real Android phone
ok, let´s do something here
ls, ok, we can make a list as in any Linux
and we see everything which is inside the root directory
with ls system bin we can see the command that we have in this Linux
Remember this is not a complete Linux, it´s a modified version
and here in data data we can see all the packages that store data
There is one package for each application
and inside this directory data-data and the name of the package of the application
we can find the data for each application
if the application contained a database we can find a database directory inside
we can see with this instruction all the databases
ok, we have all these databases
Contacts 2;is the one we are interested in
This database contains the data I wrote here in the application Contacts
Edu 4java and Eli 4 java
Let´s see if we can get the information
Ok, the database is exactly here; com.android.providers.contacts
it´s a data provider
then we can access to this database using an SQLite 3
It´s an application that we have in the phone
We feed this application with the name of the database
Ok, we are in
Inside the Sqlite we can write Sql
There is a shortcut; .tables is a shortcut for this Select that you can see now
and then we get a list of all the tables we have in the database
here there is a data table that we can make a Select to see what we can find
here is the information I wrote inside the Contacts; Edu 4java, Edu is the name
and 4java is the last name... 555-555 is the number
444-444 this is another number for Eli 4java... edu4java.com and... my email
Ok, let´s continue...
We can see with this shortcut, schema data... we can see the structure
The way that Sqlite shows us the structure is with the create table Sql
here is all the information you need to know about the structure
It´s an easy way to show us...
Ok,with .exit we quit from Sqlite
and with exit we quit from Linux shell
now we are again in MS-Dos
Here we can use this command adb pull to feed this command with two parameters
The first parameter is a file inside the Linux
and the other is a directory outside
this command is useful to get a file from inside the phone to our operating system
We are going to get contact2, I have already one here
I am going to delete it and run it again
Ok....if everything is ok after I press enter we are going to get the file here
Yes, this is the database I have in my phone, now it is in my PC
Then we can use a more friendly way to see what is inside the database
I searched and there is a lot but I found one that was beautiful for me
because it is a FireFox plug-in
Yes, it´s a SQLite Manager, you can see here it is a plug-in
I install it in my FireFox and then I get this; SQLite Manager
It is trying to open the database, I say no and I´m going to pick it again
as you can see you need to change here because I have a different extension
It´s in the same place I left it, ok...
And here you have a friendly view of the database,
better than the one we used before
And if you remember we checked data table is here...
and the same information is here; Edu 555-555, 444-444 Eli
Ok, we can see here all the tables, all the views here, indexes and even triggers
Yes, I think it´s a nice tool...
Let´s see something about the SQLite,
The main thing of the SQLite is that it´s Server-less
most of the famous database with which we work today;
Oracle, MySql, Postgre... all have a server
You can see a server as a waitress; any time we need data we ask the waitress
or the server in this case to get something for us
and this server-less is different; it´s like self service
you go and just get the data yourself
It´s an Api, it´s not another entity
It´s just an Api that you use to get the data
The data is in a file and there is no process working with the data
This is good for a phone, because if you have a server you need to maintain it
it´s really more complicated and nobody wants a dba for our phone
Anyway this is better than a just a file
because we use Sql, zero configuration, transactional; yes we have transactions
maybe not so powerful as Oracle or MySQl but we have ACID;
Atomic, Consistent, Isolated and Durable
if you are interested in ACID you can check in the Wiki
and it is self-contained; this is really interesting
you don´t depend on other components; it´s really encapsulated
you need an Api to access to the operating system
and you have to store it in a file
but there is a little support for an Api to handle thread
but it doesn´t depend on another service
Most Widely Deployed SDK Databases; yes, it is easy;
it´s open source, it´s free and for example Mozilla Firefox has one inside
Then you have 300 million Mozilla´s copies and 300 million databases
Mac computers have it inside so you have 20 million
PHP has one... Skype has one; 450 million people; it is really used
Ok, this is enough for the Android debug bridge
We have seen the Linux operating system,
We´ve seen the File system
We have an idea about Sqlite that we are going to use in the next tutorials
This is all for this tutorial
See you!!