Created
June 5, 2015 06:22
-
-
Save pookie13/952086a7b78989246c01 to your computer and use it in GitHub Desktop.
DataBase Function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// insert template in to DB(query) | |
public long insertdata(Model model) { | |
String sql = "INSERT INTO " + Databaseconnector.TABLE_TEMPLET | |
+ "(UNIQUEID,TEMPLET) VALUES (?,?)"; | |
SQLiteStatement objStmt = sqliteDatabase.compileStatement(sql); | |
objStmt.bindString(1, Commonvariable.getUniqueID()); | |
Log.d("tempValue", ""+model.getTemplet()); | |
string=templetOb.getTemplet(); | |
objStmt.bindString(2, templetOb.getTemplet()); | |
long longValue = objStmt.executeInsert(); | |
return longValue; | |
} | |
// get all data in arraylist from DB | |
public ArrayList<String> getAllData() { | |
ArrayList<String> arrayListofTemplet = new ArrayList<String>(); | |
Cursor cursor = sqliteDatabase.query( | |
Databaseconnector.TABLE_TEMPLET, null, null,null, null, null, null); | |
int count = cursor.getCount(); | |
if (count > 0) { | |
if (cursor.moveToFirst()) { | |
do { | |
String TotalTemplets = cursor.getString(cursor | |
.getColumnIndex("COLOMN_NAME")); | |
arrayListofTemplet.add(TotalTemplets); | |
} while (cursor.moveToNext()); | |
} | |
} | |
return arrayListofTemplet; | |
} | |
//multiple selection arg. | |
public ArrayList<Model> getData(){ | |
String table = "CONTACT_TAGS"; | |
String[] columns = {"_id"}; | |
String where = "TAG1=? OR TAG2=? OR TAG3=? OR TAG4=? OR TAG5=?"; | |
String[] args = {"tagname", "tagname", "tagname", "tagname", "tagname"}; | |
SQLiteDatabase db = [yourDatabaseHelper].getReadableDatabase(); | |
Cursor cursor = db.query(table, columns, where, args, null, null, null); | |
int count = cursor.getCount(); | |
if (count > 0) { | |
if (cursor.moveToFirst()) { | |
do { | |
String TotalTemplets = cursor.getString(cursor | |
.getColumnIndex("COLOMN_NAME")); | |
arrayListofTemplet.add(TotalTemplets); | |
} while (cursor.moveToNext()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment