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

public static void closeDB(SQLiteDatabase db) {
    db.close();
}

From source file:Main.java

public static void close(SQLiteDatabase db) {
    if (db != null && db.isOpen()) {
        db.close();
    }
}

From source file:Main.java

public static void closeDb(SQLiteDatabase... dbs) {
    if (dbs == null)
        return;//from   w  ww .j av a2s.c  om
    for (SQLiteDatabase db : dbs) {
        if (db != null) {
            db.close();
            db = null;
        }
    }
}

From source file:Main.java

public static boolean exists() {
    SQLiteDatabase checkDB = null;
    try {//from   w w w  .j  av a  2  s  . c o m
        checkDB = SQLiteDatabase.openDatabase(CHIRSTMAIS_IS_COMING, null, SQLiteDatabase.OPEN_READONLY);
        checkDB.close();
    } catch (SQLiteException ex) {
        // database doesn't exist yet.
    }
    return checkDB != null ? true : false;
}

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

public static void setFileAsDownloaded(int pos, boolean a) {
    DB db = new DB(MainActivity.appContext);
    SQLiteDatabase d = db.getWritableDatabase();
    if (d == null)
        return;//from   www.  ja  va2s  .  c o m
    d.execSQL(String.format("UPDATE %s SET %s=\"%b\" WHERE id = \"%s\"", DB_entry.TABLE_CANCIONES,
            DB_entry.COLUMN_CANCIONES_DOWNLOADED, a, pos));
    d.close();
    MainActivity.songList.get(pos).put("downloaded", a ? "{fa-mobile}" : "{fa-cloud}");
}

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

public static void deleteOfflineSentPost(long id, Context context) {

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

    dbwrite.execSQL("DELETE FROM offline_sent_posts WHERE _id=" + id);
    dbwrite.close();
    db.close();/*from w  w  w  .  j  av a2s  . c  o  m*/
}

From source file:Main.java

static String getAccessTokenFromTable(Context context, String tableName) {
    String token = null;//from ww w.  ja v a 2  s  .  c  o m
    try {
        SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null);
        Cursor c = db.rawQuery(
                "SELECT " + DEPRECATED_ACCESS_TOKEN_COLUMN + " FROM " + tableName + " WHERE local_id=0", null);
        if (c.moveToFirst() && c.getColumnIndex(DEPRECATED_ACCESS_TOKEN_COLUMN) != -1) {
            token = c.getString(c.getColumnIndex(DEPRECATED_ACCESS_TOKEN_COLUMN));
        }
        c.close();
        db.close();
    } catch (SQLException e) {
        // DB doesn't exist
    }
    return token;
}

From source file:Main.java

public static void insert(SQLiteDatabase db, String title, String pubdate, String itemDetail, String link,
        String firstImgUrl, String sectionTitle) {
    ContentValues values = new ContentValues();
    values.put("title", title);
    values.put("pubdate", pubdate);
    values.put("item_detail", itemDetail);
    values.put("link", link);
    values.put("first_img_url", firstImgUrl);
    values.put("table_name", sectionTitle);
    db.insert("favorite_item", null, values);
    db.close();
}

From source file:com.google.zxing.client.android.history.HistoryManager.java

private static void close(Cursor cursor, SQLiteDatabase database) {
    if (cursor != null) {
        cursor.close();/*  w  ww . j  a  v a 2  s  . c o  m*/
    }
    if (database != null) {
        database.close();
    }
}

From source file:br.com.anteros.android.persistence.backup.ExportDatabaseTask.java

public static String executarBackup(String databaseName, String databasePath, SharedPreferences preferences,
        Context context) {/* w ww  .  ja  va 2s. co  m*/

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(context,
                    Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        throw new BackupException(
                "No foi possvel executar a tarefa de backup pois voc no possu permisso para isto. Verifique se solicitou permisso no manifesto ou requisitou a permisso caso esteja usando Android(Marshmallow) 6 ou acima.");
    }

    File dbFile = new File(databasePath);

    File exportDir = new File(Environment.getExternalStorageDirectory(), "backup");

    if (!exportDir.exists()) {
        exportDir.mkdirs();
    }

    if (countBackupFiles(exportDir, dbFile.getName()) >= maxBackupFiles) {
        deleteOldBackup(exportDir, dbFile.getName());
    }

    lastBackup = new File(exportDir, generateBackupName(dbFile));
    try {
        lastBackup.createNewFile();
        AndroidFileUtils.copyFile(dbFile, lastBackup);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(BackupService.DATE_TIME_LAST_BACKUP, new Date().getTime());
        editor.commit();
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }

    SQLiteDatabase db = null;
    try {
        db = context.openOrCreateDatabase(databaseName, SQLiteDatabase.OPEN_READWRITE, null);
        db.execSQL("vacuum;");
        db.execSQL("reindex;");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            db.close();
        } catch (Exception e2) {
        }
    }

    return "OK";
}