cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antonio Gallardo" <>
Subject Re: DatabaseAddAction and unique or primary keys
Date Sat, 08 Feb 2003 00:17:00 GMT

Today morning I told you about the MODULAR Database Actions, also I
pointed you to:

There you can find ALL the info about how to do what you mean. Also I can
work with sequence (you told before you use PostgreSQL 7.2).

Sheraz Sharif dijo:
> Hello all,
> I have been working on a website for a while.  Here is my problem - I
> can easily verify user input through forms and return any error messages
> through the xsp-formval tags.  After validation, the input is passed to
> the database.  However, I get an SQL exception :
> ProcessingException: Could not add record: java.sql.SQLException: ERROR:
> Cannot insert a duplicate key into unique index category_name_key
> This is happening because I am attempting to insert a value into a key
> column where that value already exists.  I am looking for a solution
> where cocoon will connect to the database and attempt to retreive the
> key value before the insert.  If it does not exist, it will insert it,
> otherwise it will fail and I can notify the user of the error.

I think you can do a select before and check for the result of the select.
Sorry, I use XSP, but maybe the example will work:

    SELECT the_key
    FROM the_table
    WHERE the_key=<esql:parameter type="int"><xsp-request:get-parameter
name="mykey_id" default=""/></esql:parameter>
    <!-- The key does not exist, we are going to insert a new record. -->
        INSERT INTO the_table(the_key, the_data1, the_data2) ......
    <!-- Here the_key value exist! ==> SHOW YOUR ERROR AS YOU WANT! -->

Best Regards,

Antonio Gallardo

Please check that your question  has not already been answered in the
FAQ before posting.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message