Good afternoon, I need to do a query but I can not use the cursor.
Example I have an object that I created that is called DatabaseHelper, inside it I have created some methods (prepare, bindParam, getQuery, execute), however in executing I need the return to be a JSONArray or an array as it is done in PHP with or mysql. Dry down an example of what I'm trying to do. I have this need because the query will be executed via JavaScript in an ApacheCordova application, but I can not use the cursor.
@JavascriptInterface
public JSONObject execute() throws JSONException{
String sql = this.sql_prepare;
JSONObject retorno = new JSONObject();
try
{
SQLiteDatabase db = this.getReadableDatabase();
db.execSQL(sql);
retorno.put("ok", true);
retorno.put("return", "Aqui deve conter um objeto array para que eu possa trabalhar com o javascript e esse objeto deve conter todo o retorno do execSQL");
return retorno;
} catch(Exception e){
AlertDialog.Builder erro = new AlertDialog.Builder(contexto);
erro.setTitle("Erro de SQL");
erro.setMessage("Ocorreu um erro na execução de sua query.\nQuery: "+sql+"\nErro:"+e.getMessage());
erro.setPositiveButton("OK", null);
erro.show();
retorno.put("ok", false);
retorno.put("return", e.getMessage().toString());
return retorno;
}
}