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.wallpaper.board.databases.Database.java

public List<Wallpaper> getFilteredWallpapers() {
    List<Wallpaper> wallpapers = new ArrayList<>();
    List<String> selected = getSelectedCategories(false);
    List<String> selection = new ArrayList<>();
    if (selected.size() == 0)
        return wallpapers;

    StringBuilder CONDITION = new StringBuilder();
    for (String item : selected) {
        if (CONDITION.length() > 0) {
            CONDITION.append(" OR ").append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?");
        } else {/*from  w w  w .  j  a va 2s.  co m*/
            CONDITION.append("LOWER(").append(KEY_CATEGORY).append(")").append(" LIKE ?");
        }
        selection.add("%" + item.toLowerCase(Locale.getDefault()) + "%");
    }
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_WALLPAPERS, null, CONDITION.toString(),
            selection.toArray(new String[selection.size()]), null, null, KEY_ADDED_ON + " DESC, " + KEY_ID);
    if (cursor.moveToFirst()) {
        do {
            Wallpaper wallpaper = new Wallpaper(cursor.getInt(0), cursor.getString(1), cursor.getString(2),
                    cursor.getString(3), cursor.getString(4), cursor.getInt(6) == 1);
            wallpapers.add(wallpaper);
        } while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return wallpapers;
}

From source file:com.clutch.ClutchStats.java

public ArrayList<ABRow> getABLogs() {
    SQLiteDatabase db = getReadableDatabase();
    String[] args = {};//from  w  ww  .  ja va  2s  .  c o m
    ArrayList<ABRow> res = new ArrayList<ABRow>();
    Cursor cur = db.rawQuery("SELECT uuid, ts, data FROM ablog ORDER BY ts", args);
    cur.moveToFirst();
    while (!cur.isAfterLast()) {
        String uuid = cur.getString(0);
        double ts = cur.getDouble(1);
        JSONObject data;
        try {
            data = new JSONObject(cur.getString(2));
        } catch (JSONException e) {
            Log.w(TAG, "Could not serialize to JSON: " + cur.getString(3));
            cur.moveToNext();
            continue;
        }
        res.add(new ABRow(uuid, ts, data));
        cur.moveToNext();
    }
    db.close();
    return res;
}

From source file:net.smart_json_database.JSONDatabase.java

/**
 * Get a property from db or the defaultValue
 * /*w w  w  .j  ava  2  s  .c  o m*/
 * @param key
 * @param defaultValue
 * @return a property from db
 */
public String getPropterty(String key, String defaultValue) {
    String returnValue = defaultValue;

    SQLiteDatabase db = dbHelper.getReadableDatabase();

    returnValue = getPropterty(db, key, defaultValue);

    db.close();

    return returnValue;
}

From source file:com.acrylicgoat.devchat.MainActivity.java

private void getToday(String owner) {
    //Log.d("MainActivity", "getToday() called: " + owner);

    DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext());
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    cursor = db.rawQuery(getTodaySQL(), null);
    if (cursor.getCount() > 0) {
        cursor.moveToNext();//from  w  w  w  . j  a  va 2  s.c  o m
        int notesColumn = cursor.getColumnIndex(Notes.NOTE);
        today.setText(cursor.getString(notesColumn));

    } else {
        if (devs.size() > 0) {
            today.setText("");
        } else {
            today.setText(getString(R.string.no_devs));

        }

    }
    Linkify.addLinks(today, Linkify.ALL);
    cursor.close();
    db.close();
}

