sqlite multiple table

13
Think Android Lesson : Sqlite Multiple Tables By : Danang Kukuh P

Upload: danang-kukuh-pribadi

Post on 30-Jan-2015

1.400 views

Category:

Education


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Sqlite Multiple Table

Think AndroidLesson : Sqlite Multiple Tables

By : Danang Kukuh P

Page 2: Sqlite Multiple Table

What is Sqlite? SQLite is an Open Source database. SQLite supports

standard relational database features like SQL syntax, transactions and prepared statements.

Page 3: Sqlite Multiple Table

Sqlite in Android SQLite is embedded into every Android device. Using an

SQLite database in Android does not require a setup procedure or administration of the database.

You only have to define the SQL statements for creating and updating the database. Afterwards the database is automatically managed for you by the Android platform.

Page 4: Sqlite Multiple Table

Sqlite Multiple Tables I explained how to use SQLite database in your android

application. But that covered the scenario, only when you have one table in the database. I am getting lot of queries about handling the sqlite database when it is having multiple tables.

Page 5: Sqlite Multiple Table

Introduction to the project

Database Design

FIELD TYPE KEY

Id INTEGER PK

Name TEXT  

created_at DATETIME  

Film Kategori

FIELD TYPE KEY

Id INTEGER PK

name TEXT  

created_at DATETIME  

FIELD TYPE KEY

Id INTEGER PK

Film_id INTEGER  

Kategori_id INTEGER  

Film_kategori

Page 6: Sqlite Multiple Table

Example Data

Id Name

1 Ketika Jomblo Bertasbih

2 Petualangan si gundul

3 Transformer

4 Sadako

5 3 Hati 2 Dunia 1 Cinta

Id Name

1 Action

2 Horror

3 Adventure

4 Drama

Id Film_id Kategori_id

1 1 4

2 2 3

3 3 1

4 4 2

5 5 4

Film Kategori

Film_Kategori

Page 7: Sqlite Multiple Table

Let’s Start a New Project Click New in the toolbar. In the window that appears,

open the Android folder,

select Android Application

Project,

and click Next. Figure 1.

The New Android App

Project wizard in Eclipse.

Page 8: Sqlite Multiple Table

Creating Model Class for Tables Create Class Film.java and Kategori.java in package model

And create constructor, setter and getter

Page 9: Sqlite Multiple Table

Creating DatabaseHelper Create Class DatabaseHelper.java in package helper And create CRUD(Create, Read, Update, Delete) Operations

Page 10: Sqlite Multiple Table

MainActivity In the below I just created sample Kategori and Film data

and performed the all the operations by calling the methods which we prepared in DatabaseHelper class.

Page 11: Sqlite Multiple Table

Run App….Check data in Database I Check data in Database Sqlite with Sqlite Editor

Page 12: Sqlite Multiple Table

Source Code? Check Source Code in My GitHub https://github.com/dpapayas/SqliteMultipleTables

Page 13: Sqlite Multiple Table

Thanks