List of utility methods to do SqliteDatabase Command
int | executeSqlStatements(SQLiteDatabase db, String[] statements) execute Sql Statements int count = 0; for (String line : statements) { line = line.trim(); if (line.length() > 0) { db.execSQL(line); count++; return count; |
int | executeSqlStatementsInTx(SQLiteDatabase db, String[] statements) execute Sql Statements In Tx db.beginTransaction(); try { int count = executeSqlStatements(db, statements); db.setTransactionSuccessful(); return count; } finally { db.endTransaction(); |
ArrayList | getListOfDays(SQLiteDatabase db) get List Of Days Cursor cursor = db.query(true, NESTLE_TABLE_NAME, new String[] { NESTLE_COLUMN_1 }, null, null, null, null, null, null); ArrayList<String> list = new ArrayList<String>(); while (cursor.moveToNext()) list.add(cursor.getString(cursor .getColumnIndex(NESTLE_COLUMN_1))); return list; ... |
boolean | insertIntoTable(SQLiteDatabase database, String table, String[] data) insert Into Table String values = ""; for (int i = 0; i < data.length; i++) { if (data[i].trim().length() != 0) { if (i == data.length - 1) values += quote(data[i]); else values += quote(data[i]) + ", "; } else { ... |
ArrayList | selectFromTable(SQLiteDatabase db, String table, String sample) select From Table ArrayList<String> list = new ArrayList<String>(); Cursor cursor = db.query(table, new String[] { NESTLE_COLUMN_1, NESTLE_COLUMN_2, NESTLE_COLUMN_3, NESTLE_COLUMN_4 }, NESTLE_PRIMARY_KEY + " LIKE ?", new String[] { sample }, null, null, null); while (cursor.moveToNext()) { String s = null; StringBuffer buffer = new StringBuffer(); ... |
void | updateTable(SQLiteDatabase database, String table, String id, String[] newValues) update Table ContentValues cv = new ContentValues(); if (table.equals(NESTLE_TABLE_NAME)) { try { cv.put(NESTLE_COLUMN_1, newValues[0]); } catch (ArrayIndexOutOfBoundsException e) { try { cv.put(NESTLE_COLUMN_2, newValues[1]); ... |
Cursor | getTaskCursor(SQLiteDatabase database, String name) get Task Cursor String where = NAME + "='" + name + "'"; Cursor cursor = database.query(TASK_TABLE_NAME, null, where, null, null, null, null); return cursor; |
String | SQLiteSanitize(String input) Replaces SINGLE_QUOTEs with double SINGLE_QUOTEs return input.replaceAll("'", "''").trim(); |
String | getFreeTourName(SQLiteDatabase db, String tourName) get Free Tour Name if (!tourNameExists(db, tourName)) { return tourName; for (int i = 1; i < Integer.MAX_VALUE; i++) { String checkTourName = tourName + " " + Integer.toString(i); if (!tourNameExists(db, checkTourName)) return checkTourName; return tourName + " changeme"; |
int | getNewTourPointPosition(SQLiteDatabase db, long tourId) get New Tour Point Position Cursor cursor = db.query(TOUR_POINT_TABLE_NAME, new String[] { "max(" + TOUR_POINT_POSITION + ")" }, TOUR_POINT_TOUR_ID + "=" + tourId, null, null, null, null); cursor.moveToFirst(); int position = cursor.getInt(0); cursor.close(); return ++position; |