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

  • SEARCH
  • Home
  • 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 4008534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:46:01+00:00 2026-05-20T08:46:01+00:00

I have problems when making queries with parameters to DB on Android platform (2.2).

  • 0

I have problems when making queries with parameters to DB on Android platform (2.2). I have created table like this:

db.execSQL("CREATE VIRTUAL TABLE " + Msg._TABLE_NAME + " USING FTS3 ("
            + Msg._ID + " INTEGER, "
            (...)
            + Msg.READ + " SHORT DEFAULT 0,"
            + Msg.URGENT + " SHORT DEFAULT 0"
            + ");");

Then I am trying to query this using parametrized query:

String[] columns = new String[] {Msg.ROWID, Msg.TITLE, Msg.READ, Msg.URGENT};
(...)
getContentResolver().query(Msg.CONTENT_URI, columns, 
    Msg.URGENT + "=? AND " + Msg.READ + "=?" + , whereArgs, null);

where whereArgs varies for each query:

String[] urgentUnread = new String[]{"1", "0"};
String[] regularUnread = new String[]{"0", "0"};

but no matter what it returns 0 results/rows even though data exist. The content provider does not change the params and the query returns nothing using QueryBuilder as well as when calling query “directly”:

Cursor c = db.query(tables, columns, where, whereArgs, groupBy, having, orderBy, limit);

The query works if I do just String concat:

getContentResolver().query(Msg.CONTENT_URI, columns, 
    Msg.READ + "=0 AND " + Msg.URGENT + "=1", null, null);

but that seems to kill the purpose of param queries and is nasty to cache. Dalvik complains (after making lot of queries) that there is no space in cache for query and, ironically, tells me to use parametrized queries with ‘?’. I would love to, trust me 🙂

I know JavaDoc states that parameters are bound as StringS but I just simply can’t believe that… because that would be major …ahem, … WTF

Where did I go wrong here?

Thanks in advance.

  • 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-20T08:46:01+00:00Added an answer on May 20, 2026 at 8:46 am

    This is OP, I was researching and experimenting further and came to conclusion that there is FTS3 to blame. Since I need the data to be searchable by fulltext I was creating VIRTUAL TABLE USING FTS3 and then the parameters binding failed.

    As I do not want to query shadow table (Msg_content) directly, my solution is to split data into 2 related tables:

    db.execSQL("CREATE TABLE " + Msg._TABLE_NAME + " (" +
        Msg._ID + PRIMARY_KEY_AUTOINC + 
        Msg.PRIORITY + " TEXT," +
        Msg.RECEIVED + " INTEGER," +
        Msg.MOBILE_STATUS + " INTEGER DEFAULT 0," +
        Msg.READ + " SHORT DEFAULT 0," +
        Msg.FLASH + " SHORT DEFAULT 0" +
    ");");
    
    db.execSQL("CREATE VIRTUAL TABLE " + MsgText._TABLE_NAME + " USING FTS3 (" + 
        MsgText._ID + PRIMARY_KEY +
        MsgText.TITLE + " TEXT," +
        MsgText.CONTENT + " TEXT," +
        MsgText.KEYWORDS + " TEXT," +
        "FOREIGN KEY(" + MsgText._ID + ") " +
        "REFERENCES " + Msg._TABLE_NAME + "(" + Msg._ID + ") " +
    ");");
    

    Then I created View to use by queries:

    db.execSQL("CREATE VIEW IF NOT EXISTS " + View.MSG_CONTENT +
        " AS SELECT " +
        Msg._TABLE_NAME + "." + Msg._ID + ", " +
        Msg._TABLE_NAME + "." + Msg.READ + ", " +
        Msg._TABLE_NAME + "." + Msg.FLASH + ", " +
    (...)
        MsgText._TABLE_NAME + "." + MsgText.TITLE + ", " +
        MsgText._TABLE_NAME + "." + MsgText.CONTENT +
        " FROM " + Msg._TABLE_NAME + ", " + MsgText._TABLE_NAME +
        " WHERE " + Msg._TABLE_NAME + "." + Msg._ID + "=" +
        MsgText._TABLE_NAME + "." + MsgText._ID);
    

    This works very well for me as I can query data using parameters and do fulltext search when needed. Query performance is the same as when using just one table.

    I hope this helps someone else who might bump into the same issue.

    Cheers,
    PeS

    P.S. Checked Meta and it is OK to reply to self, apparently.

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

Sidebar

Related Questions

I'm starting with linqToSql and I still have some problems making my queries. For
I am making a CRUD application in jquery and i have this problem in
I have the following problem. I am making this website you can see in
I'm currently making a webpage and I have run in to some problems with
I have problems with making my models to work. Here is my appname.misc.models file
Im making a table generator as a school project. In MySQL I have 3
I have some problems with making a stacked bar chart in ggplot2. I know
I have some problems making a google map that loads XML file that have
UPDATE I have Fullscreen background image. This creates problems for mobile browsing for the
I have a problem making an advanced (for me) query. I am trying to

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.