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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:31:43+00:00 2026-05-13T14:31:43+00:00

For my application, I am trying to add entries without having a duplicate entry,

  • 0

For my application, I am trying to add entries without having a duplicate entry, and if there are a duplicate notify the user and have him try again. Using SQLite, which I know very very little about, I have tried these two ways and want to know which one is better, more efficient or a better way to develop it?

First way:

db.execSQL("INSERT INTO " + DatabaseHelper.DATABASE_TABLE + 
"(LATITUDE, LONGITUDE, RATING) SELECT " + latitude + ", " + longitude + ", " + rating +
" WHERE NOT EXISTS (SELECT 1 FROM " + DatabaseHelper.DATABASE_TABLE +
" WHERE LATITUDE = " + latitude + " AND LONGITUDE = " + longitude + ")");

Second way:

    long id = -1;
    try {
        id = db.compileStatement(
                "SELECT COUNT(*) FROM " + DatabaseHelper.DATABASE_TABLE
                        + " WHERE LATITUDE = " + latitude
                        + " AND LONGITUDE = " + longitude)
                .simpleQueryForLong();
    } catch (NullPointerException e) {
        return -1;
    }
    return id;

The first way, either inserts or ignores the values, I check by doing so, storing the row-count of the rows into a variable before the call, call that function, and then check its results. If the results is not higher than it was before the call, the insert was made ignored, prompt the user with the ‘values exist’ message. (Very sloppy, I know but desperate times calls for desperate measures)

The second way, returns the actual count of rows that match the numbers I want to store, if the number returned greater than 1, prompt the user with the ‘values exist’ message.

I have been going back and forth, trying different ways but I do not know how to set up SQLite to have UNIQUE pairs, which I was told would be the easiest. If anyone can correct either of these ways and/or comment on them, that’d be greatly appreciated.

Thanks

  • 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-13T14:31:43+00:00Added an answer on May 13, 2026 at 2:31 pm

    I have decided to go with my second approach (see above)

    Reason being since creating a UNIQUE INDEX seem to not to work for me and proved to be a difficult task for me to accomplish whether that was result from my or SQLite’s end.

    It’s purpose is not trivial, approach may be elementary but it does what I need it to do.

    I hope people encountering a situation like this can be influenced by the answers left here and wish they have better luck with it than I had.

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

Sidebar

Related Questions

I am trying to create an iPhone application where the user can add entries.
I'm trying to add globalization support to my C# application. According to MSDN, there
I am trying to add an external javascript file to Codeigniter application. I have
I'm trying to add a Search-ActionView to my application (as explained here http://developer.android.com/guide/topics/search/search-dialog.html#UsingSearchWidget ).
I am trying to add a sqlite DB into an application using this: CoreData:
I'm trying to add an AdMob ad to my android application but whenever I'm
I'm trying to add the iTunesArtwork file to my iPhone application in order to
I'm trying to add a CalendarView in my application, which uses the Theme.Light theme.
I am trying to add some specific modular functonality to my application, I need
I'm trying to add a css file in my zend application layout.php the problem

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.