Example usage for android.database Cursor getColumnIndexOrThrow

List of usage examples for android.database Cursor getColumnIndexOrThrow

Introduction

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

Prototype

int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;

Source Link

Document

Returns the zero-based index for the given column name, or throws IllegalArgumentException if the column doesn't exist.

Usage

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * ???ID// w w w. ja  va 2s  .co m
 *
 * @param contactId
 * @return
 */
public static long querySessionIdForByContactId(String contactId) {
    Cursor cursor = null;
    long threadId = 0;
    if (contactId != null) {
        String where = IThreadColumn.CONTACT_ID + " = '" + contactId + "' ";
        try {
            cursor = getInstance().sqliteDB().query(DatabaseHelper.TABLES_NAME_IM_SESSION, null, where, null,
                    null, null, null);
            if (cursor != null && cursor.getCount() > 0) {
                if (cursor.moveToFirst()) {
                    threadId = cursor.getLong(cursor.getColumnIndexOrThrow(IThreadColumn.ID));
                }
            }
        } catch (SQLException e) {
            LogUtil.e(TAG + " " + e.toString());
        } finally {
            if (cursor != null) {
                cursor.close();
                cursor = null;
            }
        }
    }
    return threadId;
}

From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java

private void syncCheckins(ContentProviderClient provider, String cookie) {
    Cursor cursor = null;
    try {// w w w.  j  ava 2  s.  c o  m
        cursor = provider.query(Table.ATTENDEE.getBaseUri(),
                new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, },
                Table.Attendee.CHECKIN_MODIFIED, null, null);
        if (0 == cursor.getCount()) {
            Log.d(TAG, "No checkin to sync.");
            return;
        }
        int syncCount = 0;
        while (cursor.moveToNext()) {
            String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID));
            String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID));
            long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN));
            long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie);
            if (serverCheckin >= 0) {
                ContentValues values = new ContentValues();
                values.put(Table.Attendee.CHECKIN_MODIFIED, false);
                if (0 == serverCheckin) {
                    values.putNull(Table.Attendee.CHECKIN);
                } else {
                    values.put(Table.Attendee.CHECKIN, serverCheckin);
                }
                provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null);
                ++syncCount;
            }
        }
        Log.d(TAG, syncCount + " checkin(s) synced.");
    } catch (RemoteException e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

public static String queryBodyBymsgId(String contactId) {
    Cursor cursor = null;
    String threadId = null;//from  w w w . ja va  2s.  c  om
    if (contactId != null) {
        String where = IMessageColumn.MESSAGE_ID + " = '" + contactId + "' ";
        try {
            cursor = getInstance().sqliteDB().query(DatabaseHelper.TABLES_NAME_IM_MESSAGE, null, where, null,
                    null, null, null);
            if (cursor != null && cursor.getCount() > 0) {
                if (cursor.moveToFirst()) {
                    threadId = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.BODY));
                }
            }
        } catch (SQLException e) {
            LogUtil.e(TAG + " " + e.toString());
        } finally {
            if (cursor != null) {
                cursor.close();
                cursor = null;
            }
        }
    }
    return threadId;
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

/**
 * getting real path from attachment URI.
 * /*from   w  ww. j a  v a  2  s  .c  o m*/
 * @param contentUri
 * @return
 */
private String getFilenameFromUri(Uri contentUri) {
    String filename = "unknown";
    if (contentUri.getScheme().toString().compareTo("content") == 0) {
        Cursor cursor = getContentResolver().query(contentUri, null, null, null, null);
        if (cursor.moveToFirst()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            filename = cursor.getString(column_index);
            File fl = new File(filename);
            filename = fl.getName();
        }
    } else if (contentUri.getScheme().compareTo("file") == 0) {
        filename = contentUri.getLastPathSegment().toString();
    } else {
        filename = filename + "_" + contentUri.getLastPathSegment();
    }
    return filename;
}

From source file:com.dwdesign.tweetings.fragment.AccountsFragment.java

