0
To view tables I use a plugin called Questoidplugin and works very well, but and to view results of queries, has something?
0
To view tables I use a plugin called Questoidplugin and works very well, but and to view results of queries, has something?
1
Cursor cursor;
select_query = "SELECT a,b,c FROM table";
cursor = db.rawQuery(select_query, null);
if(cursor.getCount()>0){
while (cursor.moveToNext()) { //se a select devolver várias colunas
cursor.moveToFirst();
According to the type of column data the query will return, you use the following command to get the column (in this case if it is double, if it is String is getString...)
cursor.getDouble(cursor.getColumnIndex(nome_da_Coluna)))
} //fim do while
} //fim do if
0
Use a cursor to return your QUERY results
Example:
Cursor c = database.rawQuery("SELECT * FROM nome_da_tabela", null);
c.moveToFirst();
With this you can use the "c" to return your results.
0
You can use the class DatabaseHelper
creating an object db
using helper.getReadableDatabase()
, as shown in the example below.
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT _id, tipo_viagem, destino, " +
"data_chegada, data_saida, orcamento FROM viagem",
null);
cursor.moveToFirst();
viagens = new ArrayList<Map<String, Object>>();
for (int i = 0; i < cursor.getCount(); i++) {
Map<String, Object> item =new HashMap<String, Object>();
String id = cursor.getString(0);
int tipoViagem = cursor.getInt(1);
String destino = cursor.getString(2);
long dataChegada = cursor.getLong(3);
long dataSaida = cursor.getLong(4);
double orcamento = cursor.getDouble(5);
item.put("id", id);
if (tipoViagem == Constantes.VIAGEM_LAZER) {
item.put("imagem", R.drawable.lazer);
} else {
item.put("imagem", R.drawable.negocios);
}
item.put("destino", destino);
Date dataChegadaDate = new Date(dataChegada);
Date dataSaidaDate = new Date(dataSaida);
String periodo = dateFormat.format(dataChegadaDate) +
" a " + dateFormat.format(dataSaidaDate);
item.put("data", periodo);
double totalGasto = calcularTotalGasto(db, id);
item.put("total", "Gasto total R$ " + totalGasto);
double alerta = orcamento * valorLimite / 100;
Double [] valores =
new Double[] { orcamento, alerta, totalGasto };
item.put("barraProgresso", valores);
viagens.add(item);
cursor.moveToNext();
}
cursor.close();
Now you just need to adapt your need.
Browser other questions tagged android sqlite
You are not signed in. Login or sign up in order to post.
Follow the documentation link to add the eclipse plugin: http://tylerfrankenstein.com/browse-android-emulator-sqlite-database-eclipse
– Thiago Luiz Domacoski
Want to view by Sqlitebrowser ?
– Wellington Avelino