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:Main.java

/**
 * Check if the database exist//from   ww  w  . j  a  v a2 s.  c  o m
 *
 * @return true if it exists, false if it doesn't
 */
public static boolean checkDataBase(Context context) {
    SQLiteDatabase checkDB = null;
    int count = 0;
    try {
        if (android.os.Build.VERSION.SDK_INT >= 17) {
            DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
        } else {
            DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
        }
        checkDB = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);

        String selectRegistros = "SELECT COUNT(*) FROM Grupo_Gastos";

        Cursor mCursor = checkDB.query(true, "Grupo_Gastos", new String[] { "_id" }, null, null, null, null,
                null, null);
        count = mCursor.getCount();

        checkDB.close();
    } catch (SQLiteException e) {
        // database doesn't exist yet.
        return false;
    }
    return count > 0;
}

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

public static Date geLastRequest(Context context, PublicScript script, String trollId) {

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

    Cursor cursor = database.rawQuery(SQL_LAST_REQUEST, new String[] { trollId, script.name() });
    Date result = null;/*from   www .  j a  va  2 s .  c  om*/
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        long resultTimestamp = cursor.getLong(0);
        result = new Date(resultTimestamp);
    }

    cursor.close();
    database.close();

    String format = "Last request for category %s (script=%s) and troll=%s is: '%s'";
    String message = String.format(format, script.category, script, trollId, result);
    Log.d(TAG, message);

    return result;
}

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

public static Date geLastUpdate(Context context, PublicScript script, String trollId) {

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

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

    cursor.close();
    database.close();

    String format = "Last update for category %s (script=%s) and troll=%s is: '%s'";
    String message = String.format(format, script.category, script, trollId, result);
    Log.d(TAG, message);

    return result;
}

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

protected static void saveFetch(Context context, PublicScript script, String trollId, String uuid,
        String status) {//  w ww  .j  av  a 2 s. co  m

    String format = "Saving fetch for category %s (script=%s) and troll=%s";
    String message = String.format(format, script.category, script, trollId);
    Log.d(TAG, message);

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

    ContentValues values = new ContentValues(2);
    long now = System.currentTimeMillis();
    values.put(MhDlaSQLHelper.SCRIPTS_END_DATE_COLUMN, now);
    values.put(MhDlaSQLHelper.SCRIPTS_STATUS_COLUMN, status);

    String whereClause = String.format("%s = ?", MhDlaSQLHelper.SCRIPTS_ID_COLUMN);
    database.update(MhDlaSQLHelper.SCRIPTS_TABLE, values, whereClause, new String[] { uuid });

    database.close();
}

From source file:Main.java

public static Map<Integer, List> getCityByPid(int id, File file) {

    String sql = "select cityid,city  from city where provinceid= " + id;
    SQLiteDatabase db = null;
    Cursor c = null;//from   ww  w. ja  v a2 s .c  om
    Map<Integer, List> cityData = new HashMap<Integer, List>();
    //List cityList = null;
    try {
        db = SQLiteDatabase.openOrCreateDatabase(file, null);
        c = db.rawQuery(sql, null);
        List cityList1 = new ArrayList();
        List cityList2 = new ArrayList();
        while (c.moveToNext()) {
            Map cityMap = new HashMap();
            cityMap.put(c.getString(1), c.getInt(0));
            cityList1.add(cityMap);
            cityList2.add(c.getString(1));
        }
        cityData.put(0, cityList1);
        cityData.put(1, cityList2);

    } catch (Exception e) {
        Log.d("WineStock", "getCityByPid:" + e.getMessage());
    } finally {
        if (c != null) {
            c.close();
        }
        if (db != null) {
            db.close();
        }
    }
    return cityData;
}

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

static void loadDays(Context context) {
    MyApp.dateInfos = new DateInfos();
    LecturesDBOpenHelper lecturesDB = new LecturesDBOpenHelper(context);

    SQLiteDatabase lecturedb = lecturesDB.getReadableDatabase();
    Cursor cursor;/*from  ww w .j a  va  2s  .  c o  m*/

    try {
        cursor = lecturedb.query(LecturesTable.NAME, LecturesDBOpenHelper.allcolumns, null, null, null, null,
                null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        lecturesDB.close();
        return;
    }

    if (cursor.getCount() == 0) {
        // evtl. Datenbankreset wg. DB Formatnderung -> neu laden
        cursor.close();
        lecturesDB.close();
        lecturedb.close();
        return;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        int day = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DAY));
        String date = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DATE));

        DateInfo dateItem = new DateInfo(day, date);
        if (!MyApp.dateInfos.contains(dateItem)) {
            MyApp.dateInfos.add(dateItem);
        }
        cursor.moveToNext();
    }
    cursor.close();

    for (DateInfo dateInfo : MyApp.dateInfos) {
        MyApp.LogDebug(LOG_TAG, "DateInfo: " + dateInfo);
    }
    lecturesDB.close();
    lecturedb.close();
}

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

