如何使用正则EX pression在Android的搜索SQLite数据库?正则、如何使用、数据库、SQLite

2023-09-05 03:37:18 作者:漫长的青春。

我试图寻找使用常规EX pression在sqlite的数据库。这是我的code:

I am trying to search a database using regular expression in sqlite. Here is my code:

cursor = db.rawQuery("SELECT _id, employee FROM employees WHERE employee REGEXP ?", 
                    new String[]{"%" + prepareSearchText()  + "%"});
    adapter = new SimpleCursorAdapter(
            this,
            R.layout.search_row, 
            cursor, 
            new String[] {"_id", "employee "}, 
            new int[] {R.id.idField, R.id.nameField});
    setListAdapter(adapter);

但是我收到此错误:

However I am getting this error:

Caused by: android.database.sqlite.SQLiteException: no such function: REGEXP.

我用MySQL的函数REGEXP之前,所以我认为它存在于sqlite的,但显然事实并非如此。

I used the function REGEXP in MySQL before so I assumed it exists in sqlite, but apparently it is not.

什么是android的查询SQLite数据库时,定期进行EX pression最好的方法是什么?

What is the best way to perform regular expression when querying sqlite database in android?

推荐答案

在sqllite的正规表达式功能不包括在默认情况下,你需要滚你自己的。

In sqllite the "REGEXP" function is not included by default and you need to "roll your own".

但喜欢经营者应该做你想要只要你的搜索是相当简单的事情。

However the "LIKE" operator should do what you want as long as your searches are reasonably simple.

的文档