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:com.dm.material.dashboard.candybar.databases.Database.java

public void addRequest(Request request) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_NAME, request.getName());
    values.put(KEY_ACTIVITY, request.getActivity());

    db.insert(TABLE_REQUEST, null, values);
    db.close();
}

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

public static HashSet<String> getBannedTrolls(Context context) {

    HashSet<String> bannedTrolls = null;

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

    String q = "SELECT name FROM banned_users WHERE bandisabled=0";

    Cursor c = dbwrite.rawQuery(q, null);

    int count = c.getCount();
    if (count > 0) {

        bannedTrolls = new HashSet<String>(c.getColumnCount());
        c.moveToFirst();//ww  w .j av a2  s  . co m

        for (int i = 0; i < count; i++) {
            bannedTrolls.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbwrite.close();
    db.close();

    if (bannedTrolls == null)
        bannedTrolls = new HashSet<String>(0);
    return bannedTrolls;
}

From source file:com.emuneee.speeedreader.test.DatabaseUtilsTestCase.java

public void testDatabaseIsCreated() {
    SQLiteDatabase database;
    SQLiteHelper helper;/*from ww  w. j a v a 2s  . c  o m*/

    helper = SQLiteHelper.getSQLiteHelper(mActivity);
    database = helper.getReadableDatabase();
    assertNotNull(database);
    assertEquals(true, database.isOpen());
    database.close();
}

From source file:com.dm.material.dashboard.candybar.databases.Database.java

public boolean isRequested(String activity) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_REQUEST, null, KEY_ACTIVITY + " = ?", new String[] { activity }, null, null,
            null, null);//from w  ww .  jav  a2  s.c  o m
    int rowCount = cursor.getCount();
    cursor.close();
    db.close();
    return rowCount > 0;
}

From source file:com.melchor629.musicote.MainActivity.java

@Override
public boolean onQueryTextChange(String newText) {
    if (newText.length() == 0 && oldText.length() > 0) {
        SQLiteDatabase db = new DB(MainActivity.this).getReadableDatabase();
        cursordb(db);//ww w  . ja  va 2  s.c o m
        db.close();
    } else {
        onQueryTextSubmit(newText);
    }
    oldText = newText;
    return false;
}

From source file:com.denimgroup.android.training.pandemobium.stocktrader.ManageTipsActivity.java

private void doSaveTip() {
    String symbol = etSymbol.getText().toString();
    Double targetPrice = Double.parseDouble(etTargetPrice.getText().toString());
    String reason = etReason.getText().toString();

    //   TOFIX - Read the username from the credentials.properties file

    String sql = "INSERT INTO tip (tip_creator, symbol, target_price, reason) VALUES (?, ?, ?, ?)";

    StockDatabase dbHelper = new StockDatabase(this.getApplicationContext());
    SQLiteDatabase db = dbHelper.openDatabase();
    SQLiteStatement stmt = db.compileStatement(sql);
    stmt.bindString(1, "USERNAME");
    stmt.bindString(2, symbol);//from w ww  .j a  va  2  s .c o  m
    stmt.bindDouble(3, targetPrice);
    stmt.bindString(4, reason);
    stmt.execute();
    stmt.close();

    db.close();

    tvTipStatus.setText("Tip saved!");
}

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

public static HashSet<String> getReadMessagesSet(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    HashSet<String> readSet = null;

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT server_article_id FROM headers WHERE read=1 AND subscribed_group_id=" + groupid;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        readSet = new HashSet<String>(c.getCount());
        c.moveToFirst();//from w  ww  .j ava2  s  .co  m

        for (int i = 0; i < count; i++) {
            readSet.add(c.getString(0));
            c.moveToNext();
        }
    }

    c.close();
    dbread.close();
    db.close();

    if (readSet == null)
        readSet = new HashSet<String>(0);
    return readSet;
}

From source file:com.clutch.ClutchStats.java

public void logAction(String action, Map<String, ?> data) {
    SQLiteDatabase db = getWritableDatabase();
    Object[] args = { ClutchUtils.getUUID(), System.currentTimeMillis() / 1000.0, action,
            new JSONObject(data).toString() };
    db.execSQL("INSERT INTO stats (uuid, ts, action, data) VALUES (?, ?, ?, ?)", args);
    db.close();
}

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

public static Vector<Object> isHeaderInDatabase(Long number, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();
    Vector<Object> retVal = null;

    String q = "SELECT _id, server_article_id FROM headers WHERE subscribed_group_id=" + groupid
            + " AND server_article_number=" + number;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        c.moveToFirst();//from   ww  w.  j  a va 2s  .c  o m
        retVal = new Vector<Object>(2);
        retVal.add(c.getLong(0));
        retVal.add(c.getString(1));
    }

    c.close();
    dbread.close();
    db.close();

    return retVal;
}

From source file:com.dm.material.dashboard.candybar.databases.Database.java

public void addPremiumRequest(String orderId, String productId, String request) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_ORDER_ID, orderId);//from ww  w .j ava 2  s. c o m
    values.put(KEY_PRODUCT_ID, productId);
    values.put(KEY_REQUEST, request);

    db.insert(TABLE_PREMIUM_REQUEST, null, values);
    db.close();
}