2

I have a scenario that "create virtual table if not exists searchcontent using fts4(_id text, desc text)" is crashing with: near "NOT": syntax error: , while compiling: CREATE VIRTUAL TABLE IF NOT EXISTS

This is only happening on a galaxy nexus phone which is running 4.0.2. when I try it on a galaxy note 2 that is running 4.1.2 everything is working fine. If I remove "if not exists" again it will work on nexus phone. Does anyone know what is the error? is it android version problem?

in my sqlitehelper class:

public static final String SearchContentTable_DATABASE_CREATE = "CREATE VIRTUAL TABLE IF NOT EXISTS " + TABLE_NAME + " USING fts4 ( " + 
        COLUMN_ID + " " + "TEXT" + " , " + 
        COLUMN_TITLE + " " + "TEXT" + " , " + 
        COLUMN_DESCRIPTION + " " + "TEXT" + " , " + 
        COLUMN_KEYWORDS + " " + "TEXT" + " , " + 
        COLUMN_TYPE + " " + "TEXT" + " );";

@Override
public void onCreate( SQLiteDatabase database )
{
   .
   .
   .
    database.execSQL( SearchContentTable_DATABASE_CREATE );
   .
   .
   .
}
4
  • a part of code added. Commented Nov 8, 2013 at 17:10
  • I saw the same issue on a device running 4.0.4 today. Commented Nov 8, 2013 at 20:05
  • I'm facing the same problem on versions 4.0.x (4.0.1, 4.0.2, 4.0.3, and 4.0.4). I have an app compatible with v4+ versions and only versions 4.0.x present this problem. Commented Nov 25, 2013 at 21:46
  • I've tried the "EXIST" solution, but it is not supported, only "EXISTS". I really think this is an issue on these versions. Something related to "VIRTUAL TABLE" and "IF NOT EXISTS" commands used together, but I don't have a device running any of these versions to test possible workarounds and it has been very hard to find a solution. Any tip will be welcome! Commented Nov 25, 2013 at 21:54

1 Answer 1

2

"IF NOT EXISTS" statement does not work in some versions of Android, specifically 4.0.x versions. At least when creating virtual tables. It has crashed one of my published apps several times in versions 4.0.4 and 4.0.3. My app works properly in versions 4+ but crashes as soon as it uses DB only in these specific versions.

In fact, you don't need "IF NOT EXISTS" statement since you make correct use of onCreate and onUpgrade functions in your SQLiteOpenHelper implementation. I was using it just for precaution and to avoid problems during development.

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.