Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6734939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:56:57+00:00 2026-05-26T10:56:57+00:00

I have an android application with a SQLite database and I am trying to

  • 0

I have an android application with a SQLite database and I am trying to implement a search interface. First of all, I realize that making a FTS database is the way to go, but I thought that I could use a LIKE statement and get similar results if I use wildcards. That way the interface can be tested and the backend updated later.

Here is how I build the query:

public Cursor getMatching(String query) {
    Cursor mCursor = db.query(false, TABLE, new String[] { KEY_ROWID,
            KEY_NAME }, KEY_NAME + " LIKE ?",
            new String[] { "%" + query + "%" }, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

KEY_NAME is the text column that I want results for, and query is the lowercase string that I want to match against. I would expect that it would return results where the query appears anywhere in the name, case insensitive. However, what I observe is different. The results of querying “” (empty string):

Coch**** ****
Squi*** St*****
Owe** ****
Smi** Ca****
G. Bur** Jo******
Gr******* Brown

Now when I query “o”:

Owe** ****
G. Bur** Jo******
Gr******* Brown

Oddly enough, the first result is filtered out, although it contains an ‘o’. When I query “ow”:

Gr******* Brown

And finally when I query with “own”:

null

Here is the method I use to handle the cursor:

public static void logMatches(Context context, String query) {
    DBAdapter adapter = new DBAdapter(context);
    adapter.open();

    Cursor c = adapter.getMatching(query);

    if (c == null)
        return;

    while (c.moveToNext()) {
        String name = c.getString(c
                .getColumnIndex(DBAdapter.KEY_NAME));
        Log.d(TAG, name);
    }

    c.close();
    adapter.close();
}

Where DBAdapter contains the SQLiteOpenHelper. The context I am passing in comes from a ContentProvider by using the getContext() method.

I want to implement a FTS table eventually, but my database is quite small now so I hoped that I could implement similar functionality using existing tables for now. Is it possible to do what I want with the LIKE clause? Am I making an obvious mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:56:58+00:00Added an answer on May 26, 2026 at 10:56 am

    I did not tried it myself but fts actually implemented in SQLite for android. See for example here and here.

    Ah, yes. Instead of while (c.moveToNext()) {} put do { } while (c.moveToNext())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple Android application that uses a sqlite database which is
I'm using SQLite in an Android application. In all of my tables I have
I have an android application using an SQLite database. I open the database when
In android application i have a custom listview and sqlite database. I want to
I have a pre-baked sqlite database that I want to use in my Android
I am working on my first Android Application and I am trying to implement
I have an SQLite database within my Android application, which stores dates as integers.
I'm working on an Android application that stores data in a SQLite database. My
I have an Android application that connects to Facebook to request authorization of an
I have a Web Service and an Android application that uses this web service.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.