Example usage for android.database.sqlite SQLiteException printStackTrace

List of usage examples for android.database.sqlite SQLiteException printStackTrace

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

static void loadDays(Context context) {
    MyApp.dateInfos = new DateInfos();
    LecturesDBOpenHelper lecturesDB = new LecturesDBOpenHelper(context);

    SQLiteDatabase lecturedb = lecturesDB.getReadableDatabase();
    Cursor cursor;//from  w  w w. j  a  v a 2s  . co  m

    try {
        cursor = lecturedb.query(LecturesTable.NAME, LecturesDBOpenHelper.allcolumns, null, null, null, null,
                null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        lecturesDB.close();
        return;
    }

    if (cursor.getCount() == 0) {
        // evtl. Datenbankreset wg. DB Formatnderung -> neu laden
        cursor.close();
        lecturesDB.close();
        lecturedb.close();
        return;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        int day = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DAY));
        String date = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DATE));

        DateInfo dateItem = new DateInfo(day, date);
        if (!MyApp.dateInfos.contains(dateItem)) {
            MyApp.dateInfos.add(dateItem);
        }
        cursor.moveToNext();
    }
    cursor.close();

    for (DateInfo dateInfo : MyApp.dateInfos) {
        MyApp.LogDebug(LOG_TAG, "DateInfo: " + dateInfo);
    }
    lecturesDB.close();
    lecturedb.close();
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

public static void deleteAlarm(Context context, Lecture lecture) {
    AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context);
    SQLiteDatabase db = alarmDB.getWritableDatabase();
    Cursor cursor;// ww w .  j a v a2s  . c  om

    try {
        cursor = db.query(AlarmsTable.NAME, AlarmsDBOpenHelper.allcolumns, AlarmsTable.Columns.EVENT_ID + "=?",
                new String[] { lecture.lecture_id }, null, null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        MyApp.LogDebug("delete alarm", "failure on alarm query");
        db.close();
        return;
    }

    if (cursor.getCount() == 0) {
        db.close();
        cursor.close();
        MyApp.LogDebug("delete_alarm", "alarm for " + lecture.lecture_id + " not found");
        return;
    }

    cursor.moveToFirst();

    Intent intent = new Intent(context, AlarmReceiver.class);

    String lecture_id = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_ID));
    intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture_id);
    int day = cursor.getInt(cursor.getColumnIndex(AlarmsTable.Columns.DAY));
    intent.putExtra(BundleKeys.ALARM_DAY, day);
    String title = cursor.getString(cursor.getColumnIndex(AlarmsTable.Columns.EVENT_TITLE));
    intent.putExtra(BundleKeys.ALARM_TITLE, title);
    long startTime = cursor.getLong(cursor.getColumnIndex(AlarmsTable.Columns.TIME));
    intent.putExtra(BundleKeys.ALARM_START_TIME, startTime);

    // delete any previous alarms of this lecture
    db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id });
    db.close();

    intent.setAction("de.machtnix.fahrplan.ALARM");
    intent.setData(Uri.parse("alarm://" + lecture.lecture_id));

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id),
            intent, 0);

    // Cancel any existing alarms for this lecture
    alarmManager.cancel(pendingintent);

    lecture.has_alarm = false;
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

static void loadMeta(Context context) {
    MetaDBOpenHelper metaDB = new MetaDBOpenHelper(context);
    SQLiteDatabase metadb = metaDB.getReadableDatabase();

    Cursor cursor;//from  w  w  w .  ja  v a  2  s  .c o  m
    try {
        cursor = metadb.query(MetasTable.NAME, MetaDBOpenHelper.allcolumns, null, null, null, null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        metaDB.close();
        metadb.close();
        metadb = null;
        return;
    }

    MyApp.numdays = MetasTable.Defaults.NUM_DAYS_DEFAULT;
    ;
    MyApp.version = "";
    MyApp.title = "";
    MyApp.subtitle = "";
    MyApp.dayChangeHour = MetasTable.Defaults.DAY_CHANGE_HOUR_DEFAULT;
    MyApp.dayChangeMinute = MetasTable.Defaults.DAY_CHANGE_MINUTE_DEFAULT;
    MyApp.eTag = null;

    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        int columnIndexNumDays = cursor.getColumnIndex(MetasTable.Columns.NUM_DAYS);
        if (cursor.getColumnCount() > columnIndexNumDays) {
            MyApp.numdays = cursor.getInt(columnIndexNumDays);
        }
        int columIndexVersion = cursor.getColumnIndex(MetasTable.Columns.VERSION);
        if (cursor.getColumnCount() > columIndexVersion) {
            MyApp.version = cursor.getString(columIndexVersion);
        }
        int columnIndexTitle = cursor.getColumnIndex(MetasTable.Columns.TITLE);
        if (cursor.getColumnCount() > columnIndexTitle) {
            MyApp.title = cursor.getString(columnIndexTitle);
        }
        int columnIndexSubTitle = cursor.getColumnIndex(MetasTable.Columns.SUBTITLE);
        if (cursor.getColumnCount() > columnIndexSubTitle) {
            MyApp.subtitle = cursor.getString(columnIndexSubTitle);
        }
        int columnIndexDayChangeHour = cursor.getColumnIndex(MetasTable.Columns.DAY_CHANGE_HOUR);
        if (cursor.getColumnCount() > columnIndexDayChangeHour) {
            MyApp.dayChangeHour = cursor.getInt(columnIndexDayChangeHour);
        }
        int columnIndexDayChangeMinute = cursor.getColumnIndex(MetasTable.Columns.DAY_CHANGE_MINUTE);
        if (cursor.getColumnCount() > columnIndexDayChangeMinute) {
            MyApp.dayChangeMinute = cursor.getInt(columnIndexDayChangeMinute);
        }
        int columnIndexEtag = cursor.getColumnIndex(MetasTable.Columns.ETAG);
        if (cursor.getColumnCount() > columnIndexEtag) {
            MyApp.eTag = cursor.getString(columnIndexEtag);
        }
    }

    MyApp.LogDebug(LOG_TAG, "loadMeta: numdays=" + MyApp.numdays + " version:" + MyApp.version + " "
            + MyApp.title + " " + MyApp.eTag);
    cursor.close();

    metadb.close();
    metaDB.close();
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

/**
 * Load all Lectures from the DB on the day specified
 *
 * @param context The Android Context/*  w w  w  .  j  a v  a 2s . c o  m*/
 * @param day The day to load lectures for (0..), or -1 for all days
 * @return ArrayList of Lecture objects
 */
public static LectureList loadLecturesForDayIndex(Context context, int day) {
    MyApp.LogDebug(LOG_TAG, "load lectures of day " + day);

    SQLiteDatabase lecturedb = null;
    LecturesDBOpenHelper lecturesDB = new LecturesDBOpenHelper(context);
    lecturedb = lecturesDB.getReadableDatabase();

    HighlightDBOpenHelper highlightDB = new HighlightDBOpenHelper(context);
    SQLiteDatabase highlightdb = highlightDB.getReadableDatabase();

    LectureList lectures = new LectureList();
    Cursor cursor, hCursor;
    boolean allDays;

    if (day == ALL_DAYS) {
        allDays = true;
    } else {
        allDays = false;
    }

    try {
        cursor = lecturedb.query(LecturesTable.NAME, LecturesDBOpenHelper.allcolumns,
                allDays ? null : (LecturesTable.Columns.DAY + "=?"),
                allDays ? null : (new String[] { String.format("%d", day) }), null, null,
                LecturesTable.Columns.DATE_UTC);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        highlightdb.close();
        lecturesDB.close();
        return null;
    }
    try {
        hCursor = highlightdb.query(HighlightsTable.NAME, HighlightDBOpenHelper.allcolumns, null, null, null,
                null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        highlightdb.close();
        lecturesDB.close();
        return null;
    }
    MyApp.LogDebug(LOG_TAG, "Got " + cursor.getCount() + " rows.");
    MyApp.LogDebug(LOG_TAG, "Got " + hCursor.getCount() + " highlight rows.");

    if (cursor.getCount() == 0) {
        cursor.close();
        lecturedb.close();
        highlightdb.close();
        lecturesDB.close();
        return null;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Lecture lecture = new Lecture(cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.EVENT_ID)));
        lecture.title = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TITLE));
        lecture.subtitle = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.SUBTITLE));
        lecture.day = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DAY));
        lecture.room = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.ROOM));
        lecture.startTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.START));
        lecture.duration = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DURATION));
        lecture.speakers = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.SPEAKERS));
        lecture.track = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TRACK));
        lecture.type = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TYPE));
        lecture.lang = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.LANG));
        lecture.abstractt = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.ABSTRACT));
        lecture.description = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DESCR));
        lecture.relStartTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.REL_START));
        lecture.date = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DATE));
        lecture.links = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.LINKS));
        lecture.dateUTC = cursor.getLong(cursor.getColumnIndex(LecturesTable.Columns.DATE_UTC));
        lecture.room_index = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.ROOM_IDX));
        lecture.recordingLicense = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.REC_LICENSE));
        lecture.recordingOptOut = cursor.getInt(
                cursor.getColumnIndex(LecturesTable.Columns.REC_OPTOUT)) == LecturesTable.Values.REC_OPTOUT_OFF
                        ? Lecture.RECORDING_OPTOUT_OFF
                        : Lecture.RECORDING_OPTOUT_ON;
        lecture.changedTitle = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TITLE)) != 0;
        lecture.changedSubtitle = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_SUBTITLE)) != 0;
        lecture.changedRoom = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_ROOM)) != 0;
        lecture.changedDay = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_DAY)) != 0;
        lecture.changedSpeakers = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_SPEAKERS)) != 0;
        lecture.changedRecordingOptOut = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_RECORDING_OPTOUT)) != 0;
        lecture.changedLanguage = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_LANGUAGE)) != 0;
        lecture.changedTrack = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TRACK)) != 0;
        lecture.changedIsNew = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_IS_NEW)) != 0;
        lecture.changedTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TIME)) != 0;
        lecture.changedDuration = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_DURATION)) != 0;
        lecture.changedIsCanceled = cursor
                .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_IS_CANCELED)) != 0;

        lectures.add(lecture);
        cursor.moveToNext();
    }
    cursor.close();

    hCursor.moveToFirst();
    while (!hCursor.isAfterLast()) {
        String lecture_id = hCursor.getString(hCursor.getColumnIndex(HighlightsTable.Columns.EVENT_ID));
        int highlightState = hCursor.getInt(hCursor.getColumnIndex(HighlightsTable.Columns.HIGHLIGHT));
        MyApp.LogDebug(LOG_TAG, "lecture " + lecture_id + " is hightlighted:" + highlightState);

        for (Lecture lecture : lectures) {
            if (lecture.lecture_id.equals(lecture_id)) {
                lecture.highlight = (highlightState == HighlightsTable.Values.HIGHLIGHT_STATE_ON ? true
                        : false);
            }
        }
        hCursor.moveToNext();
    }
    hCursor.close();

    highlightdb.close();
    lecturedb.close();
    lecturesDB.close();
    return lectures;
}

From source file:com.phonegap.Storage.java

/**
 * Execute SQL statement./*w  w  w .  j  a  v  a2 s . c  o  m*/
 * 
 * @param query            The SQL query
 * @param params         Parameters for the query
 * @param tx_id            Transaction id
 */
public void executeSql(String query, String[] params, String tx_id) {
    try {
        Cursor myCursor = this.myDb.rawQuery(query, params);
        this.processResults(myCursor, tx_id);
        myCursor.close();
    } catch (SQLiteException ex) {
        ex.printStackTrace();
        System.out.println("Storage.executeSql(): Error=" + ex.getMessage());

        // Send error message back to JavaScript
        this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
    }
}

From source file:org.apache.cordova.legacywebsql.LegacyWebSql.java

/**
 * Execute SQL statement./*from w  ww .j a v a  2s  . c  om*/
 *
 * @param query
 *            The SQL query
 * @param params
 *            Parameters for the query
 * @param tx_id
 *            Transaction id
 */
public void executeSql(String query, String[] params, String tx_id) {
    try {
        if (isDDL(query)) {
            this.myDb.execSQL(query);
            this.webView.sendJavascript(
                    "cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');");
        } else {
            Cursor myCursor = this.myDb.rawQuery(query, params);
            this.processResults(myCursor, tx_id);
            myCursor.close();
        }
    } catch (SQLiteException ex) {
        ex.printStackTrace();
        System.out.println("Storage.executeSql(): Error=" + ex.getMessage());

        // Send error message back to JavaScript
        this.webView.sendJavascript("cordova.require('cordova/plugin/android/storage').failQuery('"
                + ex.getMessage() + "','" + tx_id + "');");
    }
}

From source file:org.skt.runtime.original.Storage.java

/**
 * Execute SQL statement.//w ww  .  ja  va2  s  . c om
 * 
 * @param query
 *            The SQL query
 * @param params
 *            Parameters for the query
 * @param tx_id
 *            Transaction id
 */
public void executeSql(String query, String[] params, String tx_id) {
    try {
        if (isDDL(query)) {
            this.myDb.execSQL(query);
            this.sendJavascript(
                    "srt.sktrequire('srt/plugin/android/storage').completeQuery('" + tx_id + "', '');");
        } else {
            Cursor myCursor = this.myDb.rawQuery(query, params);
            this.processResults(myCursor, tx_id);
            myCursor.close();
        }
    } catch (SQLiteException ex) {
        ex.printStackTrace();
        System.out.println("Storage.executeSql(): Error=" + ex.getMessage());

        // Send error message back to JavaScript
        this.sendJavascript("srt.sktrequire('srt/plugin/android/storage').failQuery('" + ex.getMessage() + "','"
                + tx_id + "');");
    }
}

From source file:com.phonegap.plugin.sqlitePlugin.SQLitePlugin.java

/**
 * Execute SQL statement./*from www  . j a v a 2 s  .  co  m*/
 *
 * @param query
 *            The SQL query
 * @param params
 *            Parameters for the query
 * @param tx_id
 *            Transaction id
 */
public void executeSql(String query, String[] params, String tx_id) {
    String cmd = query.toLowerCase();

    try {
        if (cmd.startsWith("insert")) {
            SQLiteStatement myStatement = this.myDb.compileStatement(query);
            long insertId = myStatement.executeInsert();
            this.sendJavascript("dddb.completeQuery('" + tx_id + "', [{'insertId':'" + insertId
                    + "', 'rowsAffected':'1'}]);");
            /* Test fix for #22, requires API 11+: **
            } else if (cmd.startsWith("update") || cmd.startsWith("delete")) {
               SQLiteStatement myStatement = this.myDb.compileStatement(query);
               int rowsAffected = myStatement.executeUpdateDelete();
               this.sendJavascript("dddb.completeQuery('" + tx_id + "', [{'rowsAffected':'" + rowsAffected + "'}]);");
             * END of Test fix for #22, requires API 11+ */
        } else if (isDDL(query)) {
            this.myDb.execSQL(query);
            this.sendJavascript("dddb.completeQuery('" + tx_id + "', '');");
        } else {
            Cursor myCursor = this.myDb.rawQuery(query, params);
            this.processResults(myCursor, tx_id);
            myCursor.close();
        }
    } catch (SQLiteException ex) {
        ex.printStackTrace();
        System.out.println("SQLitePlugin.executeSql(): Error=" + ex.getMessage());

        // Send error message back to JavaScript
        this.sendJavascript("dddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
    }
}

From source file:com.phonegap.plugins.sqlitePlugin.SQLitePlugin.java

public void executeSqlBatch(String[] queryarr, String[][] paramsarr, String[] queryIDs, String tx_id) {
    try {//  w w  w . j  ava  2  s.  c  om
        this.myDb.beginTransaction();
        String query = "";
        String query_id = "";
        String[] params;
        int len = queryarr.length;
        for (int i = 0; i < len; i++) {
            query = queryarr[i];
            params = paramsarr[i];
            query_id = queryIDs[i];
            Cursor myCursor = this.myDb.rawQuery(query, params);

            this.processResults(myCursor, query_id, tx_id);
            myCursor.close();
        }
        this.myDb.setTransactionSuccessful();
    } catch (SQLiteException ex) {
        ex.printStackTrace();
        Log.v("executeSqlBatch", "SQLitePlugin.executeSql(): Error=" + ex.getMessage());
        this.sendJavascript(
                "SQLitePluginTransaction.txErrorCallback('" + tx_id + "', '" + ex.getMessage() + "');");
    } finally {
        this.myDb.endTransaction();
        Log.v("executeSqlBatch", tx_id);
        this.sendJavascript("SQLitePluginTransaction.txCompleteCallback('" + tx_id + "');");
    }
}

From source file:com.android.server.MaybeDatabaseHelper.java

private void initDatabase(Context context) {
    try {/* w w w .  j av a2 s. co m*/
        sDatabase = context.openOrCreateDatabase(DBNAME, 0, null);
    } catch (SQLiteException e) {
        Log.e(DBTAG, "Exception while opening database. Retrying.");
        e.printStackTrace();
        if (context.deleteDatabase(DBNAME)) {
            sDatabase = context.openOrCreateDatabase(DBNAME, 0, null);
        }
    }

    if (sDatabase == null) {
        //Use for any damage control because something went wrong horribly 
        //if sDatabase is null at this point
        Log.d(DBTAG, "sDatabase is null");
    }

    //sDatabase.execSQL("DROP TABLE IF EXISTS apptable");

    sDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + APP_TABLE_NAME + " (" + ID_COL + " INTEGER PRIMARY_KEY, "
            + PACKAGE_COL + " TEXT, " + GCM_COL + " TEXT, " + URL_COL + " TEXT, " + HASH_COL + " TEXT, "
            + DATA_COL + " TEXT, " + STALE_COL + " BOOLEAN, " + PUSH_COL + " BOOLEAN " + ");");

}