14 Jan

Android SQlite DAO

Dear Android Developers,

At this time I want to show you, using “Android SQLite DAO” to code Android SQLite using more simple.

First time, this tutorial is taken from this link:
http://code.google.com/p/android-sqlite-dao/

Here is the usage:
1. Create New Class, for example class Item

   public class Item {
     @Persistent
     @PrimaryKey(autoIncrement = true)
     private long   _id;

     @Persistent
     private String title;
     ...
     // getter, setter, or something
     ...
   }
   

2. Call SQLiteDAO.getInstance() in onCreate() method Activity

   SQLiteDAO dao = SQLiteDAO.getInstance(this, Item.class);
   

3. How to Insert Data

   Item item = new Item();
   item.setTitle("sample title");
   dao.insert(item);
   

4. How to Select Data

   List<Item> list = dao.get(Item.class);
   

5. How to Update Data

   Item afterItem = new Item();
   afterItem.setTitle("after title");
   dao.update(afterItem, "title=?", "beforeTitle");
   

6. How to Delete Data

   dao.delete(Item.class, "title=?", "deleteTitle");
   

Supported Data Types
int
long
short
float
double
boolean
byte (BLOB)
String
Date
enum

SQLite DAO Features
auto generate tables
SELECT, INSERT, UPDATE, DELETE
create primary keys and constraints
create auto increment integer primary key

No Feature in SQLite DAO
join tables
use sub queries
table scheme update

Best Regards,
Andi Taru – CEO