ASA error on delete

I have a form that is connected to our people_degrees table. In that table is a field id_t_degrees which is connected by a foreign key to the t_degrees table.

There are servoy sequences for the primary keys of both tables.

There are no children of the people_degrees table – only parents.

There are no database triggers on the people_degrees table.

When the user presses a delete button I execute

forms[application.getMethodTriggerFormName()].controller.deleteRecord()

The record is actually deleted and removed from the form, but then I get an error:

com.sybase.jdbc2.jdbc.SybSQLException: ASA Error -198: Primary key for row in table ‘t_degrees’ is referenced by foreign key ‘id_types_degrees_have_names’ in table ‘people_degrees’ ASA Error -198: Primary key for row in table ‘t_degrees’ is referenced by foreign key ‘id_types_degrees_have_names’ in table ‘people_degrees’

The only way it seems that I can get this error to stop popping up is to set the DB foreign key to cascade deletes (which we really don’t want to do).

I don’t see why this is happening and it doesn’t happen if I do the delete via an executed stored procedure.

But, we want to do it with the servoy method so the delete will be broadcasted to the other clients.

Is there any way to do this without setting the FK to cascade deletes?

Looks like you have a backend constraint - and you’re not deleting the clild record(s) BEFORE deleting the master.

Bob,

No. Thats not whats happening. Thats the weird part. I am ONLY deleting the child. There is nothing going on to delete the parent at all. If I execute the delete SQL directly on the database everything is fine. Somehow Servoy is triggering the wrong thing.

Anyway, I figured out how to correct the problem without having to turn cascade deletes on for the parent. It seems when Servoy imports existing relationships from a DB it sets by default the Delete Related Records option to True (it probably should not do this but it does). Anyway, once I turned this off on the relationship that was firing when it shouldn’t everything seems to be ok…

I too think you have some sort of child type constraint. In Sybase Central you can view constraints on tables as well as get “Referencing Tables” information to get a handle on what may be causing the problem.

Assuming you do need a child type constraint or foreign key, you can control what happens with a Trigger. Triggers are fired based on data modification and allow you to implement your own referential integrity rules. I am not sure what kind of logic you need but triggers are very flexible in what they can accomplish.

Look at the CREATE TRIGGER syntax.

Chris Gruber
iAnywhere Solutions