当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.update方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.update方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.update方法的具体用法?Java SQLiteDatabase.update怎么用?Java SQLiteDatabase.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteDatabase的用法示例。


在下文中一共展示了SQLiteDatabase.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    DebugLog.logMethod();
    DebugLog.logMessage("Uri: " + uri);

    int numRowsAffected = 0;
    SQLiteDatabase writableDatabase = couponDbHelper.getWritableDatabase();
    switch (uriMatcher.match(uri)) {
        case COUPON_WITH_ID: {
            DebugLog.logMessage("COUPON_WITH_ID");
            String couponId = CouponContract.CouponTable.getCouponIdFromUri(uri);
            numRowsAffected = writableDatabase.update(
                    CouponContract.CouponTable.TABLE_NAME,
                    values,
                    CouponContract.CouponTable.COLUMN_ID + " = ?",
                    new String[]{ couponId }
            );
            break;
        }

        default: {
        }
    }
    notifyDataChange(uri);
    return numRowsAffected;
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:27,代码来源:CouponProvider.java

示例2: resetUsage

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void resetUsage(int uid) {
    lock.writeLock().lock();
    try {
        // There is a segmented index on uid
        SQLiteDatabase db = this.getWritableDatabase();
        db.beginTransactionNonExclusive();
        try {
            ContentValues cv = new ContentValues();
            cv.putNull("sent");
            cv.putNull("received");
            cv.putNull("connections");
            db.update("access", cv,
                    (uid < 0 ? null : "uid = ?"),
                    (uid < 0 ? null : new String[]{Integer.toString(uid)}));

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } finally {
        lock.writeLock().unlock();
    }

    notifyAccessChanged();
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:26,代码来源:DatabaseHelper.java

示例3: update

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs)
{
    
    String tableName = getTableName(uri);
    if (null == tableName)
    {
        throw new IllegalArgumentException(Constant_DB.CONTENTPROVIDER_UNRECOGNIZED_URI + uri);
    }
    SQLiteDatabase db = MIPProvider.getWritableDatabase();
    int count = 0;
    count = db.update(tableName, values, selection, selectionArgs);
    
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}
 
开发者ID:zhuyu1022,项目名称:amap,代码行数:17,代码来源:MIPDBProvider.java

示例4: refreshBooksDbWithDirectory

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Scan the program directory and check each book data base file against the StoredBooks Database
 *
 * @return true if the directory  already exist and files were refreshed , false if the directory didn't exist or was empty in yhis case the directory is created
 */

public void refreshBooksDbWithDirectory(Context context) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(BooksInformationDBContract.StoredBooks.COLUMN_NAME_FILESYSTEM_SYNC_FLAG,
            VALUE_FILESYSTEM_SYNC_FLAG_NOT_PRESENT);
    db.update(BooksInformationDBContract.StoredBooks.TABLE_NAME,
            contentValues, null, null);


    File booksDir = new File(StorageUtils.getIslamicLibraryShamelaBooksDir(context));
    if (!(booksDir.exists() && booksDir.isDirectory())) {
        booksDir.mkdirs();
    } else {
        String[] files = booksDir.list();
        if (files.length == 0) {
            return;
        }

        db.beginTransaction();
        try {
            for (String file : files) {
                String fullFilePath = booksDir + File.separator + file;

                //validate file name against <integer>.sqlite
                Matcher matcher = uncompressedBookFileRegex.matcher(file);
                if (matcher.matches()) {
                    int book_id = Integer.parseInt(matcher.group(1));
                    checkFileInDbOrInsert(db, book_id, context, fullFilePath);
                } else {
                    Matcher compressedMatcher = compressedBookFileRegex.matcher(file);
                    if (compressedMatcher.matches()) {
                        int bookId = Integer.parseInt(compressedMatcher.group(1));

                        Intent localIntent =
                                new Intent(BROADCAST_ACTION)
                                        // Puts the status into the Intent
                                        .putExtra(EXTRA_DOWNLOAD_STATUS, DownloadsConstants.STATUS_WAITING_FOR_UNZIP)
                                        .putExtra(DownloadsConstants.EXTRA_DOWNLOAD_BOOK_ID, bookId);
                        context.sendOrderedBroadcast(localIntent, null);

                        Intent serviceIntent = new Intent(context, UnZipIntentService.class);
                        serviceIntent.putExtra(UnZipIntentService.EXTRA_FILE_PATH, fullFilePath);
                        context.startService(serviceIntent);
                        // Broadcasts the Intent to receivers in this app.

                    }
                }
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }

        //delete book entries that doesn't have files in file system
        db.delete(BooksInformationDBContract.StoredBooks.TABLE_NAME,
                BooksInformationDBContract.StoredBooks.COLUMN_NAME_FILESYSTEM_SYNC_FLAG + "=?",
                new String[]{String.valueOf(BooksInformationDBContract.StoredBooks.VALUE_FILESYSTEM_SYNC_FLAG_NOT_PRESENT)}
        );

    }
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:68,代码来源:BooksInformationDbHelper.java

示例5: insert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void insert(SQLiteDatabase database,String packageName,int type){
    Cursor cursor=database.query(TABLE_NAME,null,COLUMN_PACKAGE+" = ?",new String[]{packageName},null,null,null);
    int rowId=-1;
    if (cursor!=null && cursor.moveToFirst()){
        int rowIndex = cursor.getColumnIndex(COLUMN_ID);
        rowId=cursor.getInt(rowIndex);
    }
    ContentValues values=new ContentValues();
    values.put(COLUMN_PACKAGE,packageName);
    values.put(COLUMN_TYPE,type);
    if (rowId==-1){
        database.insert(TABLE_NAME,null,values);
    }else {
        values.put(COLUMN_ID,rowId);
        database.update(TABLE_NAME,values,COLUMN_ID+" = ?",new String[]{""+rowId});
    }
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:18,代码来源:SelectionDbHelper.java

示例6: updateCategory

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean updateCategory(String catID, String displayName, String displayNameFull, boolean isTiny) {
    try {
        SQLiteDatabase db = this.getWritableDatabase();

        // Log.d("DB", "adding catID " + catID);
        ContentValues values = new ContentValues();

        values.put(LABEL, displayName);
        values.put(LABELFULL, displayNameFull);
        values.put(ISTINY, isTiny?1:0);

        db.update(TAB_ORDER_TABLE, values, CATID + "=?", new String[]{catID});
    } catch (Exception e) {
        Log.e("LaunchDB", "Can't select catID " + catID, e);
        return false;
    }
    return true;
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:19,代码来源:DB.java

示例7: updateItem

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void updateItem(Item i) {
    if (i.getId() < 0)
        return;

    SQLiteDatabase db = getWritableDatabase();
    ContentValues values = createValuesForItem(i);

    db.update(ITEM_TABLE_NAME, values, ITEM_TABLE_COL_ID + " = ?", new String[]{i.getId() + ""});
}
 
开发者ID:marc-urschick,项目名称:a_whattobuy,代码行数:10,代码来源:BuylistOpenHelper.java

示例8: movePropertiesFromBody

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private static void movePropertiesFromBody(SQLiteDatabase db) {
    Cursor cursor = db.query("notes", new String[] { "_id", "content" }, null, null, null, null, null);

    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            long noteId = cursor.getLong(0);
            String content = cursor.getString(1);

            if (!TextUtils.isEmpty(content)) {
                StringBuilder newContent = new StringBuilder();
                List<String[]> properties = getPropertiesFromContent(content, newContent);

                if (properties.size() > 0) {
                    int pos = 1;
                    for (String[] property: properties) {
                        long nameId = DbPropertyName.getOrInsert(db, property[0]);
                        long valueId = DbPropertyValue.getOrInsert(db, property[1]);
                        long propertyId = DbProperty.getOrInsert(db, nameId, valueId);
                        DbNoteProperty.getOrInsert(db, noteId, pos++, propertyId);
                    }

                    /* Update content and its line count */
                    ContentValues values = new ContentValues();
                    values.put("content", newContent.toString());
                    values.put("content_line_count", MiscUtils.lineCount(newContent.toString()));
                    db.update("notes", values, "_id = " + noteId, null);
                }
            }
        }
    } finally {
        cursor.close();
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:34,代码来源:DatabaseMigration.java

示例9: b

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void b(SQLiteDatabase sQLiteDatabase) {
    Cursor query;
    Object th;
    Cursor cursor;
    Throwable th2;
    try {
        query = sQLiteDatabase.query("events", null, null, null, null, null, null);
        try {
            List<x> arrayList = new ArrayList();
            while (query.moveToNext()) {
                arrayList.add(new x(query.getLong(0), query.getString(1), query.getInt(2),
                        query.getInt(3)));
            }
            ContentValues contentValues = new ContentValues();
            for (x xVar : arrayList) {
                contentValues.put(Utils.RESPONSE_CONTENT, k.c(xVar.b));
                sQLiteDatabase.update("events", contentValues, "event_id=?", new
                        String[]{Long.toString(xVar.a)});
            }
            if (query != null) {
                query.close();
            }
        } catch (Throwable th3) {
            th2 = th3;
            if (query != null) {
                query.close();
            }
            throw th2;
        }
    } catch (Throwable th4) {
        th2 = th4;
        query = null;
        if (query != null) {
            query.close();
        }
        throw th2;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:39,代码来源:w.java

示例10: disableProfile

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void disableProfile(Profile profile) {
    mProfileList.remove(profile);

    SQLiteDatabase db = getWritableDatabase();
    ContentValues content_values = new ContentValues(3);
    content_values.put(PROFILE_COLUMN_NAME_ENABLED, false);
    db.update(TABLE_NAME_PROFILE, content_values, PROFILE_COLUMN_NAME_ID+"=?", new String[]{""+profile.id});
}
 
开发者ID:gbizzotto,项目名称:dapay,代码行数:9,代码来源:DBHelper.java

示例11: updatePlaylistData

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int updatePlaylistData(PlaylistData playlistData) {

        // Get table data
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        // Update data
        values.put(KEY_NAME, playlistData.getPlaylistName());
        values.put(KEY_LIST, playlistToString(playlistData));
        return db.update(TABLE_PLAYLISTS, values, KEY_NAME + " = ?", new String[]{String.valueOf(playlistData.getPlaylistName())});
    }
 
开发者ID:Davarco,项目名称:Divertio,代码行数:12,代码来源:PlaylistDBHandler.java

示例12: update

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void update(String table_name, int id, String text) {
    SQLiteDatabase db = this.getWritableDatabase();
    String where = "_id" + " = ?";
    String[] whereValue = {Integer.toString(id)};
    ContentValues cv = new ContentValues();
    cv.put("url_data", text);
    db.update(table_name, cv, where, whereValue);
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:9,代码来源:DBHelper.java

示例13: updateFlashcard

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int updateFlashcard(Flashcard contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, contact.getTitle());
    values.put(KEY_COUNT, contact.getCount());
    values.put(KEY_LABEL, contact.getLabel());
    values.put(KEY_COLOR, contact.getColor());
    values.put(KEY_USE_COUNT, contact.getUseCount());

    // updating row
    return db.update(TABLE_FLASHCARDS, values, KEY_ID + " = ?",
            new String[]{contact.getSetId()});
}
 
开发者ID:AbduazizKayumov,项目名称:Flashcard-Maker-Android,代码行数:15,代码来源:TrashFlashcardDb.java

示例14: encodeRookUris

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * file:/dir/file name.org
 * file:/dir/file%20name.org
 */
private static void encodeRookUris(SQLiteDatabase db) {
    Cursor cursor = db.query("rook_urls", new String[] { "_id", "rook_url" }, null, null, null, null, null);

    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            long id = cursor.getLong(0);
            String uri = cursor.getString(1);

            String encodedUri = MiscUtils.encodeUri(uri);

            if (! uri.equals(encodedUri)) {
                /* Update unless same URL already exists. */
                Cursor c = db.query("rook_urls", new String[] { "_id" },
                        "rook_url = ?", new String[] { encodedUri }, null, null, null);
                try {
                    if (!c.moveToFirst()) {
                        ContentValues values = new ContentValues();
                        values.put("rook_url", encodedUri);
                        db.update("rook_urls", values, "_id = " + id, null);
                    }
                } finally {
                    c.close();
                }
            }
        }
    } finally {
        cursor.close();
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:34,代码来源:DatabaseMigration.java

示例15: update

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    Log.d(TAG, "update()");

    SQLiteDatabase sqlDB =  dbHelper.getWritableDatabase();
    int count = 0;
    switch (myUriMatcher.match(uri)) {
        case 1:
            count = sqlDB.update(MySQLiteHelper.TABLE_POINT, values, selection, selectionArgs);
            break;
        case 2:
            count = sqlDB.update(MySQLiteHelper.TABLE_ACHIEVEMENT, values, selection, selectionArgs);
            break;
        case 3:
            count = sqlDB.update(MySQLiteHelper.TABLE_GAME, values, selection, selectionArgs);
            break;
        case 4:
            count = sqlDB.update(MySQLiteHelper.TABLE_CATEGORY, values, selection, selectionArgs);
            break;
        default:
            Log.d(TAG, " Switch-case default!");
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    if (count<1) {
        Log.e(TAG, "during update() count = "+count);
        Toast.makeText(getContext(), "Update possible error: no row was updated", Toast.LENGTH_LONG).show();
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
}
 
开发者ID:stefanonicolai,项目名称:AstronomyTourPadova,代码行数:31,代码来源:LocalContentProvider.java


注:本文中的android.database.sqlite.SQLiteDatabase.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。