Java Code Examples for android.database.sqlite.SQLiteException

The following are top voted examples for showing how to use android.database.sqlite.SQLiteException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PeSanKita-android   File: ApnDatabase.java   Source Code and License 10 votes vote down vote up
private ApnDatabase(final Context context) throws IOException {
  this.context = context;

  File dbFile = context.getDatabasePath(DATABASE_NAME);

  if (!dbFile.getParentFile().exists() && !dbFile.getParentFile().mkdir()) {
    throw new IOException("couldn't make databases directory");
  }

  Util.copy(context.getAssets().open(ASSET_PATH, AssetManager.ACCESS_STREAMING),
            new FileOutputStream(dbFile));

  try {
    this.db = SQLiteDatabase.openDatabase(context.getDatabasePath(DATABASE_NAME).getPath(),
                                          null,
                                          SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
  } catch (SQLiteException e) {
    throw new IOException(e);
  }
}
 
Example 2
Project: AIMSICDL   File: AIMSICDDbAdapter.java   Source Code and License 7 votes vote down vote up
/**
 * Check if the database already exist to avoid re-copying the file each time you open the application.
 *
 * ToDo: NOTE:  This is a dumb check, as it currently only tries to open it.
 *              It may be other reasons why it can't be opened even if it already exists.
 *
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {

    SQLiteDatabase checkDB = null;
    try {
        Log.i(TAG, mTAG + "Checking if DB exists...");
        checkDB = SQLiteDatabase.openDatabase(mDatabasePath, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        Log.i(TAG, mTAG + "SQL Exception! Database can\'t be opened: " + e);
        //Log.i(TAG, mTAG + "Database not yet created: " + e);
    }

    if (checkDB != null) {
        checkDB.close();
        Log.i(TAG, mTAG + "OK (found)");
        return true;
    }
    Log.i(TAG, mTAG + "Database probably not yet created.");
    return false;
}
 
Example 3
Project: q-mail   File: MigrationTo45.java   Source Code and License 6 votes vote down vote up
public static void changeThreadingIndexes(SQLiteDatabase db) {
    try {
        db.execSQL("DROP INDEX IF EXISTS msg_empty");
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_empty ON messages (empty)");

        db.execSQL("DROP INDEX IF EXISTS msg_thread_root");
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_root ON messages (thread_root)");

        db.execSQL("DROP INDEX IF EXISTS msg_thread_parent");
        db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_parent ON messages (thread_parent)");
    } catch (SQLiteException e) {
        if (!e.getMessage().startsWith("duplicate column name:")) {
            throw e;
        }
    }
}
 
Example 4
Project: sealtalk-android-master   File: RongDatabaseDriver.java   Source Code and License 6 votes vote down vote up
public Database.ExecuteSQLResponse executeSQL(String databaseName, String query, ExecuteResultHandler<Database.ExecuteSQLResponse> handler)
        throws SQLiteException {
    Util.throwIfNull(query);
    Util.throwIfNull(handler);
    SQLiteDatabase database = openDatabase(databaseName);
    try {
        String firstWordUpperCase = getFirstWord(query).toUpperCase();
        switch (firstWordUpperCase) {
            case "UPDATE":
            case "DELETE":
                return executeUpdateDelete(database, query, handler);
            case "INSERT":
                return executeInsert(database, query, handler);
            case "SELECT":
            case "PRAGMA":
            case "EXPLAIN":
                return executeSelect(database, query, handler);
            default:
                return executeRawQuery(database, query, handler);
        }
    } finally {
        database.close();
    }
}
 
Example 5
Project: q-mail   File: LockableDatabase.java   Source Code and License 6 votes vote down vote up
/**
 *
 * @throws UnavailableStorageException
 */
private void openOrCreateDataspace() throws UnavailableStorageException {

    lockWrite();
    try {
        final File databaseFile = prepareStorage(mStorageProviderId);
        try {
            doOpenOrCreateDb(databaseFile);
        } catch (SQLiteException e) {
            // TODO handle this error in a better way!
            Timber.w(e, "Unable to open DB %s - removing file and retrying", databaseFile);
            if (databaseFile.exists() && !databaseFile.delete()) {
                Timber.d("Failed to remove %s that couldn't be opened", databaseFile);
            }
            doOpenOrCreateDb(databaseFile);
        }
        if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
            mSchemaDefinition.doDbUpgrade(mDb);
        }
    } finally {
        unlockWrite();
    }
}
 
Example 6
Project: justintrain-client-android   File: SQLiteAssetHelper.java   Source Code and License 6 votes vote down vote up
/**
 * Create and/or open a database.  This will be the same object returned by
 * {@link #getWritableDatabase} unless some problem, such as a full disk,
 * requires the database to be opened read-only.  In that case, a read-only
 * database object will be returned.  If the problem is fixed, a future call
 * to {@link #getWritableDatabase} may succeed, in which case the read-only
 * database object will be closed and the read/write object will be returned
 * in the future.
 *
 * <p class="caution">Like {@link #getWritableDatabase}, this method may
 * take a long time to return, so you should not call it from the
 * application main thread, including from
 * {@link android.content.ContentProvider#onCreate ContentProvider.onCreate()}.
 *
 * @return a database object valid until {@link #getWritableDatabase}
 * or {@link #close} is called.
 * @throws SQLiteException if the database cannot be opened
 */
