List of usage examples for android.database Cursor getCount
int getCount();
From source file:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java
@Override public AutoSelectSet getAutoSelect() { AutoSelectSet autoSelectSet = new AutoSelectSet(); SQLiteDatabase database = this.database.openDatabase(false); Cursor query = this.database.queryWithLoginSetKey(database, DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME); Assert.isTrue(query.getCount() <= 1, "More than one auto-select entry for " + this.database.getLoginSetKeyForTable() + "."); int indexEnabled = query.getColumnIndex(DatabaseAutoSelectConstants.ENABLED); int indexType = query.getColumnIndex(DatabaseAutoSelectConstants.TYPE); int indexValue = query.getColumnIndex(DatabaseAutoSelectConstants.VALUE); while (query.moveToNext()) { boolean enabled = query.getInt(indexEnabled) > 0; String type = query.getString(indexType); int value = query.getInt(indexValue); autoSelectSet.setEnabled(enabled); autoSelectSet.setAutoSelectType(type); autoSelectSet.setAutoSelectValue(value); }// ww w . jav a 2 s . co m query.close(); this.database.closeDatabase(database); return autoSelectSet; }
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
private boolean doesTableExists(Class<?> clazz) { final String query = "SELECT DISTINCT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = ?"; Cursor cursor = db.rawQuery(query, new String[] { SQLBuilder.getTableName(clazz) }); boolean exists = cursor.getCount() == 1; cursor.close();/*from www. j a v a2 s . co m*/ return exists; }
From source file:DictionaryDatabase.java
public long findWordID(String word) { long returnVal = -1; SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery("SELECT _id FROM " + TABLE_DICTIONARY + " WHERE " + FIELD_WORD + " = ?", new String[] { word }); Log.i("findWordID", "getCount()=" + cursor.getCount()); if (cursor.getCount() == 1) { cursor.moveToFirst();/*from ww w . j a v a 2s .c o m*/ returnVal = cursor.getInt(0); } return returnVal; }
From source file:edu.pdx.cecs.orcycle.Uploader.java
private boolean SendAllSegments() { boolean result = true; Vector<Long> unsentSegmentIds = new Vector<Long>(); mDb.openReadOnly();/* ww w .j av a 2 s . c o m*/ try { Cursor cursor = mDb.fetchUnsentSegmentIds(); try { if (cursor != null && cursor.getCount() > 0) { // pd.setMessage("Sent. You have previously unsent notes; submitting those now."); while (!cursor.isAfterLast()) { unsentSegmentIds.add(Long.valueOf(cursor.getLong(0))); cursor.moveToNext(); } } } finally { cursor.close(); } } finally { mDb.close(); } for (Long segmentId : unsentSegmentIds) { result &= uploadOneSegment(segmentId); } return result; }
From source file:org.francho.apps.zgzpolen.service.PollenService.java
/** * is the database udpdated?//from www.j a v a 2s . c o m * * @return */ private boolean isUpdated() { Cursor c = getContentResolver().query(Pollen.getPollenUri(), null, null, null, null); try { if (c.getCount() < 1) { return false; } } finally { c.close(); } final SharedPreferences prefs = getSharedPreferences(POLLEN_SERVICE_PREFS, Context.MODE_PRIVATE); long lastTimeStamp = prefs.getLong(PREF_POLLEN_DATE, 0); Log.d(TAG, "" + System.currentTimeMillis() + " " + lastTimeStamp + ":" + (System.currentTimeMillis() - lastTimeStamp)); return DateUtils.isToday(lastTimeStamp); }
From source file:com.example.android.myargmenuplanner.data.LoadMenu.java
@Override protected String[] doInBackground(String... params) { Uri mUri = MenuEntry.CONTENT_URI; Cursor mCursor = mContext.getContentResolver().query(mUri, null, null, null, null); if (mCursor.getCount() == 0) { int shift = 0; DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); String sDate = df.format(cal.getTime()); int dayofweek = cal.get(Calendar.DAY_OF_WEEK); Log.i(LOG_TAG, "Init Date: " + date); Vector<ContentValues> cVVector = new Vector<ContentValues>(14 - dayofweek); for (int i = dayofweek; i <= 14; i++) { ContentValues values = new ContentValues(); values.put(MenuEntry.COLUMN_DATE, sDate); values.put(MenuEntry.COLUMN_LUNCH, "Empty"); values.put(MenuEntry.COLUMN_ID_LUNCH, 0); values.put(MenuEntry.COLUMN_DINNER, "Empty"); values.put(MenuEntry.COLUMN_ID_DINNER, 0); cVVector.add(values);//from w w w .j ava 2s .co m cal.add(Calendar.DATE, 1); sDate = df.format(cal.getTime()); // Log.i(LOG_TAG, "Day of the week: "+cal.get(Calendar.DAY_OF_WEEK)); // Log.i(LOG_TAG, "Date: "+date); } int inserted = 0; // // add to database Log.i(LOG_TAG, "Creando registros en base de datos. Tabla Menu "); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(MenuEntry.CONTENT_URI, cvArray); Log.i(LOG_TAG, "Registros nuevos creados en Tabla Menu: " + inserted); } } else { //ya tengo registros, tengo que fijarme las fechas DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); String dateNow = df.format(cal.getTime()); int dayofweek = cal.get(Calendar.DAY_OF_WEEK); String date = ""; String week = ""; while (mCursor.moveToNext()) { date = mCursor.getString(1); if (dateNow.equals(date)) { } } } return null; }
From source file:cn.loveapple.client.android.database.impl.TemperatureDaoImpl.java
/** * //from w w w . j a v a2 s .c om * @param cursor * @return */ private TemperatureEntity getTemperatureEntity(Cursor cursor) { if (cursor.getCount() < 1) { return null; } TemperatureEntity result = new TemperatureEntity(); result.setDate(cursor.getString(0)); result.setTimestamp(cursor.getString(1)); result.setTemperature(cursor.getDouble(2)); result.setCoitusFlg(cursor.getString(3)); result.setMenstruationFlg(cursor.getString(4)); result.setDysmenorrheaFlg(cursor.getString(5)); result.setLeukorrhea(cursor.getString(6)); result.setMenstruationLevel(cursor.getString(7)); result.setMenstruationCycle(cursor.getInt(8)); return result; }
From source file:com.general.vvvv.cmr.MySplash.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); dbLogin = new DbLogin(MySplash.this, DbLogin.DB_NAME, null, DbLogin.DB_VERSION); db_read = dbLogin.getReadableDatabase(); db_write = dbLogin.getWritableDatabase(); String identifier = null;/*from w w w . j a va 2 s. c o m*/ TelephonyManager tm = (TelephonyManager) this.getSystemService(this.TELEPHONY_SERVICE); if (tm != null) { identifier = tm.getDeviceId(); } if (identifier == null || identifier.length() == 0) { identifier = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); } Toast.makeText(MySplash.this, "Your IMEI no:" + identifier, Toast.LENGTH_LONG).show(); System.out.println("IMEI no:" + identifier); Log.d("IMEI or Android id:", identifier); Cursor cursor = dbLogin.getData(db_read); if (cursor.getCount() > 0) { Intent intent = new Intent(MySplash.this, MyLogin.class); startActivity(intent); } else { Toast.makeText(MySplash.this, "Login database is empty", Toast.LENGTH_SHORT).show(); if (identifier != null) { new AsynchLogin().execute(identifier); } else { Toast.makeText(MySplash.this, "Unable to find your IMEI no.", Toast.LENGTH_LONG).show(); } } }
From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java
@Override protected void onHandleIntent(Intent intent) { Context context = getApplicationContext(); Bundle bundle = intent.getExtras();//w w w .j a va 2 s .c o m String query = bundle.getString(QUERY); int instances_id = bundle.getInt(INSTANCES_ID); int accounts_id = bundle.getInt(ACCOUNTS_ID, -1); boolean forceReload = bundle.getBoolean(FORCE_RELOAD); ArrayList<Product> products = null; if (!forceReload) { String selection = Products.Columns.INSTANCES_ID.getName() + "=" + instances_id + " AND " + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id; String sortOrder = Products.Columns.NAME.getName(); Cursor cursor = context.getContentResolver().query(Products.CONTENT_URI, Products.PROJECTION, selection, null, sortOrder); if (cursor.getCount() > 0) { products = new ArrayList<Product>(); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); Product product = Product.toProduct(cursor); products.add(product); } sendResult(intent, products); return; } cursor.close(); } String jsonString = NetworkUtils.readJson(query).result; products = parse(jsonString); sendResult(intent, products); // Delete old products for instance String selection = Products.Columns.INSTANCES_ID + "=" + instances_id + " AND " + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id; context.getContentResolver().delete(Products.CONTENT_URI, selection, null); context.getContentResolver().bulkInsert(Products.CONTENT_URI, Product.toContentValues(products, instances_id, accounts_id)); }