Returns the number of records in a variable, Sqlite, Android, Java

My ultimate goal is to limit the entries that you can create in order to have a trial version of my application. I think I can do this quite simply by returning an int variable in the sqlite count expression and using a simple IF statement to determine if a new record should be created.

I call it this way:

int jcount = 0;
            mDbHelper.countjournals (jcount);

I'm trying to execute this now

 public int countjournals (int jcount) {
             mDb.execSQL (jcount + "= SELECT COUNT (*) FROM" + DATABASE_JOURNAL_TABLE);
            return jcount;
        }

the error i get is:

08-27 22: 42: 32.417: ERROR / AndroidRuntime (3976): android.database.sqlite.SQLiteException: near "0": syntax error: 0 = SELECT COUNT (*) FROM journals

+5
4

, , . , .

  public long countjournals() {

            return DatabaseUtils.queryNumEntries(mDb,DATABASE_JOURNAL_TABLE);

        }
+14
public int countjournals() {
    SQLiteStatement dbJournalCountQuery;
    dbJournalCountQuery = mDb.compileStatement("select count(*) from" + DATABASE_JOURNAL_TABLE);
    return (int) dbJournalCountQuery.simpleQueryForLong();
}
+6

, , :

    public int countjournals() {
        Cursor dataCount = mDb.rawQuery("select count(*) from" + DATABASE_JOURNAL_TABLE, null);
        dataCount.moveToFirst();
        int jcount = dataCount.getInt(0);
        dataCount.close();
        return jcount;
    }

. , ( , ), SQLite. () .

+3

from, .....

Cursor dataCount = mDb.rawQuery("select count(*) from " + DATABASE_JOURNAL_TABLE, null);
+1

All Articles