@Override
public synchronized SQLiteDatabase getReadableDatabase() {
    if (mDatabase != null && mDatabase.isOpen()) {
        return mDatabase;  // The database is already open for business
    }

    if (mIsInitializing) {
        throw new IllegalStateException("getReadableDatabase called recursively");
    }

    try {
        return getWritableDatabase();
    } catch (SQLiteException e) {
        if (mName == null) throw e;  // Can't open a temp database read-only!
        Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", e);
    }

    SQLiteDatabase db = null;
    try {
        mIsInitializing = true;
        String path = mContext.getDatabasePath(mName).getPath();
        db = SQLiteDatabase.openDatabase(path, mFactory, SQLiteDatabase.OPEN_READONLY);
        if (db.getVersion() != mNewVersion) {
            throw new SQLiteException("Can't upgrade read-only database from version " +
                    db.getVersion() + " to " + mNewVersion + ": " + path);
        }

        onOpen(db);
        Log.w(TAG, "Opened " + mName + " in read-only mode");
        mDatabase = db;
        return mDatabase;
    } finally {
        mIsInitializing = false;
        if (db != null && db != mDatabase) db.close();
    }
}
 
Example 7
Project: justintrain-client-android   File: SQLiteAssetHelper.java   Source Code and License 6 votes vote down vote up
private SQLiteDatabase returnDatabase() {
    try {
        SQLiteDatabase db = SQLiteDatabase.openDatabase(mDatabasePath + "/" + mName, mFactory, SQLiteDatabase.OPEN_READWRITE);
        Log.i(TAG, "successfully opened database " + mName);
        return db;
    } catch (SQLiteException e) {
        Log.w(TAG, "could not open database " + mName + " - " + e.getMessage());
        return null;
    }
}
 
Example 8
Project: youkes_browser   File: BrowserActivity.java   Source Code and License 6 votes vote down vote up
public boolean getSystemBrowser() {
	Cursor c = null;
	String[] columns = new String[] { "url", "title" };
	boolean browserFlag;
	try {

		//Uri bookmarks = Browser.BOOKMARKS_URI;
		//c = getContentResolver().query(bookmarks, columns, null, null, null);
	} catch (SQLiteException | IllegalStateException | NullPointerException e) {
		e.printStackTrace();
	}

	if (c != null) {
		Log.d("Browser", "System Browser Available");
		browserFlag = true;
	} else {
		Log.e("Browser", "System Browser Unavailable");
		browserFlag = false;
	}
	if (c != null) {
		c.close();
	}
	mPreferences.setSystemBrowserPresent(browserFlag);
	return browserFlag;
}
 
Example 9
Project: yyox   File: KF5SDKtoHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @throws SQLiteException
 */
public void openDatabase() throws SQLiteException {

    openHelper = new DBOpenHelper(context, MD5Utils.GetMD5Code("kf5_ticket_" + SPUtils.getUserId()) + ".db", null, VERSION);
    try {
        db = openHelper.getWritableDatabase();
    } catch (SQLiteException e) {
        e.printStackTrace();
        db = openHelper.getReadableDatabase();
    }
    boolean isTableExit = tableIsExist(openHelper, DB_TABLE);
    if (!isTableExit) {
        db.execSQL(DB_CREATE);
    }

}
 
Example 10
Project: sealtalk-android-master   File: RongDatabaseDriver.java   Source Code and License 6 votes vote down vote up
public List<String> getTableNames(String databaseName)
        throws SQLiteException {
    SQLiteDatabase database = openDatabase(databaseName);
    try {
        Cursor cursor = database.rawQuery("SELECT name FROM sqlite_master WHERE type IN (?, ?)",
                new String[]{"table", "view"});
        try {
            List<String> tableNames = new ArrayList<String>();
            while (cursor.moveToNext()) {
                tableNames.add(cursor.getString(0));
            }
            return tableNames;
        } finally {
            cursor.close();
        }
    } finally {
        database.close();
    }
}
 
Example 11
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param isGetAll   true if want to get all subject
 * @param teacher_id Integer
 * @return {@link ArrayList<Subject>}
 * @throws NullObjectException if connect to database fail or day_start after day_end
 */
public ArrayList<Subject> getSubjectList(Boolean isGetAll, @Nonnegative Integer teacher_id) throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getSubjectList error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    String query;
    if (isGetAll) {
        query = "SELECT * FROM " + TABLE_SUBJECTS;
    } else if (teacher_id != null) {
        query = "SELECT * FROM " + TABLE_SUBJECTS + " WHERE " + Teacher_ID + " = " + teacher_id;
    } else {
        return new ArrayList<>();
    }
    return getSubjectListByQuery(query, db);
}
 
Example 12
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param subject_id   Integer
 * @param subject_name String
 * @return Subject
 * @throws NullObjectException if connect to database fail or not found subject
 */
public Subject getSubject(@Nonnegative @Nullable Integer subject_id, @Nullable String subject_name) throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getSubject error:" + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    String query;
    if (subject_id != null) {
        query = "SELECT * FROM " + TABLE_SUBJECTS + " WHERE " + Subjects_ID + " = " + subject_id;
    } else if (subject_name != null) {
        query = "SELECT * FROM " + TABLE_SUBJECTS + " WHERE " + Subjects_Name + " = '" + subject_name + "'";
    } else {
        Log.d(TAG, "getSubject error: Not found subject");
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_SUBJECT));
    }
    return getSubjectByQuery(query, db);
}
 
Example 13
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * Delete a subject
 *
 * @param subject_id subject id
 * @return DATABASE_CODE
 */
public DATABASE_CODE deleteSubject(@Nonnegative int subject_id) {
    SQLiteDatabase db;
    try {
        db = this.getWritableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "deleteSubject error: " + e.toString());
        return DATABASE_CODE.CONNECT_FAIL;
    }

    String whereClause = Subjects_ID + " = " + subject_id;

    if (db.delete(TABLE_SUBJECTS, whereClause, null) != 0) {
        Log.d(TAG, "deleteSubject success");
        return DATABASE_CODE.DELETE_SUBJECT_SUCCESS;
    }
    Log.d(TAG, "deleteSubject error");
    return DATABASE_CODE.DELETE_SUBJECT_FAIL;
}
 
Example 14
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param repeat_id   Integer
 * @param repeat_name String
 * @return Repeat
 * @throws NullObjectException if connect to database fail or not found repeat
 */
