List of usage examples for android.database.sqlite SQLiteDatabase execSQL
public void execSQL(String sql) throws SQLException
From source file:com.manning.androidhacks.hack042.db.DatabaseHelper.java
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS pois;"); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void setAuthorFavorite(boolean isFavorite, boolean mustBeFavorite, String author, Context context) {// w w w . j av a 2 s. c o m if (isFavorite && mustBeFavorite || !isFavorite && !mustBeFavorite) return; DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwrite = dbhelper.getWritableDatabase(); if (isFavorite && !mustBeFavorite) { // Remove from the table dbwrite.execSQL("DELETE FROM favorite_users WHERE name=" + esc(author)); } else if (!isFavorite && mustBeFavorite) { // Insert into the table ContentValues cv = new ContentValues(); cv.put("name", author); dbwrite.insert("favorite_users", null, cv); } dbwrite.close(); dbhelper.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void storeGroupLastFetchedMessageNumber(String group, long lastNumber, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); String wQuery = "UPDATE subscribed_groups SET lastFetched=" + lastNumber + " WHERE _id=" + groupid; dbwrite.execSQL(wQuery); dbwrite.close();// w ww . ja va 2 s . co m db.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void setMessageCatched(long id, boolean catched, Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getReadableDatabase(); int numbool;/*from w w w . j a v a2 s . c om*/ if (catched) numbool = 1; else numbool = 0; dbwrite.execSQL("UPDATE headers SET catched=" + numbool + " WHERE _id=" + id); dbwrite.close(); db.close(); }
From source file:ru.ming13.gambit.database.DatabaseOperator.java
private void insertDatabaseContents(SQLiteDatabase database, File databaseFile) { database.execSQL(SqlBuilder.buildAttachingClause(databaseFile.getAbsolutePath(), DATABASE_ALIAS)); try {//w w w . j a v a 2 s .c o m database.beginTransaction(); database.execSQL(SqlBuilder.buildInsertionClause(DatabaseSchema.Tables.DECKS, DATABASE_ALIAS)); database.execSQL(SqlBuilder.buildInsertionClause(DatabaseSchema.Tables.CARDS, DATABASE_ALIAS)); database.setTransactionSuccessful(); } finally { database.endTransaction(); } database.execSQL(SqlBuilder.buildDetachingClause(DATABASE_ALIAS)); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void updateHeaderRecordAttachments(int headerId, Vector<HashMap<String, String>> attachsVector, Context context) {// w ww . j av a2 s . c o m if (attachsVector == null || attachsVector.size() == 0) return; StringBuffer strbu = new StringBuffer(); HashMap<String, String> attachData = null; int len = attachsVector.size(); for (int i = 0; i < len; i++) { attachData = attachsVector.get(i); strbu.append(attachData.get("md5")); if (i != len - 1) strbu.append(";"); } DBHelper db = new DBHelper(context); SQLiteDatabase dbwriter = db.getWritableDatabase(); String q = "UPDATE headers SET has_attachments=1, attachments_fnames=" + esc(strbu.toString()) + " WHERE _id=" + headerId; dbwriter.execSQL(q); dbwriter.close(); db.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void groupMarkAllRead(String group, Context context) { int groupid = getGroupIdFromName(group, context); if (groupid == -1) return;//from ww w. ja v a2 s . c o m DBHelper db = new DBHelper(context); SQLiteDatabase dbWrite = db.getWritableDatabase(); String query = "UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE subscribed_group_id=" + groupid; dbWrite.execSQL(query); query = "UPDATE subscribed_groups SET unread_count=0 WHERE _ID=" + groupid; dbWrite.execSQL(query); dbWrite.close(); db.close(); }
From source file:com.alchemiasoft.common.content.BookDBOpenHelper.java
@Override public void onCreate(SQLiteDatabase db) { try {/*from w w w . j a v a2s .c o m*/ db.beginTransaction(); db.execSQL(BookDB.Book.CREATE_TABLE); String input = null; try { input = ResUtil.assetAsString(mContext, Constants.BOOKS_PATH); } catch (Exception e) { Log.e(TAG_LOG, "Cannot read the input at assets/" + Constants.BOOKS_PATH); } // Adding the default entries if (!TextUtils.isEmpty(input)) { Log.d(TAG_LOG, "Adding into the DB: " + input); final JSONArray arr = new JSONArray(input); final List<Book> books = Book.allFrom(arr); // Adding the all the books as a batch for (final Book book : books) { db.insert(BookDB.Book.TABLE, null, book.toValues()); } } db.setTransactionSuccessful(); Log.i(TAG_LOG, "Successfully created " + BookDB.NAME); } catch (Exception e) { Log.e(TAG_LOG, "Error creating " + BookDB.NAME + ": ", e); } finally { db.endTransaction(); } }
From source file:ru.ming13.gambit.database.DatabaseOperator.java
private void deleteDatabaseContents(SQLiteDatabase database) { try {//from w w w .j a v a 2s. c om database.beginTransaction(); database.execSQL(SqlBuilder.buildDeletionClause(DatabaseSchema.Tables.CARDS)); database.execSQL(SqlBuilder.buildDeletionClause(DatabaseSchema.Tables.DECKS)); database.setTransactionSuccessful(); } finally { database.endTransaction(); } }
From source file:com.manning.androidhacks.hack041.data.DatabaseHelper.java
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); db.execSQL("PRAGMA foreign_keys=ON;"); }