Example usage for android.database.sqlite SQLiteDatabase execSQL

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

Introduction

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

Prototype

public void execSQL(String sql) throws SQLException 

Source Link

Document

Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.

Usage

From source file:Main.java

public static void updateRecord(SQLiteDatabase db, String date, String time, String record) {
    String sqlStr = "update " + TABLE_NAME + " set record='" + record + "' where date='" + date + "' and time='"
            + time + "';";
    db.execSQL(sqlStr);
}

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;/*w w  w .j a  v a 2s .  com*/
    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.contentful.vault.SqliteHelper.java

static void execCreate(SpaceHelper helper, SQLiteDatabase db) {
    db.execSQL(CREATE_ENTRY_TYPES);
    db.execSQL(CREATE_SYNC_INFO);/*from  w w  w  .  j  a  va  2  s. co  m*/
    for (String code : helper.getLocales()) {
        db.execSQL(createAssets(code));
        db.execSQL(createLinks(code));
    }
    for (ModelHelper<?> modelHelper : helper.getModels().values()) {
        for (String sql : modelHelper.getCreateStatements(helper)) {
            db.execSQL(sql);
        }
    }
}

From source file:com.github.longkai.zhihu.util.Utils.java

public static void dropTables(SQLiteDatabase db) {
    db.execSQL("DROP TABLE IF EXISTS " + TOPICS);
    db.execSQL("DROP TABLE IF EXISTS " + ITEMS);
}

From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java

public static void removeTranslation(SQLiteDatabase db, String translationShortName) {
    db.execSQL(String.format("DROP TABLE IF EXISTS %s", translationShortName));

    db.delete(DatabaseHelper.TABLE_BOOK_NAMES,
            String.format("%s = ?", DatabaseHelper.COLUMN_TRANSLATION_SHORT_NAME),
            new String[] { translationShortName });
}

From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java

public static void createTranslationTable(SQLiteDatabase db, String translationShortName) {
    db.execSQL(String.format(
            "CREATE TABLE %s (%s INTEGER NOT NULL, %s INTEGER NOT NULL, %s INTEGER NOT NULL, %s TEXT NOT NULL);",
            translationShortName, DatabaseHelper.COLUMN_BOOK_INDEX, DatabaseHelper.COLUMN_CHAPTER_INDEX,
            DatabaseHelper.COLUMN_VERSE_INDEX, DatabaseHelper.COLUMN_TEXT));
    db.execSQL(String.format("CREATE INDEX INDEX_%s ON %s (%s, %s, %s);", translationShortName,
            translationShortName, DatabaseHelper.COLUMN_BOOK_INDEX, DatabaseHelper.COLUMN_CHAPTER_INDEX,
            DatabaseHelper.COLUMN_VERSE_INDEX));
}

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

public static String executarBackup(String databaseName, String databasePath, SharedPreferences preferences,
        Context context) {//from ww  w.ja va  2  s.c o  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";
}

From source file:Main.java

static void createHistoryTable(SQLiteDatabase db) {
    String CREATE_HISTORY_TABLE = "CREATE TABLE " + TABLE_HISTORY + "(" + KEY_HISTORY_ID
            + " INTEGER PRIMARY KEY," + KEY_HISTORY_TYPE + " INTEGER," + KEY_HISTORY_LEVEL + " INTEGER,"
            + KEY_HISTORY_POINT + " INTEGER," + KEY_HISTORY_DATETIME + " INTEGER," + KEY_HISTORY_DESCRIPTION
            + " TEXT)";
    db.execSQL(CREATE_HISTORY_TABLE);
}

From source file:Main.java

private static void createUsageHistory(SQLiteDatabase db) {
    String sql = "CREATE TABLE usage_history(" + "package_name TEXT," + "lat REAL, " + "lon REAL,"
            + "weekday INTEGER DEFAULT (strftime('%w', 'now')),"
            + "start_hour INTEGER DEFAULT (strftime('%H', 'now'))," + "use_second INTEGER DEFAULT 1,"
            + "created_at INTEGER DEFAULT (strftime('%s', 'now'))" + ")";
    db.execSQL(sql);
}

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();/*  w  w  w.  ja v a2s .com*/
    db.close();
}