public Repeat getRepeat(@Nonnegative Integer repeat_id, String repeat_name) throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getRepeat error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }
    String query;
    if (repeat_id != null) {
        query = "SELECT *  FROM " + TABLE_REPEAT + " WHERE " + Repeat_ID + " = " + repeat_id;
    } else if (repeat_name != null) {
        query = "SELECT *  FROM " + TABLE_REPEAT + " WHERE " + Repeat_Name + " = '" + repeat_name + "'";
    } else {
        Log.d(TAG, "getRepeat error: Not found repeat");
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_REPEAT));
    }
    return getRepeatByQuery(query, db);
}
 
Example 15
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param subject_id Integer
 * @return {@link ArrayList<WeekLesson>}
 * @throws NullObjectException if connect database fail or day_start after day_end
 */
public ArrayList<WeekLesson> getWeekLessonList(Integer subject_id) throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getWeekLessonList error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    String query;
    if (subject_id != null) {
        query = "SELECT * FROM " + TABLE_WEEK_LESSON + " WHERE " + Subjects_ID + " = " + subject_id;
    } else {
        query = "SELECT * FROM " + TABLE_WEEK_LESSON;
    }
    return getWeekLessonListByQuery(query, db);
}
 
Example 16
Project: KBUnitTest   File: ShadowDatabaseUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Prints the contents of a Cursor's current row to a StringBuilder.
 *
 * @param cursor the cursor to print
 * @param sb     the StringBuilder to print to
 */
public static void dumpCurrentRow(Cursor cursor, StringBuilder sb) {
    String[] cols = cursor.getColumnNames();
    sb.append("" + cursor.getPosition() + " {\n");
    int length = cols.length;
    for (int i = 0; i < length; i++) {
        String value;
        try {
            value = cursor.getString(i);
        } catch (SQLiteException e) {
            // assume that if the getString threw this exception then the column is not
            // representable by a string, e.g. it is a BLOB.
            value = "<unprintable>";
        }
        sb.append("   " + cols[i] + '=' + value + "\n");
    }
    sb.append("}\n");
}
 
Example 17
Project: YuiHatano   File: ShadowDatabaseUtils.java   Source Code and License 6 votes vote down vote up
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) {
    switch (code) {
        case 2:
            throw new IllegalArgumentException(msg);
        case 3:
            throw new UnsupportedOperationException(msg);
        case 4:
            throw new SQLiteAbortException(msg);
        case 5:
            throw new SQLiteConstraintException(msg);
        case 6:
            throw new SQLiteDatabaseCorruptException(msg);
        case 7:
            throw new SQLiteFullException(msg);
        case 8:
            throw new SQLiteDiskIOException(msg);
        case 9:
            throw new SQLiteException(msg);
        case 11:
            throw new OperationCanceledException(msg);
        default:
            reply.readException(code, msg);
    }
}
 
Example 18
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param location_id   Integer
 * @param location_name Integer
 * @return Location
 * @throws NullObjectException if connect to database fail or not found location
 */
public Location getLocation(@Nonnegative Integer location_id, String location_name) throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getLocation error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    String selectQuery;
    if (location_id != null) {
        selectQuery = "SELECT *  FROM " + TABLE_LOCATION + " WHERE " + Location_ID + " = " + location_id;
    } else if (location_name != null) {
        selectQuery = "SELECT *  FROM " + TABLE_LOCATION + " WHERE " + Location_Name + " = '" + location_name + "'";
    } else {
        Log.d(TAG, "getLocation error: Not found location");
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_LOCATION));
    }
    return getLocationByQuery(selectQuery, db);
}
 
Example 19
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param location_id location_id
 * @return {@link DATABASE_CODE#CONNECT_FAIL},{@link DATABASE_CODE#DELETE_LOCATION_SUCCESS},{@link DATABASE_CODE#DELETE_LOCATION_FAIL}
 */
public DATABASE_CODE deleteLocation(@Nonnegative int location_id) {
    SQLiteDatabase db;
    try {
        db = this.getWritableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "deleteLocation error: " + e.toString());
        return DATABASE_CODE.CONNECT_FAIL;
    }

    String whereClause = Location_ID + " = " + location_id;

    //Deleting a record
    if (db.delete(TABLE_LOCATION, whereClause, null) != 0) {
        Log.d(TAG, "deleteLocation success");
        return DATABASE_CODE.DELETE_LOCATION_SUCCESS;
    }
    Log.d(TAG, "deleteLocation error");
    return DATABASE_CODE.DELETE_LOCATION_FAIL;
}
 
Example 20
Project: jackknife   File: Transaction.java   Source Code and License 6 votes vote down vote up
public static boolean execute(Worker worker) {
    SQLiteDatabase db = Orm.getDatabase();
    db.beginTransaction();
    try {
        boolean isOk = worker.doTransition(db);
        if (isOk) {
            db.setTransactionSuccessful();
        }
        return isOk;
    } catch(SQLiteException e) {
        e.printStackTrace();
    } finally {
        db.endTransaction();
    }
    return false;
}
 
