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

ListgetTourNames(SQLiteDatabase db)
get Tour Names
List<String> tourNames = new ArrayList<String>();
Cursor cursor = db.query(true, TOUR_TABLE_NAME,
        new String[] { TOUR_NAME }, null, null, null, null, null,
        null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
    tourNames.add(cursor.getString(0));
cursor.close();
return tourNames;
longinsertTour(SQLiteDatabase db, String tourName)
insert Tour
ContentValues values = new ContentValues();
values.put(TOUR_NAME, tourName);
long id = db.insert(TOUR_TABLE_NAME, null, values);
return id;
booleanisCompanyInTour(SQLiteDatabase db, long companyId, long tourId)
is Company In Tour
Cursor cursor = db.query(
        true,
        TOUR_POINT_TABLE_NAME,
        new String[] { TOUR_POINT_TOUR_ID, TOUR_POINT_COMPANY_ID },
        TOUR_POINT_TOUR_ID + "=? " + " AND "
                + TOUR_POINT_COMPANY_ID + "=?",
        new String[] { Long.toString(tourId),
                Long.toString(companyId) }, null, null, null, null);
...
booleantourNameExists(SQLiteDatabase db, String tourName)
tour Name Exists
Cursor cursor = db.query(TOUR_TABLE_NAME,
        new String[] { TOUR_NAME }, TOUR_NAME + "=?",
        new String[] { tourName }, null, null, null);
cursor.moveToFirst();
if (cursor.getCount() == 0)
    return false;
else
    return true;
...
ListgetColumns(SQLiteDatabase db, String tableName)
Get a list of column base_dictionary for the selected table
List<String> ar = null;
Cursor c = null;
try {
    c = db.rawQuery("select * from " + tableName + " limit 1", null);
    if (c != null) {
        ar = new ArrayList<String>(
                Arrays.asList(c.getColumnNames()));
} catch (Exception e) {
    Log.v(tableName, e.getMessage(), e);
    e.printStackTrace();
} finally {
    if (c != null)
        c.close();
return ar;
voiddropAllViews(SQLiteDatabase sqlitedatabase)
drop All Views
Cursor cursor = null;
try {
    String name = null;
    cursor = sqlitedatabase.query("sqlite_master", MASTER_COLUMNS,
            "type='view'", null, null, null, null);
    do {
        if (!cursor.moveToNext())
            break;
...
longgetRowsCount(SQLiteDatabase sqlitedatabase, String s, String s1, String as[])
get Rows Count
Cursor cursor = null;
try {
    cursor = sqlitedatabase.query(s, new String[] { "COUNT(*)" },
            null, null, null, null, null);
    if (!cursor.moveToFirst())
        return 0L;
    else
        return cursor.getLong(0);
...
StringformatCalendarForSQLite(Calendar calendar)
format Calendar For SQ Lite
SimpleDateFormat dateFormatter = new SimpleDateFormat(
        "yyyy-MM-dd hh:mm:ss.SSS");
return dateFormatter.format(calendar.getTime());
DategetCalendarFromSqlite(String dateString)
get Calendar From Sqlite
SimpleDateFormat dateFormatter = new SimpleDateFormat(
        "yyyy-MM-dd hh:mm:ss.SSS");
try {
    return dateFormatter.parse(dateString);
} catch (ParseException e) {
    e.printStackTrace();
return null;
...
voidexecMultipleSQL(SQLiteDatabase db, ArrayList sqlStatements)
Execute all of the SQL statements in the ArrayList.
for (String statement : sqlStatements) {
    if (statement.trim().length() > 0) {
        db.execSQL(statement);