Search in sources :

Example 91 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project danci by ling0322.

the class InitActivity method setupDict.

public void setupDict() throws Exception {
    //
    // first delete this file
    //
    File f = new File(Config.DICT_12_PATH);
    if (f.exists() == true && f.length() > 1 * 1024 * 1024)
        return;
    if (f.exists() == true && f.length() < 1 * 1024 * 1024)
        f.delete();
    SQLiteDatabase conn = SQLiteDatabase.openOrCreateDatabase(Config.DICT_12_PATH, null);
    conn.beginTransaction();
    try {
        conn.execSQL("create table dict(word text primary key, definition text)");
        for (int i = 0; i < Config.DICT_12_PARTS; ++i) {
            BufferedReader in = new BufferedReader(new InputStreamReader(activity.getAssets().open("dict-12-v2.part".concat(Integer.toString(i)))));
            String line;
            while (null != (line = in.readLine())) {
                String[] sp = line.split(" :: ");
                conn.execSQL("insert into dict(word, definition) values(?, ?)", sp);
            }
            sendDisplayMessage(String.format("初始化中, 请稍等 dict-12-v2 %d/%d", i, Config.DICT_12_PARTS));
        }
        conn.setTransactionSuccessful();
    } finally {
        conn.endTransaction();
    }
    conn.close();
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 92 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project ADWLauncher2 by boombuler.

the class AppDBProvider method insert.

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    SqlArguments args = new SqlArguments(uri);
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final long rowId = db.insert(args.table, null, initialValues);
    if (rowId <= 0)
        return null;
    return ContentUris.withAppendedId(uri, rowId);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SqlArguments(org.adw.launcher2.LauncherProvider.SqlArguments)

Example 93 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project FileDownloaderManager by arlyxiao.

the class FileRecord method get_data.

public Map<Integer, Integer> get_data(String path) {
    SQLiteDatabase db = db_open_helper.getReadableDatabase();
    Cursor cursor = db.rawQuery("select threadid, downlength from filedownlog where downpath=?", new String[] { path });
    Map<Integer, Integer> data = new HashMap<Integer, Integer>();
    while (cursor.moveToNext()) {
        data.put(cursor.getInt(0), cursor.getInt(1));
    }
    cursor.close();
    db.close();
    return data;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) HashMap(java.util.HashMap) Cursor(android.database.Cursor)

Example 94 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project Brion-Learns-OAuth by brione.

the class BloaProvider method update.

@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    int count = 0;
    // Get the database and run the query
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    String recId;
    String whereClause;
    switch(sUriMatcher.match(uri)) {
        case USER_STATUS_RECORDS:
            count = db.update(USER_STATUS_RECORDS_TABLE_NAME, values, where, whereArgs);
            break;
        case USER_STATUS_RECORD_ID:
            recId = uri.getPathSegments().get(1);
            whereClause = UserStatusRecord._ID + "=" + recId + (!TextUtils.isEmpty(where) ? " AND (" + where + ")" : "");
            count = db.update(USER_STATUS_RECORDS_TABLE_NAME, values, whereClause, whereArgs);
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    mCR.notifyChange(uri, null);
    return count;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 95 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project Brion-Learns-OAuth by brione.

the class BloaProvider method bulkInsert.

@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
    int count = 0;
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    db.beginTransaction();
    count = super.bulkInsert(uri, values);
    if (count == values.length) {
        db.setTransactionSuccessful();
    }
    db.endTransaction();
    return count;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1658 Cursor (android.database.Cursor)527 ContentValues (android.content.ContentValues)350 ArrayList (java.util.ArrayList)111 File (java.io.File)65 Test (org.junit.Test)59 SQLiteException (android.database.sqlite.SQLiteException)48 SQLException (android.database.SQLException)44 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 IOException (java.io.IOException)43 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)38 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21