Java Code Examples for android.database.SQLException#getMessage()
The following examples show how to use
android.database.SQLException#getMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserConfigurationTest.java From clear-todolist with GNU General Public License v3.0 | 6 votes |
/** * Should try to use the legacy parser by default, which is be unable to handle the SQL script. */ public void testLegacyMigration() { try { Configuration configuration = new Configuration.Builder(getContext()) .setDatabaseName("migration.db") .setDatabaseVersion(2) .create(); DatabaseHelper helper = new DatabaseHelper(configuration); SQLiteDatabase db = helper.getWritableDatabase(); helper.onUpgrade(db, 1, 2); fail("Should not be able to parse the SQL script."); } catch (SQLException e) { final String message = e.getMessage(); assertNotNull(message); assertTrue(message.contains("syntax error")); assertTrue(message.contains("near \"MockMigration\"")); } }
Example 2
Source File: ContactsController.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 6 votes |
void addContact(ArrayList<Map<String, String>> list, String username, String sipuri) throws Exception { try { DatabaseManager.getInstance().addContact(username, sipuri); } catch (SQLException e) { if (e.getMessage().contains("UNIQUE constraint failed")) { throw new Exception("Contact already exists", e); } else { throw new Exception(e.getMessage(), e); } } list.add(createEntry(sipuri, username)); }
Example 3
Source File: LocationService.java From trekarta with GNU General Public License v3.0 | 5 votes |
public void addPoint(boolean continuous, double latitude, double longitude, float elevation, float speed, float bearing, float accuracy, long time) { if (mTrackDB == null) { openDatabase(); if (mTrackDB == null) return; } ContentValues values = new ContentValues(); values.put("latitude", (int) (latitude * 1E6)); values.put("longitude", (int) (longitude * 1E6)); values.put("code", continuous ? 0 : 1); values.put("elevation", elevation); values.put("speed", speed); values.put("track", bearing); values.put("accuracy", accuracy); values.put("datetime", time); try { mTrackDB.insertOrThrow("track", null, values); } catch (SQLException e) { logger.error("addPoint", e); mErrorMsg = e.getMessage(); mErrorTime = System.currentTimeMillis(); updateNotification(); closeDatabase(); } }
Example 4
Source File: LocationService.java From Androzic with GNU General Public License v3.0 | 5 votes |
public void addPoint(boolean continous, double latitude, double longitude, double elevation, float speed, float bearing, float accuracy, long time) { if (trackDB == null) { openDatabase(); if (trackDB == null) return; } ContentValues values = new ContentValues(); values.put("latitude", latitude); values.put("longitude", longitude); values.put("code", continous ? 0 : 1); values.put("elevation", elevation); values.put("speed", speed); values.put("track", bearing); values.put("accuracy", accuracy); values.put("datetime", time); try { trackDB.insertOrThrow("track", null, values); } catch (SQLException e) { Log.e(TAG, "addPoint", e); errorMsg = e.getMessage(); errorTime = System.currentTimeMillis(); updateNotification(); closeDatabase(); } }
Example 5
Source File: DataProvider.java From callmeter with GNU General Public License v3.0 | 4 votes |
/** * Try to backup fields from table. * * @param db {@link SQLiteDatabase} * @param table table * @param cols columns * @param selection selection * @param selectionArgs selection arguments * @param strip column to forget on backup, eg. _id * @param os optional {@link ObjectOutputStream} for saving {@link ContentValues} to * @return array of rows if os is not null * @throws IOException IOException */ private static ContentValues[] backup(final SQLiteDatabase db, final String table, final String[] cols, final String selection, final String[] selectionArgs, final String strip, final ObjectOutputStream os) throws IOException { Log.d(TAG, "backup(db,", table, ",cols,sel,args,", strip, ")"); ArrayList<ContentValues> ret = null; if (os == null) { ret = new ArrayList<ContentValues>(); } String[] proj = cols; if (strip != null) { ArrayList<String> a = new ArrayList<String>(cols.length); for (String c : cols) { if (strip.equals(c)) { Log.d(TAG, "ignore column: ", c); continue; } a.add(c); } proj = a.toArray(new String[a.size()]); } final int l = proj.length; Cursor cursor; try { cursor = db.query(table, proj, selection, selectionArgs, null, null, null); } catch (SQLException e) { if (l == 1) { return null; } final String err = e.getMessage(); if (!err.startsWith("no such column:")) { throw new IllegalStateException("Could not parse exeption message: " + err); } Matcher m = P.matcher(err); if (!m.find()) { throw new IllegalStateException("Could not parse exeption message: " + err); } final String str = m.group(1); return backup(db, table, proj, selection, selectionArgs, str, os); } if (cursor != null && cursor.moveToFirst()) { do { int cnt = 0; ContentValues cv = os == null ? new ContentValues() : null; HashMap<String, String> map = os == null ? null : new HashMap<String, String>(); for (int i = 0; i < l; i++) { final String s = cursor.getString(i); if (s != null) { if (os == null) { cv.put(proj[i], s); } else { map.put(proj[i], s); } } } if (os == null) { ret.add(cv); } else { os.writeObject(map); if (cnt % 10 == 0) { os.reset(); } } ++cnt; } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } if (ret == null) { return null; } return ret.toArray(new ContentValues[ret.size()]); }