我在数据库里建了一个名字叫user的表,然后里面有个参数是userid 我是想记录user的数量,也就是看看我插入了多少条用户信息
@Override
public void onCreate(SQLiteDatabase db) {
tableCreate = new StringBuffer();
tableCreate.append("create table ")
.append(DB_TABLENAME)
.append(" (")
.append("userid integer primary key autoincrement,")
.append("name text,")
.append("mobilephone text,")
.append("imageadress text")
.append(")");
System.out.println(tableCreate.toString());
db.execSQL(tableCreate.toString());
}然后里面有一个操作 删除所有用户 /**
* 删除所有联系人
*/
public void deleteAll() {
dbInstance.delete(DB_TABLENAME, null, null);
}
我现在想在删除所有联系人的操作后同时把用户id置为0,代表没用户了,该怎么写代码呢?
还有,/**
* 删除一个联系人
*/
public void delete(int userId) {
dbInstance.delete(DB_TABLENAME, "userid=?", new String[]{String.valueOf(userId)});
}
如果只删除一个联系人,我想同时把用户id减小一个,该怎么写代码呢?
现在的情况是,userid integer primary key autoincrement 一直是增加的,只要我插入一次用户,它就自增一下,就算我删除了用户,它也不会减小……求大家给我看看~不胜感激~
@Override
public void onCreate(SQLiteDatabase db) {
tableCreate = new StringBuffer();
tableCreate.append("create table ")
.append(DB_TABLENAME)
.append(" (")
.append("userid integer primary key autoincrement,")
.append("name text,")
.append("mobilephone text,")
.append("imageadress text")
.append(")");
System.out.println(tableCreate.toString());
db.execSQL(tableCreate.toString());
}然后里面有一个操作 删除所有用户 /**
* 删除所有联系人
*/
public void deleteAll() {
dbInstance.delete(DB_TABLENAME, null, null);
}
我现在想在删除所有联系人的操作后同时把用户id置为0,代表没用户了,该怎么写代码呢?
还有,/**
* 删除一个联系人
*/
public void delete(int userId) {
dbInstance.delete(DB_TABLENAME, "userid=?", new String[]{String.valueOf(userId)});
}
如果只删除一个联系人,我想同时把用户id减小一个,该怎么写代码呢?
现在的情况是,userid integer primary key autoincrement 一直是增加的,只要我插入一次用户,它就自增一下,就算我删除了用户,它也不会减小……求大家给我看看~不胜感激~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货