Example 21
Project: MyCalendar   File: DBHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param day_lesson_id day_lesson_id
 * @return {@link DATABASE_CODE#CONNECT_FAIL}, {@link DATABASE_CODE#DELETE_DAY_LESSON_SUCCESS}
 * ,{@link DATABASE_CODE#DELETE_DAY_LESSON_FAIL}
 */
public DATABASE_CODE deleteDayLesson(int day_lesson_id) {
    SQLiteDatabase db;
    try {
        db = this.getWritableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "deleteDayLesson error: " + e.toString());
        return DATABASE_CODE.CONNECT_FAIL;
    }

    String whereClause = DayLesson_ID + " = " + day_lesson_id;

    if (db.delete(TABLE_DAY_LESSON, whereClause, null) != 0) {
        Log.d(TAG, "deleteDayLesson success");
        return DATABASE_CODE.DELETE_DAY_LESSON_SUCCESS;
    }

    Log.d(TAG, "deleteDayLesson error");
    return DATABASE_CODE.DELETE_DAY_LESSON_FAIL;
}
 
Example 22
Project: browser   File: BrowserActivity.java   Source Code and License 6 votes vote down vote up
public boolean getSystemBrowser() {
	Cursor c = null;
	String[] columns = new String[] { "url", "title" };
	boolean browserFlag;
	try {

		//Uri bookmarks = Browser.BOOKMARKS_URI;
		//c = getContentResolver().query(bookmarks, columns, null, null, null);
	} catch (SQLiteException | IllegalStateException | NullPointerException e) {
		e.printStackTrace();
	}

	if (c != null) {
		Log.d("Browser", "System Browser Available");
		browserFlag = true;
	} else {
		Log.e("Browser", "System Browser Unavailable");
		browserFlag = false;
	}
	if (c != null) {
		c.close();
	}
	mPreferences.setSystemBrowserPresent(browserFlag);
	return browserFlag;
}
 
Example 23
Project: gitio   File: SeanDBHelper.java   Source Code and License 6 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    switch (oldVersion) {
        case 0:
            try {
                db.execSQL("CREATE TABLE main.history " +
                        "(_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
                        "url TEXT NOT NULL, " +
                        "code TEXT NOT NULL," +
                        "date INTEGER NOT NULL)");

                db.execSQL("CREATE TABLE main.params " +
                        "(_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
                        "kind TEXT NOT NULL, " +
                        "value TEXT)");
            } catch (SQLiteException e) {
                Log.e("db", "onUpgrade", e);
            }
    }
}
 
Example 24
Project: Pocket-Plays-for-Twitch   File: SubscriptionsDbHelper.java   Source Code and License 6 votes vote down vote up
private ArrayList<Integer> getUsersNotToNotify(SQLiteDatabase db) throws SQLiteException {
	String query = "SELECT * FROM " + SubscriptionsDbHelper.TABLE_NAME + " WHERE " + SubscriptionsDbHelper.COLUMN_NOTIFY_WHEN_LIVE + "=" + 0 + ";";
	Cursor cursor = db.rawQuery(query, null);

	ArrayList<Integer> usersToNotify = new ArrayList<>();

	while(cursor.moveToNext()) {
		int idPosition = cursor.getColumnIndex(SubscriptionsDbHelper.COLUMN_ID);
		int userId = cursor.getInt(idPosition);

		usersToNotify.add(userId);
	}

	cursor.close();

	return usersToNotify;
}
 
Example 25
Project: KBUnitTest   File: ShadowDatabaseUtils.java   Source Code and License 6 votes vote down vote up
private static final void readExceptionFromParcel(Parcel reply, String msg, int code) {
    switch (code) {
        case 2:
            throw new IllegalArgumentException(msg);
        case 3:
            throw new UnsupportedOperationException(msg);
        case 4:
            throw new SQLiteAbortException(msg);
        case 5:
            throw new SQLiteConstraintException(msg);
        case 6:
            throw new SQLiteDatabaseCorruptException(msg);
        case 7:
            throw new SQLiteFullException(msg);
        case 8:
            throw new SQLiteDiskIOException(msg);
        case 9:
            throw new SQLiteException(msg);
        case 11:
            throw new OperationCanceledException(msg);
        default:
            reply.readException(code, msg);
    }
}
 
Example 26
Project: weex-3d-map   File: HistoryManager.java   Source Code and License 6 votes vote down vote up
public void trimHistory() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getWritableDatabase();      
    cursor = db.query(DBHelper.TABLE_NAME,
                      ID_COL_PROJECTION,
                      null, null, null, null,
                      DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(MAX_ITEMS);
    while (cursor.moveToNext()) {
      String id = cursor.getString(0);
      Log.i(TAG, "Deleting scan history ID " + id);
      db.delete(DBHelper.TABLE_NAME, DBHelper.ID_COL + '=' + id, null);
    }
  } catch (SQLiteException sqle) {
    // We're seeing an error here when called in CaptureActivity.onCreate() in rare cases
    // and don't understand it. First theory is that it's transient so can be safely ignored.
    Log.w(TAG, sqle);
    // continue
  } finally {
    close(cursor, db);
  }
}
 
Example 27
Project: letv   File: LiveBookFragment.java   Source Code and License 6 votes vote down vote up
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (cursor != null) {
        Set<String> mBookedPrograms = new HashSet();
        while (cursor.moveToNext()) {
            try {
                int idx = cursor.getColumnIndexOrThrow(Field.MD5_ID);
                if (idx != -1) {
                    mBookedPrograms.add(cursor.getString(idx));
                }
            } catch (SQLiteException e) {
                e.printStackTrace();
                return;
            }
        }
        if (this.mAdapter != null) {
            this.mAdapter.setBookedPrograms(mBookedPrograms);
        }
    }
}
 
Example 28
Project: nifi-android-s2s   File: SQLiteDataPacketIterator.java   Source Code and License 6 votes vote down vote up
public void transactionFailed() throws SQLiteIOException {
    close();
    SQLiteDatabase writableDatabase = siteToSiteDB.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
        ContentValues contentValues = new ContentValues();
        contentValues.putNull(DATA_PACKET_QUEUE_TRANSACTION_COLUMN);
        writableDatabase.update(DATA_PACKET_QUEUE_TABLE_NAME, contentValues, DATA_PACKET_QUEUE_TRANSACTION_COLUMN + " = ?", new String[] {Long.toString(transactionId)});
        writableDatabase.delete(DATA_PACKET_QUEUE_TRANSACTIONS_TABLE_NAME, DATA_PACKET_QUEUE_TRANSACTION_COLUMN + " = ?", new String[] {Long.toString(transactionId)});
        writableDatabase.setTransactionSuccessful();
    } catch (SQLiteException e) {
        throw new SQLiteIOException("Unable to clear transaction from failed data packets.", e);
    } finally {
        writableDatabase.endTransaction();
        writableDatabase.close();
    }
}
 