protected static int computeRequestCount(Context context, ScriptCategory category, String trollId) {

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

    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.HOUR_OF_DAY, -24);
    Date sinceDate = instance.getTime();

    Cursor cursor = database.rawQuery(SQL_COUNT,
            new String[] { trollId, category.name(), "" + sinceDate.getTime() });
    int result = 0;
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();/* w w  w  .j a  va  2s  .  c  o m*/
        result = cursor.getInt(0);
    }

    cursor.close();
    database.close();

    String format = "Quota for category %s and troll=%s since '%s' is: %d";
    String message = String.format(format, category, trollId, sinceDate, result);
    Log.d(TAG, message);

    return result;
}

From source file:com.onesignal.NotificationOpenedProcessor.java

static void processIntent(Context incContext, Intent inIntent) {
    context = incContext;/*from ww  w .  ja v a2s  .c o m*/
    intent = inIntent;

    String summaryGroup = intent.getStringExtra("summary");

    boolean dismissed = intent.getBooleanExtra("dismissed", false);

    OneSignalDbHelper dbHelper = new OneSignalDbHelper(context);
    SQLiteDatabase writableDb = dbHelper.getWritableDatabase();

    JSONArray dataArray = null;
    if (!dismissed) {
        try {
            dataArray = NotificationBundleProcessor
                    .newJsonArray(new JSONObject(intent.getStringExtra("onesignal_data")));
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    // We just opened a summary notification.
    if (!dismissed && summaryGroup != null)
        addChildNotifications(dataArray, summaryGroup, writableDb);

    markNotificationsConsumed(writableDb);

    // Notification is not a summary type and is a single notification part of a group.
    if (summaryGroup == null && intent.getStringExtra("grp") != null)
        updateSummaryNotification(writableDb);

    writableDb.close();

    if (!dismissed)
        OneSignal.handleNotificationOpened(context, dataArray, inIntent.getBooleanExtra("from_alert", false));
}

From source file:Main.java

public static Map<Integer, List> getAreaByPid(int id, File file) {

    String sql = "select area,areaid  from area where cityid= " + id;
    SQLiteDatabase db = null;
    Cursor c = null;/*from  w  ww . j  a  va 2  s  .  c om*/
    List<String> areaList = null;
    List areaIdList = null;
    Map<Integer, List> areaData = new HashMap<Integer, List>();
    try {
        db = SQLiteDatabase.openOrCreateDatabase(file, null);
        c = db.rawQuery(sql, null);
        areaList = new ArrayList<String>();
        areaIdList = new ArrayList<String>();

        while (c.moveToNext()) {
            Map areaMap = new HashMap();
            areaMap.put(c.getString(0), c.getInt(1));
            areaList.add(c.getString(0));
            areaIdList.add(areaMap);
        }
        areaData.put(0, areaList);
        areaData.put(1, areaIdList);
    } catch (Exception e) {
        Log.d("WineStock", "getAreaByPid:" + e.getMessage());
    } finally {
        if (c != null) {
            c.close();
        }
        if (db != null) {
            db.close();
        }
    }
    return areaData;
}

From source file:Main.java

public static Map<Integer, List> getProvince(File file) {

    String sql = "select provinceid ,province from province ";
    SQLiteDatabase db = null;
    Cursor c = null;//from   ww w. j a va2 s. c  om
    Map<Integer, List> provinceData = new HashMap<Integer, List>();
    //List provinceList = null;
    try {
        db = SQLiteDatabase.openOrCreateDatabase(file, null);
        c = db.rawQuery(sql, null);
        List provinceList1 = new ArrayList();
        List provinceList2 = new ArrayList();
        while (c.moveToNext()) {
            Map provinceMap = new HashMap();
            provinceMap.put(c.getString(1), c.getInt(0));
            provinceList1.add(provinceMap);
            provinceList2.add(c.getString(1));
        }
        provinceData.put(0, provinceList1);
        provinceData.put(1, provinceList2);
    } catch (Exception e) {
        Log.d("WineStock", "getProvince:" + e.getMessage());
    } finally {
        if (c != null) {
            c.close();
        }
        if (db != null) {
            db.close();
        }
    }
    return provinceData;
}