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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations