Skip to content

Instantly share code, notes, and snippets.

@pookie13
Created June 5, 2015 06:22
Show Gist options
  • Save pookie13/952086a7b78989246c01 to your computer and use it in GitHub Desktop.
Save pookie13/952086a7b78989246c01 to your computer and use it in GitHub Desktop.
DataBase Function.
// 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