Java Code Examples for android.database.sqlite.SQLiteDatabase

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.

Source file: LogViewActivity.java

  18 
vote

@Override public void onClick(View v){
  DBOpenHelper dbHelper=new DBOpenHelper(v.getContext());
  SQLiteDatabase db=dbHelper.getWritableDatabase();
  db.delete("log",null,null);
  LogViewActivity.this.refreshLog();
  db.close();
}
 

Example 2

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/repository/db/.

Source file: AirCastingDB.java

  18 
vote

public synchronized <T>T executeWritableTask(WritableDatabaseTask<T> task){
  SQLiteDatabase database=getDatabase();
  T result;
  database.beginTransaction();
  try {
    result=measureExecution(task,database);
    database.setTransactionSuccessful();
  }
  finally {
    database.endTransaction();
  }
  return result;
}
 

Example 3

From project Airports, under directory /src/com/nadmm/airports/.

Source file: ActivityBase.java

  18 
vote

public Cursor getAirportDetails(String siteNumber){
  SQLiteDatabase db=getDatabase(DatabaseManager.DB_FADDS);
  SQLiteQueryBuilder builder=new SQLiteQueryBuilder();
  builder.setTables(Airports.TABLE_NAME + " a LEFT OUTER JOIN " + States.TABLE_NAME+ " s"+ " ON a."+ Airports.ASSOC_STATE+ "=s."+ States.STATE_CODE);
  Cursor c=builder.query(db,new String[]{"*"},Airports.SITE_NUMBER + "=?",new String[]{siteNumber},null,null,null,null);
  if (!c.moveToFirst()) {
    return null;
  }
  return c;
}
 

Example 4

From project aksunai, under directory /src/org/androidnerds/app/aksunai/data/.

Source file: ServerDbAdapter.java

  18 
vote

public int deleteServer(long id){
  SQLiteDatabase db=getWritableDatabase();
  int result=db.delete(DB_TABLE,"_id = ?",new String[]{String.valueOf(id)});
  db.close();
  return result;
}
 

Example 5

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/db/.

Source file: AmenDaoImpl.java

  18 
vote

private User findUserById(long id){
  SQLiteDatabase db=dbHelper.getReadableDatabase();
  Cursor cursor=db.query(AmenDBHelper.USERS_TABLE,null,AmenDBHelper.KEY_ID + "=?",new String[]{"" + id},null,null,null);
  if (cursor.getCount() == 0) {
    return null;
  }
  cursor.moveToFirst();
  User result=new User();
  result.setId(cursor.getLong(cursor.getColumnIndex(AmenDBHelper.KEY_ID)));
  return result;
}
 

Example 6

From project Android, under directory /app/src/main/java/com/github/mobile/persistence/.

Source file: DatabaseCache.java

  18 
vote

private <E>List<E> requestAndStore(final SQLiteOpenHelper helper,final PersistableResource<E> persistableResource) throws IOException {
  final List<E> items=persistableResource.request();
  final SQLiteDatabase db=getWritable(helper);
  if (db == null)   return items;
  db.beginTransaction();
  try {
    persistableResource.store(db,items);
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  return items;
}
 

Example 7

From project android-client_1, under directory /src/com/buddycloud/content/.

Source file: ChannelDataHelper.java

  18 
vote

public static Cursor queryChannelData(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder,BuddycloudProvider provider){
  SQLiteDatabase database=provider.getDatabase();
synchronized (database) {
    Cursor c=database.query(BuddycloudProvider.TABLE_CHANNEL_DATA,projection,selection,selectionArgs,null,null,sortOrder);
    c.setNotificationUri(provider.getContext().getContentResolver(),ChannelData.CONTENT_URI);
    return c;
  }
}
 

Example 8

From project android-flash-cards, under directory /src/org/thomasamsler/android/flashcards/db/.

Source file: DataSource.java

  18 
vote

public void createCardSet(CardSet cardSet){
  try {
    ContentValues contentValues=new ContentValues();
    contentValues.put(DatabaseHelper.CST_CARD_SET_ID,cardSet.getExternalId());
    contentValues.put(DatabaseHelper.CST_TITLE,cardSet.getTitle());
    contentValues.put(DatabaseHelper.CST_CARD_COUNT,cardSet.getCardCount());
    SQLiteDatabase db=mDbH.getWritableDatabase();
    long id=db.insert(DatabaseHelper.TABLE_CARD_SETS,null,contentValues);
    cardSet.setId(id);
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,"EXCEPTION: " + e.getMessage());
  }
}
 

Example 9

