Example usage for android.database.sqlite SQLiteDatabase close

List of usage examples for android.database.sqlite SQLiteDatabase close

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteDatabase close.

Prototype

public void close() 

Source Link

Document

Releases a reference to the object, closing the object if the last reference was released.

Usage

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

public static void deleteAlarm(Context context, Lecture lecture) {
    AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context);
    SQLiteDatabase db = alarmDB.getWritableDatabase();
    Cursor cursor;/*  ww w  .ja  va2 s.  co  m*/

    try {
        cursor = db.query(AlarmsTable.NAME, AlarmsDBOpenHelper.allcolumns, AlarmsTable.Columns.EVENT_ID + "=?",
                new String[] { lecture.lecture_id }, null, null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        MyApp.LogDebug("delete alarm", "failure on alarm query");
        db.close();
        return;
    }

    if (cursor.getCount() == 0) {
        db.close();
        cursor.close();
        MyApp.LogDebug("delete_alarm", "alarm for " + lecture.lecture_id + " not found");
        return;
    }

    cursor.moveToFirst();

    Intent intent = new Intent(context, AlarmReceiver.class);

    String lecture_id = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_ID));
    intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture_id);
    int day = cursor.getInt(cursor.getColumnIndex(AlarmsTable.Columns.DAY));
    intent.putExtra(BundleKeys.ALARM_DAY, day);
    String title = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_TITLE));
    intent.putExtra(BundleKeys.ALARM_TITLE, title);
    long startTime = cursor.getLong(cursor.getColumnIndex(AlarmsTable.Columns.TIME));
    intent.putExtra(BundleKeys.ALARM_START_TIME, startTime);

    // delete any previous alarms of this lecture
    db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id });
    db.close();

    intent.setAction("de.machtnix.fahrplan.ALARM");
    intent.setData(Uri.parse("alarm://" + lecture.lecture_id));

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id),
            intent, 0);

    // Cancel any existing alarms for this lecture
    alarmManager.cancel(pendingintent);

    lecture.has_alarm = false;
}

From source file:nz.co.wholemeal.christchurchmetro.Stop.java

private static ArrayList<Stop> doArrayListQuery(Context context, String query) {
    ArrayList<Stop> stops = new ArrayList<Stop>();

    Log.d(TAG, "query: " + query);

    DatabaseHelper databaseHelper = new DatabaseHelper(context);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    Cursor cursor = database.rawQuery(query, null);

    try {/*w  w w .j  av  a  2s.  c  o m*/
        if (cursor.moveToFirst()) {
            do {
                Stop stop = new Stop();
                stop.platformTag = cursor.getString(0);
                stop.platformNumber = cursor.getString(1);
                stop.name = cursor.getString(2);
                stop.roadName = cursor.getString(3);
                stop.latitude = cursor.getDouble(4);
                stop.longitude = cursor.getDouble(5);
                stops.add(stop);
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
    Log.d(TAG, "stops.size() = " + stops.size());
    database.close();
    return stops;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void unBanUser(String decodedfrom, Context context) {

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    dbwrite.execSQL("DELETE FROM banned_users WHERE name=" + esc(decodedfrom));
    dbwrite.close();
    db.close();/*from   ww  w .ja  v a  2  s .c o  m*/
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

protected static void createFetchLog(Context context, PublicScript script, String trollId, String uuid) {

    String format = "Create fetch log for script=%s and troll=%s";
    String message = String.format(format, script, trollId);
    Log.d(TAG, message);/*from   w  ww. j a va  2 s  . c  o m*/

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getWritableDatabase();

    ContentValues values = new ContentValues(6);
    long now = System.currentTimeMillis();
    values.put(MhDlaSQLHelper.SCRIPTS_ID_COLUMN, uuid);
    values.put(MhDlaSQLHelper.SCRIPTS_START_DATE_COLUMN, now);
    values.put(MhDlaSQLHelper.SCRIPTS_SCRIPT_COLUMN, script.name());
    values.put(MhDlaSQLHelper.SCRIPTS_CATEGORY_COLUMN, script.category.name());
    values.put(MhDlaSQLHelper.SCRIPTS_TROLL_COLUMN, trollId);
    values.put(MhDlaSQLHelper.SCRIPTS_STATUS_COLUMN, "PENDING");

    database.insert(MhDlaSQLHelper.SCRIPTS_TABLE, null, values);

    database.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void updateUnreadInGroupsTable(int unreadCount, int groupid, Context context) {
    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase dbwriter = dbhelper.getWritableDatabase();
    dbwriter.execSQL("UPDATE subscribed_groups SET unread_count=" + unreadCount + " WHERE _id=" + groupid);
    dbwriter.close();
    dbhelper.close();//from  w  ww .j ava  2s.  co  m
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static Map<PublicScript, Date> geLastUpdates(Context context, String trollId,
        Set<PublicScript> scripts) {

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Map<PublicScript, Date> result = new HashMap<PublicScript, Date>();

    for (PublicScript script : scripts) {

        Cursor cursor = database.rawQuery(SQL_LAST_UPDATE,
                new String[] { trollId, script.name(), MhDlaSQLHelper.STATUS_SUCCESS });
        Date lastUpdate = null;/*from w  w  w  .  ja v a  2  s.c om*/
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            long resultTimestamp = cursor.getLong(0);
            lastUpdate = new Date(resultTimestamp);
        }

        result.put(script, lastUpdate);
        cursor.close();
    }
    database.close();

    String format = "Last updates for troll=%s are: '%s'";
    String message = String.format(format, trollId, result);
    Log.i(TAG, message);

    return result;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void markAsUnread(String msgId, Context context) {

    if (msgId != null) {

        DBHelper dbhelper = new DBHelper(context);
        SQLiteDatabase dbwriter = dbhelper.getWritableDatabase();

        dbwriter.execSQL("UPDATE headers SET read=0, read_unixdate=0 WHERE server_article_id=" + esc(msgId));
        dbwriter.close();
        dbhelper.close();/* w w  w  .  jav  a  2 s  . c  om*/
    }
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void storeGroupLastFetchedMessageNumber(String group, long lastNumber, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    String wQuery = "UPDATE subscribed_groups SET lastFetched=" + lastNumber + " WHERE _id=" + groupid;
    dbwrite.execSQL(wQuery);//from   w  w  w  . j a va 2 s  .  c o m

    dbwrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static long insertOfflineSentPost(Context context) {

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    ContentValues cv = new ContentValues();
    cv.put("foo", 1);
    long ret = dbwrite.insert("offline_sent_posts", null, cv);

    dbwrite.close();
    db.close();//  w  w  w  . jav  a  2  s. c om

    return ret;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void markAsUnRead(long server_article_number, Context context) {

    DBHelper dbhelper = new DBHelper(context);
    SQLiteDatabase dbwriter = dbhelper.getWritableDatabase();
    dbwriter.execSQL(//from   w  w w  .  j a  va2  s. c o m
            "UPDATE headers SET read=0, read_unixdate=0 WHERE server_article_number=" + server_article_number);
    dbwriter.close();
    dbhelper.close();
}