Note that there are some explanatory texts on larger screens.

plurals
  1. POcounting total rows in sql lite
    primarykey
    data
    text
    <p>I wrote a method in my database manager that is suppose to return the total amount of rows in a table called homeIcons; but i noticed that it returns 0 when there are 0, 1 there is 1, and then 10 when there are 3? so something is wrong with my method.. please see below:</p> <pre><code>public int getHomeScreenTotal (){ SQLiteDatabase db=this.getReadableDatabase(); Cursor c = db.rawQuery("select count(*) as count from "+ homeIcons,null); c.moveToFirst(); int total = c.getInt(0); return total; } </code></pre> <p><em>EDIT</em> so i edited my code.. and i have rewritten this method in just about every way possible.. The problem is not that it isn't returning the right amount of rows, because it is.. it is just that it is returning the number in binary.. instead of 3, it returns 11 instead of 5 it returns 101 .. UHG!!!! i just want an int! I can't tell if this is a bug in the adroid/java method for accessing a SQLite DB or if i am missing something.. I have even tried duck punching it to an int, but to no avail.. :(</p> <p><em>EDIT</em> ok i just tried to force the binary to an int using the following method:</p> <pre><code>public int getHomeScreenTotal (){ SQLiteDatabase db=this.getReadableDatabase(); int rows; String bin = ""+ db.compileStatement("SELECT COUNT(*) FROM " + homeIcons).simpleQueryForLong(); rows = Integer.parseInt(bin, 2); return rows; } </code></pre> <p>this throws an Error of </p> <p><em>java.lang.NumberFormatException: Invalid int: "7"</em></p> <p>where the "7" is, is actually the number it is suppose to return.. if i have 5 rows i get an error of Invalid int "5"; ect..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload