Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

In this page you can find the example usage for android.database Cursor getInt.

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java

/** 
 * Check the travel border wait table for any starred entries. If we find some, save them
 * to a list so we can re-star those after we flush the database.
 *///from  w ww.  j  ava2  s .com
private List<Integer> getStarred() {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    List<Integer> starred = new ArrayList<Integer>();

    try {
        cursor = resolver.query(BorderWait.CONTENT_URI, new String[] { BorderWait.BORDER_WAIT_ID },
                BorderWait.BORDER_WAIT_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:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Gets ID of a person by UUID.//from  w  w  w .j  a v a2  s  . c  o  m
  * @param uuid UUID
 * @return Person ID
 */
private int getPersonIDByUUID(String uuid) {
    int result = -1;
    String query = "SELECT pe.person_id FROM person pe WHERE pe.uuid = ?";
    Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid });
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        result = cursor.getInt(0);
    }
    cursor.close();
    return result;
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Gets ID of an encounter by UUID.//www . j  a v  a2 s  .  c o  m
  * @param uuid UUID
 * @return Encounter ID
 */
private int getEncounterIDByUUID(String uuid) {
    int result = -1;
    String query = "SELECT en.encounter_id FROM encounter en WHERE en.uuid = ?";
    Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid });
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        result = cursor.getInt(0);
    }
    cursor.close();
    return result;
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Gets ID of an observation by UUID./*ww w  .  ja v a  2  s . c o  m*/
  * @param uuid UUID
 * @return Observation ID
 */
private int getObsIDByUUID(String uuid) {
    int result = -1;
    String query = "SELECT o.obs_id FROM obs o WHERE o.uuid = ?";
    Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid });
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        result = cursor.getInt(0);
    }
    cursor.close();
    return result;
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Is patient row modified?//w w w  .  j  a v  a  2s.c om
  * @param id ID
 * @return -1 if new, 0 if not modified, 1 if modified
 */
private int isPatientDirty(int id) {
    int dirty = -1;
    String query = "SELECT dirty FROM patient WHERE patient_id = ?;";
    Cursor cursor = mDatabase.rawQuery(query, new String[] { "" + id });
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        dirty = cursor.getInt(0);
    }
    cursor.close();
    return dirty;
}

From source file:de.fahrgemeinschaft.RideDetailsFragment.java

private boolean isReoccuring(Cursor ride) {
    return ride.getInt(COLUMNS.TYPE) == FahrgemeinschaftConnector.TYPE_OFFER_REOCCURING;
}

From source file:de.fahrgemeinschaft.RideDetailsFragment.java

private boolean isActive(Cursor ride) {
    return (ride.getInt(COLUMNS.ACTIVE) == 1);
}

From source file:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java

/** 
 * Check the travel times table for any starred entries. If we find some, save them
 * to a list so we can re-star those after we flush the database.
 *///from  w  w  w.j av a  2  s .  co m
