List of usage examples for android.database.sqlite SQLiteDatabase execSQL
public void execSQL(String sql) throws SQLException
From source file:com.nextgis.maplib.map.VectorLayer.java
@Override public boolean delete() { //drop table// ww w . j av a2 s . co m MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); SQLiteDatabase db = map.getDatabase(true); String tableDrop = "DROP TABLE IF EXISTS " + mPath.getName(); db.execSQL(tableDrop); return super.delete(); }
From source file:au.org.ala.fielddata.mobile.dao.DatabaseHelper.java
private void createIndexes(SQLiteDatabase db, String[] tables, String[] columns, boolean unique) { String uniqueStr = unique ? "UNIQUE " : ""; String columnsSuffix = join(columns, "_"); for (String table : tables) { db.execSQL("CREATE " + uniqueStr + "INDEX IF NOT EXISTS " + table + "_" + columnsSuffix + " ON " + table + "(" + join(columns, ",") + ")"); }/*from w w w. j av a2 s .c o m*/ }
From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java
private void updateStorageInfo(String updated_info) { //as far as I think, this should receive all the information about all four products //so whenever we substitute some product, the original one will not be kept in there //or we need some level of delete functionality? or do we need a sync adapter? //is this a good idea? what happens when the number of item increases? try {/*www .j av a 2 s . c om*/ DataDbHelper dbHelper = new DataDbHelper(this); SQLiteDatabase database = dbHelper.getWritableDatabase(); database.delete(DataContract.ItemEntry.TABLE_NAME, null, null); database.execSQL( "DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + DataContract.ItemEntry.TABLE_NAME + "'"); //get this valueArray from the string JSONArray valueArray = new JSONArray(updated_info); for (int lc = 0; lc < valueArray.length(); ++lc) { JSONObject infoJson = valueArray.getJSONObject(lc); //everything is the same as following code ContentValues newValues = new ContentValues(); newValues.put(DataContract.ItemEntry.COLUMN_REMAINING_NUM, infoJson.getInt("remaining_num")); newValues.put(DataContract.ItemEntry.COLUMN_SHORT_DESC, infoJson.getString("short_desc")); newValues.put(DataContract.ItemEntry.COLUMN_PRICE, infoJson.getString("item_price")); newValues.put(DataContract.ItemEntry.COLUMN_ITEM_NAME, infoJson.getString("item_name")); Uri returnedUri = getContentResolver().insert(DataContract.ItemEntry.CONTENT_URI, newValues); Log.i(TAG, "inserted row num " + ContentUris.parseId(returnedUri)); } database.close(); dbHelper.close(); } catch (JSONException e) { Log.e(TAG, "error when parsing Json"); } }
From source file:com.liferay.alerts.database.DatabaseHelper.java
private void _renameColumn(SQLiteDatabase database, String tableName, String createTableSQL) { String temp = "TEMP_" + tableName; StringBuilder alter = new StringBuilder(); alter.append("ALTER TABLE "); alter.append(tableName);/*ww w . j a v a 2 s . c om*/ alter.append(" RENAME TO "); alter.append(temp); database.execSQL(alter.toString()); database.execSQL(createTableSQL); StringBuilder copy = new StringBuilder(); copy.append("INSERT INTO "); copy.append(tableName); copy.append(" SELECT * FROM "); copy.append(temp); database.execSQL(copy.toString()); StringBuilder drop = new StringBuilder(); drop.append("DROP TABLE "); drop.append(temp); database.execSQL(drop.toString()); }
From source file:heartware.com.heartware_master.DBAdapter.java
@Override public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) { final String queryProfiles = "DROP TABLE IF EXISTS " + PROFILES_TABLE; final String queryWorkouts = "DROP TABLE IF EXISTS " + MEETUPS_TABLE; database.execSQL(queryProfiles); database.execSQL(queryWorkouts);//from w w w . j a va 2 s . c o m onCreate(database); }
From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java
private void updatePurchaseInfo(String purchaseInfo) { try {//www . j a v a 2s.c o m DataDbHelper dbHelper = new DataDbHelper(this); SQLiteDatabase database = dbHelper.getWritableDatabase(); database.delete(DataContract.PurchasedEntry.TABLE_NAME, null, null); database.execSQL( "DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + DataContract.PurchasedEntry.TABLE_NAME + "'"); JSONArray valueArray = new JSONArray(purchaseInfo); Log.i(TAG, "the valueArray length: " + Integer.toString(valueArray.length())); for (int lc = 0; lc < valueArray.length(); ++lc) { JSONObject infoJson = valueArray.getJSONObject(lc); String item_name = infoJson.getString("item_name"); database.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + DataContract.PurchasedEntry.TABLE_NAME + "'"); //query based on this item_name and get item id //currently if queried has no such item in current database then don't insert to purchase table //find user id using the stored email Cursor itemIDCursor; int waitTime = 0; boolean breaked = false; do { String[] itemProj = new String[] { DataContract.ItemEntry._ID }; String[] itemSelArgs = new String[] { item_name }; itemIDCursor = database.query(DataContract.ItemEntry.TABLE_NAME, itemProj, DataContract.ItemEntry.COLUMN_ITEM_NAME + " = ?", itemSelArgs, null, null, null); if (waitTime != 0) { // if the item is not yet exists in the item table, probably means update purchase get called before update storage. So wait until find SystemClock.sleep(1000); if (++waitTime > 30) { breaked = true; break; } } else if (waitTime == 0) { waitTime = 1; } } while (itemIDCursor == null || itemIDCursor.getCount() == 0); if (!breaked) { itemIDCursor.moveToNext(); int itemID = itemIDCursor.getInt(0); itemIDCursor.close(); String[] userProj = new String[] { DataContract.UserEntry._ID }; String user_email = infoJson.getString("email"); String[] userSelArgs = new String[] { user_email }; Cursor userIDCursor = database.query(DataContract.UserEntry.TABLE_NAME, userProj, DataContract.UserEntry.COLUMN_EMAIL + " = ?", userSelArgs, null, null, null); userIDCursor.moveToNext(); Log.i(TAG, "userID: " + user_email); int userID = userIDCursor.getInt(0); Log.i(TAG, "itemID: " + itemID); Log.i(TAG, "userID: " + userID); userIDCursor.close(); ContentValues newValues = new ContentValues(); newValues.put(DataContract.PurchasedEntry.COLUMN_ITEM_KEY, itemID); newValues.put(DataContract.PurchasedEntry.COLUMN_USER_KEY, userID); newValues.put(DataContract.PurchasedEntry.COLUMN_ORDER_TIME, infoJson.getString("order_time")); newValues.put(DataContract.PurchasedEntry.COLUMN_PICK_UP_TIME, infoJson.getString("pickup_time")); newValues.put(DataContract.PurchasedEntry.COLUMN_QUANTITY, infoJson.getString("quantity")); newValues.put(DataContract.PurchasedEntry.COLUMN_RECEIPT_NUM, infoJson.getString("receipt")); Uri returnedUri = getContentResolver().insert(DataContract.PurchasedEntry.CONTENT_URI, newValues); Log.i(TAG, "inserted row num " + ContentUris.parseId(returnedUri)); } } database.close(); dbHelper.close(); } catch (JSONException e) { Log.e(TAG, "error when parsing Json"); } }
From source file:org.opendatakit.common.android.database.DataModelDatabaseHelper.java
private void commonTableDefn(SQLiteDatabase db) { // db.execSQL(SurveyConfigurationColumns.getTableCreateSql(SURVEY_CONFIGURATION_TABLE_NAME)); db.execSQL(InstanceColumns.getTableCreateSql(UPLOADS_TABLE_NAME)); db.execSQL(FormsColumns.getTableCreateSql(FORMS_TABLE_NAME)); db.execSQL(ColumnDefinitionsColumns.getTableCreateSql(COLUMN_DEFINITIONS_TABLE_NAME)); db.execSQL(KeyValueStoreColumns.getTableCreateSql(KEY_VALUE_STORE_DEFAULT_TABLE_NAME)); db.execSQL(KeyValueStoreColumns.getTableCreateSql(KEY_VALUE_STORE_ACTIVE_TABLE_NAME)); db.execSQL(KeyValueStoreColumns.getTableCreateSql(KEY_VALUE_STORE_SERVER_TABLE_NAME)); db.execSQL(KeyValueStoreColumns.getTableCreateSql(KEY_VALULE_STORE_SYNC_TABLE_NAME)); db.execSQL(TableDefinitionsColumns.getTableCreateSql(TABLE_DEFS_TABLE_NAME)); }
From source file:com.liferay.alerts.database.DatabaseHelper.java
private void _upgradeToVersion3(SQLiteDatabase database) { StringBuilder alter = new StringBuilder(); alter.append("ALTER TABLE "); alter.append(AlertDAO.TABLE_NAME);//from ww w .ja v a 2s . com alter.append(" ADD COLUMN "); alter.append(Alert.READ); alter.append(CharPool.SPACE); alter.append(TableColumn.INTEGER); alter.append(" DEFAULT 0"); database.execSQL(alter.toString()); }
From source file:mobisocial.bento.anyshare.util.DBHelper.java
private void dropAll(SQLiteDatabase db) { db.execSQL("DROP TABLE IF EXISTS " + ItemObject.TABLE); }
From source file:tritop.android.naturalselectionnews.DBHelper.java
@Override public void onCreate(SQLiteDatabase db) { if (DEBUG_ON) { Log.e(LOGTAG, "On Create "); }// ww w.j a v a2s .c o m db.execSQL(CREATE_WAR_STATS_TABLE_STATEMENT); db.execSQL(CREATE_KILL_STATS_TABLE_STATEMENT); db.execSQL(CREATE_NEWS_FEED_TABLE_STATEMENT); db.execSQL(CREATE_TWITTER_FEED_TABLE_STATEMENT); }