Bad request for field slot 0,1 on rawQuery() Cursor
I am pretty new to android, and I have the following problem. This is my code where I'm trying to get data from the database into my list.
private List<Model> getModel(int a) {
dbHelper = new DbHelper(this);
db = dbHelper.getWritableDatabase();
Log.d("Model Int: ", "Model int: " + 开发者_如何学JAVAa);
sql = "SELECT * FROM shows";
resultCursor = db.rawQuery(sql, new String [] {});
resultCursor.moveToFirst();
List<Model> list = new ArrayList<Model>();
list.add(get(Html.fromHtml(resultCursor.getString(a)).toString()));
for (resultCursor.moveToFirst(); resultCursor.moveToNext(); resultCursor
.isAfterLast()) {
list.add(get(Html.fromHtml(resultCursor.getString(a))
.toString()));
}
startManagingCursor(resultCursor);
resultCursor.close();
db.close();
dbHelper.close();
return list;
}
that works fine, but when i do not want to get all the columns with * but with
sql = "SELECT title subtitle FROM shows";
instead. I get errors like this
ERROR/CursorWindow(371): Bad request for field slot 0,1. numRows = 162, numColumns = 1
Any ideas what's going wrong?
Thanks in advance.
SELECT title subtitle FROM shows
Really means
SELECT title AS subtitle FROM shows
In english: select only one column: title
, but rename that column to "subtitle" in the resultset.
This is called assigning an alias
to a column.
See: http://beginner-sql-tutorial.com/sql-aliases.htm
Solution
Do:
SELECT title, subtitle FROM shows
Now you are selecting two columns.
Disclaimer
I do not vouch for the quality of the info in that link, there are a lot of poor quality tutorials
on the net. I just looked at the "alias" section and that section looks useful.
I didn't perfectly understand your question but I think u need specific field then
select title, subtitle from shows
define the fields seperated by commas
精彩评论