0

I've spend some time in try to fix this, but I don't know where is the problem in my sql create entries..

The error:

android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: CREATE VIRTUAL TABLE CommerceName ( _id TEXT  PRIMARY KEY,id INTEGER,name TEXT,category TEXT,imageref TEXT )

Thanks in advance

CODE:

 public static final String SQL_CREATE_ENTRIES =
            "CREATE VIRTUAL TABLE " + CommerceSearchReaderDbHelper.CommerceNameSearchEntry.TABLE_NAME + " ( " +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry._ID            + TEXT_TYPE +"  PRIMARY KEY," +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_ID      + INTEGER_TYPE + COMMA_SEP +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_NAME    + TEXT_TYPE + COMMA_SEP  +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_CATEGORY+ TEXT_TYPE + COMMA_SEP  +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_IMAGEREF + TEXT_TYPE +
                    " )";

    public static final String SQL_DELETE_ENTRIES =
            "DROP TABLE IF EXISTS " + CommerceSearchReaderDbHelper.CommerceNameSearchEntry.TABLE_NAME;

    public static abstract class CommerceNameSearchEntry implements BaseColumns {
        public static final String TABLE_NAME       = "CommerceName";
        public static final String COLUMN_ID        = SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA;
        public static final String COLUMN_NAME      = SearchManager.SUGGEST_COLUMN_TEXT_1;
        public static final String COLUMN_CATEGORY  = SearchManager.SUGGEST_COLUMN_TEXT_2;
        public static final String COLUMN_IMAGEREF  = SearchManager.SUGGEST_COLUMN_ICON_1;
    }

2 Answers 2

1

You are missing the spaces between your CommerceSearchReaderDbHelper.CommerceNameSearchEntry._ID and TEXT_TYPE, etc. Use this instead:

public static final String SQL_CREATE_ENTRIES =
            "CREATE VIRTUAL TABLE " + 
             CommerceSearchReaderDbHelper.CommerceNameSearchEntry.TABLE_NAME + " ( " + CommerceSearchReaderDbHelper.CommerceNameSearchEntry._ID          
             + " " + TEXT_TYPE +"  PRIMARY KEY," +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_ID + " " + INTEGER_TYPE + COMMA_SEP +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_NAME + " " + TEXT_TYPE + COMMA_SEP  +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_CATEGORY + " " + TEXT_TYPE + COMMA_SEP  +
                    CommerceSearchReaderDbHelper.CommerceNameSearchEntry.COLUMN_IMAGEREF + " " + TEXT_TYPE +
             " );";
Sign up to request clarification or add additional context in comments.

Comments

1

If you really intend to create a virtual table, then you are missing "USING module_name". See here.

If you instead do not intend to create a virtual table (which is likely since you are using Android), then you should remove "VIRTUAL" from the CREATE statement. The syntax is here.

3 Comments

what do you mean with: missing "USING module_name
Virtual tables require a backing implementation. Since you have specified the Android tag, I would actually assume you do not intend to create a virtual table (since that is relatively complicated). More likely you intend to create a regular table. I will update the answer.
Also, if TEXT_TYPE and INTEGER_TYPE are not defined to include space(s) at the beginning, you may indeed have the problem hinted by the other answer once you sort out the CREATE syntax.

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.