List of utility methods to do SqliteDatabase Command
List | getTourNames(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; |
long | insertTour(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; |
boolean | isCompanyInTour(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); ... |
boolean | tourNameExists(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; ... |
List | getColumns(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; |
void | dropAllViews(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; ... |
long | getRowsCount(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); ... |
String | formatCalendarForSQLite(Calendar calendar) format Calendar For SQ Lite SimpleDateFormat dateFormatter = new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss.SSS"); return dateFormatter.format(calendar.getTime()); |
Date | getCalendarFromSqlite(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; ... |
void | execMultipleSQL(SQLiteDatabase db, ArrayList Execute all of the SQL statements in the ArrayList for (String statement : sqlStatements) { if (statement.trim().length() > 0) { db.execSQL(statement); |