List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:com.odoo.addons.notes.models.NoteNote.java
public int tagCount(int tag_id) { NoteTag tags = new NoteTag(mContext, getUser()); String rel_table = getTableName() + "_" + tags.getTableName() + "_rel as rel "; StringBuffer query = new StringBuffer(); query.append("SELECT count(id) FROM "); query.append(getTableName() + " as notes "); query.append("LEFT JOIN " + rel_table); query.append("ON rel.note_note_id = notes." + OColumn.ROW_ID); query.append(" WHERE rel.note_tag_id = " + tag_id); query.append(" and notes._is_active = 'true' and trashed = '0'"); Cursor cr = executeQuery(query.toString(), null); if (cr.moveToFirst()) { return cr.getInt(0); }/*from www. j av a 2 s . co m*/ return 0; }
From source file:com.bourke.kitchentimer.utils.Utils.java
public static boolean exportCSV(Context context, Cursor cursor) { if (cursor.getCount() == 0) return true; // An array to hold the rows that will be written to the CSV file. final int rowLenght = FoodMetaData.COLUMNS.length - 1; String[] row = new String[rowLenght]; System.arraycopy(FoodMetaData.COLUMNS, 1, row, 0, rowLenght); CSVWriter writer = null;/* w ww . j a v a 2 s .c om*/ boolean success = false; try { writer = new CSVWriter(new FileWriter(Constants.CSV_FILE)); // Write descriptive headers. writer.writeNext(row); int nameIndex = cursor.getColumnIndex(FoodMetaData.NAME); int hoursIndex = cursor.getColumnIndex(FoodMetaData.HOURS); int minutesIndex = cursor.getColumnIndex(FoodMetaData.MINUTES); int secondsIndex = cursor.getColumnIndex(FoodMetaData.SECONDS); if (cursor.requery()) { while (cursor.moveToNext()) { row[0] = cursor.getString(nameIndex); row[1] = cursor.getInt(hoursIndex) + ""; row[2] = cursor.getInt(minutesIndex) + ""; row[3] = cursor.getInt(secondsIndex) + ""; // NOTE: writeNext() handles nulls in row[] gracefully. writer.writeNext(row); } } success = true; } catch (Exception ex) { Log.e("Utils", "exportCSV", ex); } finally { try { if (null != writer) writer.close(); } catch (IOException ex) { } } return success; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void banThread(String group, String clean_subject, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); // First, check if it already is on the banned_threads table (it could be with unbanned=1) Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_threads " + " WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject), null); if (c.getCount() > 0) { // Existed c.moveToFirst();/* w ww. j a v a 2 s .c om*/ dbwrite.execSQL("UPDATE banned_threads SET bandisabled=0 WHERE _id=" + c.getInt(0)); } else { // New troll goes down to the pit ContentValues cv = new ContentValues(); cv.put("subscribed_group_id", groupid); cv.put("bandisabled", 0); cv.put("clean_subject", clean_subject); dbwrite.insert("banned_threads", null, cv); } // Mark all the messages from the thread as read so they get cleaned later dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE subscribed_group_id=" + groupid + " AND clean_subject=" + esc(clean_subject)); c.close(); dbwrite.close(); db.close(); }
From source file:android.database.DatabaseUtils.java
/** * Reads a Integer out of a column in a Cursor and writes it to a ContentValues. * Adds nothing to the ContentValues if the column isn't present or if its value is null. * * @param cursor The cursor to read from * @param column The column to read/*from w ww . j a v a 2s . co m*/ * @param values The {@link ContentValues} to put the value into */ public static void cursorIntToContentValuesIfPresent(Cursor cursor, ContentValues values, String column) { final int index = cursor.getColumnIndexOrThrow(column); if (!cursor.isNull(index)) { values.put(column, cursor.getInt(index)); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Integer out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The INTEGER field to read * @param values The {@link ContentValues} to put the value into, with the field as the key * @param key The key to store the value with in the map *//*from w ww . j av a 2 s . co m*/ public static void cursorIntToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { values.put(key, cursor.getInt(colIndex)); } else { values.put(key, (Integer) null); } }
From source file:edu.pdx.cecs.orcycle.SegmentData.java
void populateDetails() { mDb.openReadOnly();/*w w w .ja v a2 s .c om*/ try { Cursor cursor = mDb.fetchSegment(segmentId); try { tripId = cursor.getLong(cursor.getColumnIndex("tripid")); rating = cursor.getInt(cursor.getColumnIndex("rating")); details = cursor.getString(cursor.getColumnIndex("details")); startIndex = cursor.getInt(cursor.getColumnIndex("startindex")); endIndex = cursor.getInt(cursor.getColumnIndex("endindex")); segmentStatus = cursor.getInt(cursor.getColumnIndex("status")); } finally { cursor.close(); } } finally { mDb.close(); } }
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 }); if (cursor.getCount() == 1) { cursor.moveToFirst();/*from ww w . j av a 2 s. com*/ returnVal = cursor.getInt(0); } return returnVal; }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferRecord.java
/** * Updates all the fields from database using the given Cursor. * * @param c A Cursor pointing to a transfer record. */// ww w . j a v a 2s . co m public void updateFromDB(Cursor c) { this.id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID)); this.mainUploadId = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_MAIN_UPLOAD_ID)); this.type = TransferType.getType(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_TYPE))); this.state = TransferState.getState(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE))); this.bucketName = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_BUCKET_NAME)); this.key = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_KEY)); this.versionId = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_VERSION_ID)); this.bytesTotal = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_TOTAL)); this.bytesCurrent = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_CURRENT)); this.speed = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_SPEED)); this.isRequesterPays = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_REQUESTER_PAYS)); this.isMultipart = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_MULTIPART)); this.isLastPart = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_LAST_PART)); this.isEncrypted = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_IS_ENCRYPTED)); this.partNumber = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_PART_NUM)); this.eTag = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_ETAG)); this.file = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE)); this.multipartId = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_MULTIPART_ID)); this.rangeStart = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_DATA_RANGE_START)); this.rangeLast = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_DATA_RANGE_LAST)); this.fileOffset = c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_FILE_OFFSET)); this.headerContentType = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_TYPE)); this.headerContentLanguage = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_LANGUAGE)); this.headerContentDisposition = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_DISPOSITION)); this.headerContentEncoding = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CONTENT_ENCODING)); this.headerCacheControl = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_CACHE_CONTROL)); this.headerExpire = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HEADER_EXPIRE)); this.userMetadata = JsonUtils .jsonToMap(c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_USER_METADATA))); this.expirationTimeRuleId = c .getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_EXPIRATION_TIME_RULE_ID)); this.httpExpires = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_HTTP_EXPIRES_DATE)); this.sseAlgorithm = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_SSE_ALGORITHM)); this.sseKMSKey = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_SSE_KMS_KEY)); this.md5 = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_CONTENT_MD5)); this.cannedAcl = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_CANNED_ACL)); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static Hashtable<String, Object> getHeaderRecordCatchedData(String group, long serverMsgNum, Context context) {/*from w ww . j a v a 2 s . c o m*/ int groupid = getGroupIdFromName(group, context); Hashtable<String, Object> result = null; DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Cursor c = dbread.rawQuery("SELECT _id, server_article_id, catched FROM headers WHERE subscribed_group_id=" + groupid + " AND server_article_number=" + serverMsgNum, null); if (c.getCount() == 1) { c.moveToFirst(); result = new Hashtable<String, Object>(3); result.put("id", c.getInt(0)); result.put("server_article_id", c.getString(1)); if (c.getInt(2) == 1) result.put("catched", true); else result.put("catched", false); } c.close(); dbread.close(); db.close(); return result; }
From source file:net.nordist.lloydproof.CorrectionStorage.java
public int count() { openReadDB();// w w w .j ava 2 s . c om Cursor cursor = readDB.query(TABLE_NAME, new String[] { "COUNT(1)" }, null, null, null, null, null); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getInt(0); } else { return 0; } }