List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:com.ahmed.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/* w w w . ja va2 s . co m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ public long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI Cursor query = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (query != null && query.moveToFirst()) { return query.getLong(query.getColumnIndex(WeatherContract.LocationEntry._ID)); } ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri inserted = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); return ContentUris.parseId(inserted); }
From source file:com.msrproduction.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from w w w. j a v a 2 s .c om*/ * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToNext()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:com.example.joel.sunshine.FetchWeatherTask.java
private long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOC_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else {//from w w w .ja v a 2s .c o m Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOC_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_LAT, lat); locationValues.put(LocationEntry.COLUMN_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:emroxriprap.com.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city// www. j a v a2 s . c om * @param lon the longitude of the city * @return the row ID of the added location. */ public long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; //check to see if this location already exists Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
@Override protected Boolean doInBackground(Long... tripid) { // First, send the trip user asked for: Boolean result = true;//from w w w . j av a2s. co m if (tripid.length != 0) { result = uploadOneTrip(tripid[0]); } // Then, automatically try and send previously-completed trips // that were not sent successfully. Vector<Long> unsentTrips = new Vector<Long>(); mDb.openReadOnly(); Cursor cur = mDb.fetchUnsentTrips(); if (cur != null && cur.getCount() > 0) { // Reades all unsent trips while (!cur.isAfterLast()) { unsentTrips.add(Long.valueOf(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long trip : unsentTrips) { result &= uploadOneTrip(trip); } return result; }
From source file:org.opensmc.mytracks.cyclesmc.TripUploader.java
@Override protected Boolean doInBackground(Long... tripid) { // First, send the trip user asked for: Boolean result = uploadOneTrip(tripid[0]); // TODO: not always working? //Log.d("uploading trip", tripid[0].toString()); ////////////////////////////////////////////// // Then, automatically try and send previously-completed trips // that were not sent successfully. Vector<Long> unsentTrips = new Vector<Long>(); mDb.openReadOnly();/*from w w w . j a v a2 s . co m*/ Cursor cur = mDb.fetchUnsentTrips(); if (cur != null && cur.getCount() > 0) { //pd.setMessage("Sent. You have previously unsent trips; submitting those now."); //////////// //Log.d("previously unsent count", cur.getCount() + " previously unsent trips"); //////////// while (!cur.isAfterLast()) { unsentTrips.add(Long.valueOf(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long trip : unsentTrips) { result &= uploadOneTrip(trip); /////////////// //Log.d("uploading unsent trip", trip.toString()); /////////////// } return result; }
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public ArrayList<ImageMessage> getImageMessages(String chatId) { ArrayList<ImageMessage> messages = new ArrayList<>(); SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor c = db.query(chatId, new String[] { MessageHistoryContract.MessageEntry._ID }, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_TYPE + "=?", new String[] { MessageHistory.TYPE_IMAGE }, null, null, null); c.moveToFirst();//w ww . jav a 2 s . co m do { long messageId = c.getLong(0); MessageArrayContent mac = getMessage(chatId, messageId); if (mac instanceof ImageMessage) messages.add((ImageMessage) mac); } while (c.move(1)); c.close(); db.close(); return messages; }
From source file:com.example.conor.dotaapp.FetchMatchTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param steamAccountId Steam account id of the player. * @param heroId id of the player's hero * @param playerSlot the position of the player on the team * @return the row ID of the added location. *///from w w w . j a v a2 s .c om long addPlayer(String steamAccountId, int heroId, int playerSlot) { long steamId; // First, check if the location with this city name exists in the db Cursor playerCursor = mContext.getContentResolver().query(MatchContract.PlayerEntry.CONTENT_URI, new String[] { MatchContract.PlayerEntry._ID }, MatchContract.PlayerEntry.COLUMN_ACCOUNT_ID + " = ?", new String[] { steamAccountId }, null); if (playerCursor.moveToFirst()) { int steamIdIndex = playerCursor.getColumnIndex(MatchContract.PlayerEntry._ID); steamId = playerCursor.getLong(steamIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues playerValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. playerValues.put(MatchContract.PlayerEntry.COLUMN_ACCOUNT_ID, steamAccountId); playerValues.put(MatchContract.PlayerEntry.COLUMN_HERO_ID, heroId); playerValues.put(MatchContract.PlayerEntry.COLUMN_P_SLOT, playerSlot); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(MatchContract.PlayerEntry.CONTENT_URI, playerValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. steamId = ContentUris.parseId(insertedUri); } playerCursor.close(); return steamId; }
From source file:com.facebook.stetho.inspector.protocol.module.Database.java
/** * Flatten all columns and all rows of a cursor to a single array. The array cannot be * interpreted meaningfully without the number of columns. * * @param cursor//from w w w . j a va 2 s. co m * @param limit Maximum number of rows to process. * @return List of Java primitives matching the value type of each column. */ private List<Object> flattenRows(Cursor cursor, int limit) { Util.throwIfNot(limit >= 0); List<Object> flatList = new ArrayList<Object>(); final int numColumns = cursor.getColumnCount(); for (int row = 0; row < limit && cursor.moveToNext(); row++) { for (int column = 0; column < numColumns; column++) { switch (cursor.getType(column)) { case Cursor.FIELD_TYPE_NULL: flatList.add(null); break; case Cursor.FIELD_TYPE_INTEGER: flatList.add(cursor.getLong(column)); break; case Cursor.FIELD_TYPE_FLOAT: flatList.add(cursor.getDouble(column)); break; case Cursor.FIELD_TYPE_BLOB: flatList.add(cursor.getBlob(column)); break; case Cursor.FIELD_TYPE_STRING: default: flatList.add(cursor.getString(column)); break; } } } if (!cursor.isAfterLast()) { for (int column = 0; column < numColumns; column++) { flatList.add("{truncated}"); } } return flatList; }
From source file:com.example.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from ww w . jav a2s . c om * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI long locationId; Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (locationCursor.moveToFirst()) { int columnIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(columnIndex); } else { ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); return locationId; }