Java Code Examples for android.database.sqlite.SQLiteOpenHelper

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 zxing, under directory /android/src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  19 
vote

public boolean hasHistoryItems(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=null;
  Cursor cursor=null;
  try {
    db=helper.getReadableDatabase();
    cursor=db.query(DBHelper.TABLE_NAME,COUNT_COLUMN,null,null,null,null,null);
    cursor.moveToFirst();
    return cursor.getInt(0) > 0;
  }
  finally {
    close(cursor,db);
  }
}
 

Example 2

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

Source file: DatabaseCache.java

  18 
vote

/** 
 * Load or request given resources
 * @param persistableResource
 * @return resource
 * @throws IOException
 */
public <E>List<E> loadOrRequest(PersistableResource<E> persistableResource) throws IOException {
  SQLiteOpenHelper helper=helperProvider.get();
  try {
    List<E> items=loadFromDB(helper,persistableResource);
    if (items != null) {
      Log.d(TAG,"CACHE HIT: Found " + items.size() + " items for "+ persistableResource);
      return items;
    }
    return requestAndStore(helper,persistableResource);
  }
  finally {
    helper.close();
  }
}
 

Example 3

From project cwac-loaderex, under directory /src/com/commonsware/cwac/loaderex/acl/.

Source file: SQLiteCursorLoader.java

  18 
vote

@Override protected Void doInBackground(Object... params){
  SQLiteOpenHelper db=(SQLiteOpenHelper)params[0];
  String table=(String)params[1];
  String nullColumnHack=(String)params[2];
  ContentValues values=(ContentValues)params[3];
  db.getWritableDatabase().insert(table,nullColumnHack,values);
  return (null);
}
 

Example 4

From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.

Source file: Settings.java

  18 
vote

private void openDatabase(){
  SQLiteOpenHelper helper=new SQLiteOpenHelper(mContext,"settings.db",null,1){
    private final static String mDDL="CREATE TABLE settings (key TEXT PRIMARY KEY, value TEXT);";
    @Override public void onUpgrade(    SQLiteDatabase db,    int oldVersion,    int newVersion){
      onCreate(db);
    }
    @Override public void onCreate(    SQLiteDatabase db){
      db.execSQL(mDDL);
    }
  }
;
  mDatabase=helper.getWritableDatabase();
}
 

Example 5

From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  18 
vote

void clearHistory(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=helper.getWritableDatabase();
  try {
    db.delete(DBHelper.TABLE_NAME,null,null);
  }
  finally {
    db.close();
  }
}
 

Example 6

From project Mobile-Tour-Guide, under directory /zxing-2.0/android/src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  18 
vote

public boolean hasHistoryItems(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=null;
  Cursor cursor=null;
  try {
    db=helper.getReadableDatabase();
    cursor=db.query(DBHelper.TABLE_NAME,COUNT_COLUMN,null,null,null,null,null);
    cursor.moveToFirst();
    return cursor.getInt(0) > 0;
  }
  finally {
    close(cursor,db);
  }
}
 

Example 7

From project NFCShopping, under directory /mobile phone client/NFCShopping/src/scut/bgooo/concern/.

Source file: ConcernManager.java

  18 
vote

/** 
 * <p> ????????number????? </p>
 */
