4

我的 android 应用程序有一个 sqlite 表。此表有一个字符串字段(电话)。当我想插入或更新以 + 加号开头的电话号码(例如“+905331234567”)时,它会忽略加号。它只写 905331234567。但是当我用空格(或除数字以外的任何其他字符)字符(例如“+905331234567”)修改值时,就没有问题了。

update friend set phone = "+905331234567"; //905331234567
update friend set phone = " +905331234567";// +905331234567

感谢您的回复。凯末尔


编辑

创建字符串:

private static final String CREATE_FRIEND =  // create table 
        "create table " + FriendBean.DB_TABLE_NAME + "(" + 
        FriendBean.KEY_ROWID + " integer primary key autoincrement, " +
        FriendBean.KEY_contactID + " String, " +
        FriendBean.KEY_name + " String, " +
        FriendBean.KEY_phone + " String, " +
        FriendBean.KEY_accessCode + " String, " +
        FriendBean.KEY_flag + " int " +
        ");";

插入方法:

public void insertFriend(FriendBean bean) {
    SQLiteStatement statement = database.compileStatement(FriendBean.getInsertSQL());    

    statement.bindString(1,bean.getContactID());
    statement.bindString(2,bean.getName());
    statement.bindString(3,bean.getPhone() +"");
    statement.bindString(4,bean.getAccessCode());
    statement.bindLong(5,bean.getFlag());

    long id= statement.executeInsert();
}

班级:

public class FriendBean{

    public static final String DB_TABLE_NAME = "friend";

    public static final String KEY_contactID = "contactID";
    public static final String KEY_name = "name";
    public static final String KEY_phone = "phone";
    public static final String KEY_accessCode = "accessCode";
    public static final String KEY_flag = "flag";
    ...

解决方案: 将String Fieldtype 替换为Text

参考 http://www.sqlite.org/datatype3.html 和评论。

4

2 回答 2

3

解决方案:

String Fieldtype替换为Text

创建表友(rowid整型主键自增,电话文本);

参考

  1. http://www.sqlite.org/datatype3.html
  2. 评论。
于 2012-07-19T06:15:35.863 回答
0

尝试 rawQuery:

String sql = "INSERT INTO myTable(Col1, ColDate) VALUES(1,'+7777')";
db.rawQuery(sql ,null);
于 2012-07-19T04:37:19.270 回答