SilentKiller
SilentKiller

Reputation: 6942

SqlException error occurs on cursor use

on the cursor line this error occurs.

Error:

Caused by: android.database.sqlite.SQLiteException: near ")": syntax 
error: , while compiling: SELECT value FROM system WHERE (name= ) ORDER BY name

The cursor looks like this:

 Cursor c = getContentResolver().query(Uri.parse("content://settings/system"),
 values, "name=", fields, "name");
    if (c != null) {
        c.moveToFirst();
        long lvalue = c.getLong(0);
        if (lvalue > 0) {
            m_ScreenSaverDelay = lvalue;
        }

Upvotes: 1

Views: 125

Answers (2)

JimmyB
JimmyB

Reputation: 12630

Documentation states:

You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.

So try "name=?s" instead of "name=" which will eventually be evaluated to something equivalent to

"name=\"" + fields[0] + "\""

(not taking quoting of the data input into account in this example which will (or should) be done by the DB engine).

Upvotes: 3

kosa
kosa

Reputation: 66677

Try this:

Cursor c = getContentResolver().query(Uri.parse("content://settings/system"), values, "name= '"+ theNameyouArelookingFor +"'", fields, "name");     

your query should evaluate to:

SELECT value FROM system WHERE (name='ThenameYouAreLookingFor') ORDER BY name

Upvotes: 3

Related Questions