Example 29
Project: Android-Bubble-Game   File: DataBaseHelper.java   Source Code and License 5 votes vote down vote up
/**
 * Check if the database already exist to avoid re-copying the file each time you open the
 * application.
 *
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {
  SQLiteDatabase checkDB = null;
  try {
    String myPath = DB_PATH + DB_NAME;
    checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
  } catch (SQLiteException e) {
    // database doesn't exist yet.
  }
  if (checkDB != null) {
    checkDB.close();
  }
  return checkDB != null ? true : false;
}
 
Example 30
Project: Inflix   File: FavoritesProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values)
        throws UnsupportedOperationException, SQLiteException {
    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    int match = sUriMatcher.match(uri);
    long res = -1;
    switch (match) {
        case FAVORITES_WITH_ID:
            List<String> pathSegments = uri.getPathSegments();
            if (pathSegments != null && pathSegments.size() > 2) {
                String type = pathSegments.get(1);
                String id = pathSegments.get(2);

                if (values != null) {
                    values.put(MediaEntry.COLUMN_IS_FAVORED, 1);
                    values.put(MediaEntry.COLUMN_MEDIA_TYPE, type);
                    int numRows = db.update(MediaEntry.TABLE_NAME, values,
                            MediaEntry.COLUMN_MEDIA_TYPE + " = ? AND " +
                                    MediaEntry.COLUMN_MEDIA_ID + " = ? ", new String[]{type, id});
                    if (numRows <= 0) {
                        res = db.insert(MediaEntry.TABLE_NAME, null, values);
                        if (res == -1) {
                            throw new SQLiteException("Failed to insert record: " + uri);
                        }
                    }
                }
            }
            break;
        default:
            throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    mContext.getContentResolver().notifyChange(uri, null);
    return ContentUris.withAppendedId(uri, res);
}
 
Example 31
Project: q-mail   File: MigrationTo30.java   Source Code and License 5 votes vote down vote up
public static void addDeletedColumn(SQLiteDatabase db) {
    try {
        db.execSQL("ALTER TABLE messages ADD deleted INTEGER default 0");
    } catch (SQLiteException e) {
        if (!e.toString().startsWith("duplicate column name: deleted")) {
            throw e;
        }
    }
}
 
Example 32
Project: q-mail   File: MigrationTo36.java   Source Code and License 5 votes vote down vote up
public static void addAttachmentsContentIdColumn(SQLiteDatabase db) {
    try {
        db.execSQL("ALTER TABLE attachments ADD content_id TEXT");
    } catch (SQLiteException e) {
        Timber.e("Unable to add content_id column to attachments");
    }
}
 
Example 33
Project: q-mail   File: MigrationTo40.java   Source Code and License 5 votes vote down vote up
public static void addMimeTypeColumn(SQLiteDatabase db) {
    try {
        db.execSQL("ALTER TABLE messages ADD mime_type TEXT");
    } catch (SQLiteException e) {
        Timber.e("Unable to add mime_type column to messages");
    }
}
 
Example 34
Project: AndiCar   File: DB.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean columnExists(SQLiteDatabase db, String table, String column) {
    String testSql = "SELECT " + column + " FROM " + table + " WHERE 1=2";
    try {
        db.rawQuery(testSql, null);
        return true;
    }
    catch (SQLiteException e) {
        return false;
    }
}
 
Example 35
Project: q-mail   File: MigrationTo44.java   Source Code and License 5 votes vote down vote up
public static void addMessagesThreadingColumns(SQLiteDatabase db) {
    try {
        db.execSQL("ALTER TABLE messages ADD thread_root INTEGER");
        db.execSQL("ALTER TABLE messages ADD thread_parent INTEGER");
        db.execSQL("ALTER TABLE messages ADD normalized_subject_hash INTEGER");
        db.execSQL("ALTER TABLE messages ADD empty INTEGER");
    } catch (SQLiteException e) {
        if (!e.getMessage().startsWith("duplicate column name:")) {
            throw e;
        }
    }
}
 
Example 36
Project: Pocket-Plays-for-Twitch   File: SubscriptionsDbHelper.java   Source Code and License 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	try {
		if (newVersion == 7) {
			new Settings(mContext).setUsersNotToNotifyWhenLive(getUsersNotToNotify(db));
		}
	} catch (SQLiteException e) {
		e.printStackTrace();
	}


	db.execSQL(SQL_DELETE_ENTRIES);
	onCreate(db);
	//db.close();
}
 
Example 37
Project: q-mail   File: MigrationTo35.java   Source Code and License 5 votes vote down vote up
public static void updateRemoveXNoSeenInfoFlag(SQLiteDatabase db) {
    try {
        db.execSQL("update messages set flags = replace(flags, 'X_NO_SEEN_INFO', 'X_BAD_FLAG')");
    } catch (SQLiteException e) {
        Timber.e(e, "Unable to get rid of obsolete flag X_NO_SEEN_INFO");
    }
}
 
Example 38
Project: AndiCar   File: DB.java   Source Code and License 5 votes vote down vote up
public void close() {
    try {
        mDbHelper.close();
        mDbHelper = null;
        mDb.close();
        mDb = null;
    }
    catch (SQLiteException ignored) {
    }
}
 
Example 39
Project: GitHub   File: UpdateUsingUpdateMethodTest.java   Source Code and License 5 votes vote down vote up
public void testUpdateWithStaticUpdateButWrongClass() {
	ContentValues values = new ContentValues();
	values.put("TEACHERNAME", "Toy");
	try {
		DataSupport.update(Object.class, values, teacher.getId());
	} catch (SQLiteException e) {
	}
}
 
Example 40
Project: GitHub   File: UpdateUsingUpdateMethodTest.java   Source Code and License 5 votes vote down vote up
public void testUpdateWithStaticUpdateButWrongColumn() {
	ContentValues values = new ContentValues();
	values.put("TEACHERYEARS", 13);
	try {
		DataSupport.update(Teacher.class, values, teacher.getId());
		fail("no such column: TEACHERYEARS");
	} catch (SQLiteException e) {
	}
}
 
Example 41
Project: GitHub   File: RobustSQLiteOpenHelper.java   Source Code and License 5 votes vote down vote up
@Override
public final void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	try {
		onRobustUpgrade(db, oldVersion, newVersion);
	} catch (SQLiteException e) {
		// The database has entered an unknown state. Try to recover.
		try {
			regenerateTables(db);
		} catch (SQLiteException e2) {
			dropAndCreateTables(db);
		}
	}
}
 
Example 42
Project: GitHub   File: PubkeyDatabase.java   Source Code and License 5 votes vote down vote up
@Override
public void onRobustUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) throws SQLiteException {
		switch (oldVersion) {
		case 1:
			db.execSQL("ALTER TABLE " + TABLE_PUBKEYS
					+ " ADD COLUMN " + FIELD_PUBKEY_CONFIRMUSE + " INTEGER DEFAULT 0");
			db.execSQL("ALTER TABLE " + TABLE_PUBKEYS
					+ " ADD COLUMN " + FIELD_PUBKEY_LIFETIME + " INTEGER DEFAULT 0");
		}
}
 
Example 43
Project: FindSpot   File: DatabaseHelper.java   Source Code and License 5 votes vote down vote up
public boolean checkDatabase(){
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
    }catch (SQLiteException e){

    }
    if (checkDB != null){
        checkDB.close();
    }
    return checkDB != null ? true : false;
}
 
Example 44
Project: LaunchEnr   File: IconCache.java   Source Code and License 5 votes vote down vote up
private boolean getEntryFromDB(ComponentKey cacheKey, CacheEntry entry, boolean lowRes) {
    Cursor c = null;
    try {
        c = mIconDb.query(
            new String[]{lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON,
                    IconDB.COLUMN_LABEL},
            IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?",
            new String[]{cacheKey.componentName.flattenToString(),
                    Long.toString(mUserManager.getSerialNumberForUser(cacheKey.user))});
        if (c.moveToNext()) {
            entry.icon = loadIconNoResize(c, 0, lowRes ? mLowResOptions : null);
            entry.isLowResIcon = lowRes;
            entry.title = c.getString(1);
            if (entry.title == null) {
                entry.title = "";
                entry.contentDescription = "";
            } else {
                entry.contentDescription = mUserManager.getBadgedLabelForUser(
                        entry.title, cacheKey.user);
            }
            return true;
        }
    } catch (SQLiteException e) {
        e.printStackTrace();
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return false;
}
 
Example 45
Project: stynico   File: Bookmark.java   Source Code and License 5 votes vote down vote up
public void openMyBookmark(Activity activity)
   {
try
{
    m_db = activity.openOrCreateDatabase(DBNAME, 0, null);
}
catch (SQLiteException e)
{
    m_db = null;
}
   }
 
Example 46
Project: buildAPKsApps   File: SqliteWrapper.java   Source Code and License 5 votes vote down vote up
public static Uri insert(Context context, ContentResolver resolver,
        Uri uri, ContentValues values) {
    try {
        return resolver.insert(uri, values);
    } catch (SQLiteException e) {
        Log.e(TAG, "Catch a SQLiteException when insert: ", e);
        checkSQLiteException(context, e);
        return null;
    }
}
 
Example 47
Project: sqlbrite-sqlcipher   File: BriteDatabaseTest.java   Source Code and License 5 votes vote down vote up
@Test public void badUpdateThrows() {
  try {
    db.update("missing", employee("john", "John Johnson"), "1");
    fail();
  } catch (SQLiteException e) {
    assertThat(e.getMessage()).contains("no such table: missing");
  }
}
 
Example 48
Project: MyCalendar   File: DBHelper.java   Source Code and License 5 votes vote down vote up
/**
 * Get repeat list
 *
 * @return list of repeat
 * @throws NullObjectException if connect to database fail
 */
public ArrayList<Repeat> getRepeatList() throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getRepeatList error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    ArrayList<Repeat> RepeatList = new ArrayList<>();

    //Select All Query
    String selectQuery = "SELECT * FROM " + TABLE_REPEAT;

    //get all and return to cursor
    Cursor cursor = db.rawQuery(selectQuery, null);

    // Looping through all rows and adding to list
    Repeat r;
    if (cursor.moveToFirst()) {
        do {
            r = new Repeat();
            r.setRepeat_id(cursor.getInt(0));
            r.setRepeat_name(cursor.getString(1));
            r.setRepeat_ts(cursor.getInt(2));

            // Adding  to list
            RepeatList.add(r);
        } while (cursor.moveToNext());
    }
    cursor.close();
    Log.d(TAG, "getRepeatList success");
    return RepeatList;
}
 
Example 49
Project: encdroidMC   File: EDDBHelper.java   Source Code and License 5 votes vote down vote up
public List<FileSynchronizerRule> getSyncRules(){
	SQLiteDatabase db = null;
	try {
		ArrayList<FileSynchronizerRule> rules = new ArrayList<FileSynchronizerRule>();
		db = getReadableDatabase();
		Cursor cursor = db.rawQuery("SELECT * FROM SYNC_RULES", NO_ARGS);
		if (cursor.moveToFirst()) {
			do {
				int v1 = cursor.getInt(0);
				String v2 = cursor.getString(1);
				String v3 = cursor.getString(2);
				String v4 = cursor.getString(3);
				String v5 = cursor.getString(4);
				String v6 = cursor.getString(5);
				String v7 = cursor.getString(6);

				Log.d(TAG, "getSyncRules()");

				FileSynchronizerRule rule = new FileSynchronizerRule(v1,v2,v3,v4,v5,v6,v7);

				rules.add(rule);
			} while (cursor.moveToNext());
			
		}
		return rules;
	} catch (SQLiteException e){
		createSyncRulesTable(db);
		return new ArrayList<FileSynchronizerRule>();
	} finally {
		//do nothing (i should not close db on android ??)
	}
}
 
Example 50
Project: MyCalendar   File: DBHelper.java   Source Code and License 5 votes vote down vote up
/**
 * Get location list
 *
 * @return list of location
 * @throws NullObjectException if connect to database fail
 */
public ArrayList<Location> getLocationList() throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getLocationList error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    ArrayList<Location> LocationList = new ArrayList<>();

    //Select All Query
    String selectQuery = "SELECT * FROM " + TABLE_LOCATION;

    //get all and return to cursor
    Cursor cursor = db.rawQuery(selectQuery, null);

    // Looping through all rows and adding to list
    Location l;
    if (cursor.moveToFirst()) {
        do {
            l = new Location();
            l.setLocation_id(cursor.getInt(0));
            l.setLocation_name(cursor.getString(1));
            l.setLocation_address(cursor.getString(2));
            l.setLocation_lat(cursor.getDouble(3));
            l.setLocation_lng(cursor.getDouble(4));
            l.setLocation_background(cursor.getString(5));
            l.setLocation_note(cursor.getString(6));

            // Adding  to list
            LocationList.add(l);
        } while (cursor.moveToNext());
    }
    cursor.close();
    Log.d(TAG, "getLocationList success");
    return LocationList;
}
 
Example 51
Project: financisto1-holo   File: DatabaseAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * @param accountId
 * @param period
 * @return
 */
public int getCustomClosingDay(long accountId, int period) {
	String where = CreditCardClosingDateColumns.ACCOUNT_ID+"=? AND "+
				   CreditCardClosingDateColumns.PERIOD+"=?";
	
	Cursor c = db().query(CCARD_CLOSING_DATE_TABLE, new String[] {CreditCardClosingDateColumns.CLOSING_DAY},
		    where, new String[]{Long.toString(accountId), Integer.toString(period)}, null, null, null);
	
	int res = 0;
	try {
		if (c!=null) {
			if (c.getCount()>0) {
				c.moveToFirst();
				res = c.getInt(0);
			} else {
				res = 0;
			}
		} else {
			// there is no custom closing day in database for the given account id an period
			res =  0;
		}
	} catch(SQLiteException e) {
		res = 0;
	} finally {
		c.close();
	}
	return res;
}
 
Example 52
Project: MyCalendar   File: DBHelper.java   Source Code and License 5 votes vote down vote up
/**
 * @param day_lesson_id day_lesson_id
 * @return {@link DayLesson}
 * @throws NullObjectException if connect to database fail or not found day lesson
 */
public DayLesson getDayLesson(int day_lesson_id) throws NullObjectException {
    SQLiteDatabase db;
    try {
        db = this.getReadableDatabase();
    } catch (SQLiteException e) {
        Log.d(TAG, "getDayLesson error: " + e.toString());
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
    }

    String selectQuery = "SELECT * FROM " + TABLE_DAY_LESSON + " WHERE " + DayLesson_ID + " = " + day_lesson_id;

    Cursor cursor = db.rawQuery(selectQuery, null);
    if (cursor.getCount() == 0) {
        cursor.close();
        Log.d(TAG, "getDayLesson error: Not found day lesson");
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_DAY_LESSON));
    }

    if (cursor.moveToFirst()) {
        DayLesson dayLesson = new DayLesson();
        dayLesson.setDay_lesson_id(cursor.getInt(0));
        dayLesson.setWeek_lesson_id(cursor.getInt(1));
        dayLesson.setLocation_id(cursor.getInt(2));
        dayLesson.setDay_lesson_time_start(cursor.getInt(3));
        dayLesson.setDay_lesson_time_end(cursor.getInt(4));
        dayLesson.setDay_lesson_is_cancel(cursor.getInt(5) == 1);
        dayLesson.setDay_lesson_status_reason_change(cursor.getString(6));
        Log.d(TAG, "getDayLesson success");
        cursor.close();
        return dayLesson;
    } else {
        cursor.close();
        Log.d(TAG, "getDayLesson error");
        throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_DAY_LESSON));
    }
}
 
Example 53
Project: MyCalendar   File: DBHelper.java   Source Code and License 5 votes vote down vote up
/**
 * @param dayLesson DayLesson
 * @param db        SQLiteDatabase
 * @return {@link DATABASE_CODE#LOGIC_ERROR},{@link DATABASE_CODE#INSERT_DAY_LESSON_FAIL},
 * {@link DATABASE_CODE#INSERT_DAY_LESSON_SUCCESS}
 */
private DATABASE_CODE insertDayLessonWithDB(@NonNull DayLesson dayLesson, @NonNull SQLiteDatabase db) {

    switch (checkDayLesson(dayLesson, db)) {
        case LOGIC_ERROR:
            Log.d(TAG, "insertDayLessonWithDB error : Logic error");
            return DATABASE_CODE.LOGIC_ERROR;

        case CHECK_DAY_LESSON_OK:
            break;
    }

    //Create content to insert into the database
    ContentValues values = new ContentValues();

    //Default columns
    values.put(WeekLesson_ID, dayLesson.getWeek_lesson_id());
    values.put(Location_ID, dayLesson.getLocation_id());
    values.put(DayLesson_TimeStart, dayLesson.getDay_lesson_time_start());
    values.put(DayLesson_TimeEnd, dayLesson.getDay_lesson_time_end());
    values.put(DayLesson_IsCancel, dayLesson.isDay_lesson_is_cancel() ? 1 : 0);
    values.put(DayLesson_Reason, dayLesson.getDay_lesson_status_reason_change());

    //Try to insert row
    try {
        db.insertOrThrow(TABLE_DAY_LESSON, null, values);
    } catch (SQLiteException e) {
        Log.d(TAG, "insertDayLessonWithDB error");
        return DATABASE_CODE.INSERT_DAY_LESSON_FAIL;
    }


    Log.d(TAG, "insertDayLessonWithDB success");
    return DATABASE_CODE.INSERT_DAY_LESSON_SUCCESS;
}
 