From source file:com.qi.airstat.BluetoothLeService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    int signal = 0;

    // This is special handling for the Heart Rate Measurement profile.  Data parsing is
    // carried out as per profile specifications:
    // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        int flag = characteristic.getProperties();
        int format = -1;
        if ((flag & 0x01) != 0) {
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG, "Heart rate format UINT16.");
        } else {//from w w w .  j av  a2 s  .  c  om
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG, "Heart rate format UINT8.");
        }

        final int heartRate = characteristic.getIntValue(format, 1);
        signal = heartRate;
        Log.d(TAG, String.format("Received heart rate: %d", heartRate));
        intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for (byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());

            signal = Integer.parseInt(new String(data));
        }
    }

    DatabaseManager databaseManager = new DatabaseManager(BluetoothLeService.this);
    SQLiteDatabase database = databaseManager.getWritableDatabase();

    ContentValues values = new ContentValues();
    String date = new SimpleDateFormat("yyMMddHHmmss").format(new java.util.Date());

    values.put(Constants.DATABASE_COMMON_COLUMN_TIME_STAMP, date);
    values.put(Constants.DATABASE_HEART_RATE_COLUMN_HEART_RATE, signal);
    database.insert(Constants.DATABASE_HEART_RATE_TABLE, null, values);

    database.close();

    try {
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    } catch (SecurityException exception) {
        exception.printStackTrace();
    }

    JSONObject reformedObject = new JSONObject();
    JSONArray reformedArray = new JSONArray();

    try {
        JSONObject item = new JSONObject();
        item.put("timeStamp", date);
        item.put("connectionID", Constants.CID_BLE);
        item.put("heartrate", signal);
        item.put("latitude", latitude);
        item.put("longitude", longitude);

        reformedArray.put(item);
        reformedObject.put("HR", reformedArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    HttpService httpService = new HttpService();
    String responseCode = httpService.executeConn(null, "POST",
            "http://teamc-iot.calit2.net/IOT/public/rcv_json_data", reformedObject);

    sendBroadcast(intent);
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

@Override
public void onDestroy() {
    progressDialog.dismiss();//  ww w .  j  a v a2s  .c  o  m

    /* Close our database connection. */

    SQLiteDatabase db = Singletons.i().getDatabaseHelper().getWritableDatabase();
    db.close();

    super.onDestroy();
}

From source file:com.barcamppenang2014.tabfragment.ProfileFragment.java

License:asdf

public String check() {
    // Log.d("yc", "at check()");
    String isCreated = "false";

    MyDatabase database = new MyDatabase(getActivity());
    SQLiteDatabase sqliteDatabase = database.getReadableDatabase();
    Log.d("debug", "database.getReadableDatabase()");
    String sql = "SELECT ISPFOFILECREATED FROM USERPROFILE;";
    Cursor retrieved = sqliteDatabase.rawQuery(sql, null);
    Log.d("debug", "rawQuery");

    if (retrieved.moveToFirst()) {
        isCreated = retrieved.getString(retrieved.getColumnIndex("ISPFOFILECREATED"));
    }/*  www  .  ja  v a 2 s .c  o  m*/

    Log.d("debug", "checking isProfileCreated " + isCreated);
    retrieved.close();
    database.close();
    sqliteDatabase.close();
    return isCreated;
}

From source file:net.smart_json_database.JSONDatabase.java

public JSONEntity fetchById(int id) {

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    ArrayList<JSONEntity> list = fetchByRawSQL(db, FETCH_BY_ID_SCRIPT, new String[] { "" + id });
    db.close();
    if (list.size() > 0) {
        return list.get(0);
    }/*w  w  w. j ava  2  s  . c  o m*/
    return null;
}

From source file:com.acrylicgoat.scrumnotes.MainActivity.java

private void getToday(String owner) {
    //Log.d("MainActivity", "getToday() called: " + owner);

    DatabaseHelper dbHelper = new DatabaseHelper(this.getApplicationContext());
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    cursor = db.rawQuery(getTodaySQL(), null);
    if (cursor.getCount() > 0) {
        cursor.moveToNext();//from   ww w  . j  ava  2 s  .c  o m
        int notesColumn = cursor.getColumnIndex(Notes.NOTE);
        today.setText(cursor.getString(notesColumn));

    } else {
        if (devs.size() > 0) {
            today.setText(getString(R.string.main_insert));
        } else {
            today.setText(getString(R.string.no_devs));
        }

    }
    Linkify.addLinks(today, Linkify.ALL);
    cursor.close();
    db.close();
}