Java Code Examples for android.database.sqlite.SQLiteDatabase.update()

The following are Jave code examples for showing how to use update() of the android.database.sqlite.SQLiteDatabase class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MKAPP   File: DatabaseHelper.java   View Source Code Vote up 6 votes
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();
}
 
Example 2
Project: CouponsTracker   File: CouponProvider.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: amap   File: MIPDBProvider.java   View Source Code Vote up 6 votes
@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;
}
 
Example 4
Project: IslamicLibraryAndroid   File: BooksInformationDbHelper.java   View Source Code Vote up 6 votes
/**
 * 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)}
        );

    }
}
 
Example 5
Project: Bigbang   File: SelectionDbHelper.java   View Source Code Vote up 6 votes
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});
    }
}
 
Example 6
Project: LaunchTime   File: DB.java   View Source Code Vote up 6 votes
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;
}
 
Example 7
Project: a_whattobuy   File: BuylistOpenHelper.java   View Source Code Vote up 5 votes
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() + ""});
}
 
Example 8
Project: orgzly-android   File: DatabaseMigration.java   View Source Code Vote up 5 votes
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();
    }
}
 
Example 9
Project: boohee_v5.6   File: w.java   View Source Code Vote up 5 votes
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;
    }
}
 
Example 10
Project: dapay   File: DBHelper.java   View Source Code Vote up 5 votes
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});
}
 
Example 11
Project: Divertio   File: PlaylistDBHandler.java   View Source Code Vote up 5 votes
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())});
    }
 
Example 12
Project: FreeStreams-TVLauncher   File: DBHelper.java   View Source Code Vote up 5 votes
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);
}
 
Example 13
Project: Flashcard-Maker-Android   File: TrashFlashcardDb.java   View Source Code Vote up 5 votes
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()});
}
 
Example 14
Project: orgzly-android   File: DatabaseMigration.java   View Source Code Vote up 5 votes
/**
 * 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();
    }
}
 
Example 15
Project: AstronomyTourPadova   File: LocalContentProvider.java   View Source Code Vote up 5 votes
@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;
}
 
Example 16
Project: DBPA   File: SQLite.java   View Source Code Vote up 5 votes
@Override
protected void updateAuthorAndYourPosts(Author author) {
    SQLiteDatabase db = sqLiteHelper.getWritableDatabase();

    ContentValues values = fillContentValues(author);

    db.update(SQLiteHelper.TABLE_AUTHOR, values, SQLiteHelper.AUTHOR_KEY + " = ?",
            new String[] { String.valueOf(author.getKey()) });
    db.close();
}
 
Example 17
Project: Cable-Android   File: ThreadDatabase.java   View Source Code Vote up 5 votes
public void setUnread(long threadId) {
  ContentValues contentValues = new ContentValues(1);
  contentValues.put(READ, 0);

  SQLiteDatabase db = databaseHelper.getWritableDatabase();
  db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId + ""});
  notifyConversationListListeners();
}
 
Example 18
Project: TrackPlan-app   File: DatabaseFriend.java   View Source Code Vote up 5 votes
public int updateContact(Friends contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();

    values.put(KEY_NAME, contact.getName());

    // updating row
    return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
            new String[]{String.valueOf(contact.getID())});
}
 
Example 19
Project: MyFlightbookAndroid   File: LogbookEntry.java   View Source Code Vote up 4 votes
public boolean ToDB() {
    boolean fResult = true;

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);

    ContentValues cv = new ContentValues();
    cv.put("idFlight", idFlight);
    cv.put("szUser", szUser);
    cv.put("dtFlight", df.format(dtFlight));
    cv.put("idCatClassOverride", idCatClassOverride);
    cv.put("idAircraft", idAircraft);
    cv.put("cApproaches", cApproaches);
    cv.put("cApproachPrecision", cApproachPrecision);
    cv.put("cApproachNonPrecision", cApproachNonPrecision);
    cv.put("cLandings", cLandings);
    cv.put("cNightLandings", cNightLandings);
    cv.put("cFullStopLandings", cFullStopLandings);
    cv.put("decXC", decXC);
    cv.put("decIMC", decIMC);
    cv.put("decSimulatedIFR", decSimulatedIFR);
    cv.put("decGrndSim", decGrndSim);
    cv.put("decDual", decDual);
    cv.put("decNight", decNight);
    cv.put("decPIC", decPIC);
    cv.put("decCFI", decCFI);
    cv.put("decSIC", decSIC);
    cv.put("decTotal", decTotal);
    cv.put("fHold", fHold.toString());
    cv.put("szComments", szComments);
    cv.put("szRoute", szRoute);
    cv.put("fPublic", fPublic.toString());
    cv.put("dtFlightStart", df.format(dtFlightStart));
    cv.put("dtFlightEnd", df.format(dtFlightEnd));
    cv.put("dtEngineStart", df.format(dtEngineStart));
    cv.put("dtEngineEnd", df.format(dtEngineEnd));
    cv.put("hobbsStart", hobbsStart);
    cv.put("hobbsEnd", hobbsEnd);
    cv.put("szFlightData", szFlightData);
    cv.put("szError", szError);

    SQLiteDatabase db = MFBMain.mDBHelper.getWritableDatabase();
    try {
        if (this.idLocalDB <= 0)
            this.idLocalDB = db.insert("Flights", null, cv);
        else
            db.update("Flights", cv, "_id = ?", new String[]{String.format(Locale.US, "%d", this.idLocalDB)});
    } catch (Exception e) {
        fResult = false;
        szError = e.getMessage();
        Log.e(MFBConstants.LOG_TAG, "Error persisting logbook entry to db - " + szError);
    }
    return fResult;
}
 
Example 20
Project: WeatherPlus   File: DatabaseHelper.java   View Source Code Vote up 3 votes
public synchronized void updateCity(final CityWeatherModelView city) {
    Log.d(TAG, "Updating an existing city data on db " + city.getCityName());

    SQLiteDatabase db = getWritableDatabase();

    ContentValues cv = new ContentValues();
    cv.put(ROW_DATA, new GsonBuilder().create().toJson(city));

    String cursorIndex = Integer.toString(city.getCursorIndex());

    db.update(TABLE_CITIES, cv, ROW_ID + " = ?", new String[]{cursorIndex});

    db.close();
}