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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:33:22+00:00 2026-06-07T07:33:22+00:00

I have a simple address table with the following create statement: CREATE TABLE +

  • 0

I have a simple address table with the following create statement:

"CREATE TABLE " + ADDRESSES_TABLE + " (" +
                KEY_ADDRESS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_ADDRESS_COUNTRY + " TEXT, " +
                KEY_ADDRESS_CITY + " TEXT, " +
                KEY_ADDRESS_STREET + " TEXT, " +
                KEY_ADDRESS_HOUSE + " TEXT, " +
                KEY_ADDRESS_POSTAL_CODE + " TEXT," +
                "UNIQUE("+KEY_ADDRESS_COUNTRY+","+KEY_ADDRESS_CITY+","+KEY_ADDRESS_STREET+","+KEY_ADDRESS_HOUSE+","+KEY_ADDRESS_POSTAL_CODE +") ON CONFLICT IGNORE)"

When I add duplicate records, the insert() metod returns -1 and not the id of the existing row.

The problem is reproducible only on 4.0+. The method works as expected on 2.2 and 2.3.3.

Has anyone faced the same issue?

  • 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-07T07:33:24+00:00Added an answer on June 7, 2026 at 7:33 am

    Unfortunately, the Android documentation is wrong. (And thus your code does not actually work as expected on prior versions of Android, e.g., 2.2 and 2.3.)

    In 2.2 and 2.3, insertWithOnConflict() will return the value of the SQLite C API function sqlite3_last_insert_rowid(), whose documentation clearly states that failed inserts (e.g., where the ON CONFLICT resolution, like IGNORE, is applied) do not affect the return value. Thus, if no prior insert for the connection was performed and a duplicate insert is attempted, insertWithOnConflict() will return 0. If a prior insert added a row to any table, the method will return the row id of that insert—of course this is grossly incorrect.

    In 4.0, insertWithOnConflict() will return the value of the same SQLite C API function, except returning -1 instead of 0.

    This change is why you are now observing the error. But if you check the result closely in 2.2 and 2.3, you’ll see that the row ids returned when the OR IGNORE clause is exercised are not actually the correct row ids (except coincidentally).

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

Sidebar

Related Questions

Using MySQL, I have a simple table that logs the IP Address that users
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I created a simple mysql database table using following query: CREATE TABLE customer( name
Say I have a simple address class like below: public class Address { public
I have simple database - one table with 6 collumns. 3 of them i
I have a simple report sending framework that basically does the following things: It
I have the following query in access 2003 mdb. SELECT Company.Name, Company.Address, Place.Name_of_Place, Sum(Income.Value)
I have a simple dataform created that reads address information. The address information is
I have created a very simple Rails 3.1 app with basic stuffs like following:
Here is a simple example: Assume I have a customer table that has a

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.