From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/helpers/.

Source file: ShareHelper.java

  18 
vote

public String lookupUrl(String gifPath){
  Cursor cursor;
  try {
    SQLiteDatabase db=this.getReadableDatabase();
    cursor=db.query(TABLE_NAME,new String[]{COL_URL},COL_GIFPATH + "='" + gifPath+ "'",null,null,null,null,null);
    if (cursor.moveToFirst())     return cursor.getString(0);
  }
 catch (  Exception e) {
    Log.e("DB ERROR",e.toString());
    e.printStackTrace();
  }
  return null;
}
 

Example 10

From project android-joedayz, under directory /Proyectos/TaxiLab1/src/com/mycompany/.

Source file: DatabaseHelper.java

  18 
vote

int getValidaUsuario(String usuario,String clave){
  SQLiteDatabase db=this.getWritableDatabase();
  Cursor cur=db.rawQuery("Select * from " + userTable + " where "+ colUsuario+ "='"+ usuario+ "' and "+ colClave+ "='"+ clave+ "'",null);
  int x=cur.getCount();
  cur.close();
  return x;
}
 

Example 11

From project ActionBarSherlock, under directory /samples/fragments/src/com/actionbarsherlock/sample/fragments/.

Source file: LoaderThrottleSupport.java

  17 
vote

/** 
 * Handle incoming queries.
 */
