I'm trying to do an SQLite query in my Android app, but for some reason it doesn't get the arguments correctly. If I hard-code the values, the query works just fine, so I know the overall query is correct and the data is there.
...
public String[][] traerEncuestaPostventa(int idBien,
int idEncuesta)
{
String[][] arrayDatos = null;
String[] arrayArgumentos = {String.valueOf(idBien), String.valueOf(idEncuesta), String.valueOf(idBien)};
Cursor cursor = null;
cursor = querySQL("SELECT " +
"encuestadetalle.id_encuestadetalle," +
"IFNULL(encuestapostventa.id_encuestapostventa, 0) as id_encuestapostventa," +
"encuestadetalle.zona_inmueble," +
"encuestadetalle.tarea," +
"IFNULL(encuestaobservacion.id_encuestaobservacion, 0) as id_encuestaobservacion," +
"IFNULL(encuestaobservacion.observacion, '') as observacion," +
"encuestadetalle.id_encuesta," +
"IFNULL(encuestapostventa.recepcion, 0) as recepcion" +
" FROM encuestadetalle" +
" LEFT JOIN (SELECT * FROM encuestapostventa WHERE id_bien = ?) AS encuestapostventa" +
" ON encuestadetalle.id_encuestadetalle = encuestapostventa.id_encuestadetalle" +
" LEFT JOIN encuestaobservacion" +
" ON encuestapostventa.id_encuestapostventa = encuestaobservacion.id_encuestapostventa" +
" WHERE encuestadetalle.id_encuesta = ?" +
" AND (IFNULL(encuestapostventa.id_bien, 0) IN (?, 0))" +
" ORDER BY encuestadetalle.zona_inmueble, encuestadetalle.tarea", arrayArgumentos);
if(cursor.getCount() > 0)
{
int i = 0;
arrayDatos = new String[cursor.getCount()][5];
while(cursor.moveToNext())
{
//Here I handle the data;
i = i + 1;
}
}
cursor.close();
CloseDB();
return(arrayDatos);
}
...
public Cursor querySQL(String sql, String[] selectionArgs)
{
Cursor oRet = null;
// Opens the database object in "write" mode.
db = oDB.getReadableDatabase();
oRet = db.rawQuery(sql, selectionArgs);
return(oRet);
}
...
Now if I replace the query like this, it works:
cursor = querySQL("SELECT " +
"encuestadetalle.id_encuestadetalle," +
"IFNULL(encuestapostventa.id_encuestapostventa, 0) as id_encuestapostventa," +
"encuestadetalle.zona_inmueble," +
"encuestadetalle.tarea," +
"IFNULL(encuestaobservacion.id_encuestaobservacion, 0) as id_encuestaobservacion," +
"IFNULL(encuestaobservacion.observacion, '') as observacion," +
"encuestadetalle.id_encuesta," +
"IFNULL(encuestapostventa.recepcion, 0) as recepcion" +
" FROM encuestadetalle" +
" LEFT JOIN (SELECT * FROM encuestapostventa WHERE id_bien = 5813) AS encuestapostventa" +
" ON encuestadetalle.id_encuestadetalle = encuestapostventa.id_encuestadetalle" +
" LEFT JOIN encuestaobservacion" +
" ON encuestapostventa.id_encuestapostventa = encuestaobservacion.id_encuestapostventa" +
" WHERE encuestadetalle.id_encuesta = 3" +
" AND (IFNULL(encuestapostventa.id_bien, 0) IN (5813, 0))" +
" ORDER BY encuestadetalle.zona_inmueble, encuestadetalle.tarea", null);
I also tried replacing the elements in arrayArgumentos, but it didn't work, either:
String[] arrayArgumentos = {String.valueOf(5813), String.valueOf(3), String.valueOf(5813)};
I'm guessing it has something to do with the fact that my array is a String[] and the arguments themselves are integers. How can I fix this?
Aucun commentaire:
Enregistrer un commentaire