Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database...
Transcript of Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database...
![Page 1: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/1.jpg)
Database Intro w/SQLite
How to put an embedded database on your phone and integrate with your application.
[email protected], February 28, 13
![Page 2: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/2.jpg)
Things you will need:
SQLite software to create the database comes standard on intel macs
free needs to be downloaded for windows
SQLite browser/editor software
used to create/edit databases and tables
free, just needs to be downloaded and set up
Create a simple database(s) and table(s)
Create Android Database sample application
Put database into Android project
Test app (fingers crossed, hope all goes well) :)
Thursday, February 28, 13
![Page 3: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/3.jpg)
Download & Setup SQLite software
For Mac
It is include in Mac OS X.
It is located in /usr/bin directory and called sqlite3
Thursday, February 28, 13
![Page 4: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/4.jpg)
Download & Setup SQLite software
For Windows
Download Precompiled Windows Binaries from the SQLite webpage.
http://www.sqlite.org/download.html
Extract the binaries by double clicking on the downloaded zip files. You can extract the files to your C drive (folder name C:\sqlite\ ) or to any location which suits your needs.
Thursday, February 28, 13
![Page 5: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/5.jpg)
Download & Setup SQLite Browser (same software for Win/Mac)
Download zip file from
http://sourceforge.net/projects/sqlitebrowser/
Click on the Download icon
Extract this to some location on your PC/Mac
Double click on SQLite Database Browser application to run SQLite DB Browser
Win & Mac Screen shots on next page
Thursday, February 28, 13
![Page 6: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/6.jpg)
Thursday, February 28, 13
![Page 7: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/7.jpg)
Create Database and Table
File > New Database
Enter name hit Save (put
Thursday, February 28, 13
![Page 8: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/8.jpg)
Create Table(s)
Edit > Create Table
enter Table name
Hit ADD to add fields to table
When all fields are added hit Create
Thursday, February 28, 13
![Page 9: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/9.jpg)
MUST HAVE...
Every Android database must have a table called android_metadata with one field called locale of type TEXT as seen below
Thursday, February 28, 13
![Page 10: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/10.jpg)
How to do this...Create table android_metadata in your database
Add field called locale of type TEXT
Set the default value of en_US into the locale field in the android_metadata table
See screenshot on next page...
Thursday, February 28, 13
![Page 11: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/11.jpg)
Enter this SQL string
Hit the Execute query button
Thursday, February 28, 13
![Page 12: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/12.jpg)
SQLITE Demo...create database using (sqlite browser)
I like to put a .db extension on file
create table
add column
note limited column types
be creative
Thursday, February 28, 13
![Page 13: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/13.jpg)
Linking TablesKeys are supported, but difficult to enable...
http://www.sqlite.org/foreignkeys.html#fk_enable
For most apps not needed. Just use common field names between tables. “Poor mans linking”
Thursday, February 28, 13
![Page 14: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/14.jpg)
Managing Dates
SQLite does not have a date/time field type
SQLite does have date time funtions, but stores its values in TEXT fields
YYYYMMDDHHmmSS
HHmmSS is optional
Thursday, February 28, 13
![Page 15: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/15.jpg)
How to put DB in AppDrag .db file into the assets directory in your project.
Create and run your Sample App
Thursday, February 28, 13
![Page 16: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/16.jpg)
Where did it go..DP_PATH = /data/data/[PACKAGE]/databases/
DB_NAME = name you gave your DB
Thursday, February 28, 13
![Page 17: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/17.jpg)
How can you get DB from App
Window > Show View > Other... > Android > File Explorer
Navigate to /data/data/[packageName]/databases
Then use the icon to copy db to computer
Thursday, February 28, 13
![Page 18: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/18.jpg)
Add Class to DB...Enter a Class Name
Enter a Class Number
Click Submit to insertdata into database
Thursday, February 28, 13
![Page 19: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/19.jpg)
Code Segments...!I will make the sample project available on MeetUp (somehow)
Thursday, February 28, 13
![Page 20: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/20.jpg)
Sample Application
Grade Book Application
Paper Prototype
Here is an example of a SQLite database with some tables and fields
Thursday, February 28, 13
![Page 21: Database Intro w/SQLite · 2013-03-01 · Database Intro w/SQLite How to put an embedded database on your phone and integrate with your application. deano@webenefitall.com Thursday,](https://reader035.fdocuments.in/reader035/viewer/2022062602/5e8bca3a3aba617d885c89a8/html5/thumbnails/21.jpg)
Questions...
Thursday, February 28, 13