cocoon-users mailing list archives

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

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

http://wiki.cocoondev.org/Wiki.jsp?page=ModularDatabaseActions

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:

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

Best Regards,

Antonio Gallardo



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message