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 8299661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:14:04+00:00 2026-06-08T16:14:04+00:00

I have different variants of a query. All value types are Strings! (don’t ask

  • 0

I have different variants of a query. All value types are Strings! (don’t ask why…)
The first one might look like this:

SELECT * FROM item WHERE arg1=false

The string (“sqlWhere”) for the arg(s) looks like this:
“arg1=?”

The string for the arg(s)-Array (args) at index 0 looks like this:
“false”

This works fine. I’ve got 715 results.

Now, if i have something like this:

SELECT * FROM item WHERE (arg1=40 OR arg2=42) AND arg3=false

I’ll expect 110 results for this. But there aren’t any results, no Exception is thrown

If I’ll generate a raw query in Firefox SQLite Manager:

SELECT COUNT(*) FROM item WHERE (arg1=40 OR arg2=42) AND arg3=false

I’ll get the error: “no such column: false”
If I generate a query like this:

SELECT COUNT(*) FROM item WHERE (arg1=40 OR arg2=42) AND arg3="false"

It’ll not fail. BUT. I’m using selectionargs. I’ve read, that they should AVOID this situation. But they don’t. Even, If I put into the selectionargs for arg3 = “\”+”false”+”\”” or arg3 = “\’+”false”+”\'” or even arg3=”‘”+”false”+”‘” it won’t work. Maybe an android specific problem?
The value “false” comes from a list of values. It is initialized with an emty string.

Query-Method looks like this:

public List<Map<String,String>> getSearchResults(String sqlWhere, String[]args)
    {
        List<Map<String,String>> specs = new ArrayList<Map<String,String>>();
        String[] specnames = this.getSpecNames();

        Cursor cursor = mDb.query(dbSchema.SpecSchema.TABLE_NAME, specnames, sqlWhere, args, null, null, dbSchema.SpecSchema._ID + dbSchema.SORT_ASC);
        cursor.moveToFirst();
        while(!cursor.isAfterLast())
        {
            Map<String, String> temp = new HashMap<String, String>();
            for(int i = 0; i < specnames.length; i++)
                temp.put(specnames[i], cursor.getString(cursor.getColumnIndex(specnames[i])));
            specs.add(temp);

            cursor.moveToNext();
        }

        if(cursor != null)
            cursor.close();

        return specs;
    }
  • 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-06-08T16:14:08+00:00Added an answer on June 8, 2026 at 4:14 pm

    The documentation for SQLiteDatabase.query() says:

    selectionArgs – You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear
    in the selection. The values will be bound as Strings.

    When you execute this query:

    SELECT * FROM item WHERE (arg1=40 OR arg2=42) AND arg3=false
    

    and bind the arguments using the selectionArgs-parameter, the integers and the boolean will be bound as strings. This is not the same as in your database. I know you said all your columns are of type TEXT, but read the SQLite Documentation:

    The type affinity of a column is the recommended type for data stored
    in that column.
    The important idea here is that the type is
    recommended, not required. Any column can still store any type of
    data.
    It is just that some columns, given the choice, will prefer to
    use one storage class over another.

    That means, when you insert your integer values in your string-table, SQLite will convert those and store them as integers. The next important point is comparison:

    SQLite may attempt to convert values between the storage classes
    INTEGER, REAL, and/or TEXT before performing a comparison.
    […]

    • An expression that is a simple reference to a column value has the same affinity as the column.

    The docs give the following example:

    CREATE TABLE t1(
        a TEXT,      -- text affinity
        b NUMERIC,   -- numeric affinity
        c BLOB,      -- no affinity
        d            -- no affinity
    );
    
    -- Because column "a" has text affinity, numeric values on the
    -- right-hand side of the comparisons are converted to text before
    -- the comparison occurs.
    SELECT a < 40,   a < 60,   a < 600 FROM t1;
    0|1|1
    

    In your case that means the following:

    1. Your TEXT-table gets integers inserted, which are then converted (and stored) as INTEGERs.
    2. When performing your comparison, you give in TEXT-values (which are your integers). Those should be (but don’t need to be) converted to TEXT-values, because your table indicates it’s values are of type TEXT.
    3. You compare INTEGER to TEXT, which is not equal and therefor doesn’t give you the correct results.

    To insert different data-types (other then string) into the SQLiteDatabase, use Prepared Statements.

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

Sidebar

Related Questions

in the past hour i have been trying different variants of this query but
I have a simple but subtle question. Below you see two different declaration variants
I have different select boxes. I want to select second one with related id.
I have a SCons file which calls others to build different variants of a
I'm doing a webshop, and every product can have several variants. All variants are
The C standard allows pointers to different types to have different sizes, e.g. sizeof(char*)
I have different Bundles: MainBundle (Homepage), SecurityBundle (Login, Registration), MessageBundle (Message System), ShopBundle. I
I have different values in different classes. I need to insert them in the
I have different blocks of 34 threads each (0...33). I need to find a
I have different php output in jQuery-based tabs. This output is formed from database

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.