0

I have an application where user needs to input data via edittext and it cant be duplicate, so i create unique index. But how to make the comment if unique index is met? So user knows what is the error.

db.execSQL("CREATE UNIQUE INDEX DIFFERENT ON user(name, gender)");
kumisku
  • 103
  • 4
  • 17

1 Answers1

0

Your question is not clear. If you are looking for a way to specify that a column is your primary key (so unique and not null)

ALTER TABLE user ADD PRIMARY KEY (name)

EDIT I noticed now that maybe you are talking about Sqllite. Have a look to this

EDIT2 Toast toast = Toast.makeText(context, "The value "+yourVariable+" already exists. Please insert a different one", Toast.LENGTH_LONG);

Community
  • 1
  • 1
kingston
  • 11,053
  • 14
  • 62
  • 116
  • i create the unique index to prevent user input the same data, so i want to the application throw a message to tell that the data is exist – kumisku Dec 16 '11 at 06:20
  • I edited my answer although I'm still unsure I understood your question – kingston Dec 16 '11 at 13:23
  • the unique index code puts in different file where i want to toast the error to the user. i still cant get your answer, how can i get the condition if i use your solution? e.g if (exist) {toast} else insert the value. How can i put the unique index condition? – kumisku Dec 16 '11 at 16:02
  • I see. what about if you try to insert and in case of error you show the message? – kingston Dec 16 '11 at 17:26
  • yup, thats i want to do, but i dont have any idea how to create that thing, can i do it if i implement unique index? – kumisku Dec 16 '11 at 17:57