List of usage examples for android.database.sqlite SQLiteDatabase close
public void close()
From source file:com.rener.sea.DBHelper.java
private JSONArray getOption() { JSONArray data;/*from w ww. j a va 2s . c om*/ data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_OPTION, new String[] { DBSchema.OPTION_ID, DBSchema.OPTION_PARENT_ID, DBSchema.OPTION_NEXT_ID, DBSchema.OPTION_LABEL }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.OPTION_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.OPTION_PARENT_ID, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.OPTION_NEXT_ID, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.OPTION_LABEL, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private long setLocation(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;// ww w.ja v a2s.c om try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); if (!item.isNull(DBSchema.LOCATION_ID)) values.put(DBSchema.LOCATION_ID, item.getLong(DBSchema.LOCATION_ID)); if (!item.isNull(DBSchema.LOCATION_NAME)) values.put(DBSchema.LOCATION_NAME, item.getString(DBSchema.LOCATION_NAME)); if (!item.isNull(DBSchema.LOCATION_ADDRESS_ID)) values.put(DBSchema.LOCATION_ADDRESS_ID, item.getLong(DBSchema.LOCATION_ADDRESS_ID)); if (!item.isNull(DBSchema.LOCATION_OWNER_ID)) values.put(DBSchema.LOCATION_OWNER_ID, item.getLong(DBSchema.LOCATION_OWNER_ID)); if (!item.isNull(DBSchema.LOCATION_MANAGER_ID)) values.put(DBSchema.LOCATION_MANAGER_ID, item.getLong(DBSchema.LOCATION_MANAGER_ID)); if (!item.isNull(DBSchema.LOCATION_LICENSE)) values.put(DBSchema.LOCATION_LICENSE, item.getString(DBSchema.LOCATION_LICENSE)); if (!item.isNull(DBSchema.LOCATION_AGENT_ID)) values.put(DBSchema.LOCATION_AGENT_ID, item.getLong(DBSchema.LOCATION_AGENT_ID)); if (!item.isNull(DBSchema.STATUS)) values.put(DBSchema.STATUS, item.getLong(DBSchema.STATUS)); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.insertWithOnConflict(DBSchema.TABLE_LOCATION, null, values, 5); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.odoo.orm.OModel.java
/** * Update relation columns values for ManyToMany and OneToMany * //from ww w . ja v a2 s . c o m * @param vals * @param newId * @return */ @SuppressWarnings("unchecked") private boolean updateRelationColumns(OValues values) { SQLiteDatabase db = getWritableDatabase(); for (OColumn column : getColumns()) { if (column.getRelationType() != null && values.contains(column.getName())) { switch (column.getRelationType()) { case ManyToMany: OModel rel_model = createInstance(column.getType()); Command command = Command.Replace; List<Integer> rel_ids = new ArrayList<Integer>(); if (values.get(column.getName()) instanceof ORelIds) { ORelIds rel_objs = (ORelIds) values.get(column.getName()); Integer base_id = rel_objs.getBaseId(); if (base_id == null) { base_id = values.getInt(OColumn.ROW_ID); } for (String key : rel_objs.keys()) { RelData data = rel_objs.get(key); command = data.getCommand(); rel_ids = new ArrayList<Integer>(); rel_ids.addAll(data.getIds()); if (command == Command.Add) { manageManyToManyRecords(db, rel_model, rel_ids, base_id, Command.Replace); } } } else { rel_ids = (List<Integer>) values.get(column.getName()); if (rel_ids == null) { rel_ids = new ArrayList<Integer>(); } manageManyToManyRecords(db, rel_model, rel_ids, values.getInt(OColumn.ROW_ID), command); } break; case OneToMany: rel_model = createInstance(column.getType()); command = Command.Replace; Integer rec_id = 0; if (values.get(column.getName()) instanceof ORelIds) { ORelIds rel_objs = (ORelIds) values.get(column.getName()); rec_id = rel_objs.getBaseId(); if (rec_id == null) { rec_id = values.getInt(OColumn.ROW_ID); } for (String key : rel_objs.keys()) { RelData data = rel_objs.get(key); command = data.getCommand(); rel_ids = new ArrayList<Integer>(); rel_ids.addAll(data.getIds()); OValues rel_vals = new OValues(); switch (command) { case Add: rel_vals.put(column.getRelatedColumn(), rec_id); break; case Delete: rel_vals.put(column.getRelatedColumn(), false); break; default: break; } String whr = OColumn.ROW_ID + " IN (" + StringUtils.repeat(" ?, ", rel_ids.size() - 1) + "?)"; Object[] args = new Object[] { rel_ids }; if (rel_ids.size() > 0) rel_model.update(rel_vals, whr, args); } } break; default: break; } } } db.close(); return true; }
From source file:com.rener.sea.DBHelper.java
private long setReport(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;/*w w w. j a va2 s. c o m*/ try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); if (!item.isNull(DBSchema.REPORT_ID)) values.put(DBSchema.REPORT_ID, item.getLong(DBSchema.REPORT_ID)); if (!item.isNull(DBSchema.REPORT_CREATOR_ID)) values.put(DBSchema.REPORT_CREATOR_ID, item.getLong(DBSchema.REPORT_CREATOR_ID)); if (!item.isNull(DBSchema.REPORT_LOCATION_ID)) values.put(DBSchema.REPORT_LOCATION_ID, item.getLong(DBSchema.REPORT_LOCATION_ID)); // if(!item.isNull(DBSchema.REPORT_SUBJECT_ID)) // values.put(DBSchema.REPORT_SUBJECT_ID, item.getLong(DBSchema.REPORT_SUBJECT_ID)); if (!item.isNull(DBSchema.REPORT_FLOWCHART_ID)) values.put(DBSchema.REPORT_FLOWCHART_ID, item.getLong(DBSchema.REPORT_FLOWCHART_ID)); if (!item.isNull(DBSchema.REPORT_NOTE)) values.put(DBSchema.REPORT_NOTE, item.getString(DBSchema.REPORT_NOTE)); if (!item.isNull(DBSchema.REPORT_DATE_FILED)) values.put(DBSchema.REPORT_DATE_FILED, item.getString(DBSchema.REPORT_DATE_FILED)); if (!item.isNull(DBSchema.REPORT_NAME)) values.put(DBSchema.REPORT_NAME, item.getString(DBSchema.REPORT_NAME)); if (!item.isNull(DBSchema.REPORT_STATUS)) values.put(DBSchema.REPORT_STATUS, item.getLong(DBSchema.REPORT_STATUS)); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.insertWithOnConflict(DBSchema.TABLE_REPORT, null, values, 5); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
private long setPerson(JSONArray data) { SQLiteDatabase db = this.getWritableDatabase(); int i = -1;// w w w .j av a2 s .c om try { for (i = 0; i < data.length(); i++) { JSONObject item = data.getJSONObject(i); ContentValues values = new ContentValues(); if (!item.isNull(DBSchema.PERSON_ID)) values.put(DBSchema.PERSON_ID, item.getLong(DBSchema.PERSON_ID)); if (!item.isNull(DBSchema.PERSON_LAST_NAME1)) values.put(DBSchema.PERSON_LAST_NAME1, item.getString(DBSchema.PERSON_LAST_NAME1)); if (!item.isNull(DBSchema.PERSON_FIRST_NAME)) values.put(DBSchema.PERSON_FIRST_NAME, item.getString(DBSchema.PERSON_FIRST_NAME)); if (!item.isNull(DBSchema.PERSON_EMAIL)) values.put(DBSchema.PERSON_EMAIL, item.getString(DBSchema.PERSON_EMAIL)); // if(!item.isNull(DBSchema.PERSON_SPEC_ID)) // values.put(DBSchema.PERSON_SPEC_ID, item.getLong(DBSchema.PERSON_SPEC_ID)); if (!item.isNull(DBSchema.PERSON_LAST_NAME2)) values.put(DBSchema.PERSON_LAST_NAME2, item.getString(DBSchema.PERSON_LAST_NAME2)); if (!item.isNull(DBSchema.PERSON_MIDDLE_INITIAL)) values.put(DBSchema.PERSON_MIDDLE_INITIAL, item.getString(DBSchema.PERSON_MIDDLE_INITIAL)); if (!item.isNull(DBSchema.PERSON_PHONE_NUMBER)) values.put(DBSchema.PERSON_PHONE_NUMBER, item.getString(DBSchema.PERSON_PHONE_NUMBER)); if (!item.isNull(DBSchema.STATUS)) values.put(DBSchema.STATUS, item.getString(DBSchema.STATUS)); values.put(DBSchema.MODIFIED, DBSchema.MODIFIED_NO); db.insertWithOnConflict(DBSchema.TABLE_PERSON, null, values, 5); } } catch (JSONException e) { e.printStackTrace(); } db.close(); return i; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getUsers() { JSONArray data;/* ww w.j av a 2 s . c o m*/ data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_USERS, new String[] { DBSchema.USER_ID, DBSchema.USER_USERNAME, DBSchema.USER_PASSHASH, DBSchema.USER_PERSON_ID, DBSchema.USER_SALT }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.USER_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.USER_USERNAME, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.USER_PASSHASH, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.USER_PERSON_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.USER_SALT, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getAddress() { JSONArray data;/*from w ww . j ava 2 s . co m*/ data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_ADDRESS, new String[] { DBSchema.ADDRESS_ID, DBSchema.ADDRESS_LINE1, DBSchema.ADDRESS_CITY, DBSchema.ADDRESS_ZIPCODE, DBSchema.ADDRESS_LINE2 }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.ADDRESS_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.ADDRESS_LINE1, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.ADDRESS_CITY, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.ADDRESS_ZIPCODE, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.ADDRESS_LINE2, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getDevices() { JSONArray data;// w ww . ja va 2 s . com data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_DEVICES, new String[] { DBSchema.DEVICE_ID, DBSchema.DEVICE_NAME, DBSchema.DEVICE_ID_NUMBER, DBSchema.DEVICE_USER_ID, DBSchema.DEVICE_LATEST_SYNC }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.DEVICE_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.DEVICE_NAME, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.DEVICE_ID_NUMBER, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.DEVICE_USER_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.DEVICE_LATEST_SYNC, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getFlowchart() { JSONArray data;//from w w w . ja va2 s. com data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_FLOWCHART, new String[] { DBSchema.FLOWCHART_ID, DBSchema.FLOWCHART_FIRST_ID, DBSchema.FLOWCHART_NAME, DBSchema.FLOWCHART_END_ID, DBSchema.FLOWCHART_CREATOR_ID, DBSchema.FLOWCHART_VERSION }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.FLOWCHART_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.FLOWCHART_FIRST_ID, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.FLOWCHART_NAME, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.FLOWCHART_END_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.FLOWCHART_CREATOR_ID, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.FLOWCHART_VERSION, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }
From source file:com.rener.sea.DBHelper.java
private JSONArray getAppointments() { JSONArray data;/*from www . jav a 2 s. c om*/ data = new JSONArray(); SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.query(DBSchema.TABLE_APPOINTMENTS, new String[] { DBSchema.APPOINTMENT_ID, DBSchema.APPOINTMENT_DATE, DBSchema.APPOINTMENT_TIME, DBSchema.APPOINTMENT_REPORT_ID, DBSchema.APPOINTMENT_PURPOSE, DBSchema.APPOINTMENT_MAKER_ID }, DBSchema.MODIFIED + "=?", new String[] { DBSchema.MODIFIED_YES }, null, null, null, null); if (cursor.moveToFirst()) { if ((cursor != null) && (cursor.getCount() > 0)) for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { JSONObject map = new JSONObject(); try { if (!cursor.isNull(0)) map.put(DBSchema.APPOINTMENT_ID, cursor.getString(0)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(1)) map.put(DBSchema.APPOINTMENT_DATE, cursor.getString(1)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(2)) map.put(DBSchema.APPOINTMENT_TIME, cursor.getString(2)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(3)) map.put(DBSchema.APPOINTMENT_REPORT_ID, cursor.getString(3)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(4)) map.put(DBSchema.APPOINTMENT_PURPOSE, cursor.getString(4)); } catch (JSONException e) { e.printStackTrace(); } try { if (!cursor.isNull(5)) map.put(DBSchema.APPOINTMENT_MAKER_ID, cursor.getString(5)); } catch (JSONException e) { e.printStackTrace(); } data.put(map); } } db.close(); cursor.close(); return data; }