0

I am creating a table which works on the simulator but not on the device. I get this error message:

Failure 1 (near "(": syntax error) on 0x2d69a8 when preparing 'CREATE TABLE request(requestidINTEGER PRIMARY KEY,longitudefromDECIMAL(10,5),lattitudefromDECIMAL(10,5),phoneINTEGER)

I am creating the table like this:

 String CREATE_REQUEST_TABLE= "CREATE TABLE " + TABLE_REQUEST + "(" 
                    + KEY_REQUESTID + "INTEGER PRIMARY KEY," 
                    + KEY_LONGITUDEFROM + "DECIMAL(10,5)," 
                    + KEY_LATTITUDEFROM + "DECIMAL(10,5)," 
                    + KEY_TO + "TEXT," 
                    + KEY_DEPARTURETIME + "TIME," 
                    + KEY_ARRIVALTIME + "TIME," 
                    + KEY_DESCRIPTION + "TEXT," 
                    + KEY_PHONE + "INTEGER" + ")"; 
            db.execSQL(CREATE_REQUEST_TABLE); 

3 Answers 3

2

You do not have spaces in your request. Add space before and after key:

String CREATE_REQUEST_TABLE= "CREATE TABLE " + TABLE_REQUEST + " (" 
                + KEY_REQUESTID + " INTEGER PRIMARY KEY, " 
                + KEY_LONGITUDEFROM + " DECIMAL(10,5), " 
                + KEY_LATTITUDEFROM + " DECIMAL(10,5), " 
                + KEY_TO + " TEXT, " 
                + KEY_DEPARTURETIME + " TIME, " 
                + KEY_ARRIVALTIME + " TIME, " 
                + KEY_DESCRIPTION + " TEXT, " 
                + KEY_PHONE + " INTEGER" + ")"; 
Sign up to request clarification or add additional context in comments.

1 Comment

thank you that was it but i was wondering why on the emulator it was working fine when i tried it on the device it crashes.. but now everything is working
1

Try with space between your id and "INTEGER PRIMARY KEY,"

Like;

    KEY_REQUESTID + " INTEGER PRIMARY KEY,"

Comments

1

Well, as you can see in the error message, KEY_REQUESTID + "INTEGER PRIMARY KEY," turns into requestidINTEGER PRIMARY which is not requestid INTEGER PRIMARY. Basically, there is no space between the column name and the column type which makes them look (to SQLite) as a single token.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.