com.readystatesoftware.sqliteasset.SQLiteAssetHelper Java Examples

The following examples show how to use com.readystatesoftware.sqliteasset.SQLiteAssetHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotesTable.java    From 4pdaClient-plus with Apache License 2.0 6 votes vote down vote up
public static void deleteAll(SQLiteAssetHelper helper) throws IOException {

        SQLiteDatabase db = null;
        Cursor c = null;
        try {


            db = helper.getWritableDatabase();

            db.execSQL("delete from " + TABLE_NAME);


        } finally {
            if (db != null) {
                if (c != null)
                    c.close();
                db.close();
            }
        }
    }
 
Example #2
Source File: NotesTable.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
public static void insertNote(SQLiteAssetHelper helper, Note note) {
    SQLiteDatabase db = null;

    try {

        db = helper.getWritableDatabase();
        // db.beginTransaction();

        ContentValues values = new ContentValues();

        values.put(COLUMN_TITLE, note.Title);
        values.put(COLUMN_BODY, note.Body);
        values.put(COLUMN_URL, note.Url);
        values.put(COLUMN_TOPIC_ID, note.TopicId);
        values.put(COLUMN_POST_ID, note.PostId);
        values.put(COLUMN_USER_ID, note.UserId);
        values.put(COLUMN_USER, note.User);
        values.put(COLUMN_TOPIC, note.Topic);
        values.put(COLUMN_DATE, DbHelper.DateTimeFormat.format(note.Date));


        db.insertOrThrow(TABLE_NAME, null, values);

    } catch (Exception ex) {
        AppLog.e(App.getInstance(), ex);
    } finally {
        if (db != null) {
            // db.endTransaction();
            db.close();
        }
    }
}
 
Example #3
Source File: NotesTable.java    From 4pdaClient-plus with Apache License 2.0 4 votes vote down vote up
public static ArrayList<Note> getNotes(SQLiteAssetHelper helper, String topicId) throws ParseException, IOException {
    ArrayList<Note> notes = new ArrayList<Note>();

    SQLiteDatabase db = null;
    Cursor c = null;
    try {

        db = helper.getWritableDatabase();
        String selection = null;
        String[] selectionArgs = null;

        if (!TextUtils.isEmpty(topicId)) {
            selection = COLUMN_TOPIC_ID + "=?";
            selectionArgs = new String[]{topicId};
        }
        c = db.query(TABLE_NAME, null, selection, selectionArgs, null, null, COLUMN_DATE + " DESC");

        if (c.moveToFirst()) {
            int columnIdIndex = c.getColumnIndex(COLUMN_ID);
            int columnTitleIndex = c.getColumnIndex(COLUMN_TITLE);
            int columnBodyIndex = c.getColumnIndex(COLUMN_BODY);
            int columnUrlIndex = c.getColumnIndex(COLUMN_URL);
            int columnTopicIdIndex = c.getColumnIndex(COLUMN_TOPIC_ID);
            int columnPostIdIndex = c.getColumnIndex(COLUMN_POST_ID);
            int columnUserIdIndex = c.getColumnIndex(COLUMN_USER_ID);
            int columnUserIndex = c.getColumnIndex(COLUMN_USER);
            int columnTopicIndex = c.getColumnIndex(COLUMN_TOPIC);
            int columnDateIndex = c.getColumnIndex(COLUMN_DATE);
            do {
                Note note = new Note();
                note.Id = c.getString(columnIdIndex);
                note.Title = c.getString(columnTitleIndex);
                note.Body = c.getString(columnBodyIndex);
                note.Url = c.getString(columnUrlIndex);
                note.TopicId = c.getString(columnTopicIdIndex);
                note.PostId = c.getString(columnPostIdIndex);
                note.UserId = c.getString(columnUserIdIndex);
                note.User = c.getString(columnUserIndex);
                note.Topic = c.getString(columnTopicIndex);
                note.Date = DbHelper.parseDate(c.getString(columnDateIndex));
                notes.add(note);
            } while (c.moveToNext());
        }
    } finally {
        if (db != null) {
            if (c != null)
                c.close();
            db.close();
        }
    }

    return notes;
}