I am new in Android and tried to make my own ContentProvider.
I can now insert rows and I can delete,update and query a whole Table.
Now I wanted to implement to query a single row of a table with its _id and I stucked at this problem.
In my Test-Program I query the row with the _id = 1 with this code:
Using java Syntax Highlighting
- String[] projection = new String[]{
- Dates.DB_entry._ID,
- Dates.DB_entry.TITLE
- };
- Uri uri_id = Dates.DB_entry.CONTENT_URI;
- String number = new String();
- number = number.valueOf(1);
- uri_id = uri_id.withAppendedPath(Dates.DB_entry.CONTENT_URI, number);
- Cursor c = managedQuery(uri_id, projection, null, null);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Then, the program jumps into the query-function of the ContentProvider, which looks like that:
Using java Syntax Highlighting
- @Override
- public Cursor query (Uri url, String[] projection, String selection, String[] selectionArgs, String sort)
- {
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- int i = URL_MATCHER.match(url);
- switch(URL_MATCHER.match(url))
- {
- case ENTRY_ID:
- //qb.setTables("Termin");
- qb.appendWhere("_id="+ "=" + ContentUris.parseId(url));
- case ENTRIES: //Alle Dates ausgeben
- qb.setTables("Termin");
- qb.setProjectionMap(DATES_LIST_PROJECTION_MAP);
- break;
- case VAR_ID:
- //qb.setTables("Vars");
- qb.appendWhere("(_id="+ "=" + ContentUris.parseId(url));
- case VARS: //Alle Dates ausgeben
- qb.setTables("Vars");
- qb.setProjectionMap(VAR_LIST_PROJECTION_MAP);
- break;
- default: //ungültige URI
- throw new IllegalArgumentException("Unknown URL " + url);
- }
- // If no sort order is specified use the default
- String orderBy;
- if (TextUtils.isEmpty(sort))
- {
- orderBy = Dates.DB_Variablen.DEFAULT_SORT_ORDER;
- } else
- {
- orderBy = sort;
- }
- String s = qb.buildQuery(projection, selection, selectionArgs, null, null, null);
- Cursor c = qb.query(mDB, projection, selection, selectionArgs, null, null, null);
- c.setNotificationUri(getContext().getContentResolver(), url);
- return c;
- }
Parsed in 0.053 seconds, using GeSHi 1.0.8.4
The program then gets in the case ENTRIES_ID and does everything, then it used to be.
After that the String s, which I only implemented for testing, is "SELECT _id,title FROM Termin WHERE (_id==1)" which looks good for me. When I query this String with SQlite3 in the console i also get this row as a result.
But when I start the qb.query, I get the error-message
Application Error: swt2.db
An error has occured in swt2.db. near ")": syntax error, while compiling:
SELECT COUNT(*) FROM (SELECT _id, title FROM Termin WHERE (_id==1))).
Can someone please tell me, why the compiler extends the SQL-Query with "SELECT COUNT(.....)) and how I can solve these problems.
Thanks a lot
thomacco