public void deleteConcernItem(int number){
  SQLiteOpenHelper helper=new DBHelper(activity,DBHelper.DB_NAME,null,DBHelper.DB_VERSION);
  SQLiteDatabase db=null;
  Cursor cursor=null;
  try {
    db=helper.getReadableDatabase();
    cursor=db.query(DBHelper.CONCERN_TABLE_NAME,ID_COL_PROJECTION,null,null,null,null,DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    db.delete(DBHelper.CONCERN_TABLE_NAME,DBHelper.ID_COL + '=' + cursor.getString(0),null);
  }
  finally {
    close(cursor,db);
  }
}
 

Example 8

From project PartyWare, under directory /android/src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  18 
vote

void clearHistory(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=helper.getWritableDatabase();
  try {
    db.delete(DBHelper.TABLE_NAME,null,null);
  }
  finally {
    db.close();
  }
}
 

Example 9

From project Playlist, under directory /src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  18 
vote

void clearHistory(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=helper.getWritableDatabase();
  try {
    db.delete(DBHelper.TABLE_NAME,null,null);
  }
  finally {
    db.close();
  }
}
 

Example 10

From project SimpleMoney-Android, under directory /Zxing/bin/src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  18 
vote

public boolean hasHistoryItems(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=null;
  Cursor cursor=null;
  try {
    db=helper.getReadableDatabase();
    cursor=db.query(DBHelper.TABLE_NAME,COUNT_COLUMN,null,null,null,null,null);
    cursor.moveToFirst();
    return cursor.getInt(0) > 0;
  }
  finally {
    close(cursor,db);
  }
}
 

Example 11

From project zxing-iphone, under directory /android/src/com/google/zxing/client/android/history/.

Source file: HistoryManager.java

  18 
vote

void clearHistory(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  SQLiteDatabase db=helper.getWritableDatabase();
  try {
    db.delete(DBHelper.TABLE_NAME,null,null);
  }
  finally {
    db.close();
  }
}
 

Example 12

From project No-Pain-No-Game, under directory /src/edu/ucla/cs/nopainnogame/weightchart/.

Source file: Database.java

  17 
vote

public Database(Context context){
  mHelper=new SQLiteOpenHelper(context,"data",null,1){
    @Override public void onCreate(    SQLiteDatabase db){
      db.execSQL("CREATE TABLE weight (_id INTEGER PRIMARY KEY AUTOINCREMENT, weight, created_at)");
      db.execSQL("CREATE INDEX weight_created_at ON weight (created_at)");
    }
    @Override public void onUpgrade(    SQLiteDatabase db,    int oldVersion,    int newVersion){
    }
  }
;
  mDatabase=mHelper.getWritableDatabase();
}
 

Example 13

From project zxing-android, under directory /src/com/laundrylocker/barcodescanner/history/.

Source file: HistoryManager.java

  17 
vote

public AlertDialog buildAlert(){
  SQLiteOpenHelper helper=new DBHelper(activity);
  List<Result> items=new ArrayList<Result>();
  List<String> dialogItems=new ArrayList<String>();
  SQLiteDatabase db=null;
  Cursor cursor=null;
  try {
    db=helper.getWritableDatabase();
    cursor=db.query(DBHelper.TABLE_NAME,GET_ITEM_COL_PROJECTION,null,null,null,null,DBHelper.TIMESTAMP_COL + " DESC");
    while (cursor.moveToNext()) {
      Result result=new Result(cursor.getString(0),null,null,BarcodeFormat.valueOf(cursor.getString(2)),cursor.getLong(3));
      items.add(result);
      String display=cursor.getString(1);
      if (display == null || display.length() == 0) {
        display=result.getText();
      }
      dialogItems.add(display);
    }
  }
 catch (  SQLiteException sqle) {
    Log.w(TAG,"Error while opening database",sqle);
  }
 finally {
    if (cursor != null) {
      cursor.close();
    }
    if (db != null) {
      db.close();
    }
  }
  Resources res=activity.getResources();
  dialogItems.add(res.getString(R.string.history_send));
  dialogItems.add(res.getString(R.string.history_clear_text));
  DialogInterface.OnClickListener clickListener=new HistoryClickListener(this,activity,items);
  AlertDialog.Builder builder=new AlertDialog.Builder(activity);
  builder.setTitle(R.string.history_title);
  builder.setItems(dialogItems.toArray(new String[dialogItems.size()]),clickListener);
  return builder.create();
}
 

Example 14

From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/database/.

Source file: DbSync.java

  15 
vote

/** 
 * Constructor.
 * @param helper	DBHelper to open underlying database
 * @param sync		Synchronizer to use
 */
public SynchronizedDb(SQLiteOpenHelper helper,Synchronizer sync){
  mSync=sync;
  SyncLock l=mSync.getExclusiveLock();
  try {
    mDb=helper.getWritableDatabase();
  }
  finally {
    l.unlock();
  }
}
 

Example 15

From project platform_packages_apps_browser, under directory /src/com/android/browser/provider/.

Source file: BrowserProvider2.java

  15 
vote

@Override public SQLiteOpenHelper getDatabaseHelper(Context context){
synchronized (this) {
    if (mOpenHelper == null) {
      mOpenHelper=new DatabaseHelper(context);
    }
    return mOpenHelper;
  }
}
 

Example 16

From project platform_packages_providers_calendarprovider, under directory /tests/src/com/android/providers/calendar/.

Source file: CalendarProvider2Test.java

  15 
vote

public void wipeAndInitData(SQLiteOpenHelper helper,SQLiteDatabase db) throws CalendarCache.CacheException {
  db.beginTransaction();
  db.delete("Calendars",null,null);
  db.delete("Events",null,null);
  db.delete("EventsRawTimes",null,null);
  db.delete("Instances",null,null);
  db.delete("CalendarMetaData",null,null);
  db.delete("CalendarCache",null,null);
  db.delete("Attendees",null,null);
  db.delete("Reminders",null,null);
  db.delete("CalendarAlerts",null,null);
  db.delete("ExtendedProperties",null,null);
  initCalendarCacheLocked(helper,db);
  long now=System.currentTimeMillis();
  ContentValues values=new ContentValues();
  values.put("localTimezone","America/Los_Angeles");
  values.put("minInstance",1207008000000L);
  values.put("maxInstance",now + ONE_WEEK_MILLIS);
  db.insert("CalendarMetaData",null,values);
  db.setTransactionSuccessful();
  db.endTransaction();
}
 

Example 17

From project platform_packages_providers_contactsprovider, under directory /src/com/android/providers/contacts/.

Source file: VoicemailContentTable.java

  15 
vote

public VoicemailContentTable(String tableName,Context context,SQLiteOpenHelper dbHelper,VoicemailTable.DelegateHelper contentProviderHelper,CallLogInsertionHelper callLogInsertionHelper){
  mTableName=tableName;
  mContext=context;
  mDbHelper=dbHelper;
  mDelegateHelper=contentProviderHelper;
  mVoicemailProjectionMap=new ProjectionMap.Builder().add(Voicemails._ID).add(Voicemails.NUMBER).add(Voicemails.DATE).add(Voicemails.DURATION).add(Voicemails.IS_READ).add(Voicemails.STATE).add(Voicemails.SOURCE_DATA).add(Voicemails.SOURCE_PACKAGE).add(Voicemails.HAS_CONTENT).add(Voicemails.MIME_TYPE).add(Voicemails._DATA).add(OpenableColumns.DISPLAY_NAME,createDisplayName(context)).add(OpenableColumns.SIZE,"NULL").build();
  mCallLogInsertionHelper=callLogInsertionHelper;
}
 

Example 18

From project rbb, under directory /src/com/btmura/android/reddit/provider/.

Source file: CommentListing.java

  15 
vote

public static CommentListing get(Context context,SQLiteOpenHelper dbHelper,String accountName,String sessionId,long sessionTimestamp,String thingId,String cookie) throws IOException {
  long t1=System.currentTimeMillis();
  URL url=Urls.commentsUrl(thingId);
  HttpURLConnection conn=RedditApi.connect(url,cookie,false);
  InputStream input=new BufferedInputStream(conn.getInputStream());
  long t2=System.currentTimeMillis();
  try {
    JsonReader reader=new JsonReader(new InputStreamReader(input));
    CommentListing listing=new CommentListing(context,dbHelper,accountName,sessionId,sessionTimestamp,thingId);
    listing.parseListingArray(reader);
    if (BuildConfig.DEBUG) {
      long t3=System.currentTimeMillis();
      listing.networkTimeMs=t2 - t1;
      listing.parseTimeMs=t3 - t2;
    }
    return listing;
  }
  finally {
    input.close();
    conn.disconnect();
  }
}
 

Example 19

From project spring-android, under directory /spring-android-auth/src/main/java/org/springframework/social/connect/sqlite/.

Source file: SQLiteConnectionRepository.java

  15 
vote

public SQLiteConnectionRepository(String userId,SQLiteOpenHelper repositoryHelper,ConnectionFactoryLocator connectionFactoryLocator,TextEncryptor textEncryptor){
  this.userId=userId;
  this.repositoryHelper=repositoryHelper;
  this.connectionFactoryLocator=connectionFactoryLocator;
  this.textEncryptor=textEncryptor;
}