vendredi 13 février 2015

android.database.sqlite.SQLiteException: no such column: favorite1 (code 1)

An error came up when I debugging my app, I can't really find what have I done wrong, I really don't know why there is a 1 behind favorite, hopefully someone can give me a hint, thanks.

LogCat:



02-13 07:42:49.070 1331-1331/me.knoxc.fdemo E/SQLiteLog﹕ (1) no such column: favorite1 02-13 07:42:49.082 1331-1331/me.knoxc.fdemo E/AndroidRuntime﹕ FATAL EXCEPTION: main android.database.sqlite.SQLiteException: no such column: favorite1 (code 1): , while compiling: SELECT (SELECT COUNT() FROM entries WHERE isread IS NULL), (SELECT COUNT() FROM entries WHERE favorite1) FROM entries JOIN (SELECT _id AS joined_feed_id, name, url, icon, groupid FROM feeds) AS f ON (entries.feedid = f.joined_feed_id) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400) at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:294) at me.knoxc.fdemo.provider.FeedDataContentProvider.query(FeedDataContentProvider.java:269) at android.content.ContentProvider.query(ContentProvider.java:744) at android.content.ContentProvider$Transport.query(ContentProvider.java:199) at android.content.ContentResolver.query(ContentResolver.java:414) at android.content.ContentResolver.query(ContentResolver.java:357) at me.knoxc.fdemo.adapter.DrawerAdapter.updateNumbers(DrawerAdapter.java:208) at me.knoxc.fdemo.adapter.DrawerAdapter.(DrawerAdapter.java:60) at me.knoxc.fdemo.activity.MainActivity.onLoadFinished(MainActivity.java:331) at me.knoxc.fdemo.activity.MainActivity.onLoadFinished(MainActivity.java:39) at android.app.LoaderManagerImpl$LoaderInfo.callOnLoadFinished(LoaderManager.java:483) at android.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManager.java:451) at android.content.Loader.deliverResult(Loader.java:144) at android.content.CursorLoader.deliverResult(CursorLoader.java:110) at android.content.CursorLoader.deliverResult(CursorLoader.java:43) at android.content.AsyncTaskLoader.dispatchOnLoadComplete(AsyncTaskLoader.java:256) at android.content.AsyncTaskLoader$LoadTask.onPostExecute(AsyncTaskLoader.java:91) at android.os.AsyncTask.finish(AsyncTask.java:631) at android.os.AsyncTask.access$600(AsyncTask.java:177) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5103) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)



Key code of FeedDataContentProvider.java



public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

int matchCode = URI_MATCHER.match(uri);

if ((matchCode == URI_FEEDS || matchCode == URI_GROUPS || matchCode == URI_FEEDS_FOR_GROUPS) && sortOrder == null) {
sortOrder = FeedData.FeedColumns.PRIORITY;
}

switch (matchCode) {
case URI_GROUPED_FEEDS: {
queryBuilder.setTables(FeedData.FEEDS_TABLE_WITH_GROUP_PRIORITY);
sortOrder = "IFNULL(group_priority, " + FeedData.FeedColumns.PRIORITY + "), IFNULL(" + FeedData.FeedColumns.GROUP_ID + ", " + FeedData.FeedColumns._ID + "), " + FeedData.FeedColumns.IS_GROUP + " DESC, " + FeedData.FeedColumns.PRIORITY;
break;
}
case URI_GROUPS: {
queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.IS_GROUP).append(Constants.DB_IS_TRUE).append(Constants.DB_OR)
.append(FeedData.FeedColumns.GROUP_ID).append(Constants.DB_IS_NULL));
break;
}
case URI_FEEDS_FOR_GROUPS: {
queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.GROUP_ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
case URI_GROUP:
case URI_FEED: {
queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns._ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
case URI_FEEDS: {
queryBuilder.setTables(FeedData.FeedColumns.TABLE_NAME);
queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.IS_GROUP).append(Constants.DB_IS_NULL));
break;
}
case URI_FILTERS: {
queryBuilder.setTables(FeedData.FilterColumns.TABLE_NAME);
break;
}
case URI_FILTERS_FOR_FEED: {
queryBuilder.setTables(FeedData.FilterColumns.TABLE_NAME);
queryBuilder.appendWhere(new StringBuilder(FeedData.FilterColumns.FEED_ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
case URI_ENTRY_FOR_FEED:
case URI_ENTRY_FOR_GROUP:
case URI_SEARCH_ENTRY: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns._ID).append('=').append(uri.getPathSegments().get(3)));
break;
}
case URI_ENTRIES_FOR_FEED: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns.FEED_ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
case URI_ENTRIES_FOR_GROUP: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
queryBuilder.appendWhere(new StringBuilder(FeedData.FeedColumns.GROUP_ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
case URI_ALL_ENTRIES:
case URI_ENTRIES: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
break;
}
case URI_SEARCH: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
queryBuilder.appendWhere(getSearchWhereClause(uri.getPathSegments().get(2)));
break;
}
case URI_FAVORITES_ENTRY:
case URI_ALL_ENTRIES_ENTRY:
case URI_ENTRY: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns._ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
case URI_FAVORITES: {
queryBuilder.setTables(FeedData.ENTRIES_TABLE_WITH_FEED_INFO);
queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns.IS_FAVORITE).append(Constants.DB_IS_TRUE));
break;
}
case URI_TASKS: {
queryBuilder.setTables(FeedData.TaskColumns.TABLE_NAME);
break;
}
case URI_TASK: {
queryBuilder.setTables(FeedData.TaskColumns.TABLE_NAME);
queryBuilder.appendWhere(new StringBuilder(FeedData.EntryColumns._ID).append('=').append(uri.getPathSegments().get(1)));
break;
}
default:
throw new IllegalArgumentException("Illegal query. Match code=" + matchCode + "; uri=" + uri);
}

SQLiteDatabase database = mDatabaseHelper.getReadableDatabase();

Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder);

cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}<br>


Key code of FeedData.java



public static class EntryColumns implements BaseColumns {
public static final String TABLE_NAME = "entries";

public static final String FEED_ID = "feedid";
public static final String TITLE = "title";
public static final String ABSTRACT = "abstract";
public static final String MOBILIZED_HTML = "mobilized";
public static final String DATE = "date";
public static final String FETCH_DATE = "fetch_date";
public static final String IS_READ = "isread";
public static final String LINK = "link";
public static final String IS_FAVORITE = "favorite";
public static final String ENCLOSURE = "enclosure";
public static final String GUID = "guid";
public static final String AUTHOR = "author";
public static final String IMAGE_URL = "image_url";
public static final String[] PROJECTION_ID = new String[]{EntryColumns._ID};
public static final String WHERE_READ = EntryColumns.IS_READ + Constants.DB_IS_TRUE;
public static final String WHERE_UNREAD = "(" + EntryColumns.IS_READ + Constants.DB_IS_NULL + Constants.DB_OR + EntryColumns.IS_READ + Constants.DB_IS_FALSE + ')';
public static final String[][] COLUMNS = new String[][]{{_ID, TYPE_PRIMARY_KEY}, {FEED_ID, TYPE_EXTERNAL_ID}, {TITLE, TYPE_TEXT},
{ABSTRACT, TYPE_TEXT}, {MOBILIZED_HTML, TYPE_TEXT}, {DATE, TYPE_DATE_TIME}, {FETCH_DATE, TYPE_DATE_TIME}, {IS_READ, TYPE_BOOLEAN}, {LINK, TYPE_TEXT},
{IS_FAVORITE, TYPE_BOOLEAN}, {ENCLOSURE, TYPE_TEXT}, {GUID, TYPE_TEXT}, {AUTHOR, TYPE_TEXT}, {IMAGE_URL, TYPE_TEXT}};
public static final String WHERE_NOT_FAVORITE = "(" + EntryColumns.IS_FAVORITE + Constants.DB_IS_NULL + Constants.DB_OR + EntryColumns.IS_FAVORITE + Constants.DB_IS_FALSE + ')';

public static Uri ENTRIES_FOR_FEED_CONTENT_URI(String feedId) {
return Uri.parse(CONTENT_AUTHORITY + "/feeds/" + feedId + "/entries");
}

public static Uri ENTRIES_FOR_FEED_CONTENT_URI(long feedId) {
return Uri.parse(CONTENT_AUTHORITY + "/feeds/" + feedId + "/entries");
}

public static final Uri CONTENT_URI = Uri.parse(CONTENT_AUTHORITY + "/entries");

public static Uri ENTRIES_FOR_GROUP_CONTENT_URI(String groupId) {
return Uri.parse(CONTENT_AUTHORITY + "/groups/" + groupId + "/entries");
}

public static Uri ENTRIES_FOR_GROUP_CONTENT_URI(long groupId) {
return Uri.parse(CONTENT_AUTHORITY + "/groups/" + groupId + "/entries");
}

public static Uri ALL_ENTRIES_CONTENT_URI(String entryId) {
return Uri.parse(CONTENT_AUTHORITY + "/all_entries/" + entryId);
}

public static final Uri ALL_ENTRIES_CONTENT_URI = Uri.parse(CONTENT_AUTHORITY + "/all_entries");

public static Uri CONTENT_URI(String entryId) {
return Uri.parse(CONTENT_AUTHORITY + "/entries/" + entryId);
}

public static Uri CONTENT_URI(long entryId) {
return Uri.parse(CONTENT_AUTHORITY + "/entries/" + entryId);
}

public static Uri PARENT_URI(String path) {
return Uri.parse(CONTENT_AUTHORITY + path.substring(0, path.lastIndexOf('/')));
}

public static final Uri FAVORITES_CONTENT_URI = Uri.parse(CONTENT_AUTHORITY + "/favorites");

public static Uri SEARCH_URI(String search) {
return Uri.parse(CONTENT_AUTHORITY + "/entries/search/" + (TextUtils.isEmpty(search) ? " " : Uri.encode(search))); // The space is mandatory here with empty search
}


}

Aucun commentaire:

Enregistrer un commentaire