Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop index not working SQlite Android

I tried this two queries on a database which already has indexes defined:

myDB.rawQuery("drop index my_index", null);
myDB.rawQuery("create index my_index on mytable(row_table)", null);

And I get this error:

(1) index my_index already exists

And yet, when I do these very sames queries into a shell on my computer with sqlite3, it works perfectly!

What is wrong with these queries on Android?

like image 725
vital Avatar asked Nov 19 '25 14:11

vital


1 Answers

You can add IF EXISTS clause to attempt to drop index only if it exists, thus avoiding an error about missing index:

database.execSQL("DROP INDEX IF EXISTS INDEX_NAME")

This worked for me.

like image 146
Andrey Danilov Avatar answered Nov 22 '25 04:11

Andrey Danilov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!