Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
* ui: The `ProductResolver.Builder` now requires a project as constructor param, since the default value has been removed
### Removed
### Fixed
* core: Handle `SQLiteDatabaseLockedException` to fix app crash when updating the database
* ui: Avoid npe caused by `isEmpty()` check on a null shopping cart
* ui: Change project reference in `ProductResolver.kt` to get rid of IllegalArgumentException

Expand Down
35 changes: 21 additions & 14 deletions core/src/main/java/io/snabble/sdk/ProductDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.CancellationSignal;
Expand Down Expand Up @@ -332,8 +333,14 @@ synchronized void applyDeltaUpdate(InputStream inputStream) throws IOException {
project.logErrorEvent("Could not copy db to temp file: %s", e.getMessage());
throw e;
}
final SQLiteDatabase tempDb;

SQLiteDatabase tempDb = SQLiteDatabase.openOrCreateDatabase(tempDbFile, null);
try {
tempDb = SQLiteDatabase.openOrCreateDatabase(tempDbFile, null);
} catch (SQLiteCantOpenDatabaseException e) {
project.logErrorEvent("Could not open or create db: %s", e.getMessage());
throw new IOException("Could not open or create db", e);
}

Scanner scanner = new Scanner(inputStream, "UTF-8");

Expand Down Expand Up @@ -531,9 +538,9 @@ private Cursor rawQuery(String sql, String[] args, CancellationSignal cancellati
* <p>
* While updating, the database can still be queried for data, after the update completes calls to the database
* return the updated data.
*
* <p>
* Note that database updates are usually very cheap and do not transmit data that is already on your device.
*
* <p>
* If the database is not present or schematic changes are done that can not be resolved via a delta update
* a full update is needed.
*/
Expand All @@ -549,9 +556,9 @@ public void update() {
* <p>
* While updating, the database can still be queried for data, after the update completes calls to the database
* return the updated data.
*
* <p>
* Note that database updates are usually very cheap and do not transmit data that is already on your device.
*
* <p>
* If the database is not present or schematic changes are done that can not be resolved via a delta update
* a full update is needed.
*
Expand All @@ -570,9 +577,9 @@ public void update(final UpdateCallback callback) {
* <p>
* While updating, the database can still be queried for data, after the update completes calls to the database
* return the updated data.
*
* <p>
* Note that database updates are usually very cheap and do not transmit data that is already on your device.
*
* <p>
* If the database is not present or schematic changes are done that can not be resolved via a delta update
* a full update is needed.
*
Expand Down Expand Up @@ -849,7 +856,7 @@ public Product productAtCursor(Cursor cursor) {
String[] split = isPrimaryStr.split(SEPARATOR, -1);
if (split.length > 0) {
codeIsPrimaryCode = new boolean[split.length];
for (int i=0; i<split.length; i++) {
for (int i = 0; i < split.length; i++) {
if (split[i].equals("1")) {
codeIsPrimaryCode[i] = true;
} else {
Expand All @@ -864,7 +871,7 @@ public Product productAtCursor(Cursor cursor) {
String[] split = specifiedQuantities.split(SEPARATOR, -1);
if (split.length > 0) {
codeSpecifiedQuantities = new int[split.length];
for (int i=0; i<split.length; i++) {
for (int i = 0; i < split.length; i++) {
try {
int value = Integer.parseInt(split[i]);
codeSpecifiedQuantities[i] = value;
Expand Down Expand Up @@ -961,7 +968,7 @@ public Product productAtCursor(Cursor cursor) {

Shop shop = Snabble.getInstance().getCheckedInShop();

if(!queryPrice(builder, sku, shop)) {
if (!queryPrice(builder, sku, shop)) {
queryPrice(builder, sku, null);
}

Expand Down Expand Up @@ -1045,7 +1052,7 @@ private String productSqlString(String appendFields, String appendSql, boolean d
"p.weighing," +
"(SELECT group_concat(s.code, \"" + SEPARATOR + "\") FROM scannableCodes s WHERE s.sku = p.sku)," +
"p.subtitle" +
",p.saleRestriction"+
",p.saleRestriction" +
",p.saleStop" +
",p.notForSale" +
",(SELECT group_concat(ifnull(s.transmissionCode, \"\"), \"" + SEPARATOR + "\") FROM scannableCodes s WHERE s.sku = p.sku)" +
Expand Down Expand Up @@ -1080,7 +1087,7 @@ public boolean isAvailableOffline() {

/**
* Return true if the database was updated recently and can be used to display accurate prices.
*
* <p>
* {@link Config#maxProductDatabaseAge} can be used to set the time window the product database
* is considered up to date.
*/
Expand Down Expand Up @@ -1432,7 +1439,7 @@ public Cursor searchByCode(String searchString, CancellationSignal cancellationS

String query = productSqlString("", sb.toString(), true) + " LIMIT 100";

return rawQuery(query, new String[]{ searchString + "*", searchString + "*" }, cancellationSignal);
return rawQuery(query, new String[]{searchString + "*", searchString + "*"}, cancellationSignal);
}

private void notifyOnDatabaseUpdated() {
Expand Down Expand Up @@ -1468,4 +1475,4 @@ public interface UpdateCallback {

void error();
}
}
}