Example 54
Project: AndroidSnooper   File: DatabaseReader.java   Source Code and License 5 votes vote down vote up
private SQLiteDatabase getDatabase(String path) {
  SQLiteDatabase sqLiteDatabase = null;
  try {
    sqLiteDatabase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
  } catch (SQLiteException exception) {
    Logger.e(TAG, "Exception while opening the database", exception);
  }
  return sqLiteDatabase;
}
 
Example 55
Project: Poetry   File: JsonPersister.java   Source Code and License 5 votes vote down vote up
/**
 * Process an ID field giving JSON input and serialization information.
 * If no object is found in the database, a new one is inserted and its ID is returned.
 *
 * @param databaseField the Ormlite annotation
 * @param field         the field that is annotated by databaseField
 * @param jsonObject    the object that is being mapped
 * @param jsonKey       the key where the value of the id field can be found within the jsonObject
 * @param tableName     the table to insert a new row in case the ID is not found in the database
 * @return the ID field value of this object (never null)
 * @throws JSONException when the ID field value cannot be determined
 */
private Object processIdField(DatabaseField databaseField, Field field, JSONObject jsonObject, String jsonKey, String tableName) throws JSONException {
	String db_field_name = OrmliteReflection.getFieldName(field, databaseField);

	Object object_id = JsonUtils.getValue(jsonObject, jsonKey, field.getType());

	if (object_id == null) {
		throw new RuntimeException(String.format("failed to get a value from JSON with key %s and type %s", jsonKey, field.getType().getName()));
	}

	String sql = String.format("SELECT * FROM '%s' WHERE %s = ? LIMIT 1", tableName, db_field_name);
	String[] selection_args = new String[]{object_id.toString()};
	Cursor cursor = database.rawQuery(sql, selection_args);
	boolean object_exists = (cursor.getCount() > 0);
	cursor.close();

	if (object_exists) {
		// return existing object id
		return object_id;
	} else { // create object
		ContentValues values = new ContentValues(1);

		if (!JsonUtils.copyValue(object_id, db_field_name, values)) {
			throw new JSONException(String.format("failed to process id field %s for table %s and jsonKey %s", field.getName(), tableName, jsonKey));
		}

		long inserted_id = database.insert("'" + tableName + "'", null, values);

		if (inserted_id == -1) {
			throw new SQLiteException(String.format("failed to insert %s with id %s=%s", field.getType().getName(), db_field_name, object_id.toString()));
		}

		Log.i(getClass().getName(), String.format("prepared %s row (id=%s/%s)", tableName, object_id.toString(), Long.toString(inserted_id)));

		return object_id; // don't return inserted_id, because it's always long (while the target type might be int or another type)
	}
}
 
Example 56
Project: vinyl-cast   File: DatabaseAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void onCreate(SQLiteDatabase db)
		throws SQLiteConstraintException, SQLiteDiskIOException,
              SQLiteException {

	db.execSQL(CREATE_TABLE_SEARCH_HISTORY);
	db.execSQL(CREATE_TABLE_RESPONSES);
	db.execSQL(CREATE_INDEX_DATE);
	Log.i(TAG, "Tables created...");

}
 
Example 57
Project: vinyl-cast   File: DatabaseAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
		throws SQLiteConstraintException, SQLiteDiskIOException,
              SQLiteException {
	Log.i(TAG, "table upgraded");
	db.execSQL("DROP TABLE IF EXISTS "+MUSIC_HISTORY_RESPONSE_TABLE);
	db.execSQL("DROP TABLE IF EXISTS "+MUSIC_HISTORY_TABLE);
	onCreate(db);
}
 
Example 58
Project: XSnow   File: DBManager.java   Source Code and License 5 votes vote down vote up
@Override
public boolean insert(@NotNull M m) {
    try {
        getAbstractDao().insert(m);
    } catch (SQLiteException e) {
        ViseLog.e(e);
        return false;
    }
    return true;
}
 
Example 59
Project: XSnow   File: DBManager.java   Source Code and License 5 votes vote down vote up
@Override
public boolean insertOrReplace(@NotNull M m) {
    try {
        getAbstractDao().insertOrReplace(m);
    } catch (SQLiteException e) {
        ViseLog.e(e);
        return false;
    }
    return true;
}
 
Example 60
Project: OpenHub   File: Downloader.java   Source Code and License 5 votes vote down vote up
private void checkStatus() {
    //cause SQLiteException at 乐视 LE X820 Android 6.0.1,level 23
    try{
        DownloadManager.Query query = new DownloadManager.Query();
        query.setFilterById(downloadId);
        Cursor c = downloadManager.query(query);
        if (c.moveToFirst()) {
            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
            switch (status) {
                case DownloadManager.STATUS_PAUSED:
                    break;
                case DownloadManager.STATUS_PENDING:
                    break;
                case DownloadManager.STATUS_RUNNING:
                    break;
                case DownloadManager.STATUS_SUCCESSFUL:
                    String tip = mContext.getString(R.string.download_complete)
                            .concat("\n").concat(getFilePath());
                    Toasty.success(mContext, tip).show();
                    unregister();
                    break;
                case DownloadManager.STATUS_FAILED:
                    Toasty.error(mContext, mContext.getString(R.string.download_failed)).show();
                    unregister();
                    break;
            }
        }
        c.close();
    }catch (SQLiteException e){
        Logger.d(e);
        unregister();
    }

}