database intro w/sqlite · 2013-03-01 · database intro w/sqlite how to put an embedded database...

Post on 28-Mar-2020

14 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Database Intro w/SQLite

How to put an embedded database on your phone and integrate with your application.

deano@webenefitall.comThursday, February 28, 13

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

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

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

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

Thursday, February 28, 13

Create Database and Table

File > New Database

Enter name hit Save (put

Thursday, February 28, 13

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

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

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

Enter this SQL string

Hit the Execute query button

Thursday, February 28, 13

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

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

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

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

Where did it go..DP_PATH = /data/data/[PACKAGE]/databases/

DB_NAME = name you gave your DB

Thursday, February 28, 13

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

Add Class to DB...Enter a Class Name

Enter a Class Number

Click Submit to insertdata into database

Thursday, February 28, 13

Code Segments...!I will make the sample project available on MeetUp (somehow)

Thursday, February 28, 13

Sample Application

Grade Book Application

Paper Prototype

Here is an example of a SQLite database with some tables and fields

Thursday, February 28, 13

Questions...

Thursday, February 28, 13

top related