mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Catch a few more SQLExceptions in HistoryManager
This commit is contained in:
parent
1861cf4f01
commit
379e18daf4
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package com.google.zxing.client.android.history;
|
package com.google.zxing.client.android.history;
|
||||||
|
|
||||||
import android.database.CursorIndexOutOfBoundsException;
|
|
||||||
import android.database.SQLException;
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
import com.google.zxing.client.android.Intents;
|
import com.google.zxing.client.android.Intents;
|
||||||
|
@ -28,6 +26,8 @@ import android.app.Activity;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.database.CursorIndexOutOfBoundsException;
|
||||||
|
import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -169,6 +169,8 @@ public final class HistoryManager {
|
||||||
try (SQLiteDatabase db = helper.getWritableDatabase()) {
|
try (SQLiteDatabase db = helper.getWritableDatabase()) {
|
||||||
// Insert the new entry into the DB.
|
// Insert the new entry into the DB.
|
||||||
db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
|
db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
|
||||||
|
} catch (SQLException sqle) {
|
||||||
|
Log.w(TAG, sqle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +209,8 @@ public final class HistoryManager {
|
||||||
db.update(DBHelper.TABLE_NAME, values, DBHelper.ID_COL + "=?", new String[] { oldID });
|
db.update(DBHelper.TABLE_NAME, values, DBHelper.ID_COL + "=?", new String[] { oldID });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (SQLException sqle) {
|
||||||
|
Log.w(TAG, sqle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,14 +257,14 @@ public final class HistoryManager {
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
CharSequence buildHistory() {
|
CharSequence buildHistory() {
|
||||||
|
StringBuilder historyText = new StringBuilder(1000);
|
||||||
SQLiteOpenHelper helper = new DBHelper(activity);
|
SQLiteOpenHelper helper = new DBHelper(activity);
|
||||||
try (SQLiteDatabase db = helper.getWritableDatabase();
|
try (SQLiteDatabase db = helper.getReadableDatabase();
|
||||||
Cursor cursor = db.query(DBHelper.TABLE_NAME,
|
Cursor cursor = db.query(DBHelper.TABLE_NAME,
|
||||||
COLUMNS,
|
COLUMNS,
|
||||||
null, null, null, null,
|
null, null, null, null,
|
||||||
DBHelper.TIMESTAMP_COL + " DESC")) {
|
DBHelper.TIMESTAMP_COL + " DESC")) {
|
||||||
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
||||||
StringBuilder historyText = new StringBuilder(1000);
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
|
|
||||||
historyText.append('"').append(massageHistoryField(cursor.getString(0))).append("\",");
|
historyText.append('"').append(massageHistoryField(cursor.getString(0))).append("\",");
|
||||||
|
@ -276,8 +280,10 @@ public final class HistoryManager {
|
||||||
|
|
||||||
historyText.append('"').append(massageHistoryField(cursor.getString(4))).append("\"\r\n");
|
historyText.append('"').append(massageHistoryField(cursor.getString(4))).append("\"\r\n");
|
||||||
}
|
}
|
||||||
return historyText;
|
} catch (SQLException sqle) {
|
||||||
|
Log.w(TAG, sqle);
|
||||||
}
|
}
|
||||||
|
return historyText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearHistory() {
|
void clearHistory() {
|
||||||
|
|
Loading…
Reference in a new issue