Search in sources :

Example 6 with SQLException

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;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 7 with SQLException

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;
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 8 with SQLException

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;
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 9 with SQLException

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;
}
Also used : SQLException(android.database.SQLException) Cursor(android.database.Cursor)

Example 10 with SQLException

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;
}
Also used : HashMap(java.util.HashMap) SQLException(android.database.SQLException) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

SQLException (android.database.SQLException)154 Cursor (android.database.Cursor)51 ContentValues (android.content.ContentValues)50 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)31 Uri (android.net.Uri)30 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 ArrayList (java.util.ArrayList)10 DatabaseUtils (android.database.DatabaseUtils)8 Gson (com.google.gson.Gson)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)7 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 IOException (java.io.IOException)5 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 ContentResolver (android.content.ContentResolver)3 Context (android.content.Context)3 LayoutInflater (android.view.LayoutInflater)3