views:

63

answers:

5

I have to run a very simple query like this in SQLite3.

INSERT OR REPLACE INTO tblPhoneList(Phone, PeopleId, StorageType) VALUES('+91912345789', '1','1');

But whatever I do, the number is stored as 91912345789. The + prefix is ignored. The field Phone is a String. Why does it ignore the + prefix? Is there anyway to avoid this?

P.S. This code is run inside Android

EDIT: This is the schema of the table

CREATE TABLE tblPhoneList(Phone STRING PRIMARY KEY ON CONFLICT REPLACE, StorageT
ype INTEGER, PeopleId INTEGER, FOREIGN KEY(PeopleId) references tblPeople(id));
+1  A: 

the field Phone in your DB cannot be a String, you'd better check it, TEXT or VARCHAR may work. Good Luck!

Zoozy
It is indeed String. Please check my edit.
Codevalley
+2  A: 

It's text! SQLite only supports Integer, Text, Real and BLOB.

Husky110
It is String, I have posted the Schema.
Codevalley
Lol :) SQLite will glob just about any term, such as string, into the closest match (text, integer, real, blob). see "affinity" section of this: http://www.sqlite.org/datatype3.html
Brad Hein
+1  A: 

<UPDATE> from the manual:

the declared type of "STRING" has an affinity of NUMERIC, not TEXT

so please change the type of this column to TEXT, and you should be done. </UPDATE END>

what is the type of your Phone column (try PRAGMA table_info (tblPhoneList))?. if it is TEXT (or BLOB), you shouldn't have any problems - just tried this here. if it is INTEGER or REAL, you should convert it to TEXT - you cannot expect an INTEGER or REAL column to store the + string.

for all the details, see Datatypes In SQLite Version 3.

ax
I checked the type. It is String. I have posted the schema here.
Codevalley
see my updated answer
ax
A: 

try this:

INSERT OR REPLACE INTO tblPhoneList(Phone, PeopleId, StorageType) VALUES('\+91912345789', '1','1');
Praveen Chandrasekaran
I tried that. It just stores '\+91912345789' as it is. With the slash.
Codevalley
Okay. you have to clarify one thing.i.e you are passing a string as query? if yes then try this: "INSERT OR REPLACE INTO tblPhoneList(Phone, PeopleId, StorageType) VALUES('"+"\+"+"91912345789', '1','1');"
Praveen Chandrasekaran
A: 

Thanks for all the replies. I changed the type String (yes, String type IS supported) to Varchar(32) and this error magically goes off. Looks like String type is poorly supported in here.

Codevalley
you might consider accepting the answer (other than your own) that brought you there.
ax