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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:07:44+00:00 2026-05-23T13:07:44+00:00

I have been using the notepad SQLhelper (notesDBadapter) as a model, some of it

  • 0

I have been using the notepad SQLhelper (notesDBadapter) as a model, some of it works, some doesn’t. I can get a cursor for ‘fetchallrecords() but it crashes if I try a call passing an argument and using the ‘WHERE’. The argument is passed but the cursor fails. My code in activity;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listselectedfile);    

    //Button ID clicked in previous activity
    Bundle bundle = getIntent().getExtras();
    int BtnId = bundle.getInt("ButtonID");
    Toast.makeText(this, "ButtonID selected in Main:= " + BtnId, Toast.LENGTH_LONG) .show(); 

    mDbHelper = new SectionsDbAdapter(this);
    mDbHelper.open();
    fillData();

}  
    private void fillData() {
        // Get all of the notes from the database and create the item list
        //Cursor c = mDbHelper.fetchAllRecords();       <=== works fine
        Cursor c = mDbHelper.fetchRecordsbySource("UK"); <=== fails in DBhelper
        startManagingCursor(c);

        String[] from = new String[] { SectionsDbAdapter.KEY_DESC };
        //String[] from = new String[] { SectionsDbAdapter.KEY_SOURCE }; <=== can fetch this column from table
        int[] to = new int[] { R.id.tv_full_width };  //the R.id.xxx= view in the .xml file

        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter records =
            new SimpleCursorAdapter(this, R.layout.section_row_full_width, c, from, to);  //the .xml file containing the R.id.xxxx
        setListAdapter(records);
    }

In the DBhelper;
This call works and returns the full table;

    public Cursor fetchAllRecords() {

    return mDb.query(DATABASE_TABLE, new String[] {
    KEY_ROWID, KEY_DESC, KEY_DEPTH, KEY_TWEB, 
    KEY_BF1, KEY_TF1, KEY_BF2, KEY_TF2, 
    KEY_IMAJOR, KEY_IMINOR, 
    KEY_PLMAJOR, KEY_PLMINOR, 
    KEY_JTORSION, KEY_AREA,  
    KEY_WARPING, KEY_CYCHANNEL, 
    KEY_SHAPE, KEY_SOURCE, 
    KEY_UNITS},null, null, null, null, null);
}

This call fails on the cursor (the argument is passed successfully);

    public Cursor fetchRecordsbySource(String source) throws SQLException {
    Log.v("In fetchRecordsbySource", "source = " +source);      

    Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] {
    KEY_ROWID, KEY_DESC}, KEY_SOURCE + " = " + source, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

There is nothing obvious to me in the Eclipse debug, but, as a newby, I probably have not got the necessary perspective.

Can anyone spot the error?

  • 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-23T13:07:45+00:00Added an answer on May 23, 2026 at 1:07 pm

    In the code you have, if source is a non-numeric value, it needs to surrounded by single quotes, like this:

    KEY_ROWID, KEY_DESC}, KEY_SOURCE + " = '" + source + "'", null, null, null, null, null)
    

    But you will be better off if you pass your filter arguments as ?; this avoids (among other things) SQL injection attacks

    KEY_ROWID, KEY_DESC}, KEY_SOURCE + " = ?", new String[] { source }, null, null, null, null)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been using it for a while with CodeIgniter and I can't remember if
I have been using a stored procedure for more than 1.5 years. But I've
I have been using VS2010 without any issues, always on the same application. Suddenly
I have been using Snipshot's API to provide simple image editing inside a web
I have been using SourceMonitor on my project for a couple of years to
I have been using Selenium Webdriver successfully with JAR downloaded from their pages or
I have been using the ASP.net membership system, with code such as: <asp:Login id=Login1
I have a Silverlight application that I am maintaining. I am currently using Visual
I am working on a simplistic website using PHP, a language I haven't touched
I don't expect anyone to be able to help out with this but let's

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.