use of android.database.SQLException in project android-app by eoecn.
the class APNManager method setDefaultApn.
/**
* 设置默认的apn
*
* @param apnId
* @return
*/
public boolean setDefaultApn(int apnId) {
boolean res = false;
ContentValues values = new ContentValues();
values.put("apn_id", apnId);
try {
resolver.update(PREFERRED_APN_URI, values, null, null);
Cursor c = resolver.query(PREFERRED_APN_URI, new String[] { "name", "apn" }, "_id=" + apnId, null, null);
if (c != null) {
res = true;
c.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return res;
}
use of android.database.SQLException in project DBFlow by Raizlabs.
the class AndroidDatabaseStatement method executeUpdateDelete.
@Override
public long executeUpdateDelete() {
long count = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
count = statement.executeUpdateDelete();
} else {
statement.execute();
Cursor cursor = null;
try {
cursor = database.rawQuery("SELECT changes() AS affected_row_count", null);
if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
count = cursor.getLong(cursor.getColumnIndex("affected_row_count"));
}
} catch (SQLException e) {
// Handle exception here.
} finally {
if (cursor != null) {
cursor.close();
}
}
}
return count;
}
use of android.database.SQLException in project Anki-Android by Ramblurr.
the class AnkiDb method queryLongScalar.
public long queryLongScalar(String query, boolean throwException) throws SQLException {
Cursor cursor = null;
long scalar;
try {
cursor = mDatabase.rawQuery(query, null);
if (!cursor.moveToNext()) {
if (throwException) {
throw new SQLException("No result for query: " + query);
} else {
return 0;
}
}
scalar = cursor.getLong(0);
} finally {
if (cursor != null) {
cursor.close();
}
}
return scalar;
}
use of android.database.SQLException in project Anki-Android by Ramblurr.
the class AnkiDb method queryScalar.
public int queryScalar(String query, boolean throwException) throws SQLException {
Cursor cursor = null;
int scalar;
try {
cursor = mDatabase.rawQuery(query, null);
if (!cursor.moveToNext()) {
if (throwException) {
throw new SQLException("No result for query: " + query);
} else {
return 0;
}
}
scalar = cursor.getInt(0);
} finally {
if (cursor != null) {
cursor.close();
}
}
return scalar;
}
use of android.database.SQLException in project Anki-Android by Ramblurr.
the class Finder method findCardsForCardBrowser.
/** Return a list of card ids for QUERY */
public ArrayList<HashMap<String, String>> findCardsForCardBrowser(String query, String _order, HashMap<String, String> deckNames) {
String[] tokens = _tokenize(query);
Pair<String, String[]> res1 = _where(tokens);
String preds = res1.first;
String[] args = res1.second;
ArrayList<HashMap<String, String>> res = new ArrayList<HashMap<String, String>>();
if (preds == null) {
return res;
}
Pair<String, Boolean> res2 = _order(_order);
String order = res2.first;
boolean rev = res2.second;
String sql = _query(preds, order, true);
Cursor cur = null;
try {
cur = mCol.getDb().getDatabase().rawQuery(sql, args);
while (cur.moveToNext()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", cur.getString(0));
map.put("sfld", cur.getString(1));
map.put("deck", deckNames.get(cur.getString(2)));
int queue = cur.getInt(3);
String tags = cur.getString(4);
map.put("flags", Integer.toString((queue == -1 ? 1 : 0) + (tags.matches(".*[Mm]arked.*") ? 2 : 0)));
map.put("tags", tags);
res.add(map);
}
} catch (SQLException e) {
// invalid grouping
Log.e(AnkiDroidApp.TAG, "Invalid grouping, sql: " + sql);
return new ArrayList<HashMap<String, String>>();
} finally {
if (cur != null) {
cur.close();
}
}
if (rev) {
Collections.reverse(res);
}
return res;
}
Aggregations