sugar: SQLiteException: no such table:
Hello I have been encountering this issue both on the emulator and on my physical Nexus 5. My code works as follow:
-
the fragment calls this line in onCreateView
if(FavoriteUtils.checkIfThisIsFavorite(mShow)) -
then this method gets executed
public static boolean checkIfThisIsFavorite(Show s){
List<Show> results = getListFromDb(s, WHERE_CLAUSE_ID);
if(results.size() > 0){
//found match
return true;
}else {
//no match
return false;
}
}
- Then finally this
private static List<Show> getListFromDb(Show s, String whereClause){
int showId = s.getShowId();
return Select.from(Show.class)
.where(Condition.prop(whereClause)
.eq(Integer.valueOf(showId)
.toString()))
.list(); // Line of crash
}
This is the version of sugar ORM I’m using compile 'com.github.satyan:sugar:1.4'.
This is my manifest’s application tag.
<application
android:name="com.orm.SugarApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="DATABASE" android:value="fav.db" />
<meta-data android:name="VERSION" android:value="2" />
//I manually removed the other two tags just to be sure, no difference
...
</application>
And this is my model class:
public class Show extends SugarRecord {
int showId;
String title; // original_title
String image; // poster_path
String image2; // backdrop_path used in DetailActivity
String overview;
int rating; // vote_average
String date; // release_date
public Show() {
}
public Show(JSONObject movie) throws JSONException {
this.showId = movie.getInt("id");
this.title = movie.getString("original_title");
this.image = movie.getString("poster_path");
this.image2 = movie.getString("backdrop_path");
this.overview = movie.getString("overview");
this.rating = movie.getInt("vote_average");
this.date = movie.getString("release_date");
}
public Show(JSONObject movie, int notNeeded) throws JSONException {
this.showId = movie.getInt("id");
this.title = movie.getString("original_name");
this.image = movie.getString("poster_path");
this.image2 = movie.getString("backdrop_path");
this.overview = movie.getString("overview");
this.rating = movie.getInt("vote_average");
this.date = movie.getString("first_air_date");
}
public int getShowId() {
return showId;
}
public String getTitle() {
return title;
}
public String getImage() {
return "http://image.tmdb.org/t/p/w185" + image;
}
public String getImage2() {
return "http://image.tmdb.org/t/p/w300" + image2;
}
public String getOverview() {
return overview;
}
public int getRating() {
return rating;
}
public String getDate() {
return date;
}
}
Stacktrace:
9-15 18:41:59.507 6307-6307/com.dcs.shows E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dcs.shows, PID: 6307
android.database.sqlite.SQLiteException: no such table: SHOW (code 1): , while compiling: SELECT * FROM SHOW WHERE (SHOW_ID = ? )
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1240)
at com.orm.SugarRecord.find(SugarRecord.java:192)
at com.orm.query.Select.list(Select.java:118)
at com.dcs.shows.utils.FavoriteUtils.getListFromDb(FavoriteUtils.java:38)
at com.dcs.shows.utils.FavoriteUtils.checkIfThisIsFavorite(FavoriteUtils.java:23)
at com.dcs.shows.DetailFragment.onCreateView(DetailFragment.java:83)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:532)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 15
@fermatijoe,

Example my domain of class package is db all SugarRecords objects here. Please look my previous message, link contains all details.
@ayebaretony , firstly close Instant Run than add prog-guard rule. I explained here: https://mehmethanoglu.com.tr/tips/15-activedroid-ve-sugarorm-1.5-android-studio-2.2-kullanimi.html
Apparently the bug was fixed in this version of SugarORM so maybe that’s why it happens with such unpredictability. I am not sure about your question, if you are asking what I see when that method gets called here it is:
SQL Log: SQLiteQuery: SELECT * FROM SHOW WHERE (SHOW_ID = ? )The method basically returns a List<>. The list can both have 0 items (the movie was not favorited) or 1 item (the movie was in favorites). The List cannot have 2 or more items since every movie has an unique ID in the SHOW_ID column.