Example usage for android.database Cursor getCount

List of usage examples for android.database Cursor getCount

Introduction

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

Prototype

int getCount();

Source Link

Document

Returns the numbers of rows in the cursor.

Usage

From source file:io.vit.vitio.Managers.ConnectDatabase.java

public int getCoursesCount() {
    String countQuery = "SELECT  * FROM " + TABLE_COURSES;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);

    int count = cursor.getCount();

    cursor.close();//  w w  w  . j  a  v  a  2  s  . c o m
    db.close();

    return count;
}

From source file:com.googlecode.android_scripting.facade.SmsFacade.java

@Rpc(description = "Returns the number of messages.")
public Integer smsGetMessageCount(@RpcParameter(name = "unreadOnly") Boolean unreadOnly,
        @RpcParameter(name = "folder") @RpcDefault("inbox") String folder) {
    Uri uri = buildFolderUri(folder);/*from  w  w  w .  j  a  va2 s .c o  m*/
    Integer result = 0;
    String selection = buildSelectionClause(unreadOnly);
    Cursor cursor = mContentResolver.query(uri, null, selection, null, null);
    if (cursor != null) {
        result = cursor.getCount();
        cursor.close();
    } else {
        result = 0;
    }
    return result;
}

From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java

public void setCurrentServerProfile(long id) {
    Cursor cursor = queryServerProfile(id);

    if (cursor != null) {
        try {/* www.j  a  v  a2  s .c  o m*/
            if (cursor.getCount() > 0) {
                cursor.moveToPosition(0);
                setCurrentServerProfile(cursor);
            }
        } finally {
            cursor.close();
        }
    }
}

From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java

public void setCurrentInfoSnapshot(long profileId) {
    Cursor cursor = queryServerProfile(profileId);
    if (cursor != null) {
        try {//from w ww  .  jav a2s  .c o m
            if (cursor.getCount() > 0) {
                cursor.moveToPosition(0);
                serverInfoSnapshot.setProfile(new ServerProfiles(cursor));
            }
        } finally {
            cursor.close();
        }
    }
}

From source file:com.taxicop.sync.SyncAdapter.java

public int count(ContentProviderClient provider) {
    try {//from w w w  .j a  v  a  2 s . c o  m
        Cursor c = provider.query(PlateContentProvider.URI_REPORT, null, null, null, null);
        int ret = c.getCount();
        c.close();
        return ret;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(TAG, "" + e.getMessage());
    }
    return 0;
}

From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java

public void updateCurrentInfoSnapshot(long profileId, ServerInfo serverInfo) {
    Cursor cursor = queryServerProfile(profileId);
    if (cursor != null) {
        try {/* ww  w .  j a  va 2 s .c om*/
            if (cursor.getCount() > 0) {
                cursor.moveToPosition(0);
                ServerProfiles profile = new ServerProfiles(cursor);
                profile.setVersioncode(serverInfo.getVersionCode());
                profile.setEdition(serverInfo.getEdition());

                Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SERVER_PROFILES_CONTENT_URI,
                        String.valueOf(profileId));
                context.getContentResolver().update(uri, profile.getContentValues(), null, null);
                serverInfoSnapshot.setProfile(profile);
            }
        } finally {
            cursor.close();
        }
    }
}

From source file:edu.cwru.apo.Directory.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.directory);/*  w  ww.jav  a 2 s.  c  o  m*/
    userTable = (TableLayout) findViewById(R.id.userTable);
    phoneDB = new PhoneOpenHelper(this);
    database = phoneDB.getWritableDatabase();
    Cursor results = database.query("phoneDB", new String[] { "first", "last", "_id" }, null, null, null, null,
            "first");
    if (results.getCount() < 1) {
        API api = new API(this);
        if (!api.callMethod(Methods.phone, this, (String[]) null)) {
            Toast msg = Toast.makeText(this, "Error: Calling phone", Toast.LENGTH_LONG);
            msg.show();
        }
    } else
        loadTable();
}

