android - SQLiteDatabases and Cursors -


I was thinking that someone could give me a brief overview of the Android cursor, some specific questions:

  public static cursor getVehicles () {SQLiteDatabase db = vehicleData. GetReadableDatabase (); Cursor cursor = db.query (TABLE_NAME, GET_VEHICLES_FROM_CLAUSE, empty, empty, empty, empty, ORDER_BY); Return cursor; }   

To do housekeeping, I tried db.close () before the return statement. However, the cursor did not have any rows returned due to this. Why is this?

2 - What is the difference between closing a cursor and closing the database? <3> - Do I have to call the cursor if this is a local variable, or can I leave garbage collector to clean it?

4 - My database is small and only used by my application - can I keep it open? The cursor is simply an indicator for the data obtained from your query, in which all the data from your query will be included.

It is not included to increase performance / efficiency (big results are not read at one time - & gt; low memory is used) Therefore, if you close the database, the cursor can not retrieve the data - & gt; It's empty.

2) When you close the cursor, all associated resources are issued - & gt; You can not access the data associated with this cursor (because it has been released), but you can do a new query using this or other cursor. When you close a database, you can not query it anymore (unless you open it again).

3) Always close the cursor, otherwise you will get into problems - GC will complain that the cursor is not closed and new questions are blocked.

4) If you close it, then your app ends, yes.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -