Download presentation
Presentation is loading. Please wait.
Published byOctavia Simmons Modified over 9 years ago
1
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions
2
Content 2 SQLite Helper classes Gotchas Permissions Readings
3
SQLite 3 Small,fast,compact, embedded SQL database Not a full featured SQL dialect Every Android phone has a copy of SQLite No database administration Need to write Java code to create and alter table structures
4
SQLite 4 One file per database Locally available persistent data store – can access information when not connected to the internet / network DDL and DML Can perform CRUD (create, read, update, delete) Insert Select Update Delete Using RAW SQL interface or SQLite helper methods
5
SQLite Application Structure 5 Extend SQLiteOpenHelper and override OnCreate() OnUpgrade() Define database fields, table name and database version Declare helper subclass in Activity object Open Readable or Writable database as needed
6
Declare Constants 6 public final static int VERSION = 1; public final static String NAME = "mobile.db"; public final static String TABLE = "CLIENT"; public final static String CID ="CID"; public final static String FIRSTNAME="FIRSTNAME"; public final static String LASTNAME="LASTNAME"; public final static String NOTES="NOTES";
7
7 public class W5DBHelper extends SQLiteOpenHelper { public final static int VERSION = 1; //... this is where the constants from previous page would go public W5DBHelper(Context context) { super(context, NAME, null, VERSION); } @Override public void onCreate(SQLiteDatabase db) { String sql = "create table " +TABLE +" ("+CID+" integer primary key, "+FIRSTNAME+" text, "+LASTNAME+" text, "+NOTES+" text);"; db.execSQL(sql); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("drop table if exists "+TABLE); onCreate(db); } Define Helper
8
Using the Helper class 8 W5DBHelper helper = new W5DBHelper(getApplicationContext()); dbHandler = helper.getWritableDatabase(); String sqlInsert = "insert into CLIENT (CID,FIRSTNAME, LASTNAME, NOTES) values(null,'John','Casey','blah blah blah');"; dbHandler.execSQL(sqlInsert);
9
SQLite Helper Methods 9 ContentValues values = new ContentValues(); values.putNull(W5DBHelper.CID); values.put(W5DBHelper.FIRSTNAME,"John"); values.put(W5DBHelper.LASTNAME,"Casey"); values.put(W5DBHelper.NOTES,"Blah blah”); dbHandler.insert(W5DBHelper.TABLE,null, values);
10
Things to remember... 10 SQLite isn’t Oracle or MS SQL Server Has its own very unique syntax Android’s SQLite appears to be slightly different to plain old SQLite Does not completely implement all the SQL features you would normally expect: data types, stored procs, even some types of join query
11
Permissions 11 Per resource model: Grant / Revoke Location Phone calls Blue tooth Network access Wi-fi Internet Personal information Spend money on the market Its easy!
12
Permissions 12 Declare resources that the application needs in the manifest file – before the application XML block Application will then prompt user to grant that resource to the application
13
Readings 13 http://www.vogella.de/articles/AndroidSQLite/article.ht ml http://www.vogella.de/articles/AndroidSQLite/article.ht ml http://www.sqlite.org/ http://developer.android.com/reference/android/database /sqlite/package-summary.html http://developer.android.com/reference/android/database /sqlite/package-summary.html http://mobile.tutsplus.com/tutorials/android/android- sqlite/ http://mobile.tutsplus.com/tutorials/android/android- sqlite/ http://android-er.blogspot.co.nz/2011/06/simple- example-using-androids-sqlite.html http://android-er.blogspot.co.nz/2011/06/simple- example-using-androids-sqlite.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.