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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:45:30+00:00 2026-06-01T09:45:30+00:00

I have looked through several sites for any useful documentation and have come up

  • 0

I have looked through several sites for any useful documentation and have come up empty. The flow charts from the official site might as well be greek and examples I have attempted from other relevant posts on this site have gotten me errors. I am writing a simple app to place user input in a database, however I need a combination of 2 columns to be unique. From what I have seen this can be accomplished with UNIQUE or PRIMARY KEY. I also need some way of capturing the error to Toast the user that their input is faulty. I know that I can do this in the Java side easily enough yet I would prefer not to loop through the table on every proposed insert.

This is what I have so far:

db.execSQL("CREATE TABLE inventory (category TEXT, itemNum TEXT, quantity INTEGER, price REAL, image INTEGER, UNIQUE(category, itemNum) ON CONFLICT FAIL;");

The table constructed properly until I added UNIQUE…

Which threw:
ERROR/SQLiteOpenHelper(1037): android.database.sqlite.SQLiteException: near “;”: syntax error: CREATE TABLE inventory (category TEXT, itemNum TEXT, quantity INTEGER, price REAL, image INTEGER, CONSTRAINT unq UNIQUE(category, itemNum) ON CONFLICT FAIL;

EDIT:

… fill ContentValues values with user input.

try{
db.getWritableDatabase().insert(DatabaseHelper.TABLE_NAME, DatabaseHelper.CATEGORY, values);
fillItemNumbers();  // Updates screen       
}
catch(SQLiteConstraintException e)
{
Toast
.makeText(this, "User error",Toast.LENGTH_LONG)
.show();            
}
  • 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-01T09:45:32+00:00Added an answer on June 1, 2026 at 9:45 am

    You have mismatched parenthesis. There should be another ) after FAIL.

    Once you’ve sorted that, you can catch the exception that happens when the constraint is breached.

    try {
        // insert new data
    } catch (SQLiteConstraintException e) {
        Toast.makeText(context, 
                       "The combination of A and B must be unique",
                       Toast.LENGTH_LONG).show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've downloaded the Windows Media Center SDK and have looked through the documentation, but
Ok.. I have looked through this site and just can't seem to find the
Composer is a PHP package manager. I have looked through the documentation here: http://getcomposer.org/
I've looked through several other questions here and on other sites regarding this issue,
I've looked through several Google searches now, and continue to keep coming up empty
I have looked through several answers for loading CSS pages. http://docs.djangoproject.com/en/dev/howto/static-files/ Basically, I believe
I have looked through and couldn't find the answer on here... We are doing
OK, I have been looking for weeks now. I have looked through Eclipse and
i know, similar questions have been asked, and i've already looked through everything i
I have read the boost asio reference, gone through the tutorial and looked at

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.