0

I get a Syntax error when my app tries to create a sqlite table.

this is the code that creates the table:

@Override
public void onCreate(SQLiteDatabase db) {
    String SQL = pictureTable();
    db.execSQL(SQL);
}

private String pictureTable() {
    return "CREATE TABLE geophoto_db_pictures ( picid integer,"
            + "name character varying(50),"
            + "city character varying(20) NOT NULL DEFAULT 'Unknown',"
            + "zipcode character varying(20) NOT NULL DEFAULT 'Unknown',"
            + "country character varying(20) NOT NULL DEFAULT 'Unknown',"
            + "picdate datetime NOT NULL DEFAULT DATETIME('now'),"
            + "tags character varying(200)," + "image BLOB NOT NULL,"
            + "uploaded integer NOT NULL DEFAULT 0, PRIMARY KEY (picid))";
}

The error is: android.database.sqlite.SQLiteException: near "(":sytax error (code 1)

Any help is greatly appreciated !

3
  • Try "varying character()" instead of "character varying()" Commented Jan 4, 2015 at 12:51
  • error stays the same after changing it to "varying character" :( Commented Jan 4, 2015 at 12:57
  • 1
    Your picdate default value setting is wrong. [sqlite database default time value 'now'][1] [1]: stackoverflow.com/questions/200309/… Commented Jan 4, 2015 at 13:00

1 Answer 1

2

Default values cannot use function calls.

However, you can use the `CURRENT_TIMESTAMP' variable:

CREATE TABLE
    ...
    picdate datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ...
Sign up to request clarification or add additional context in comments.

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.