List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.digitalcampus.oppia.application.DbHelper.java
public long getUserId(String username) { String s = USER_C_USERNAME + "=? "; String[] args = new String[] { username }; Cursor c = db.query(USER_TABLE, null, s, args, null, null, null); c.moveToFirst();//from w ww .j av a 2 s . c o m long userId = -1; while (c.isAfterLast() == false) { userId = c.getLong(c.getColumnIndex(USER_C_ID)); c.moveToNext(); } c.close(); return userId; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public User getUser(long userId) throws UserNotFoundException { String s = USER_C_ID + "=? "; String[] args = new String[] { String.valueOf(userId) }; Cursor c = db.query(USER_TABLE, null, s, args, null, null, null); c.moveToFirst();//from w w w . jav a2s .co m User u = null; while (c.isAfterLast() == false) { u = new User(); u.setUserId(c.getLong(c.getColumnIndex(USER_C_ID))); u.setApiKey(c.getString(c.getColumnIndex(USER_C_APIKEY))); u.setUsername(c.getString(c.getColumnIndex(USER_C_USERNAME))); u.setFirstname(c.getString(c.getColumnIndex(USER_C_FIRSTNAME))); u.setLastname(c.getString(c.getColumnIndex(USER_C_LASTNAME))); u.setPoints(c.getInt(c.getColumnIndex(USER_C_POINTS))); u.setBadges(c.getInt(c.getColumnIndex(USER_C_BADGES))); u.setPasswordEncrypted(c.getString(c.getColumnIndex(USER_C_PASSWORDENCRYPTED))); c.moveToNext(); } c.close(); if (u == null) { throw new UserNotFoundException(); } return u; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public User getUser(String userName) throws UserNotFoundException { String s = USER_C_USERNAME + "=? "; String[] args = new String[] { userName }; Cursor c = db.query(USER_TABLE, null, s, args, null, null, null); c.moveToFirst();// w ww . j a v a2 s.c o m User u = null; while (c.isAfterLast() == false) { u = new User(); u.setUserId(c.getLong(c.getColumnIndex(USER_C_ID))); u.setApiKey(c.getString(c.getColumnIndex(USER_C_APIKEY))); u.setUsername(c.getString(c.getColumnIndex(USER_C_USERNAME))); u.setFirstname(c.getString(c.getColumnIndex(USER_C_FIRSTNAME))); u.setLastname(c.getString(c.getColumnIndex(USER_C_LASTNAME))); u.setPoints(c.getInt(c.getColumnIndex(USER_C_POINTS))); u.setBadges(c.getInt(c.getColumnIndex(USER_C_BADGES))); u.setPasswordEncrypted(c.getString(c.getColumnIndex(USER_C_PASSWORDENCRYPTED))); c.moveToNext(); } c.close(); if (u == null) { throw new UserNotFoundException(); } return u; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Client getLastCreatedClient() { String s = CLIENT_C_ID + "= (SELECT MAX(" + CLIENT_C_ID + ") FROM" + CLIENT_TABLE + " )"; //String[] args = new String[] { Integer.toString(1) }; Cursor c = db.query(CLIENT_TABLE, null, s, null, null, null, null); c.moveToFirst();/*from w w w .j a v a 2s. c o m*/ Client client = new Client(); while (c.isAfterLast() == false) { client.setClientId(c.getInt(c.getColumnIndex(CLIENT_C_ID))); client.setClientName(c.getString(c.getColumnIndex(CLIENT_C_NAME))); client.setClientMobileNumber(c.getLong(c.getColumnIndex(CLIENT_C_MOBILENUMBER))); client.setClientGender(c.getString(c.getColumnIndex(CLIENT_C_GENDER))); client.setClientMaritalStatus(c.getString(c.getColumnIndex(CLIENT_C_MARITALSTATUS))); client.setClientAge(c.getInt(c.getColumnIndex(CLIENT_C_AGE))); client.setClientLifeStage(c.getString(c.getColumnIndex(CLIENT_C_LIFESTAGE))); client.setClientParity(c.getString(c.getColumnIndex(CLIENT_C_PARITY))); client.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_C_HEALTHWORKER))); client.setClientServerId(c.getLong(c.getColumnIndex(CLIENT_C_SERVER_ID))); client.setAgeYoungestChild(c.getInt(c.getColumnIndex(CLIENT_C_AGEYOUNGESTCHILD))); client.setHusbandName(c.getString(c.getColumnIndex(CLIENT_C_HUSBANDNAME))); client.setMethodName(c.getString(c.getColumnIndex(CLIENT_C_METHODNAME))); client.setAdaptedMethodName( ((c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] != null) ? (c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] : ""); c.moveToNext(); } c.close(); return client; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Client getClient(long clientID) { String s = CLIENT_C_ID + "=? "; String[] args = new String[] { Long.toString(clientID) }; Cursor c = db.query(CLIENT_TABLE, null, s, args, null, null, null); c.moveToFirst();//from www . j a va 2 s .co m Client client = new Client(); while (c.isAfterLast() == false) { client.setClientId(c.getInt(c.getColumnIndex(CLIENT_C_ID))); client.setClientName(c.getString(c.getColumnIndex(CLIENT_C_NAME))); client.setClientMobileNumber(c.getLong(c.getColumnIndex(CLIENT_C_MOBILENUMBER))); client.setClientGender(c.getString(c.getColumnIndex(CLIENT_C_GENDER))); client.setClientMaritalStatus(c.getString(c.getColumnIndex(CLIENT_C_MARITALSTATUS))); client.setClientAge(c.getInt(c.getColumnIndex(CLIENT_C_AGE))); client.setClientLifeStage(c.getString(c.getColumnIndex(CLIENT_C_LIFESTAGE))); client.setClientParity(c.getString(c.getColumnIndex(CLIENT_C_PARITY))); client.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_C_HEALTHWORKER))); client.setClientServerId(c.getLong(c.getColumnIndex(CLIENT_C_SERVER_ID))); client.setAgeYoungestChild(c.getInt(c.getColumnIndex(CLIENT_C_AGEYOUNGESTCHILD))); client.setHusbandName(c.getString(c.getColumnIndex(CLIENT_C_HUSBANDNAME))); client.setMethodName(c.getString(c.getColumnIndex(CLIENT_C_METHODNAME))); client.setAdaptedMethodName( ((c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] != null) ? (c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] : ""); c.moveToNext(); } c.close(); return client; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Client getServerClient(long clientServerID) { String s = CLIENT_C_SERVER_ID + "=? "; String[] args = new String[] { Long.toString(clientServerID) }; Cursor c = db.query(CLIENT_TABLE, null, s, args, null, null, null); c.moveToFirst();/* ww w . jav a 2 s .co m*/ Client client = new Client(); while (c.isAfterLast() == false) { client.setClientId(c.getInt(c.getColumnIndex(CLIENT_C_ID))); client.setClientName(c.getString(c.getColumnIndex(CLIENT_C_NAME))); client.setClientMobileNumber(c.getLong(c.getColumnIndex(CLIENT_C_MOBILENUMBER))); client.setClientGender(c.getString(c.getColumnIndex(CLIENT_C_GENDER))); client.setClientMaritalStatus(c.getString(c.getColumnIndex(CLIENT_C_MARITALSTATUS))); client.setClientAge(c.getInt(c.getColumnIndex(CLIENT_C_AGE))); client.setClientLifeStage(c.getString(c.getColumnIndex(CLIENT_C_LIFESTAGE))); client.setClientParity(c.getString(c.getColumnIndex(CLIENT_C_PARITY))); client.setHealthWorker(c.getString(c.getColumnIndex(CLIENT_C_HEALTHWORKER))); client.setClientServerId(c.getLong(c.getColumnIndex(CLIENT_C_SERVER_ID))); client.setAgeYoungestChild(c.getInt(c.getColumnIndex(CLIENT_C_AGEYOUNGESTCHILD))); client.setHusbandName(c.getString(c.getColumnIndex(CLIENT_C_HUSBANDNAME))); client.setMethodName(c.getString(c.getColumnIndex(CLIENT_C_METHODNAME))); client.setAdaptedMethodName( ((c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] != null) ? (c.getString(c.getColumnIndex(CLIENT_ADAPTED_METHOD_NAME))).split("_")[0] : ""); c.moveToNext(); } c.close(); return client; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<User> getAllUsers() { Cursor c = db.query(USER_TABLE, null, null, null, null, null, null); c.moveToFirst();/*www . ja v a2 s . c o m*/ ArrayList<User> users = new ArrayList<User>(); while (c.isAfterLast() == false) { User u = new User(); u.setUserId(c.getInt(c.getColumnIndex(USER_C_ID))); u.setApiKey(c.getString(c.getColumnIndex(USER_C_APIKEY))); u.setUsername(c.getString(c.getColumnIndex(USER_C_USERNAME))); u.setFirstname(c.getString(c.getColumnIndex(USER_C_FIRSTNAME))); u.setLastname(c.getString(c.getColumnIndex(USER_C_LASTNAME))); u.setPoints(c.getInt(c.getColumnIndex(USER_C_POINTS))); u.setBadges(c.getInt(c.getColumnIndex(USER_C_BADGES))); u.setPasswordEncrypted(c.getString(c.getColumnIndex(USER_C_PASSWORDENCRYPTED))); users.add(u); c.moveToNext(); } c.close(); return users; }
From source file:edu.stanford.mobisocial.dungbeetle.DBHelper.java
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion); if (oldVersion <= 23) { Log.w(TAG, "Schema too old to migrate, dropping all."); dropAll(db);/*from w w w. j a v a 2 s . com*/ onCreate(db); return; } if (oldVersion <= 24) { Log.w(TAG, "Adding columns 'presence' and 'status' to contact table."); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.STATUS + " TEXT"); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.PRESENCE + " INTEGER DEFAULT " + Presence.AVAILABLE); } if (oldVersion <= 25) { Log.w(TAG, "Adding columns 'presence' and 'status' to contact table."); db.execSQL("ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.FEED_NAME + " TEXT"); } if (oldVersion <= 26) { Log.w(TAG, "Adding column 'picture' to contact table."); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.PICTURE + " BLOB"); } if (oldVersion <= 27) { Log.w(TAG, "Adding column 'last_presence_time' to contact table."); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.LAST_PRESENCE_TIME + " INTEGER DEFAULT 0"); } if (oldVersion <= 28) { Log.w(TAG, "Adding column 'picture' to my_info table."); db.execSQL("ALTER TABLE " + MyInfo.TABLE + " ADD COLUMN " + MyInfo.PICTURE + " BLOB"); } if (oldVersion <= 29) { Log.w(TAG, "Adding column 'version' to group table."); db.execSQL("ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.VERSION + " INTEGER DEFAULT -1"); } if (oldVersion <= 30) { Log.w(TAG, "Adding column 'E' to object table."); db.execSQL("ALTER TABLE " + DbObject.TABLE + " ADD COLUMN " + DbObject.ENCODED + " BLOB"); createIndex(db, "INDEX", "objects_by_encoded", DbObject.TABLE, DbObject.ENCODED); } if (oldVersion <= 31) { Log.w(TAG, "Adding column 'child_feed' to object table."); db.execSQL("ALTER TABLE " + DbObject.TABLE + " ADD COLUMN " + DbObject.CHILD_FEED_NAME + " TEXT"); createIndex(db, "INDEX", "child_feeds", DbObject.TABLE, DbObject.CHILD_FEED_NAME); } if (oldVersion <= 32) { // Bug fix. Log.w(TAG, "Updating app state objects."); db.execSQL("UPDATE " + DbObject.TABLE + " SET " + DbObject.CHILD_FEED_NAME + " = NULL WHERE " + DbObject.CHILD_FEED_NAME + " = " + DbObject.FEED_NAME); } if (oldVersion <= 33) { Log.w(TAG, "Adding column 'nearby' to contact table."); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.NEARBY + " INTEGER DEFAULT 0"); } if (oldVersion <= 34) { Log.w(TAG, "Adding column 'secret' to contact table."); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.SHARED_SECRET + " BLOB"); } if (oldVersion <= 35) { Log.w(TAG, "Adding column 'last_updated' to group table."); db.execSQL("ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.LAST_UPDATED + " INTEGER"); } if (oldVersion <= 36) { // Can't easily drop columns, but 'update_id' and 'is_child_feed' are dead columns. Log.w(TAG, "Adding column 'parent_feed_id' to group table."); db.execSQL( "ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.PARENT_FEED_ID + " INTEGER DEFAULT -1"); Log.w(TAG, "Adding column 'last_object_id' to group table."); db.execSQL( "ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.LAST_OBJECT_ID + " INTEGER DEFAULT -1"); } if (oldVersion <= 37) { // Can't easily drop columns, but 'update_id' and 'is_child_feed' are dead columns. Log.w(TAG, "Adding column 'num_unread' to group table."); db.execSQL("ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.NUM_UNREAD + " INTEGER DEFAULT 0"); } if (oldVersion <= 38) { Log.w(TAG, "Adding column 'raw' to object table."); db.execSQL("ALTER TABLE " + DbObject.TABLE + " ADD COLUMN " + DbObject.RAW + " BLOB"); } // sadly, we have to do this again because incoming voice obj's were not being split! if (oldVersion <= 50) { Log.w(TAG, "Converting voice and picture objs to raw."); Log.w(TAG, "Converting objs to raw."); Cursor c = db.query(DbObject.TABLE, new String[] { DbObject._ID }, DbObject.TYPE + " = ? AND " + DbObject.RAW + " IS NULL", new String[] { PictureObj.TYPE }, null, null, null); ArrayList<Long> ids = new ArrayList<Long>(); if (c.moveToFirst()) do { ids.add(c.getLong(0)); } while (c.moveToNext()); c.close(); DbEntryHandler dbh = DbObjects.forType(PictureObj.TYPE); for (Long id : ids) { c = db.query(DbObject.TABLE, new String[] { DbObject.JSON, DbObject.RAW }, DbObject._ID + " = ? ", new String[] { String.valueOf(id.longValue()) }, null, null, null); if (c.moveToFirst()) try { String json = c.getString(0); byte[] raw = c.getBlob(1); c.close(); if (raw == null) { Pair<JSONObject, byte[]> p = dbh.splitRaw(new JSONObject(json)); if (p != null) { json = p.first.toString(); raw = p.second; updateJsonAndRaw(db, id, json, raw); } } } catch (JSONException e) { } c.close(); } c = db.query(DbObject.TABLE, new String[] { DbObject._ID }, DbObject.TYPE + " = ? AND " + DbObject.RAW + " IS NULL", new String[] { VoiceObj.TYPE }, null, null, null); ids = new ArrayList<Long>(); if (c.moveToFirst()) do { ids.add(c.getLong(0)); } while (c.moveToNext()); c.close(); dbh = DbObjects.forType(VoiceObj.TYPE); for (Long id : ids) { c = db.query(DbObject.TABLE, new String[] { DbObject.JSON, DbObject.RAW }, DbObject._ID + " = ? ", new String[] { String.valueOf(id.longValue()) }, null, null, null); if (c.moveToFirst()) try { String json = c.getString(0); byte[] raw = c.getBlob(1); c.close(); if (raw == null) { Pair<JSONObject, byte[]> p = dbh.splitRaw(new JSONObject(json)); if (p != null) { json = p.first.toString(); raw = p.second; updateJsonAndRaw(db, id, json, raw); } } } catch (JSONException e) { } c.close(); } } if (oldVersion <= 40) { Log.w(TAG, "Adding column 'E' to object table."); db.execSQL("ALTER TABLE " + DbObject.TABLE + " ADD COLUMN " + DbObject.HASH + " INTEGER"); createIndex(db, "INDEX", "objects_by_hash", DbObject.TABLE, DbObject.HASH); db.execSQL("DROP INDEX objects_by_encoded"); db.delete(DbObject.TABLE, DbObject.TYPE + " = ?", new String[] { "profile" }); db.delete(DbObject.TABLE, DbObject.TYPE + " = ?", new String[] { "profilepicture" }); ContentValues cv = new ContentValues(); cv.putNull(DbObject.ENCODED); db.update(DbObject.TABLE, cv, null, null); } if (oldVersion <= 41) { db.execSQL("DROP INDEX objects_by_sequence_id"); db.execSQL("CREATE INDEX objects_by_sequence_id ON " + DbObject.TABLE + "(" + DbObject.CONTACT_ID + ", " + DbObject.FEED_NAME + ", " + DbObject.SEQUENCE_ID + ")"); } //secret to life, etc if (oldVersion <= 42) { db.execSQL("DROP INDEX objects_by_creator_id"); db.execSQL("CREATE INDEX objects_by_creator_id ON " + DbObject.TABLE + "(" + DbObject.CONTACT_ID + ", " + DbObject.SENT + ")"); } if (oldVersion <= 44) { // oops. db.execSQL("DROP TABLE IF EXISTS " + DbRelation.TABLE); createRelationBaseTable(db); } if (oldVersion <= 45) { db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.LAST_OBJECT_ID + " INTEGER"); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.LAST_UPDATED + " INTEGER"); db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.NUM_UNREAD + " INTEGER DEFAULT 0"); } if (oldVersion <= 46) { db.execSQL("ALTER TABLE " + DbObject.TABLE + " ADD COLUMN " + DbObject.DELETED + " INTEGER DEFAULT 0"); } if (oldVersion <= 47) { addRelationIndexes(db); } if (oldVersion <= 44) { createUserAttributesTable(db); } if (oldVersion <= 49) { if (oldVersion > 44) { db.execSQL("ALTER TABLE " + DbRelation.TABLE + " ADD COLUMN " + DbRelation.RELATION_TYPE + " TEXT"); createIndex(db, "INDEX", "relations_by_type", DbRelation.TABLE, DbRelation.RELATION_TYPE); } db.execSQL("UPDATE " + DbRelation.TABLE + " SET " + DbRelation.RELATION_TYPE + " = 'parent'"); } if (oldVersion <= 52) { Log.w(TAG, "Adding column 'about' to my_info table."); try { db.execSQL("ALTER TABLE " + MyInfo.TABLE + " ADD COLUMN " + MyInfo.ABOUT + " TEXT DEFAULT ''"); } catch (Exception e) { // because of bad update, we just ignore the duplicate column error } } if (oldVersion <= 53) { db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.HIDDEN + " INTEGER DEFAULT 0"); } if (oldVersion <= 55) { db.execSQL("ALTER TABLE " + DbObj.TABLE + " ADD COLUMN " + DbObj.COL_KEY_INT + " INTEGER"); } if (oldVersion <= 56) { db.execSQL("DROP INDEX attrs_by_contact_id"); createIndex(db, "INDEX", "attrs_by_contact_id", DbContactAttributes.TABLE, DbContactAttributes.CONTACT_ID); } if (oldVersion <= 57) { db.execSQL("ALTER TABLE " + DbObject.TABLE + " ADD COLUMN " + DbObject.LAST_MODIFIED_TIMESTAMP + " INTEGER"); db.execSQL("UPDATE " + DbObject.TABLE + " SET " + DbObject.LAST_MODIFIED_TIMESTAMP + " = " + DbObject.TIMESTAMP); } if (oldVersion <= 58) { db.execSQL("ALTER TABLE " + Group.TABLE + " ADD COLUMN " + Group.GROUP_TYPE + " TEXT DEFAULT 'group'"); db.execSQL("UPDATE " + Group.TABLE + " SET " + Group.GROUP_TYPE + " = 'group'"); } if (oldVersion <= 59) { createIndex(db, "INDEX", "objects_last_modified", DbObject.TABLE, DbObject.LAST_MODIFIED_TIMESTAMP); } if (oldVersion <= 60) { db.execSQL("ALTER TABLE " + Contact.TABLE + " ADD COLUMN " + Contact.PUBLIC_KEY_HASH_64 + " INTEGER DEFAULT 0"); createIndex(db, "INDEX", "contacts_by_pkp", Contact.TABLE, Contact.PUBLIC_KEY_HASH_64); Cursor peeps = db .rawQuery("SELECT " + Contact._ID + "," + Contact.PUBLIC_KEY + " FROM " + Contact.TABLE, null); peeps.moveToFirst(); while (!peeps.isAfterLast()) { db.execSQL("UPDATE " + Contact.TABLE + " SET " + Contact.PUBLIC_KEY_HASH_64 + " = " + hashPublicKey(peeps.getBlob(1)) + " WHERE " + Contact._ID + " = " + peeps.getLong(0)); peeps.moveToNext(); } peeps.close(); } db.setVersion(VERSION); }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public Payload getUnsentTrackers(long userId) { String s = TRACKER_LOG_C_SUBMITTED + "=? AND " + TRACKER_LOG_C_USERID + "=? "; String[] args = new String[] { "0", String.valueOf(userId) }; Cursor c = db.query(TRACKER_LOG_TABLE, null, s, args, null, null, null); c.moveToFirst();// w ww. j av a2 s.co m ArrayList<Object> sl = new ArrayList<Object>(); while (c.isAfterLast() == false) { TrackerLog so = new TrackerLog(); so.setId(c.getLong(c.getColumnIndex(TRACKER_LOG_C_ID))); so.setDigest(c.getString(c.getColumnIndex(TRACKER_LOG_C_ACTIVITYDIGEST))); String content = ""; try { JSONObject json = new JSONObject(); json.put("data", c.getString(c.getColumnIndex(TRACKER_LOG_C_DATA))); json.put("tracker_date", c.getString(c.getColumnIndex(TRACKER_LOG_C_DATETIME))); json.put("digest", c.getString(c.getColumnIndex(TRACKER_LOG_C_ACTIVITYDIGEST))); json.put("completed", c.getInt(c.getColumnIndex(TRACKER_LOG_C_COMPLETED))); Course m = this.getCourse(c.getLong(c.getColumnIndex(TRACKER_LOG_C_COURSEID)), userId); if (m != null) { json.put("course", m.getShortname()); } content = json.toString(); } catch (JSONException e) { Mint.logException(e); e.printStackTrace(); } so.setContent(content); sl.add(so); c.moveToNext(); } Payload p = new Payload(sl); c.close(); return p; }