@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
    mCursor = data;/*from   w  w w  .ja  va2s  .c  o  m*/
    mAdapter.swapCursor(data);

    final SparseBooleanArray checked = new SparseBooleanArray();
    data.moveToFirst();
    //if (mSelectedIds.size() == 0) {
    while (!data.isAfterLast()) {
        final boolean is_activated = data.getInt(data.getColumnIndexOrThrow(Accounts.IS_ACTIVATED)) == 1;
        final long user_id = data.getLong(data.getColumnIndexOrThrow(Accounts.USER_ID));
        //if (is_activated) {
        //mSelectedIds.add(user_id);
        //}

        //View v = (View) getListView().getItemAtPosition(data.getPosition());
        //CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
        //cb.setChecked(is_activated);
        //mAdapter.setItemChecked(data.getPosition(), is_activated);
        data.moveToNext();
    }
    /*} else {
    while (!cursor.isAfterLast()) {
    final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID));
    if (mSelectedIds.contains(user_id)) {
       checked.put(cursor.getPosition(), true);
       mAdapter.setItemChecked(cursor.getPosition(), true);
    }
    cursor.moveToNext();
    }
    }*/
}

From source file:com.ezac.gliderlogs.FlightMemberActivity.java

private void fillData(Uri uri, String date) {

    Cursor cursor;
    stringArrayList.clear();/*from  w w  w .j a v a2  s  . c  o m*/
    String[] projection = { GliderLogTables.M_CITY, GliderLogTables.M_2_NAME, GliderLogTables.M_3_NAME,
            GliderLogTables.M_1_NAME, GliderLogTables.M_ADRS, GliderLogTables.M_PHONE, GliderLogTables.M_MOBILE,
            GliderLogTables.M_CODE, GliderLogTables.M_INSTRUCTION, GliderLogTables.M_TRAIN };
    //selection = GliderLogTables.M_ACTIVE + " LIKE '*'";
    String sort = "" + GliderLogTables.M_1_NAME + " ASC";
    cursor = getContentResolver().query(uri, projection, null, null, sort);
    if ((cursor != null) && (cursor.getCount() > 0)) {
        cursor.moveToFirst();
        do {
            String tmp = cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_1_NAME)) + " "
                    + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_2_NAME)) + " "
                    + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_3_NAME));
            stringArrayList.add(tmp.replaceAll("\\s+", " "));
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_ADRS)));
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_CITY)));
            stringArrayList.add(
                    cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_PHONE)).equals("null") ? "-"
                            : cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_PHONE)));
            stringArrayList
                    .add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_MOBILE)).equals("null")
                            ? "-"
                            : cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_MOBILE)));
            tmp = " " + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_CODE));
            tmp = tmp + " - "
                    + (cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_INSTRUCTION)).equals("1")
                            ? "J"
                            : "N");
            tmp = tmp + " - "
                    + (cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.M_TRAIN)).equals("1") ? "J"
                            : "N");
            stringArrayList.add(tmp);
            stringArrayList.add("");
        } while (cursor.moveToNext());
    }
    cursor.close();
}

From source file:org.mythtv.service.dvr.v25.RecordingRuleHelperV25.java

private void processRecordingRule(final Context context, final LocationProfile locationProfile,
        ArrayList<ContentProviderOperation> ops, org.mythtv.services.api.v025.beans.RecRule recRule) {
    Log.d(TAG, "processRecordingRule : enter");

    String recRuleSelection = RecordingRuleConstants.FIELD_REC_RULE_ID + " = ?";

    recRuleSelection = appendLocationHostname(context, locationProfile, recRuleSelection,
            RecordingRuleConstants.TABLE_NAME);

    ContentValues recRuleValues = convertRecRuleToContentValues(locationProfile, recRule);
    Cursor recRuleCursor = context.getContentResolver().query(RecordingRuleConstants.CONTENT_URI,
            recRuleProjection, recRuleSelection, new String[] { String.valueOf(recRule.getId()) }, null);
    if (recRuleCursor.moveToFirst()) {
        Long id = recRuleCursor.getLong(recRuleCursor.getColumnIndexOrThrow(RecordingRuleConstants._ID));
        Log.v(TAG, "processRecordingRule : updating recRule " + id + ":" + recRule.getId() + ":"
                + recRule.getTitle());/*from www  . java2  s .c  o m*/

        ops.add(ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(RecordingRuleConstants.CONTENT_URI, id))
                .withValues(recRuleValues).build());

    } else {
        Log.v(TAG, "processRecordingRule : adding recRule " + recRule.getId() + ":" + recRule.getTitle());

        ops.add(ContentProviderOperation.newInsert(RecordingRuleConstants.CONTENT_URI).withValues(recRuleValues)
                .build());

    }
    recRuleCursor.close();

    Log.d(TAG, "processRecordingRule : exit");
}

