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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:23:00+00:00 2026-06-14T13:23:00+00:00

I am trying to check if the text the user inputs is already in

  • 0

I am trying to check if the text the user inputs is already in my database but unsure how this should be done.

So I can fetch the data from my database by calling the following in my database helper class:

public Cursor fetchDamagedComponentsForLocation(long damagedComponentId) {
    Cursor mCursor =
            rmDb.query(true, DAMAGED_COMPONENTS_TABLE, new String[] {
                    COMPONENT_ID, LOCATION_LINK, RUN_LINK, AREA_LINK, INSPECTION_LINK, LOCATION_REF, RACKING_SYSTEM, COMPONENT, POSITION, RISK, ACTION_REQUIRED, NOTES_GENERAL, MANUFACTURER, TEXT1, TEXT2, TEXT3, TEXT4, NOTES_SPEC}, 
                    LOCATION_LINK + "=" + damagedComponentId, null,
                    null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;
} 

For each of the database entries I need to check if two user inputs match two of the database fields (in this case COMPONENT and POSITION) which I get from my Spinners when the user clicks on the save button:

    String component = ((Cursor)componentSpinner.getSelectedItem()).getString(2).toString();
    String position = ((Cursor)positionSpinner.getSelectedItem()).getString(1).toString();  

This is basically to make sure there is not already that component saved.

I’m sure this is quite simple, but I can’t work out how to do it..

edit – following Sams advice, I have added the following class to my databased helper class:

 public boolean checkIfComponentAlreadySaved(long locationId, String component, String position) {
     Cursor mCursor = rmDb.query(DAMAGED_COMPONENTS_TABLE, new String[] {"1"}, 
             LOCATION_LINK + " = " + locationId + " AND " + COMPONENT + " = " + component + " AND " + POSITION + " = " + position, null, null, null, null, null);
     boolean result = mCursor.moveToFirst();
     mCursor.close();
     return result;
 }

However, I am getting the following error:

android.database.sqlite.SQLiteException: near “pin”: syntax error: , while compiling: SELECT 1 FROM damaged_components_table WHERE location_link = 3 AND component = Locking pin AND position = Not Applicable

I’m guessing this is because I am comparing Strings, but any suggestions?

  • 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-14T13:23:02+00:00Added an answer on June 14, 2026 at 1:23 pm

    moveToFirst() returns true if one or more rows exist, false if the Cursor is empty. So create a new method like this:

    public boolean isComponentDamagedForLocation(long damagedComponentId) {
        Cursor mCursor =
                rmDb.query(DAMAGED_COMPONENTS_TABLE, new String[] {"1"}, 
                        LOCATION_LINK + "=" + damagedComponentId, null,
                        null, null, null, null);
        result = mCursor.moveToFirst();
        mCursor.close();
        return result;
    }  
    

    The exact columns don’t matter so you can pass anything that you want, the WHERE clause is the heart of this query. Use this Java method, to test if the data exists. If isComponentDamagedForLocation) is false, then insert the data.


    Addition
    Since you are using Strings in your query you should use the replacement character (?) to prevent the error you are seeing now and protect yourself from SQL injection attacks:

    public boolean checkIfComponentAlreadySaved(long locationId, String component, String position) {
        Cursor mCursor = rmDb.query(DAMAGED_COMPONENTS_TABLE, new String[] {"1"}, 
                LOCATION_LINK + " = " + locationId + " AND " + COMPONENT + " = ? AND " + POSITION + " = ?", 
                new String[] {component, position}, null, null, null, null);
        // etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to check if a file exists. If I use this: NSData *data
I am trying to check if an email address already exists in a user
I'm trying to check if a color is already entered into the database if
I'm trying to pass user input form data jquery/ajax to check if there's any.
i'm trying to make it so that a user can type text in a
I'm trying to check in jQuery if a div contains some text, and then
I am trying to take a line of text like 13) Check for orphaned
I'm trying to mask text box with 2 different masks when a check box
I'm trying to check network available or not. But in my emulator it always
I'm trying to validate my inputs with jQuery before a form is sent. This

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.