List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.rener.sea.DBHelper.java
private long setSyncLocation(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;//from w ww .java2s. co m try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.update(DBSchema.TABLE_LOCATION, values, DBSchema.LOCATION_ID + " =? ", new String[] { String.valueOf(item.getLong(DBSchema.LOCATION_ID)) }); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
private long setSyncFlowchart(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;//from w w w.j ava 2 s . c om try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.update(DBSchema.TABLE_FLOWCHART, values, DBSchema.FLOWCHART_ID + " =? ", new String[] { String.valueOf(item.getLong(DBSchema.FLOWCHART_ID)) }); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
private long setSyncAppointments(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;/*from w w w. j a v a 2s. c o m*/ try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.update(DBSchema.TABLE_APPOINTMENTS, values, DBSchema.APPOINTMENT_ID + " =? ", new String[] { String.valueOf(item.getLong(DBSchema.APPOINTMENT_ID)) }); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
private long setSyncSpecialization(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;/*w w w .j a va 2s .c om*/ try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.update(DBSchema.TABLE_SPECIALIZATION, values, DBSchema.SPECIALIZATION_ID + " =? ", new String[] { String.valueOf(item.getLong(DBSchema.SPECIALIZATION_ID)) }); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
public List<Flowchart> getAllFlowcharts() { SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_FLOWCHART, new String[] { DBSchema.FLOWCHART_ID }, DBSchema.STATUS + " =? ", new String[] { String.valueOf(1) }, null, null, DBSchema.FLOWCHART_NAME + " COLLATE NOCASE", null); ArrayList<Flowchart> flowcharts; flowcharts = new ArrayList<>(); if ((cursor != null) && (cursor.getCount() > 0)) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { flowcharts.add(new Flowchart(cursor.getLong(0), this)); }/*from w w w . j ava 2 s. c o m*/ db.close(); cursor.close(); } return flowcharts; }
From source file:com.rener.sea.DBHelper.java
public List<Appointment> getAllAppointments() { SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_APPOINTMENTS, new String[] { DBSchema.APPOINTMENT_ID }, null, null, null, null, "date(" + DBSchema.APPOINTMENT_DATE + ") DESC", null); ArrayList<Appointment> Appointments; Appointments = new ArrayList<>(); if ((cursor != null) && (cursor.getCount() > 0)) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { Appointments.add(new Appointment(cursor.getLong(0), this, context.getResources().getString(R.string.date_format_medium))); }//w w w . j av a 2 s .c o m db.close(); cursor.close(); } return Appointments; }
From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java
private void updatePurchaseInfo(String purchaseInfo) { try {//from w w w. 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:com.rener.sea.DBHelper.java
public List<Report> getAllReports() { SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_REPORT, new String[] { DBSchema.REPORT_ID, DBSchema.REPORT_NAME }, DBSchema.REPORT_STATUS + " !=? ", new String[] { String.valueOf(-1) }, null, null, "date(" + DBSchema.REPORT_DATE_FILED + ") DESC, " + DBSchema.REPORT_NAME + " COLLATE NOCASE", null); ArrayList<Report> reports; reports = new ArrayList<>(); if ((cursor != null) && (cursor.getCount() > 0)) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { reports.add(new Report(cursor.getLong(0), cursor.getString(1), this)); }//from w w w . j a v a 2 s. co m db.close(); cursor.close(); } return reports; }
From source file:com.rener.sea.DBHelper.java
private long deleteLocation_category(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;//ww w .ja va2s .com try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); long id = db.delete(DBSchema.TABLE_LOCATION_CATEGORY, DBSchema.LOCATION_CATEGORY_LOCATION_ID + " =? AND " + DBSchema.LOCATION_CATEGORY_CATEGORY_ID + " =? ", new String[] { String.valueOf(item.getLong(DBSchema.LOCATION_CATEGORY_LOCATION_ID)), String.valueOf(item.getLong(DBSchema.LOCATION_CATEGORY_CATEGORY_ID)) }); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
private long setSyncPath(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;/*from w w w. j a v a 2 s .c o m*/ try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.update(DBSchema.TABLE_PATH, values, DBSchema.PATH_REPORT_ID + " =? AND " + DBSchema.PATH_OPTION_ID + " =? ", new String[] { String.valueOf(item.getLong(DBSchema.PATH_REPORT_ID)), String.valueOf(item.getLong(DBSchema.PATH_OPTION_ID)) }); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }