88443

How can i use Regex to get data from sqlite?

Question:

I want to search in a column that containing String like "I will have #dinner with @Akki on her #Bday.I am searching now like this but it's note working. while the variable search having value like #dinner. Thank you.

selectionArgs = new String[] {"'"+search+"'"}; String qur="SELECT * FROM TODOS WHERE fullnote REGEXP"; Cursor c = db.rawQuery(qur,selectionArgs);

Answer1:

Try using

String[] selectionArgs = new String[] {"%"+search+"%"}; Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE fullnote LIKE ?",selectionArgs);

See <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String,%20java.lang.String[])" rel="nofollow">Android SQLite reference</a>:

<blockquote>

public Cursor rawQuery (String sql, String[] selectionArgs)

selectionArgs - You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.

</blockquote>

Answer2:

selectionArgs = new String[] {search}; Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE fullnote LIKE '%?%'",selectionArgs);

Answer3:

After long R&D i came to point that i can not use REGEXP directly. then i tried Cursor c = db.rawQuery("SELECT * FROM TODOS WHERE tag LIKE '%"+search+"%' ",null);

and it worked fine. Thanks everybody.

Recommend

  • How to access MISSED_CALL Log in Android
  • MATCH with selectArgs looking like *queryTerm* stopped working on Android 5.0+
  • Union of Tables with Cursor in Android
  • How can i read the db in my android app which i've modified in my pc and copied back to my app&
  • The target “TransformAll” does not exist in the project T4 transformation MSBuild
  • Meteor router doesn't render the template
  • How to orderByValue onSnapshot using Firestore
  • MySQLi using an IN in a where
  • PouchDB on Cloudant
  • Removing the last digits in string
  • How to get all use statements declared in PHP class file
  • javascript regexp - replace all floating point numbers in a string with rounded numbers
  • Query timeout expired in django-mssql when executing custom SQL directly
  • Pre-populated SQLite Database not reading properly in Android Studio
  • Converting query results into DataFrame in python
  • Configure nginx to return different files to different authenticated users with the same URI
  • LESS CSS how to modify parent property in mixin
  • Angular2 - Template reference inside NgSwitch
  • VBA Excel, loop through variables
  • For loop with if condition on multiple R functions
  • Defined variables not working in javascript files when I use getScript
  • Possible to get mouse events fired when cursor is outside page?
  • ThreadStatic in asynchronous ASP.NET Web API
  • Scipy Leastsq Optional Output Variable (Mesg)
  • Scala multiline string placeholder
  • Assign variable to the value in HTML
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • Converting a WriteableBitmap image ToArray in UWP
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Updating server-side rendering client-side
  • htaccess rewriting URLs with multiple forward slashes
  • Weird JavaScript statement, what does it mean?
  • ORA-29908: missing primary invocation for ancillary operator
  • How do you troubleshoot character encoding problems?
  • How to get next/previous record number?
  • How to format a variable of double type
  • How do you join a server to an Active Directory (domain)?
  • Turn off referential integrity in Derby? is it possible?
  • How does Linux kernel interrupt the application?
  • How to Embed XSL into XML