-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong get result #731
Comments
Hi, @S1owaway ! try(Cursor cursor = dbProvider.sqLiteOpenHelper.getReadableDatabase().query("accounts", null, null, null, null, null, null, null)) {
cursor.moveToFirst();
assertThat(cursor.getColumnIndex("account5")).isEqualTo(-1);
}
dbProvider.sqLiteOpenHelper.getWritableDatabase().execSQL("ALTER TABLE accounts ADD COLUMN account5 INTEGER DEFAULT 1");
try(Cursor cursor = dbProvider.sqLiteOpenHelper.getReadableDatabase().query("accounts", null, null, null, null, null, null, null)) {
cursor.moveToFirst();
assertThat(cursor.getColumnIndex("account5")).isEqualTo(-1);
}
try(Cursor cursor = dbProvider.sqLiteOpenHelper.getReadableDatabase().query("accounts", null, null, null, null, null, null, null)) {
cursor.moveToFirst();
assertThat(cursor.getInt(cursor.getColumnIndexOrThrow("account5"))).isEqualTo(1);
} On the sqlfiddle SQLite (SQL.js) all works fine http://sqlfiddle.com/#!5/725e6/8 |
Спасибо за ответ. Поведение в представленном вами примере понятно и логично. А вот поведение StorIO непонятно. Либо это бага, либо фича такая интересная. Обидно, так как библиотека уже вплотную используется в немаленьком проекте. Неужели придется переезжать на что нибудь другое. |
Can we please continue in english to keep issue available to all interested? First of all StrIO uses sqlOpenHelper under the hood. try(Cursor cursor = dbProvider.sqLiteOpenHelper.getReadableDatabase().query("accounts", null, null, null, null, null, null, null)) {
cursor.moveToFirst();
assertThat(cursor.getColumnIndex("account5")).isEqualTo(-1);
}
dbProvider.sqLiteOpenHelper.getWritableDatabase().execSQL("ALTER TABLE accounts ADD COLUMN account5 INTEGER DEFAULT 1");
try(Cursor cursor = dbProvider.sqLiteOpenHelper.getReadableDatabase().query("accounts", null, null, null, null, null, null, null)) {
cursor.moveToFirst();
assertThat(cursor.getColumnIndex("account5")).isEqualTo(-1); // value was not updated
}
try(Cursor cursor = dbProvider.sqLiteOpenHelper.getReadableDatabase().query("accounts", null, null, null, null, null, null, null)) {
cursor.moveToFirst();
assertThat(cursor.getInt(cursor.getColumnIndexOrThrow("account5"))).isEqualTo(1);
} I havn't investigate the cause of this problem yet, but can't you instead of adding columns for every account decompose this table and add rows instead. Otherwise you can can met performance problem too. |
Thank you for your help. It seems the problem is really on the SQLite level. In my case, add a column for the table is the only way. Fortunatly it is the very rare operation. Thank you for StorIO. P.S.: by the way, using the library I faced with some discomfort. When I update some field in the table, I want to know where exactly this update happened (particular id). The current table observers are not emit data (it works only on adding and removing fields). To solve this problem i use the EventBus in bunch with observables in the DAO class. This is not very convenient. |
We can attach Query that caused Change, but it might not be helful in cases like |
such a case:
Manipulations with observesTables()/affectsTables() did not yield results. However, when I open the database using SQLiteBrowser after "ALTER TABLE..." I see that the column really added. A feeling that StorIO did't know about the changes in the table and gives first result incorrect.
The text was updated successfully, but these errors were encountered: