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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:02:07+00:00 2026-06-14T06:02:07+00:00

Recently, I’ve had a few bugs because of code like this: Cursor myCursor =

  • 0

Recently, I’ve had a few bugs because of code like this:

Cursor myCursor = myDb.rawQuery(
        "SELECT ... " +
        "  FROM ...complicated join... " +
        " WHERE field1 = ? AND (field2 = ? OR field3 = ?) ",
        new String[] {myField1, myField2});   // Oops, forgot about field3

When this happens, the query just silently ignores the missing parameter, causing bugs to go unnoticed. Is there some pedantic setting or anything else that I can use to make SQLite scream (at run-time) when the number of placeholders and the number of fields do not match?

I know that I could build my own wrapper, but I’m wondering if there’s something built-in…

  • 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-14T06:02:09+00:00Added an answer on June 14, 2026 at 6:02 am

    Android is basically just passing the args unchecked to native sqlite, see http://www.sqlite.org/c3ref/bind_blob.html

    If something is not bound it is simply considered to be bound to NULL. Binding too much should result in an error though

    I don’t know of / have not seen any debug option in Android’s source for that kind of checks but you could probably write some code that checks your sql syntax:

    SQLiteChecker mDbChecked = new SQLiteChecker(mDb);
    Cursor c = mDbChecked.rawQuery("select complicated from table where stuff=?",
            new String[] {"one", "two"});
    

    where SQLiteChecker would be something along the lines of

    /**
     * Simple Delegate for SQLiteDatabase
     */
    public class SQLiteChecker {
        private final SQLiteDatabase mDbDelegate;
        public SQLiteChecker(SQLiteDatabase db) {
            mDbDelegate = db;
        }
        // ------------ Delegate methods --------------------//
        public int delete(String table, String whereClause, String[] whereArgs) {
            checkSQL(whereClause, whereArgs);
            return mDbDelegate.delete(table, whereClause, whereArgs);
        }
    
        public int update(String table, ContentValues values, String whereClause, String[] whereArgs) {
            checkSQL(whereClause, whereArgs);
            return mDbDelegate.update(table, values, whereClause, whereArgs);
        }
    
        public void execSQL(String sql, Object[] bindArgs) throws SQLException {
            checkSQL(sql, bindArgs);
            mDbDelegate.execSQL(sql, bindArgs);
        }
    
        public Cursor rawQuery(String sql, String[] selectionArgs) {
            checkSQL(sql, selectionArgs);
            return mDbDelegate.rawQuery(sql, selectionArgs);
        }
    
        // add more if you need
    
        // -------------- checking logic -------------------//
        private static void checkSQL(String query, Object[] args) {
            // bit unreliable but simple:
            // just check if amount of ? matches args.length
            int expected = countChar(query, '?');
            int actual = args != null ? args.length : 0;
            if (expected != actual) {
                Log.e("CHECK", "You seem to have messed up [" + query + "]");
                Log.e("CHECK", "expected:" + expected + " actual:" + actual);
            }
        }
    
        private static int countChar(String string, char ch) {
            if (string == null) return 0;
            int count = 0;
            for (int i = 0; i < string.length(); i++) {
                if (string.charAt(i) == ch)
                    count++;
            }
            return count;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, we discovered odd behavior in some old code. This code has worked for
Recently I had cause to compare Blowfish algorithms. I was comparing outputs from DI
Recently I've been doing things like this: import Tkinter class C(object): def __init__(self): self.root
recently, while working on a db2 -> oracle migration project, we came across this
Recently downloaded some code for a minor open-source project related to a small webgame
Recently I've read this performance guide Let's make the web faster and was puzzled
Recently, we had released an app. Before we releasing, we tested it on Samsung
Recently I bought a new android tablet (a no-name Chinese tablet), and I'd like
recently, while reading former's code in my current project, I encounter the problems below:
Recently I've begun to code in Objective-C for iOS 5 devices. My brand new

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.