如何使用正则EX pression在Android的搜索SQLite数据库? [英] how to search sqlite database using regular expression in android?

查看:210
本文介绍了如何使用正则EX pression在Android的搜索SQLite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图寻找使用常规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.

的文档

这篇关于如何使用正则EX pression在Android的搜索SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