use of android.database.sqlite.SQLiteStatement in project WordPress-Android by wordpress-mobile.
the class ReaderUserTable method addOrUpdateUsers.
public static void addOrUpdateUsers(ReaderUserList users) {
if (users == null || users.size() == 0)
return;
SQLiteDatabase db = ReaderDatabase.getWritableDb();
db.beginTransaction();
SQLiteStatement stmt = db.compileStatement("INSERT OR REPLACE INTO tbl_users (" + COLUMN_NAMES + ") VALUES (?1,?2,?3,?4,?5,?6,?7)");
try {
for (ReaderUser user : users) {
stmt.bindLong(1, user.userId);
stmt.bindLong(2, user.blogId);
stmt.bindString(3, user.getUserName());
stmt.bindString(4, user.getDisplayName());
stmt.bindString(5, user.getUrl());
stmt.bindString(6, user.getProfileUrl());
stmt.bindString(7, user.getAvatarUrl());
stmt.execute();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
SqlUtils.closeStatement(stmt);
}
}
use of android.database.sqlite.SQLiteStatement in project sugar by satyan.
the class SugarRecord method count.
public static <T> long count(Class<T> type, String whereClause, String[] whereArgs, String groupBy, String orderBy, String limit) {
long result = -1;
String filter = (!TextUtils.isEmpty(whereClause)) ? " where " + whereClause : "";
SQLiteStatement sqliteStatement;
try {
sqliteStatement = getSugarDataBase().compileStatement("SELECT count(*) FROM " + NamingHelper.toTableName(type) + filter);
} catch (SQLiteException e) {
e.printStackTrace();
return result;
}
if (whereArgs != null) {
for (int i = whereArgs.length; i != 0; i--) {
sqliteStatement.bindString(i, whereArgs[i - 1]);
}
}
try {
result = sqliteStatement.simpleQueryForLong();
} finally {
sqliteStatement.close();
}
return result;
}
use of android.database.sqlite.SQLiteStatement in project requery by requery.
the class SqliteStatement method execute.
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
SQLiteStatement statement = null;
try {
statement = connection.getDatabase().compileStatement(sql);
if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
long rowId = statement.executeInsert();
insertResult = new SingleResultSet(this, rowId);
return true;
} else {
statement.execute();
}
} catch (android.database.SQLException e) {
SqliteConnection.throwSQLException(e);
} finally {
if (statement != null) {
statement.close();
}
}
return false;
}
use of android.database.sqlite.SQLiteStatement in project requery by requery.
the class SqliteStatement method executeUpdate.
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
SQLiteStatement statement = null;
try {
statement = connection.getDatabase().compileStatement(sql);
if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
long rowId = statement.executeInsert();
insertResult = new SingleResultSet(this, rowId);
updateCount = 1;
} else {
updateCount = statement.executeUpdateDelete();
}
} catch (android.database.SQLException e) {
SqliteConnection.throwSQLException(e);
} finally {
if (statement != null) {
statement.close();
}
}
return updateCount;
}
use of android.database.sqlite.SQLiteStatement in project Talon-for-Twitter by klinker24.
the class FavoriteTweetsDataSource method getCursor.
public synchronized Cursor getCursor(int account) {
String where = FavoriteTweetsSQLiteHelper.COLUMN_ACCOUNT + " = " + account;
Cursor cursor;
String sql = "SELECT COUNT(*) FROM " + FavoriteTweetsSQLiteHelper.TABLE_FAVORITE_TWEETS + " 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", "FavoriteTweets database has " + count + " entries");
if (count > timelineSize) {
try {
cursor = database.query(FavoriteTweetsSQLiteHelper.TABLE_FAVORITE_TWEETS, allColumns, where, null, null, null, FavoriteTweetsSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - timelineSize) + "," + timelineSize);
} catch (Exception e) {
open();
cursor = database.query(FavoriteTweetsSQLiteHelper.TABLE_FAVORITE_TWEETS, allColumns, where, null, null, null, FavoriteTweetsSQLiteHelper.COLUMN_TWEET_ID + " ASC", (count - timelineSize) + "," + timelineSize);
}
} else {
try {
cursor = database.query(FavoriteTweetsSQLiteHelper.TABLE_FAVORITE_TWEETS, allColumns, where, null, null, null, FavoriteTweetsSQLiteHelper.COLUMN_TWEET_ID + " ASC");
} catch (Exception e) {
open();
cursor = database.query(FavoriteTweetsSQLiteHelper.TABLE_FAVORITE_TWEETS, allColumns, where, null, null, null, FavoriteTweetsSQLiteHelper.COLUMN_TWEET_ID + " ASC");
}
}
return cursor;
}
Aggregations