Index Warning or Error Message

Creating tables and queries
Post Reply
datobuka
Posts: 1
Joined: Thu Jun 12, 2008 10:42 pm

Index Warning or Error Message

Post by datobuka »

I created an index with unique values for a schedule. If the time and date and person are the same a warning Pops Up saying:

Error Inserting the new record
Violation of unique index "Appt":duplicate values for columns "DateAppt","TimeAppt","Employee" in statement[Insert INTO "Appointment"....etc]

All that is fine, but the end user of this application will never read all that, is it possible to create a custom message to say for example:

STOP!!! That Date and Time is already booked for Mary!



Thanks
TerryE
Volunteer
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK

Re: Index Warning or Error Message

Post by TerryE »

This isn't problem that is unique to base. The fact is that is you rely on the DB referential model to trap user data integrity errors then the error messages that the DB engine puts out are confusing. If you want to produce meaningful error messages you basically have two options:
  • Trap the error and interpret it in order to put out a meaningful error.
  • Add additional SQL code to validate the operation before executing the insert and again put out a meaningful error e.g. do a select count(*) from Appointment where DateAppt = ....
Of course these both take extra effort, and this is the price you need to pay for meaningful errors. In practice many apps take an 90/10 rule on this: they put such decoding around the 10% of hot inserts an updates which generate the 90% of errors, and leave the 90% of statements which generate the 10% generating nasty SQL errors!
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
Post Reply