List of usage examples for android.database Cursor close
void close();
From source file:cn.sharesdk.analysis.db.MessageUtils.java
/** * ?wifi??*//* ww w . j av a2 s. c o m*/ private static synchronized ArrayList<MessageModel> getEventMsg(Context c, String selection, String[] selectionArgs) { ArrayList<MessageModel> group = new ArrayList<MessageModel>(); MessageModel model = new MessageModel(); JSONObject jsonObject = new JSONObject(); String eventID; String eventType; DBProvider provider = DBProvider.getDBProvider(c); Cursor cursor = provider.query(DBHelp.TABLE_STATISTICS, new String[] { DBHelp.COLUMN_ID, DBHelp.COLUMN_EVENT_TYPE, DBHelp.COLUMN_EVENT_DATA }, selection, selectionArgs, null); try { while (cursor != null && cursor.moveToNext()) { eventID = cursor.getString(0); eventType = cursor.getString(1); JSONObject eventObject = new JSONObject(cursor.getString(2).toString()); model.idList.add(eventID); if (jsonObject.has(eventType)) { JSONArray existArray = jsonObject.getJSONArray(eventType); existArray.put(eventObject); } else { JSONArray newArray = new JSONArray(); newArray.put(0, eventObject); jsonObject.put(eventType, newArray); } if (model.idList.size() == 50) { //?,?? model.data = jsonObject.toString(); group.add(model); model = new MessageModel(); jsonObject = new JSONObject(); continue; } } cursor.close(); //?10????\n? if (model.idList.size() != 0) { model.data = jsonObject.toString(); group.add(model); } } catch (Exception e) { e.printStackTrace(); } return group; }
From source file:com.googlecode.android_scripting.facade.SmsFacade.java
@Rpc(description = "Returns message attributes.") public JSONObject smsGetMessageById(@RpcParameter(name = "id", description = "message ID") Integer id, @RpcParameter(name = "attributes") @RpcOptional JSONArray attributes) throws JSONException { JSONObject result = new JSONObject(); Uri uri = buildMessageUri(id);// w w w . ja v a 2 s . c o m String[] columns; if (attributes == null || attributes.length() == 0) { // In case no attributes are specified we set the default ones. columns = new String[] { "_id", "address", "date", "body", "read" }; } else { // Convert selected attributes list into usable string list. columns = new String[attributes.length()]; for (int i = 0; i < attributes.length(); i++) { columns[i] = attributes.getString(i); } } Cursor cursor = mContentResolver.query(uri, columns, null, null, null); if (cursor != null) { cursor.moveToFirst(); for (int i = 0; i < columns.length; i++) { result.put(columns[i], cursor.getString(i)); } cursor.close(); } else { result = null; } return result; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSessionsHandler.java
private static boolean isSessionUpdated(Uri uri, JSONObject session, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null); try {//from w w w. j a va 2 s . c o m if (!cursor.moveToFirst()) return false; final String curTitle = cursor.getString(SessionsQuery.TITLE).toLowerCase().trim(); final String curSummary = cursor.getString(SessionsQuery.SUMMARY).toLowerCase().trim(); final String curExperience = cursor.getString(SessionsQuery.EXPERIENCE).toLowerCase().trim(); final String curType = cursor.getString(SessionsQuery.TYPE).toLowerCase().trim(); final String newTitle = session.getString("title").toLowerCase().trim(); final String newSummary = session.getString("summary").toLowerCase().trim(); final String newExperience = session.getString("experience").toLowerCase().trim(); final String newType = session.getString("type").toLowerCase().trim(); return (!curTitle.equals(newTitle) || !curSummary.equals(newSummary) || !curExperience.equals(newExperience) || !curType.equals(newType)); } finally { cursor.close(); } }
From source file:com.googlecode.android_scripting.facade.SmsFacade.java
@Rpc(description = "Returns a List of all possible message attributes.") public List<String> smsGetAttributes() { List<String> result = new ArrayList<String>(); Cursor cursor = mContentResolver.query(Uri.parse("content://sms"), null, null, null, null); if (cursor != null) { String[] columns = cursor.getColumnNames(); for (int i = 0; i < columns.length; i++) { result.add(columns[i]);/*from www. j a v a 2 s . co m*/ } cursor.close(); } else { result = null; } return result; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSpeakersHandler.java
private static boolean isSpeakerUpdated(Uri uri, JSONObject speaker, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null); try {/*from w ww .j a va 2 s .c o m*/ if (!cursor.moveToFirst()) return false; final String curFirstName = cursor.getString(SpeakersQuery.FIRST_NAME).toLowerCase().trim(); final String curLastName = cursor.getString(SpeakersQuery.LAST_NAME).toLowerCase().trim(); final String curBio = cursor.getString(SpeakersQuery.BIO).toLowerCase().trim(); final String curCompany = cursor.getString(SpeakersQuery.COMPANY).toLowerCase().trim(); final String newFirstName = speaker.has("firstName") ? speaker.getString("firstName").toLowerCase().trim() : curFirstName; final String newLastName = speaker.has("lastName") ? speaker.getString("lastName").toLowerCase().trim() : curLastName; final String newBio = speaker.has("bio") ? speaker.getString("bio").toLowerCase().trim() : curBio; final String newCompany = speaker.has("company") ? speaker.getString("company").toLowerCase().trim() : curCompany; return (!curFirstName.equals(newFirstName) || !curLastName.equals(newLastName) || !curBio.equals(newBio) || !curCompany.equals(newCompany)); } finally { cursor.close(); } }
From source file:curso.android.DAO.PerguntaDAO.java
public static Pergunta getPerguntaById(Pergunta p) { Cursor cursor = null; try {//from w w w . j a va2s .c o m cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE ask_id = " + p.getAsk_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nomeIndex = cursor.getColumnIndex("user_nome"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nomeIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); return ask; } while (!cursor.isAfterLast()); } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.googlecode.android_scripting.facade.ContactsFacade.java
@Rpc(description = "Returns a List of all contact IDs.") public List<Integer> contactsGetIds() { List<Integer> result = new ArrayList<Integer>(); String[] columns = { "_id" }; Cursor cursor = mContentResolver.query(CONTACTS_URI, columns, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { result.add(cursor.getInt(0)); }/*from ww w .j a va 2s .c o m*/ cursor.close(); } return result; }
From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java
public void setCurrentServerProfile(long id) { Cursor cursor = queryServerProfile(id); if (cursor != null) { try {//w w w .ja v a 2s .c o m if (cursor.getCount() > 0) { cursor.moveToPosition(0); setCurrentServerProfile(cursor); } } finally { cursor.close(); } } }
From source file:com.samknows.measurement.storage.TestResultDataSource.java
private List<TestResult> getTestResults(String selection, String limit) { List<TestResult> ret = new ArrayList<TestResult>(); Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, SKSQLiteHelper.TABLE_TESTRESULT_ALLCOLUMNS, selection, null, null, null, order, limit); cursor.moveToFirst();//www. j a v a 2 s. co m while (!cursor.isAfterLast()) { ret.add(cursorToTestResult(cursor)); cursor.moveToNext(); } cursor.close(); return ret; }
From source file:com.seneca.android.senfitbeta.DbHelper.java
public boolean getUser(String email, String pass) { String selectQuery = "select * from " + USER_TABLE + " where " + COLUMN_EMAIL + " = " + "'" + email + "'" + " and " + COLUMN_PASS + " = " + "'" + pass + "'"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); cursor.moveToFirst();//from www .j a va 2s . com if (cursor.getCount() > 0) { return true; } cursor.close(); db.close(); return false; }