Java – Update Sqlite tables if string fields start with a plus sign (+)?

Update Sqlite tables if string fields start with a plus sign (+)?… here is a solution to the problem.

Update Sqlite tables if string fields start with a plus sign (+)?

My android app has a sqlite table. The table has a string field (Phone). When I want to insert or update a phone number that starts with a + plus sign (e.g. “+905331234567”), it ignores the plus sign. It only writes 905331234567.
But when I modify the value with a space (or any other character other than a number),
(e.g., “+905331234567”), then that’s fine.

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

Thanks for your reply.
Mustafa Kemal.


Edit

Create string:

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 " +
        ");";

Insert method:

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();
}

Class:

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";
    ...

Workaround:
String Replace Fieldtype with Text.

Citations
http://www.sqlite.org/datatype3.html
and
Comments.

Solution

Solution:

Replace the string Fieldtype with Text.

Create a cousin (rowid integer primary key autoincrement,
SMS);

Citations

  1. http://www.sqlite.org/datatype3.html
  2. Comments.

Related Problems and Solutions