1

I'm using the Android SQLite Binding and the addCustomFunction method is unhidden. I can see how the arguments are passed in but once they've been processed I don't know how to pass it back as a result.

public class Custom implements SQLiteDatabase.CustomFunction {

    @Override
    public void callback(String[] args) {
      String.valueOf(Math.cos(Double.parseDouble(args[0])));
    }
}

I'm trying to make a cos function but it returns null every time I call the function. It's basically because I don't know where to pass the result.

db.execSQL("CREATE TABLE t1(x)");
db.execSQL("INSERT INTO t1 VALUES ('one'), ('two'), ('three')");

Custom custom = new Custom();

db.addCustomFunction("cos",1,custom);
try {
  Cursor c = db.rawQuery("SELECT cos(0.5),* FROM t1", null);
  if (c != null && c.moveToFirst()) {
    res += c.getString(0);
    Toast.makeText(this, res, Toast.LENGTH_LONG).show();
  }
}
catch (Exception e){
  Log.e("EXP","custom",e);
}

1 Answer 1

1

In the SQLite C API, the result value would be set with one of the sqlite3_result_*() functions.

The Android database API has no mechanism to call these functions.

Sign up to request clarification or add additional context in comments.

4 Comments

Android doesn't normally have access to addCustomFunction() either but this provides it so it might provide something similar to sqlite3_result_*() functions
@PriestVallon The JNI source code there states // TODO: Support functions that return values
@laalto So does that mean they haven't written a way of handing return values ya?
@laalto If that's the case how would one best create a custom function in SQLite?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.