Example usage for android.database SQLException getLocalizedMessage

List of usage examples for android.database SQLException getLocalizedMessage

Introduction

In this page you can find the example usage for android.database SQLException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.samcrow.ridgesurvey.DataEntryActivity.java

private void submit() {
    // Collect species data
    final Map<String, Boolean> speciesData = new HashMap<>();
    for (int i = 0; i < mSpeciesContainer.getChildCount(); i++) {
        final View view = mSpeciesContainer.getChildAt(i);
        if (view instanceof SpeciesView && !isNoSpeciesView((SpeciesView) view)) {
            final SpeciesView speciesView = (SpeciesView) view;
            speciesData.put(speciesView.getSpecies().getColumn(), speciesView.isChecked());
        }/*from  w w w  .jav a  2  s.c  o  m*/
    }
    final String notes = mNotesField.getText().toString();

    final Observation observation = new Observation(DateTime.now(), false, mSite.getId(), mRouteName,
            speciesData, notes);

    // Store
    try {
        final ObservationDatabase db = new ObservationDatabase(this);
        db.insertObservation(observation);
        Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();
        // Start a service to upload the observation
        startService(new Intent(this, UploadService.class));
        // Update the status bar
        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(new Intent(UploadStatusTracker.ACTION_OBSERVATION_MADE));
        setResult(RESULT_OK);
        finish();
    } catch (SQLException e) {
        new AlertDialog.Builder(this).setTitle("Failed to save").setMessage(e.getLocalizedMessage()).show();
    }

}

From source file:nl.basvanmarwijk.mylocations.viewcontroller.LocationItemDetailFragment.java

/**
 * Verwijdert item en verlaat activity/*from w  w  w.j  ava2  s .  c o  m*/
 */
private void removeCurrentItem() {
    // doe werk buiten UI thread
    new Thread(new Runnable() {
        @Override
        public void run() {
            // delete van db_depecrated
            try {
                App.getDbManager().deleteLocation(mItem);
            } catch (SQLException e) {
                Log.w(TAG, e.getLocalizedMessage());
            }

            // delete van sd kaart
            if (!mItem.getFk_location_picture().isEmpty()) {
                try {
                    for (final Location_picture pic : mItem.getFk_location_picture()) {
                        ExternalStorageHelper.removeFileFromUri(Uri.parse(pic.getPicture_path()));
                    }
                } catch (IllegalStateException e) {
                    getActivity().runOnUiThread(new ToastRunnable(R.string.sd_card_in_use));
                    Log.w(TAG, "sd in use");
                } catch (IOException e) {
                    Log.e(TAG, "Could not remove item from storage");
                }
            }

            // release resources
            mItem = null;
        }
    }).start();

    // quit activity
    getActivity().finish();
}

From source file:com.futureplatforms.kirin.extensions.databases.DatabasesBackend.java

@Override
public void endTransaction_(String txId) {
    final DBTransaction tx = mInFlightTransactions.remove(txId);
    if (tx == null) {
        Log.w(C.TAG, "Transaction {0} not valid");
        cleanupTx(tx);//from   www  . j  av  a  2  s. c  om
        return;
    }

    Runnable job = new Runnable() {
        public void run() {

            String dbName = tx.mDbName;
            SQLiteDatabase db = mDatabases.get(dbName);
            String onError = null;

            try {
                beginNativeTransaction(db);
                for (DBStatement s : tx.getEntries()) {
                    onError = s.mOnError;

                    // TODO do something for type=file.
                    s.mResult = execStatement(db, s);

                }
                setNativeTransactionSuccessful(db);
            } catch (SQLException e) {
                mKirinHelper.jsCallback(onError, e.getLocalizedMessage());
                mKirinHelper.jsCallback(tx.mOnError, e.getLocalizedMessage());
                cleanupTx(tx);
                return;
            } finally {
                endNativeTransaction(db);
            }

            IKirinDropbox dropbox = mKirinHelper.getDropbox();
            for (DBStatement s : tx.getEntries()) {
                String onSuccess = s.mOnSuccess;
                Cursor cursor = s.mResult;
                if (cursor == null || onSuccess == null) {
                    continue;
                }

                boolean emptyResults = !cursor.moveToFirst();

                switch (s.mType) {
                case rowset:
                    mKirinHelper.jsCallback(onSuccess, dropbox.put("db.rowset.", cursor));
                    break;
                case file:
                    mKirinHelper.jsCallback(onSuccess);
                    break;
                case row:
                    if (emptyResults) {
                        mKirinHelper.jsCallback(onSuccess, new JSONObject());
                    } else {
                        mKirinHelper.jsCallback(onSuccess, coerceToJSONObject(columnNames(cursor), cursor));
                    }
                    break;
                case array:
                    if (emptyResults) {
                        mKirinHelper.jsCallback(onSuccess, new JSONArray());
                    } else {
                        mKirinHelper.jsCallback(onSuccess, coerceToJSONArray(columnNames(cursor), cursor));
                    }
                case eof:
                    break;
                default:
                    break;
                }

                if (s.mType != StatementType.rowset) {
                    cursor.close();
                }
            }

            int schemaVersion = tx.mSchemaVersion;
            if (schemaVersion >= 0) {
                // update the schema version if it needs it.
                setDatabaseVersion(dbName, schemaVersion);
            }

            mKirinHelper.jsCallback(tx.mOnSuccess);
            cleanupTx(tx);
        }
    };

    executeEndTransaction(tx, job);
}