From source file:com.denimgroup.android.training.pandemobium.stocktrader.ManageTipsActivity.java

private void doSendTipData(String symbol) {
    StockDatabase dbHelper = new StockDatabase(this.getApplicationContext());
    SQLiteDatabase db = dbHelper.openDatabase();

    StringBuilder sb = new StringBuilder();

    String sql = "SELECT * FROM tip WHERE symbol = '" + symbol + "'";

    Log.d("ManageTipsActivity", "SQL to execute is: " + sql);

    Cursor tips = db.rawQuery(sql, null);

    //   Take all the data returned and package it up for sending
    int numTips = tips.getCount();
    Log.d("ManageTipsActivity", "Got " + numTips + " tips to send");
    tips.moveToFirst();/*from   ww w  . ja v a2  s .c  om*/
    for (int i = 0; i < numTips; i++) {
        sb.append("TIP");
        sb.append(i);
        sb.append(":");
        int columnCount = tips.getColumnCount();
        Log.d("ManageTipsActivity", "Tip " + i + " has " + columnCount + " columns");
        for (int j = 0; j < columnCount; j++) {
            if (j > 0) {
                sb.append("&");
            }
            sb.append(tips.getColumnName(j));
            sb.append("=");
            sb.append(tips.getString(j));
        }
        tips.moveToNext();
        sb.append("\n");
    }

    tips.close();
    db.close();

    Log.d("ManageTipsActivity", "Tip data to post is: " + sb.toString());

    String accountId = AccountUtils.retrieveAccountId(getApplicationContext());
    String tradeServiceUrl = getResources().getString(R.string.tip_service);

    String fullUrl = tradeServiceUrl + "?method=submitTips&id=" + accountId;

    Log.d("ManageTipsActivity", "Full URL for tip sending is: " + fullUrl);

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(fullUrl);
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("tipData", sb.toString()));
    try {
        post.setEntity(new UrlEncodedFormEntity(pairs));
        HttpResponse response = client.execute(post);
        tvTipStatus.setText("Tip data for " + etSymbol.getText().toString() + " sent!");

    } catch (Exception e) {
        Log.e("ManageTipsActivity", "Error when encoding or sending tip data: " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.crankworks.cycletracks.TripUploader.java

@Override
protected Boolean doInBackground(Long... tripid) {
    // First, send the trip user asked for:
    Boolean 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();//from www.j av a  2  s.  c  o m
    Cursor cur = mDb.fetchUnsentTrips();
    if (cur != null && cur.getCount() > 0) {
        //pd.setMessage("Sent. You have previously unsent trips; submitting those now.");
        while (!cur.isAfterLast()) {
            unsentTrips.add(new Long(cur.getLong(0)));
            cur.moveToNext();
        }
        cur.close();
    }
    mDb.close();

    for (Long trip : unsentTrips) {
        result &= uploadOneTrip(trip);
    }
    return result;
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.profile.ServersManagerPageTest.java

public void testValidFormCreation() {
    startActivityUnderTest();/*from   w w w  .j a  v a 2  s  .co m*/

    onView(withId(R.id.addProfile)).perform(click());
    onView(withText(R.string.sp_bc_add_profile)).check(matches(isDisplayed()));

    onView(withId(R.id.aliasEdit)).perform(typeText(DatabaseUtils.TEST_ALIAS));
    onView(withId(R.id.serverUrlEdit)).perform(typeText(DatabaseUtils.TEST_SERVER_URL));
    onView(withId(R.id.organizationEdit)).perform(typeText(DatabaseUtils.TEST_ORGANIZATION));
    onView(withId(R.id.usernameEdit)).perform(typeText(DatabaseUtils.TEST_USERNAME));
    onView(withId(R.id.passwordEdit)).perform(typeText(DatabaseUtils.TEST_PASS));

    onView(withId(R.id.saveAction)).perform(click());

    Cursor cursor = queryTestProfile(mApplication.getContentResolver());
    try {
        assertThat(cursor.getCount(), is(1));
    } finally {
        cursor.close();
    }
}