xZise
xZise

Reputation: 2379

Cursor.getCount() is negative (= -1)

I tried to load a list of values from a table, but the cursor returns a length of -1?

Is there a possibility to view a sqlite database on a android emulator?

The Code which is buggy:

final Cursor c = db.query(
    ACCESS_TOKEN_TABLE,
    new String[] { ACCESS_TOKEN_COL_ID, ACCESS_TOKEN_COL_VALUE },
    ACCESS_TOKEN_COL_SERVER_ID + "=" + serverId,
    null,
    null,
    null,
    null);

public static final String COL_ID = "_id";
public static final String ACCESS_TOKEN_TABLE = "accesstoken";
public static final String ACCESS_TOKEN_COL_ID = COL_ID;
public static final String ACCESS_TOKEN_COL_SERVER_ID = "server_id";
public static final String ACCESS_TOKEN_COL_VALUE = "value";

And there is one entry in the database. The value of ServerID is 1 and there exists one entry, where the ServerID is 1.

Sincerely xZise

PS: Two questions only to open the database.

Upvotes: 0

Views: 4217

Answers (4)

xZise
xZise

Reputation: 2379

Ahr.... I was two lines to high: So the problem isn't that the cursor returns a negative length, the problem is that it doesn't can give me the indexes of the columns.

I'm very sorry. Because of an totally other question, I posted a new question: Cursor doesn't find columns?

Sincerely xZise

Upvotes: 0

Scoobler
Scoobler

Reputation: 9719

If the cursor is -1 the SQL statement is not returning any results. Maybe if you were to add the code you are using for your SQL select statement.

As for the second, viewing the DB - yes it is possible:

  1. In Eclipse, DDMS view, click on the name of the emulator in the Devices tab (If the Devices tab isn't showing: Window->Show View->Devices)

  2. Next click on the File Explorer tab (If the tab isn't showing: Window->Show View->File Explorer)

  3. Now browse through the file tree. You need to go to: data/data/com.package.name/databases

  4. Now click on the name of the database you want to inspect. You will need to copy it to your computer. (To do this, click the picture of a floppy disc with an arrow on it. Save it somewhere you can find.)

  5. You will need an SQLite browser, like the SQLite Manager add-on for Firefox

  6. In Firefox, open the SQLite Manager (Tools->SQLite Manager)

  7. In SQLite Manager, click Database, Connect Database (You may have to change the file type from SQLite DB Files (.sqlite;) to All Files as the Android DB doesn't have to have the .sqlite extension on the file)

Another option is to use the Questiod SQLite Browser plugin for eclipse - I have just added this - makes the above process twice as easy!

Upvotes: 0

oba
oba

Reputation: 31

you have an sqlite3 command if you "adb -e shell" with a CLI interface to the db. better yet - i know of an eclipse plugin that can view sqlite database content using the ddms. but my personal favorite is to pull the db file out of the emulator, and use sqlite database browser to view the contents.

Upvotes: 3

Lior Iluz
Lior Iluz

Reputation: 26563

getCount() = -1 -> nothing to count... (are you sure your query is OK?)

Don't know about viewing sqlite db with Android emulator but you can use apps like Root Explorer to view Databases.

Upvotes: 2

Related Questions