Android Utililty Methods SqliteDatabase Command

List of utility methods to do SqliteDatabase Command

Description

The list of methods to do SqliteDatabase Command are organized into topic(s).

Method

intexecuteSqlStatements(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;
intexecuteSqlStatementsInTx(SQLiteDatabase db, String[] statements)
execute Sql Statements In Tx
db.beginTransaction();
try {
    int count = executeSqlStatements(db, statements);
    db.setTransactionSuccessful();
    return count;
} finally {
    db.endTransaction();
ArrayListgetListOfDays(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;
...
booleaninsertIntoTable(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 {
...
ArrayListselectFromTable(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();
...
voidupdateTable(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]);
...
CursorgetTaskCursor(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;
StringSQLiteSanitize(String input)
Replaces SINGLE_QUOTEs with double SINGLE_QUOTEs
return input.replaceAll("'", "''").trim();
StringgetFreeTourName(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";
intgetNewTourPointPosition(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;