gpt4 book ai didi

java - 更新某一行中的多个列 SQLITE

转载 作者:搜寻专家 更新时间:2023-10-30 22:28:17 25 4
gpt4 key购买 nike

我有 4 种方法都可以更新特定行中数据的不同部分。 (我这样做是因为我是 SQ Lite 和 Android 的新手)。我如何将所有这些压缩到一种方法中?

public void updateInt(int id,String newName, String oldName){
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
String query = "UPDATE " + TABLE_NAME + " SET " + COL2 +
" = '" + newName + "' WHERE " + COL1 + " = '" + id + "'" +
" AND " + COL2 + " = '" + oldName + "'";
sqLiteDatabase.execSQL(query);
}

public void updateAuth(int id,String newAuth, String oldAuth){
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
String query = "UPDATE " + TABLE_NAME + " SET " + COL3 +
" = '" + newAuth + "' WHERE " + COL1 + " = '" + id + "'" +
" AND " + COL3 + " = '" + oldAuth + "'";
sqLiteDatabase.execSQL(query);
}

public void updateUser(int id,String newUser, String oldUser){
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
String query = "UPDATE " + TABLE_NAME + " SET " + COL5 +
" = '" + newUser + "' WHERE " + COL1 + " = '" + id + "'" +
" AND " + COL5 + " = '" + oldUser + "'";
sqLiteDatabase.execSQL(query);
}

public void updateLocation(int id,String newLocation, String oldLocation){
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
String query = "UPDATE " + TABLE_NAME + " SET " + COL4 +
" = '" + newLocation + "' WHERE " + COL1 + " = '" + id + "'" +
" AND " + COL4 + " = '" + oldLocation + "'";
sqLiteDatabase.execSQL(query);
}

最佳答案

我会保留原样。

由于每个表达式在不同的行中设置了不同的东西(所有的WHERE条件都是不同的)所以它不能真正被合并。

关于java - 更新某一行中的多个列 SQLITE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48159292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com