Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does cursor.getString() coerce an int into a string?

The docs say:

The result and whether this method throws an exception when the column value is null or the column type is not a string type is implementation-defined.

Which implementation are they talking about? The version of sqlite? Will calling

cursor.getString(INT_COLUMN)

coerce the int value into a String?

like image 265
mariaines Avatar asked Apr 03 '13 18:04

mariaines


People also ask

What is the purpose of the cursor class?

Cursors are what contain the result set of a query made against a database in Android. The Cursor class has an API that allows an app to read (in a type-safe manner) the columns that were returned from the query as well as iterate over the rows of the result set.

Why we use cursor in android studio?

The basic purpose of a cursor is to point to a single row of the result fetched by the query. We load the row pointed by the cursor object. By using cursor we can save lot of ram and memory. Here, we pass the table name, column name only then we receive the cursor.


1 Answers

Does cursor.getString() coerce an int into a string?

Yes, the same data from your table can be returned with getString(), getInt(), getLong(), etc as long as it makes sense. For example,

  • If the column data is 42: getInt() returns 42 and getString() returns "42".
  • If the column data is plant: getString() returns "plant", getInt() returns 0.
like image 152
Sam Avatar answered Sep 30 '22 17:09

Sam