Search in sources :

Example 56 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project Talon-for-Twitter by klinker24.

the class HomeDataSource method getWearCursor.

public synchronized Cursor getWearCursor(int account) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    String clients = sharedPreferences.getString("muted_clients", "");
    String where = HomeSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
    expressions = expressions.replaceAll("'", "''");
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!clients.equals("")) {
        String[] split = clients.split("   ");
        for (String s : split) {
            where += " AND (" + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " NOT LIKE " + "'%" + s + "%'" + " OR " + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " is NULL)";
        }
    }
    if (noRetweets) {
        where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + HomeSQLiteHelper.COLUMN_RETWEETER + " is NULL";
    } else if (!rts.equals("")) {
        String[] split = rts.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    Cursor cursor;
    String sql = "SELECT COUNT(*) FROM " + HomeSQLiteHelper.TABLE_HOME + " WHERE " + where;
    SQLiteStatement statement;
    try {
        statement = database.compileStatement(sql);
    } catch (Exception e) {
        open();
        statement = database.compileStatement(sql);
    }
    long count;
    try {
        count = statement.simpleQueryForLong();
    } catch (Exception e) {
        open();
        try {
            count = statement.simpleQueryForLong();
        } catch (Exception x) {
            return null;
        }
    }
    int position = getPosition(sharedPreferences.getInt("current_account", 1));
    try {
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", count - position + "," + position);
    } catch (Exception e) {
        open();
        cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", count - position + "," + position);
    }
    return cursor;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 57 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project Talon-for-Twitter by klinker24.

the class HomeDataSource method getCursor.

public synchronized Cursor getCursor(int account) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    String clients = sharedPreferences.getString("muted_clients", "");
    String where = HomeSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
    expressions = expressions.replaceAll("'", "''");
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!clients.equals("")) {
        String[] split = clients.split("   ");
        for (String s : split) {
            where += " AND (" + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " NOT LIKE " + "'%" + s + "%'" + " OR " + HomeSQLiteHelper.COLUMN_CLIENT_SOURCE + " is NULL)";
        }
    }
    if (noRetweets) {
        where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + HomeSQLiteHelper.COLUMN_RETWEETER + " is NULL";
    } else if (!rts.equals("")) {
        String[] split = rts.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    Cursor cursor;
    String sql = "SELECT COUNT(*) FROM " + HomeSQLiteHelper.TABLE_HOME + " WHERE " + where;
    SQLiteStatement statement;
    try {
        statement = database.compileStatement(sql);
    } catch (Exception e) {
        open();
        statement = database.compileStatement(sql);
    }
    long count;
    try {
        count = statement.simpleQueryForLong();
    } catch (Exception e) {
        open();
        try {
            count = statement.simpleQueryForLong();
        } catch (Exception x) {
            return null;
        }
    }
    Log.v("talon_database", "home database has " + count + " entries");
    if (count > timelineSize) {
        try {
            cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - timelineSize) + "," + timelineSize);
        } catch (Exception e) {
            open();
            cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - timelineSize) + "," + timelineSize);
        }
    } else {
        try {
            cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC");
        } catch (Exception e) {
            open();
            cursor = database.query(HomeSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, HomeSQLiteHelper.COLUMN_TWEET_ID + " ASC");
        }
    }
    return cursor;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) SQLException(android.database.SQLException)

Example 58 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project Talon-for-Twitter by klinker24.

the class ListDataSource method getCursor.

public synchronized Cursor getCursor(long listId) {
    String users = sharedPreferences.getString("muted_users", "");
    String rts = sharedPreferences.getString("muted_rts", "");
    String hashtags = sharedPreferences.getString("muted_hashtags", "");
    String expressions = sharedPreferences.getString("muted_regex", "");
    expressions = expressions.replaceAll("'", "''");
    String where = ListSQLiteHelper.COLUMN_LIST_ID + " = " + listId;
    if (!users.equals("")) {
        String[] split = users.split(" ");
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_SCREEN_NAME + " NOT LIKE '" + s + "'";
        }
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    if (!hashtags.equals("")) {
        String[] split = hashtags.split(" ");
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_HASHTAGS + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (!expressions.equals("")) {
        String[] split = expressions.split("   ");
        for (String s : split) {
            where += " AND " + ListSQLiteHelper.COLUMN_TEXT + " NOT LIKE " + "'%" + s + "%'";
        }
    }
    if (noRetweets) {
        where += " AND " + ListSQLiteHelper.COLUMN_RETWEETER + " = '' OR " + ListSQLiteHelper.COLUMN_RETWEETER + " is NULL";
    } else if (!rts.equals("")) {
        String[] split = rts.split(" ");
        for (String s : split) {
            where += " AND " + HomeSQLiteHelper.COLUMN_RETWEETER + " NOT LIKE '" + s + "'";
        }
    }
    Cursor cursor;
    String sql = "SELECT COUNT(*) FROM " + ListSQLiteHelper.TABLE_HOME + " WHERE " + where;
    SQLiteStatement statement;
    try {
        statement = database.compileStatement(sql);
    } catch (Exception e) {
        open();
        statement = database.compileStatement(sql);
    }
    long count;
    try {
        count = statement.simpleQueryForLong();
    } catch (Exception e) {
        open();
        count = statement.simpleQueryForLong();
    }
    Log.v("talon_database", "list database has " + count + " entries");
    if (count > 400) {
        try {
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - 400) + "," + 400);
        } catch (Exception e) {
            open();
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - 400) + "," + 400);
        }
    } else {
        try {
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC");
        } catch (Exception e) {
            open();
            cursor = database.query(ListSQLiteHelper.TABLE_HOME, allColumns, where, null, null, null, ListSQLiteHelper.COLUMN_TWEET_ID + " ASC");
        }
    }
    return cursor;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteDatabaseLockedException(android.database.sqlite.SQLiteDatabaseLockedException)

Example 59 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseStatementTest method testExecuteStatement.

@MediumTest
public void testExecuteStatement() throws Exception {
    populateDefaultTable();
    SQLiteStatement statement = mDatabase.compileStatement("DELETE FROM test");
    statement.execute();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    assertEquals(0, c.getCount());
    c.deactivate();
    statement.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 60 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseStatementTest method testStatementStringBinding.

@MediumTest
public void testStatementStringBinding() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num TEXT);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (long i = 0; i < 10; i++) {
        statement.bindString(1, Long.toHexString(i));
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int numCol = c.getColumnIndexOrThrow("num");
    c.moveToFirst();
    for (long i = 0; i < 10; i++) {
        String num = c.getString(numCol);
        assertEquals(Long.toHexString(i), num);
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)252 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 Test (org.junit.Test)22 SQLException (android.database.SQLException)21 Date (java.util.Date)12 TargetApi (android.annotation.TargetApi)8 SQLiteDoneException (android.database.sqlite.SQLiteDoneException)8 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)7 SdkSuppress (android.support.test.filters.SdkSuppress)7 ArrayList (java.util.ArrayList)5 SQLiteException (android.database.sqlite.SQLiteException)4 SQLiteFullException (android.database.sqlite.SQLiteFullException)4 SQLException (java.sql.SQLException)4 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 Savepoint (java.sql.Savepoint)3 ContentValues (android.content.ContentValues)2