Forum OpenACS Development: dupicate key error

Collapse
Posted by Lilian Tong on
Hi, While trying to fix the 'FIX ME PLSQL' in the xql file (see below)
      FIX ME PLSQL
      FIX ME PLSQL

        begin
        :1 := calendar__new(
          owner_id      => :owner_id,
          private_p     => :private_p,
          calendar_name => :calendar_name,
          package_id    => :package_id,
          creation_user => :creation_user,
          creation_ip   => :creation_ip
        );
        end;
I have come up with this query instead:
        select calendar__new(
                null,
                :calendar_name,
                'calendar',
                :owner_id,
                :private_id,
                :package_id,
                null,
                now(),
                :creation_user,
                :creation_ip
        );
To test whether this query working properly, firstly I create the data-model(so the calendar__new function is created) then I try to test this query with: select cal_item__new ( 8, 1, null, null, 2, 3, null, 'cal_item', null, '07/01/1996 10:30:00', 4, 'me' ) But psql come up with this error : ERROR: Cannot insert a duplicate key into unique index acs_objects_pk Can anyone please give me a hint on this. Thanks for the help
Collapse
Posted by Ken Kennedy on
The cal_item__new procedure is calling acs_event__new, and passing in the value from your cal_item_id variable as the event_id. The procedure acs_event__new then calls acs_object__new, passing the event_id (which is your cal_item_id), as the object_id. Sounds like '8' (the number you're passing in as your cal_item_id) already exists as an acs_objects.object_id. (I wouldn't be surprised.)

There's probably a sequence being called somewhere to make sure that the id you're creating is unique. I didn't see it in the sql files for calendar, so it may be an existing one called from a procedure somewhere. Look where cal_item__new is being called in the code; just before that, the value for that cal_item_id must be getting set somehow.