From source file:org.mythtv.service.dvr.v26.RecordingRuleHelperV26.java

private void processRecordingRule(final Context context, final LocationProfile locationProfile,
        ArrayList<ContentProviderOperation> ops, org.mythtv.services.api.v026.beans.RecRule recRule) {
    Log.d(TAG, "processRecordingRule : enter");

    String recRuleSelection = RecordingRuleConstants.FIELD_REC_RULE_ID + " = ?";

    recRuleSelection = appendLocationHostname(context, locationProfile, recRuleSelection,
            RecordingRuleConstants.TABLE_NAME);

    ContentValues recRuleValues = convertRecRuleToContentValues(locationProfile, recRule);
    Cursor recRuleCursor = context.getContentResolver().query(RecordingRuleConstants.CONTENT_URI,
            recRuleProjection, recRuleSelection, new String[] { String.valueOf(recRule.getId()) }, null);
    if (recRuleCursor.moveToFirst()) {
        Long id = recRuleCursor.getLong(recRuleCursor.getColumnIndexOrThrow(RecordingRuleConstants._ID));
        Log.v(TAG, "processRecordingRule : updating recRule " + id + ":" + recRule.getId() + ":"
                + recRule.getTitle());//from   w  w  w  . j  a  v a2 s. c om

        ops.add(ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(RecordingRuleConstants.CONTENT_URI, id))
                .withValues(recRuleValues).build());

    } else {
        Log.v(TAG, "processRecordingRule : adding recRule " + recRule.getId() + ":" + recRule.getTitle());

        ops.add(ContentProviderOperation.newInsert(RecordingRuleConstants.CONTENT_URI).withValues(recRuleValues)
                .build());

    }
    recRuleCursor.close();

    Log.d(TAG, "processRecordingRule : exit");
}

From source file:com.ezac.gliderlogs.FlightReservationActivity.java

private void fillData(Uri uri, String date) {

    String selection;/*  w ww  .  j  a v a 2s  . com*/
    Cursor cursor;
    stringArrayList.clear();
    String[] projection = { GliderLogTables.R_ID, GliderLogTables.R_DATE, GliderLogTables.R_PERIOD,
            GliderLogTables.R_TYPE, GliderLogTables.R_PURPOSE, GliderLogTables.R_RESERVE,
            GliderLogTables.R_STAMPED, GliderLogTables.R_1_NAME, GliderLogTables.R_2_NAME,
            GliderLogTables.R_3_NAME };

    selection = GliderLogTables.R_DATE + " LIKE '" + date + "'";
    String sort = "" + GliderLogTables.R_STAMPED + " ASC";
    cursor = getContentResolver().query(uri, projection, selection, null, sort);
    if ((cursor != null) && (cursor.getCount() > 0)) {
        cursor.moveToFirst();
        do {
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_ID)));
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_1_NAME)) + " "
                    + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_2_NAME)) + " "
                    + cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_3_NAME)));
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_PERIOD)));
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_TYPE)));
            stringArrayList.add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_PURPOSE)));
            stringArrayList
                    .add(cursor.getString(cursor.getColumnIndexOrThrow(GliderLogTables.R_RESERVE)).equals("0")
                            ? "Nee"
                            : "Ja");
            stringArrayList.add("");
        } while (cursor.moveToNext());
    }
    cursor.close();
}

From source file:com.hackensack.umc.activity.ProfileActivity.java

private String getPath(Uri uri) {
    String[] data = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(ProfileActivity.this, uri, data, null, null, null);
    Cursor cursor = loader.loadInBackground();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from   w  w w . j a v  a2  s . c o m
    return cursor.getString(column_index);
}