Search code examples
androidsqliteandroid-cursorgetstring

cursor.getString() doesn't work properly (ex: code postal = "01234" but return "1234" instead)


I'm working with Android - SQLite. I have code postal number stored as CHAR[5] in SQLite db.

Cursor cursor = db.query( ... )
String code = cursor.getString(cursor.getColumnIndex("code"));
CREATE TABLE codepostal (
    code CHAR( 5 ) PRIMARY KEY NOT NULL UNIQUE,
    name VARCHAR( 70 ) NOT NULL
);
INSERT INTO [codepostal] ([code], [name]) VALUES (01001, 'My_city');

However it always returns with deleting "0" begining character of code postal? (ex: code postal = "01234" but return "1234" instead)

Can someone explain?


Solution

  • All response LeoLink, Frank N. Stein, Pawel Urban, AC-OpenSource was right. Thanks you guys so much.

    Must insert the value as string literals by adding 'quote'

    use

    VALUES ('01001', 'My_city');
    

    instead of

    VALUES (01001, 'My_city');