private List<Integer> getStarred() {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    List<Integer> starred = new ArrayList<Integer>();

    try {
        cursor = resolver.query(TravelTimes.CONTENT_URI, new String[] { TravelTimes.TRAVEL_TIMES_ID },
                TravelTimes.TRAVEL_TIMES_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.emailcommon.internet.Rfc822Output.java

/**
 * Write the entire message to an output stream.  This method provides buffering, so it is
 * not necessary to pass in a buffered output stream here.
 *
 * @param context system context for accessing the provider
 * @param messageId the message to write out
 * @param out the output stream to write the message to
 * @param useSmartReply whether or not quoted text is appended to a reply/forward
 *//*from   www  .j ava  2 s . c o m*/
public static void writeTo(Context context, long messageId, OutputStream out, boolean useSmartReply,
        boolean sendBcc) throws IOException, MessagingException {
    Message message = Message.restoreMessageWithId(context, messageId);
    if (message == null) {
        // throw something?
        return;
    }

    OutputStream stream = new BufferedOutputStream(out, 1024);
    Writer writer = new OutputStreamWriter(stream);

    // Write the fixed headers.  Ordering is arbitrary (the legacy code iterated through a
    // hashmap here).

    String date = DATE_FORMAT.format(new Date(message.mTimeStamp));
    writeHeader(writer, "Date", date);

    writeEncodedHeader(writer, "Subject", message.mSubject);

    writeHeader(writer, "Message-ID", message.mMessageId);

    writeAddressHeader(writer, "From", message.mFrom);
    writeAddressHeader(writer, "To", message.mTo);
    writeAddressHeader(writer, "Cc", message.mCc);
    // Address fields.  Note that we skip bcc unless the sendBcc argument is true
    // SMTP should NOT send bcc headers, but EAS must send it!
    if (sendBcc) {
        writeAddressHeader(writer, "Bcc", message.mBcc);
    }
    writeAddressHeader(writer, "Reply-To", message.mReplyTo);
    writeHeader(writer, "MIME-Version", "1.0");

    // Analyze message and determine if we have multiparts
    Body body = Body.restoreBodyWithMessageId(context, message.mId);
    String[] bodyText = buildBodyText(body, message.mFlags, useSmartReply);

    Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, messageId);
    Cursor attachmentsCursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION,
            WHERE_NOT_SMART_FORWARD, null, null);

    try {
        int attachmentCount = attachmentsCursor.getCount();
        boolean multipart = attachmentCount > 0;
        String multipartBoundary = null;
        String multipartType = "mixed";

        // Simplified case for no multipart - just emit text and be done.
        if (!multipart) {
            writeTextWithHeaders(writer, stream, bodyText);
        } else {
            // continue with multipart headers, then into multipart body
            multipartBoundary = getNextBoundary();

            // Move to the first attachment; this must succeed because multipart is true
            attachmentsCursor.moveToFirst();
            if (attachmentCount == 1) {
                // If we've got one attachment and it's an ics "attachment", we want to send
                // this as multipart/alternative instead of multipart/mixed
                int flags = attachmentsCursor.getInt(Attachment.CONTENT_FLAGS_COLUMN);
                if ((flags & Attachment.FLAG_ICS_ALTERNATIVE_PART) != 0) {
                    multipartType = "alternative";
                }
            }

            writeHeader(writer, "Content-Type",
                    "multipart/" + multipartType + "; boundary=\"" + multipartBoundary + "\"");
            // Finish headers and prepare for body section(s)
            writer.write("\r\n");

            // first multipart element is the body
            if (bodyText[INDEX_BODY_TEXT] != null) {
                writeBoundary(writer, multipartBoundary, false);
                writeTextWithHeaders(writer, stream, bodyText);
            }

            // Write out the attachments until we run out
            do {
                writeBoundary(writer, multipartBoundary, false);
                Attachment attachment = Attachment.getContent(attachmentsCursor, Attachment.class);
                writeOneAttachment(context, writer, stream, attachment);
                writer.write("\r\n");
            } while (attachmentsCursor.moveToNext());

            // end of multipart section
            writeBoundary(writer, multipartBoundary, true);
        }
    } finally {
        attachmentsCursor.close();
    }

    writer.flush();
    out.flush();
}

From source file:com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.java

public Uri recordEvent(final AnalyticsEvent event) {
    if (event != null) {
        log.info(String.format("Event Recorded to database with EventType: %s",
                StringUtil.clipString(event.getEventType(), CLIPPED_EVENT_LENGTH, true)));
    }/*  w ww .  j a  va  2  s  . com*/
    long maxPendingSize = pinpointContext.getConfiguration().optLong(KEY_MAX_PENDING_SIZE,
            DEFAULT_MAX_PENDING_SIZE);
    if (maxPendingSize < MINIMUM_PENDING_SIZE) {
        maxPendingSize = MINIMUM_PENDING_SIZE;
    }

    final Uri uri = this.dbUtil.saveEvent(event);
    if (uri != null) {
        while (this.dbUtil.getTotalSize() > maxPendingSize) {
            Cursor cursor = null;
            try {
                cursor = this.dbUtil.queryOldestEvents(5);
                while (this.dbUtil.getTotalSize() > maxPendingSize && cursor.moveToNext()) {
                    this.dbUtil.deleteEvent(cursor.getInt(EventTable.COLUMN_INDEX.ID.getValue()),
                            cursor.getInt(EventTable.COLUMN_INDEX.SIZE.getValue()));
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }

        return uri;
    } else {
        log.warn(String.format("Event: '%s' failed to record to local database.",
                StringUtil.clipString(event.getEventType(), CLIPPED_EVENT_LENGTH, true)));
        return null;
    }
}