Java whereClause如何在公共int delete中工作(字符串表、字符串whereClause、字符串[]whereRGS);
因此,我试图通过传递指定行的id从数据库中删除一行,我在网上找到了一些代码,但我真的不知道它是如何工作的。它在SQLiteDatabase的db.delete方法中使用where子句参数。有人明白背后的逻辑吗?GetWhere子句的确切作用是什么Java whereClause如何在公共int delete中工作(字符串表、字符串whereClause、字符串[]whereRGS);,java,android,database,sqlite,sql-delete,Java,Android,Database,Sqlite,Sql Delete,因此,我试图通过传递指定行的id从数据库中删除一行,我在网上找到了一些代码,但我真的不知道它是如何工作的。它在SQLiteDatabase的db.delete方法中使用where子句参数。有人明白背后的逻辑吗?GetWhere子句的确切作用是什么 //the delete method in my database class public void deleteRow(String compareColumn, String compareValue) { // ask the d
//the delete method in my database class
public void deleteRow(String compareColumn, String compareValue) {
// ask the database manager to delete the row of given id
try {
String whereClause = getWhereClause(compareColumn, compareValue);
db.delete(TABLE_NAME, whereClause, null);
//db.delete(TABLE_NAME, TABLE_ROW_ID + "=" + rowID, null);
} catch (Exception e) {
Log.e("DB DELETE ERROR", e.toString());
e.printStackTrace();
}
}
//the method that returns whereClause
private String getWhereClause(String compareColumn, String compareValue) {
String whereClause = null;
if (compareColumn == null || compareColumn == "") { }
else if (compareValue == null || compareColumn == "") { }
else { whereClause = compareColumn + "=\"" + compareValue + "\""; }
return whereClause;
它只检查参数是否为非空,并返回
WHERE
条件的语句,如下所示:message=“Superman”
。因此,结果查询类似于:DELETE FROM myTable WHERE message=“Superman”
顺便说一句,由于它是字符串文字,最好使用单引号而不是双引号,比如
whereClause=compareColumn+“=”“+compareValue+””
它只检查参数是否为非空,并返回WHERE
条件的语句,如下所示:消息=“Superman”
。因此结果查询将类似于:从myTable中删除,其中message=“Superman”
顺便说一句,由于它是字符串文字,最好使用单引号而不是双引号,比如
whereClause=comparecocolumn+“=”“+compareValue+””
它只是检查参数是否为非空,并返回WHERE
条件的语句,如下所示:消息=”超人“
。因此结果查询类似于:从myTable中删除,其中message=“Superman”
顺便说一句,由于它是字符串文字,最好使用单引号而不是双引号,比如
whereClause=comparecocolumn+“=”“+compareValue+””
它只是检查参数是否为非空,并返回WHERE
条件的语句,如下所示:消息=”超人“
。因此结果查询类似于:从myTable中删除,其中message=“Superman”
顺便说一句,因为它是字符串文字,所以最好使用单引号而不是双引号,如使用传入的whereClause
构造一个SQL语句,如DELETE FROM WHERE
。如果传入的whereClause
为null
,则省略WHERE
,并删除所有行
您的getWhereClause()
构造了一个表达式,可以用作whereClause
,将列与指定的字符串文字值进行比较,如foo=“bar”
。如果其中一个为null或空,则返回nullwhereClause
,以便所有行都匹配。delete()
使用传入的whereClause
构造一个SQL语句,如DELETE FROM WHERE
。如果传入的whereClause
为null
,则省略WHERE
,并删除所有行
您的getWhereClause()
构造了一个表达式,可以用作whereClause
,将列与指定的字符串文字值进行比较,如foo=“bar”
。如果其中一个为null或空,则返回nullwhereClause
,以便所有行都匹配。delete()
使用传入的whereClause
构造一个SQL语句,如DELETE FROM WHERE
。如果传入的whereClause
为null
,则省略WHERE
,并删除所有行
您的getWhereClause()
构造了一个表达式,可以用作whereClause
,将列与指定的字符串文字值进行比较,如foo=“bar”
。如果其中一个为null或空,则返回nullwhereClause
,以便所有行都匹配。delete()
使用传入的whereClause
构造一个SQL语句,如DELETE FROM WHERE
。如果传入的whereClause
为null
,则省略WHERE
,并删除所有行
您的
getWhereClause()
构造了一个表达式,可以用作whereClause
,将列与指定的字符串文字值进行比较,如foo=“bar”
。如果其中一个为null或空,则返回nullwhereClause
,以便所有行都匹配。简单地解释一下,它需要两个参数
1.列名
2.列值
并创建一个
字符串
文本并返回它。例如“student\u id=100”,其中列名为student\u id
,列值为100
。当两个参数中的任何一个为null时,它返回null
,简单地解释一下,它需要两个参数
1.列名
2.列值
并创建一个
字符串
文本并返回它。例如“student\u id=100”,其中列名为student\u id
,列值为100
。当两个参数中的任何一个为null时,它返回null
,简单地解释一下,它需要两个参数
1.列名
2.列值
并创建一个
字符串
文本并返回它。例如“student\u id=100”,其中列名为student\u id
,列值为100
。当两个参数中的任何一个为null时,它返回null
,简单地解释一下,它需要两个参数
1.列名
2.列值
并创建一个字符串文本并返回它。例如,“student\u id=100”,其中列名为student\u id
,列值为100
。当两个参数中的任何一个为null时,它返回null
方法
public void deleteRow(String compareColumn, String compareValue)