@Override public Cursor query(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder){
  SQLiteQueryBuilder qb=new SQLiteQueryBuilder();
  qb.setTables(MainTable.TABLE_NAME);
switch (mUriMatcher.match(uri)) {
case MAIN:
    qb.setProjectionMap(mNotesProjectionMap);
  break;
case MAIN_ID:
qb.setProjectionMap(mNotesProjectionMap);
qb.appendWhere(MainTable._ID + "=?");
selectionArgs=DatabaseUtilsCompat.appendSelectionArgs(selectionArgs,new String[]{uri.getLastPathSegment()});
break;
default :
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (TextUtils.isEmpty(sortOrder)) {
sortOrder=MainTable.DEFAULT_SORT_ORDER;
}
SQLiteDatabase db=mOpenHelper.getReadableDatabase();
Cursor c=qb.query(db,projection,selection,selectionArgs,null,null,sortOrder);
c.setNotificationUri(getContext().getContentResolver(),uri);
return c;
}
 

Example 12

From project andlytics, under directory /src/com/github/andlyticsproject/db/.

Source file: AndlyticsContentProvider.java

  17 
vote

@Override public int delete(Uri uri,String where,String[] whereArgs){
  SQLiteDatabase db=dbHelper.getWritableDatabase();
  int count;
switch (sUriMatcher.match(uri)) {
case ID_TABLE_STATS:
    count=db.delete(AppStatsTable.DATABASE_TABLE_NAME,where,whereArgs);
  break;
case ID_TABLE_APPINFO:
count=db.delete(AppInfoTable.DATABASE_TABLE_NAME,where,whereArgs);
break;
case ID_TABLE_COMMENTS:
count=db.delete(CommentsTable.DATABASE_TABLE_NAME,where,whereArgs);
break;
case ID_TABLE_ADMOB:
count=db.delete(AdmobTable.DATABASE_TABLE_NAME,where,whereArgs);
break;
default :
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri,null);
return count;
}
 

Example 13

From project android-bankdroid, under directory /src/com/liato/bankdroid/provider/.

Source file: BankTransactionsProvider.java

  17 
vote

/** 
 * {@inheritDoc}
 */
@Override public Cursor query(final Uri uri,final String[] projection,final String selection,final String[] selectionArgs,final String sortOrder){
  if (!isApiKeyEnabled(getContext())) {
    return null;
  }
  final String apiKey=uri.getPathSegments().get(1);
  Log.d(TAG,"Trying to access database with " + apiKey);
  if (!apiKey.startsWith(API_KEY,0)) {
    return null;
  }
  final String key=apiKey.replace(API_KEY,"");
  if (!key.equals(getApiKey(getContext()))) {
    return null;
  }
  final SQLiteDatabase db=dbHelper.getReadableDatabase();
  SQLiteQueryBuilder qb;
  if (BANK_ACCOUNTS_MIME.equals(getType(uri))) {
    qb=new SQLiteQueryBuilder();
    qb.setTables(BANK_ACCOUNT_TABLES);
    qb.setProjectionMap(bankAccountProjectionMap);
    qb.setDistinct(true);
  }
 else   if (TRANSACTIONS_MIME.equals(getType(uri))) {
    qb=new SQLiteQueryBuilder();
    qb.setTables(TRANSACTIONS_TABLE);
    qb.setProjectionMap(transProjectionMap);
  }
 else {
    throw new IllegalArgumentException("Unsupported URI: " + uri);
  }
  final Cursor cur=qb.query(db,projection,selection,selectionArgs,null,null,sortOrder);
  cur.setNotificationUri(getContext().getContentResolver(),uri);
  return cur;
}
 

Example 14

From project and-bible, under directory /AndBible/src/net/bible/service/db/bookmark/.

Source file: BookmarkDatabaseDefinition.java

  15 
vote

private void bootstrapDB(SQLiteDatabase db){
  Log.i(TAG,"Bootstrapping And Bible database");
  db.execSQL("CREATE TABLE " + Table.BOOKMARK + " ("+ BookmarkColumn._ID+ " INTEGER PRIMARY KEY AUTOINCREMENT,"+ BookmarkColumn.KEY+ " TEXT NOT NULL"+ ");");
  db.execSQL("CREATE TABLE " + Table.BOOKMARK_LABEL + " ("+ BookmarkLabelColumn.BOOKMARK_ID+ " INTEGER NOT NULL,"+ BookmarkLabelColumn.LABEL_ID+ " INTEGER NOT NULL"+ ");");
  db.execSQL("CREATE TABLE " + Table.LABEL + " ("+ LabelColumn._ID+ " INTEGER PRIMARY KEY AUTOINCREMENT,"+ LabelColumn.NAME+ " TEXT NOT NULL"+ ");");
  db.execSQL("CREATE TRIGGER bookmark_cleanup DELETE ON " + Table.BOOKMARK + " "+ "BEGIN "+ "DELETE FROM "+ Table.BOOKMARK_LABEL+ " WHERE "+ BookmarkLabelColumn.BOOKMARK_ID+ " = old._id;"+ "END");
  db.execSQL("CREATE TRIGGER label_cleanup DELETE ON " + Table.LABEL + " "+ "BEGIN "+ "DELETE FROM "+ Table.BOOKMARK_LABEL+ " WHERE "+ BookmarkLabelColumn.LABEL_ID+ " = old._id;"+ "END");
}
 

Example 15

From project android-client, under directory /xwiki-android-core/src/org/xwiki/android/data/rdb/.

Source file: EntityManager.java

  15 
vote

/** 
 * This is called when the database is first created. Add logic to create all db tables for defined entities.
 */
@Override public void onCreate(SQLiteDatabase database,ConnectionSource connectionSource){
  try {
    Log.i(EntityManager.class.getSimpleName(),"onCreate(): create Database");
    TableUtils.createTable(connectionSource,User.class);
    TableUtils.createTable(connectionSource,FSDocumentReference.class);
    TableUtils.createTable(connectionSource,LoginAttempt.class);
    TableUtils.createTable(connectionSource,SyncOutEntity.class);
  }
 catch (  SQLException e) {
    Log.e(EntityManager.class.getName(),"Can't create database",e);
    throw new RuntimeException(e);
  }
}
 

Example 16

From project android-context, under directory /src/edu/fsu/cs/contextprovider/.

Source file: ContextProvider.java

  15 
vote

@Override public void onCreate(SQLiteDatabase db){
  Cursor c=db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='cntxt'",null);
  try {
    if (c.getCount() == 0) {
      db.execSQL("CREATE TABLE cntxt (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, value REAL);");
      ContentValues cv=new ContentValues();
      cv.put(Cntxt.TITLE,"Gravity, Death Star I");
      cv.put(Cntxt.VALUE,SensorManager.GRAVITY_DEATH_STAR_I);
      db.insert("cntxt",getNullColumnHack(),cv);
      cv.put(Cntxt.TITLE,"Gravity, Earth");
      cv.put(Cntxt.VALUE,SensorManager.GRAVITY_EARTH);
      db.insert("cntxt",getNullColumnHack(),cv);
    }
  }
  finally {
    c.close();
  }
}
 

Example 17

From project Android-FFXIEQ, under directory /ffxieq/src/com/github/kanata3249/ffxieq/android/.

Source file: FFXIEQApplication.java

  15 
vote

@Override public SQLiteDatabase openOrCreateDatabase(String name,int mode,CursorFactory factory){
  if (name.equals(FFXIDatabase.DB_NAME)) {
    name=FFXIDatabase.getDBPath(getFFXIEQSettings().useExternalDB());
  }
  return super.openOrCreateDatabase(name,mode,factory);
}