List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult deleteSMS(JSONObject filter, CallbackContext callbackContext) { Log.d(LOGTAG, ACTION_DELETE_SMS);//from www . ja v a2 s.c o m String uri_filter = filter.has(BOX) ? filter.optString(BOX) : "inbox"; int fread = filter.has(READ) ? filter.optInt(READ) : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString(ADDRESS); String fcontent = filter.optString(BODY); Activity ctx = this.cordova.getActivity(); int n = 0; try { Uri uri = Uri.parse((SMS_URI_ALL + uri_filter)); Cursor cur = ctx.getContentResolver().query(uri, (String[]) null, "", (String[]) null, null); while (cur.moveToNext()) { int id = cur.getInt(cur.getColumnIndex("_id")); boolean matchId = fid > -1 && fid == id; int read = cur.getInt(cur.getColumnIndex(READ)); boolean matchRead = fread > -1 && fread == read; String address = cur.getString(cur.getColumnIndex(ADDRESS)).trim(); boolean matchAddr = faddress.length() > 0 && address.equals(faddress); String body = cur.getString(cur.getColumnIndex(BODY)).trim(); boolean matchContent = fcontent.length() > 0 && body.equals(fcontent); if (!matchId && !matchRead && !matchAddr && !matchContent) continue; ctx.getContentResolver().delete(uri, "_id=" + id, (String[]) null); ++n; } callbackContext.success(n); } catch (Exception e) { callbackContext.error(e.toString()); } return null; }
From source file:com.helpshift.kvstore.SharedPreferencesImpl.java
private void updateMapWithValueByKey(String key) { Cursor cursor = null; try {/* w ww .j a v a2s . c om*/ cursor = mSqLiteDatabase.query(mPreferenceName, PreferencesContent.PREFERENCES_PROJECTION, PreferencesContent.SELECTION_VAI_KEY, new String[] { key }, null, null, null); if (cursor != null && cursor.moveToNext()) { parseSettingCursor(cursor); } } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.helpshift.kvstore.SharedPreferencesImpl.java
private boolean checkIfKeyAlreadyExists(String key) { Cursor cursor = null; try {/*from w w w.j a v a 2 s .com*/ cursor = mSqLiteDatabase.query(mPreferenceName, PreferencesContent.PREFERENCES_PROJECTION, PreferencesContent.SELECTION_VAI_KEY, new String[] { key }, null, null, null); if (cursor != null && cursor.moveToNext()) { return true; } } finally { if (cursor != null) { cursor.close(); } } return false; }
From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java
public List<LabelDto> getBookmarkLabels(BookmarkDto bookmark) { String sql = "SELECT label._id, label.name " + "FROM label " + "JOIN bookmark_label ON (label._id = bookmark_label.label_id) " + "JOIN bookmark ON (bookmark_label.bookmark_id = bookmark._id) " + "WHERE bookmark._id = ?"; List<LabelDto> labels = new ArrayList<LabelDto>(); String[] args = new String[] { bookmark.getId().toString() }; Cursor c = db.rawQuery(sql, args); try {/*from www. j av a 2s . c om*/ if (c.moveToFirst()) { while (!c.isAfterLast()) { LabelDto label = getLabelDto(c); labels.add(label); c.moveToNext(); } } } finally { c.close(); } return labels; }
From source file:it.ms.theing.loquitur.functions.Storage.java
public Vector<Pair<String[], String>> loadCache(String name) { Cursor cursor = dataBase.rawQuery("select * from alias where genre=?", new String[] { name }); cursor.moveToFirst();/*from w ww. java2 s . c om*/ Vector<Pair<String[], String>> ja = new Vector<Pair<String[], String>>(); while (!cursor.isAfterLast()) { String[] sv = cursor.getString(1).split("\'| "); String s = cursor.getString(2); Pair<String[], String> p = Pair.create(sv, s); ja.add(p); cursor.moveToNext(); } return ja; }
From source file:com.HskPackage.HskNamespace.HSK1ProjectActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*ww w . j a v a 2 s. com*/ final TextView codice = (TextView) findViewById(R.id.codice); final Button carattere = (Button) findViewById(R.id.carattere); final TextView fonetica = (TextView) findViewById(R.id.fonetica); final TextView significato = (TextView) findViewById(R.id.significato); /*********** CREATE A DATABASE ******************************************************/ final String DB_PATH = "/data/data/com.HskPackage.HskNamespace/"; final String DB_NAME = "chineseX.db"; SQLiteDatabase db = null; boolean exists = (new File(DB_PATH + DB_NAME)).exists(); AssetManager assetManager = getAssets(); if (!exists) { try { InputStream in = assetManager.open(DB_NAME); OutputStream out = new FileOutputStream(DB_PATH + DB_NAME); copyFile(in, out); in.close(); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } File dbFile = new File(DB_PATH + DB_NAME); db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); } else { File dbFile = new File(DB_PATH + DB_NAME); db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); } final Integer valore = 1; //String query = "SELECT * FROM chineseX"; String query = "SELECT * FROM chineseX where _id = ? "; String[] selectionArgs = { valore.toString() }; Cursor cursor = null; cursor = db.rawQuery(query, selectionArgs); //cursor = db.rawQuery(query, null); int count = cursor.getCount(); System.out.println("il numero di dati contenuti nel database " + count); while (cursor.moveToNext()) { long id = cursor.getLong(0); System.out.println("Questo l'ID ====>" + id); scodice = cursor.getString(1); codice.setText(scodice); System.out.println("Questo il codice ====>" + codice); scarattere = cursor.getString(2); carattere.setText(scarattere); System.out.println("Questo il carattere ====>" + carattere); sfonetica = cursor.getString(3); fonetica.setText(sfonetica); System.out.println("Questo il fonet ====>" + fonetica); ssignificato = cursor.getString(4); significato.setText("?? - Visualizza Significato"); System.out.println("Questo il carattere ====>" + ssignificato); } //fine db.close(); //set up sound button final MediaPlayer mpButtonClick = MediaPlayer.create(this, R.raw.hangout_ringtone); //final MediaPlayer chword001 = MediaPlayer.create(this, R.raw.ayi001); /* // set up change Images miaImmagine = (ImageView) findViewById(R.id.Image); // dichiaro l'oggetto image view miaImmagine.setImageResource(R.drawable.uno1); // associo l'immagine alla figura uno // setto un evento di cattura del click sull'immagine miaImmagine.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { //chword001.start(); } }) ; */ final Intent first = new Intent(this, Activity2.class); final Intent immagine = new Intent(this, Activity3.class); /* * Un intent definito nella javadoc della classe android.content.Intent come una * "descrizione astratta dell'operazione da eseguire". * E un intent ESPLICITO perch cosciamo il destinatario. * Passiamo come parametri il context attuale ed la classe che identifica l'activity di destinazione. * E' importante che la classe sia registrata nell'AndroidManifest.xml * */ Button b = (Button) this.findViewById(R.id.button1); Button b2 = (Button) this.findViewById(R.id.button2); Button b3 = (Button) this.findViewById(R.id.carattere); b.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 1; valore = valore + 1; if (valore >= 153) { valore = 1; } System.out.println("AVANTI" + valore); first.putExtra("AVANTI", valore); startActivity(first); finish(); mpButtonClick.start(); } }); b2.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 153; System.out.println("AVANTI == >" + valore); first.putExtra("AVANTI", valore); startActivity(first); finish(); mpButtonClick.start(); } }); b3.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Integer valore = 1; System.out.println("AVANTI" + valore); immagine.putExtra("AVANTI", valore); startActivity(immagine); finish(); mpButtonClick.start(); } }); }
From source file:com.android.unit_tests.DbSSLSessionCacheTest.java
@LargeTest public void testExpire() throws Exception { DatabaseHelper helper = new DatabaseHelper(getContext()); // clean up/*w ww . j a va 2 s. c o m*/ DbSSLSessionCache cache = new DbSSLSessionCache(helper); cache.clear(); long t0 = System.currentTimeMillis(); for (int i = 0; i < DbSSLSessionCache.MAX_CACHE_SIZE + 2; i++) { final int port = i; cache.putSessionData(new MockSession() { public String getPeerHost() { return "test.host.com"; } public int getPeerPort() { return port; } }, new byte[256]); } long t1 = System.currentTimeMillis(); System.err.println("Time to insert " + (DbSSLSessionCache.MAX_CACHE_SIZE + 2) + " " + (t1 - t0)); // first entry should have port 1. Cursor query = helper.getReadableDatabase().query(DbSSLSessionCache.SSL_CACHE_TABLE, new String[] { "hostport", "session" }, null, null, null, null, null); int cnt = query.getCount(); assertTrue(query.moveToFirst()); // one row inserted String hostPort = query.getString(0); assertEquals("test.host.com:2", hostPort); while (query.moveToNext()) { hostPort = query.getString(0); String session = query.getString(1); } long t2 = System.currentTimeMillis(); System.err.println("Time to load " + cnt + " " + (t2 - t1)); query.close(); }
From source file:at.bitfire.ical4android.AndroidTaskList.java
protected AndroidTask[] queryTasks(String where, String[] whereArgs) throws CalendarStorageException { where = (where == null ? "" : "(" + where + ") AND ") + Tasks.LIST_ID + "=?"; whereArgs = ArrayUtils.add(whereArgs, String.valueOf(id)); @Cleanup Cursor cursor = null;/*from ww w. ja v a2s . c om*/ try { cursor = provider.client.query(syncAdapterURI(provider.tasksUri()), taskBaseInfoColumns(), where, whereArgs, null); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query calendar events", e); } List<AndroidTask> tasks = new LinkedList<>(); while (cursor != null && cursor.moveToNext()) { ContentValues baseInfo = new ContentValues(cursor.getColumnCount()); DatabaseUtils.cursorRowToContentValues(cursor, baseInfo); tasks.add(taskFactory.newInstance(this, cursor.getLong(0), baseInfo)); } return tasks.toArray(taskFactory.newArray(tasks.size())); }
From source file:gov.wa.wsdot.android.wsdot.service.CamerasSyncService.java
/** * Check the camera table for any starred entries. If we find some, save them * to a list so we can re-star those cameras after we flush the database. *///from w w w.ja va2s. c om private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(Cameras.CONTENT_URI, new String[] { Cameras.CAMERA_ID }, Cameras.CAMERA_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void addExtensionsToContactEntry(ContentResolver cr, long personId, ContactEntry entry) throws ParseException { Cursor c = cr.query(Extensions.CONTENT_URI, null, "person=" + personId, null, null); try {/*from w ww. j a v a 2s .c o m*/ JSONObject jsonObject = new JSONObject(); int nameIndex = c.getColumnIndexOrThrow(Extensions.NAME); int valueIndex = c.getColumnIndexOrThrow(Extensions.VALUE); if (c.getCount() == 0) return; while (c.moveToNext()) { try { jsonObject.put(c.getString(nameIndex), c.getString(valueIndex)); } catch (JSONException e) { throw new ParseException("bad key or value", e); } } ExtendedProperty extendedProperty = new ExtendedProperty(); extendedProperty.setName("android"); final String jsonString = jsonObject.toString(); if (jsonString == null) { throw new ParseException( "unable to convert cursor into a JSON string, " + DatabaseUtils.dumpCursorToString(c)); } extendedProperty.setXmlBlob(jsonString); entry.addExtendedProperty(extendedProperty); } finally { if (c != null) c.close(); } }