List of usage examples for android.database.sqlite SQLiteException printStackTrace
public void printStackTrace()
From source file:org.opendatakit.common.android.provider.impl.FormsDiscoveryRunnable.java
/** * Scan the given formDir and update the Forms database. If it is the * formsFolder, then any 'framework' forms should be forbidden. If it is not * the//from ww w. ja v a2s .c o m * formsFolder, only 'framework' forms should be allowed * * @param mediaPath * -- full formDir * @param isFormsFolder * @param baseStaleMediaPath * -- path prefix to the stale forms/framework directory. */ private final void updateFormDir(File formDir, boolean isFormsFolder, String baseStaleMediaPath) { String formDirectoryPath = formDir.getAbsolutePath(); Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath); boolean needUpdate = true; FormInfo fi = null; Uri uri = null; Cursor c = null; try { File formDef = new File(formDir, ODKFileUtils.FORMDEF_JSON_FILENAME); String selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "=?"; String[] selectionArgs = { ODKFileUtils.asRelativePath(appName, formDir) }; c = context.getContentResolver().query(Uri.withAppendedPath(formsProviderContentUri, appName), null, selection, selectionArgs, null); if (c == null) { Log.w(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " null cursor -- cannot update!"); return; } if (c.getCount() > 1) { c.close(); Log.w(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " multiple records from cursor -- delete all and restore!"); // we have multiple records for this one directory. // Rename the directory. Delete the records, and move the // directory back. File tempMediaPath = moveToStaleDirectory(formDir, baseStaleMediaPath); context.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName), selection, selectionArgs); FileUtils.moveDirectory(tempMediaPath, formDir); // we don't know which of the above records was correct, so // reparse this to get ground truth... fi = new FormInfo(context, appName, formDef); } else if (c.getCount() == 1) { c.moveToFirst(); String id = c.getString(c.getColumnIndex(FormsColumns.FORM_ID)); uri = Uri.withAppendedPath(Uri.withAppendedPath(formsProviderContentUri, appName), id); Long lastModificationDate = c.getLong(c.getColumnIndex(FormsColumns.DATE)); Long formDefModified = ODKFileUtils.getMostRecentlyModifiedDate(formDir); if (lastModificationDate.compareTo(formDefModified) == 0) { Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " formDef unchanged"); fi = new FormInfo(appName, c, false); needUpdate = false; } else { Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " formDef revised"); fi = new FormInfo(context, appName, formDef); needUpdate = true; } } else if (c.getCount() == 0) { // it should be new, try to parse it... fi = new FormInfo(context, appName, formDef); } // Enforce that a formId == FormsColumns.COMMON_BASE_FORM_ID can only be // in the Framework directory // and that no other formIds can be in that directory. If this is not the // case, ensure that // this record is moved to the stale directory. if (fi.formId.equals(FormsColumns.COMMON_BASE_FORM_ID)) { if (isFormsFolder) { // we have a 'framework' form in the forms directory. // Move it to the stale directory. // Delete all records referring to this directory. moveToStaleDirectory(formDir, baseStaleMediaPath); context.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName), selection, selectionArgs); return; } } else { if (!isFormsFolder) { // we have a non-'framework' form in the framework directory. // Move it to the stale directory. // Delete all records referring to this directory. moveToStaleDirectory(formDir, baseStaleMediaPath); context.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName), selection, selectionArgs); return; } } } catch (SQLiteException e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); return; } catch (IOException e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); return; } catch (IllegalArgumentException e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); try { FileUtils.deleteDirectory(formDir); Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " Removing -- unable to parse formDef file: " + e.toString()); } catch (IOException e1) { e1.printStackTrace(); Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " Removing -- unable to delete form directory: " + formDir.getName() + " error: " + e.toString()); } return; } finally { if (c != null && !c.isClosed()) { c.close(); } } // Delete any entries matching this FORM_ID, but not the same directory and // which have a version that is equal to or older than this version. String selection; String[] selectionArgs; if (fi.formVersion == null) { selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND " + FormsColumns.FORM_VERSION + " IS NULL"; String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId }; selectionArgs = temp; } else { selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND " + "( " + FormsColumns.FORM_VERSION + " IS NULL" + " OR " + FormsColumns.FORM_VERSION + " <=?" + " )"; String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId, fi.formVersion }; selectionArgs = temp; } try { context.getContentResolver().delete(Uri.withAppendedPath(formsProviderContentUri, appName), selection, selectionArgs); } catch (SQLiteException e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); return; } catch (Exception e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); return; } // See if we have any newer versions already present... if (fi.formVersion == null) { selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND " + FormsColumns.FORM_VERSION + " IS NOT NULL"; String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId }; selectionArgs = temp; } else { selection = FormsColumns.APP_RELATIVE_FORM_MEDIA_PATH + "!=? AND " + FormsColumns.FORM_ID + "=? AND " + FormsColumns.FORM_VERSION + " >?"; String[] temp = { ODKFileUtils.asRelativePath(appName, formDir), fi.formId, fi.formVersion }; selectionArgs = temp; } try { Uri uriApp = Uri.withAppendedPath(formsProviderContentUri, appName); c = context.getContentResolver().query(uriApp, null, selection, selectionArgs, null); if (c == null) { Log.w(t, "[" + instanceCounter + "] updateFormDir: " + uriApp.toString() + " null cursor -- cannot update!"); return; } if (c.moveToFirst()) { // the directory we are processing is stale -- move it to stale // directory moveToStaleDirectory(formDir, baseStaleMediaPath); return; } } catch (SQLiteException e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); return; } catch (IOException e) { e.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + e.toString()); return; } finally { if (c != null && !c.isClosed()) { c.close(); } } if (!needUpdate) { // no change... return; } try { // Now insert or update the record... ContentValues v = new ContentValues(); String[] values = fi.asRowValues(FormsColumns.formsDataColumnNames); for (int i = 0; i < values.length; ++i) { v.put(FormsColumns.formsDataColumnNames[i], values[i]); } if (uri != null) { int count = context.getContentResolver().update(uri, v, null, null); Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " " + count + " records successfully updated"); } else { context.getContentResolver().insert(Uri.withAppendedPath(formsProviderContentUri, appName), v); Log.i(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " one record successfully inserted"); } } catch (SQLiteException ex) { ex.printStackTrace(); Log.e(t, "[" + instanceCounter + "] updateFormDir: " + formDirectoryPath + " exception: " + ex.toString()); return; } }
From source file:org.spinsuite.sync.SyncDataTask.java
/** * Run a Query// ww w . ja v a 2 s . c o m * @author Carlos Parada, cparada@erpcya.com, ERPCyA http://www.erpcya.com * @param sql * @param data * @return void */ private void runQuery(String sql, Object[] data) { try { // Parse SQL String parsedSQL = Env.parseContext(sql, true); if (data != null) conn.executeSQL(parsedSQL, data); else conn.executeSQL(parsedSQL); } catch (SQLiteException e) { e.printStackTrace(); m_PublicMsg = e.getLocalizedMessage(); } catch (Exception e) { e.printStackTrace(); m_PublicMsg = e.getLocalizedMessage(); } finally { publishOnRunning(); } }
From source file:com.triarc.sync.SyncAdapter.java
private SQLiteDatabase openDatabase(SyncTypeCollection collection) throws Exception { try {//w w w . ja v a 2s . co m SQLiteDatabase db = SQLiteAccess.getInstance(this.getContext()).requestDb(collection.getName()); return db; } catch (SQLiteException e) { e.printStackTrace(); sendLogs(); throw e; } }
From source file:me.piebridge.bible.Bible.java
public String getHighlight(String osis) { highlightId = null;/*from w w w . j a v a 2 s . c o m*/ highlighted = ""; SQLiteDatabase db = mOpenHelper.getReadableDatabase(); if (!isDatabaseIntegrityOk(db)) { return highlighted; } Cursor cursor = null; try { cursor = db.query(AnnotationsDatabaseHelper.TABLE_ANNOTATIONS, new String[] { AnnotationsDatabaseHelper.COLUMN_ID, AnnotationsDatabaseHelper.COLUMN_VERSES }, AnnotationsDatabaseHelper.COLUMN_OSIS + " = ? and " + AnnotationsDatabaseHelper.COLUMN_TYPE + " = ?", new String[] { osis, "highlight" }, null, null, null); while (cursor != null && cursor.moveToNext()) { highlightId = cursor.getLong(0); highlighted = cursor.getString(1); } } catch (SQLiteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } return highlighted; }
From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java
private void loadDefaultProfile(int profile) { ArrayList<ArrayList<String>> prefs = new ArrayList<ArrayList<String>>(); try {//from w ww .j a v a 2 s . c o m prefs = myDbHelper.loadProfile(profile); } catch (SQLiteException e) { e.printStackTrace(); } if (prefs.size() > 0) { Map<String, String> set_Prefs = setPrefs(prefs); setDefaultPrefs(set_Prefs); overwritePrefs(set_Prefs); } else { readPrefs(); } }
From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java
private void saveProfile() { int length = profiles.size(); int selectedId = 0; final CharSequence[] items = new CharSequence[length]; for (int i = 0; i < length; i++) { ArrayList<String> profile_array = new ArrayList<String>(); profile_array = profiles.get(i); items[i] = profile_array.get(1).toString(); int id = Integer.parseInt(profile_array.get(0).toString()); if (profile == id) { selectedId = i;//from ww w . java 2 s.c o m } } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("select profile") .setSingleChoiceItems(items, selectedId, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "save profile " + items[which], Toast.LENGTH_LONG) .show(); profile = getprofileId(items[which].toString()); ArrayList<ArrayList<String>> prefs = new ArrayList<ArrayList<String>>(); prefs = getprefs(); try { boolean result = myDbHelper.saveProfile(profile, prefs); } catch (SQLiteException e) { e.printStackTrace(); } ArrayList<String> pref_liste = new ArrayList<String>(); int length = prefs.size(); for (int i = 0; i < length; i++) { ArrayList<String> pref = new ArrayList<String>(); pref = prefs.get(i); pref_liste.add(pref.get(0)); } saveSensorView(); dialog.dismiss(); } }).show(); }
From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java
public void saveSensorView() { ArrayList<ArrayList<String>> sensorArray = new ArrayList<ArrayList<String>>(); ArrayList<String> data = new ArrayList<String>(); boolean VisibleState = false; boolean visible = false; VisibleState = mPrefs.getBoolean("volts", visible); data.add("volts"); if (VisibleState == false) { data.add("0"); } else {//from w w w . j a v a2 s . com data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("amps", visible); data.add("amps"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("Used", visible); data.add("Used"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("receiverVoltage", visible); data.add("receiverVoltage"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("powers", visible); data.add("power"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("speeds", visible); data.add("speed"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("altitudes", visible); data.add("altitude"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("rpm1", visible); data.add("rpm1"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("temp1", visible); data.add("temp1"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("temp2", visible); data.add("temp2"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("rpm2", visible); data.add("rpm2"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("fuels", visible); data.add("fuel"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("Servo01", visible); data.add("Servo01"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("Servo02", visible); data.add("Servo02"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("Servo03", visible); data.add("Servo03"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("Servo04", visible); data.add("Servo04"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("temp5", visible); data.add("temp5"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("airpressure1", visible); data.add("airpressure1"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("airpressure2", visible); data.add("airpressure2"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("speedpressure", visible); data.add("speedpressure"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("lqi", visible); data.add("lqi"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("txState", visible); data.add("txState"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("distance", visible); data.add("distance"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); VisibleState = mPrefs.getBoolean("gpsCourse", visible); data.add("gpsCourse"); if (VisibleState == false) { data.add("0"); } else { data.add("1"); } sensorArray.add(data); data = new ArrayList<String>(); try { boolean result = myDbHelper.InsertSensorData(profile, sensorArray); } catch (SQLiteException e) { e.printStackTrace(); } }