Android的SQLite的删除查询不工作
以下SQLite的查询不会删除其ID的开头零。
The following sqlite query does not delete IDs which starts with zero.
Android的SQLite表结构
Android Sqlite Table structure
String CREATE_TABLE_BUS = "CREATE TABLE " + TABLE_BUS + "("
+ KEY_TID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ KEY_BUS_NUM + " TEXT,"
+ KEY_BUS_NAME + " TEXT,"
+ KEY_FROM + " TEXT,"
+ KEY_TO + " TEXT,"
+ KEY_TYPE + " TEXT"
+ ")";
db.execSQL(CREATE_TABLE_BUS);
我一直BUS_NUM为文本,而不是为int的某种目的。
I kept BUS_NUM as text and not as int for some purpose.
这是功能我呼吁删除行。
And this is the function I call to delete a row..
public void Delete_Bus(String bus_num) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_BUS, KEY_BUS_NUM+"="+bus_num , null);
Log.e("deleting bus num", bus_num);
db.close(); // Closing database connection
}
这code工作很细,当code不从零开始。
This code works very fine when the code does not start with zero..
它的工作原理为76555,而不是为09877.请告诉我错了我的code
It works for 76555 and not for 09877. Whats wrong with my code
本code生成的查询结尾是这样的:
The query generated by this code ends like this:
DELETE FROM BusTable WHERE BusNum = 012345
该数据库将跨preT这是一个数字,而不是字符串。
The database will interpret this as a number, not a string.
在SQL中,字符串必须用引号引起来:
In SQL, strings must be quoted:
DELETE FROM BusTable WHERE BusNum = '012345'
不过,你可以避免通过参数来格式化字符串:
However, you can avoid having to format the string by using a parameter:
db.delete(TABLE_BUS, KEY_BUS_NUM + " = ?", new String[] { bus_num });