commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank Hampshire (JIRA)" <>
Subject [jira] Created: (DBUTILS-45) ON UPDATE, ON DELETE errors for MS Sql Server - does not implement default "RESTRICT"
Date Mon, 04 Aug 2008 02:29:44 GMT
ON UPDATE, ON DELETE errors for MS Sql Server - does not implement default "RESTRICT"

                 Key: DBUTILS-45
             Project: Commons DbUtils
          Issue Type: Bug
    Affects Versions: 1.2
         Environment: MS SQL Server 2005
            Reporter: Frank Hampshire
             Fix For: 1.2

When exporting a database out of SQL Server 2005, a foreign key constrain onUpdate and onDelete
values, when not set, are set as "restrict"


In the table below for the table fktest ON DELETE has been set to 'cascade', while ON UPDATE
has not been defined (defaults to NO ACTION), but the outputted onUpdate is 'restrict'

  <table name="fktest">
    <column name="ID" primaryKey="true" required="true" type="INTEGER" size="10" autoIncrement="false"
    <column name="fktarget_id" primaryKey="false" required="false" type="INTEGER" size="10"
autoIncrement="false" />
    <foreign-key foreignTable="fktarget" name="FK_fktest_fktarget" onUpdate="restrict"
      <reference local="fktarget_id" foreign="fktarget_id" />

Now, when it comes time to create this table from the XML, back into a MSSQL Server 2005 database,
DDLUtils throws the following Exception.

org.apache.ddlutils.DatabaseOperationException: Error while executing SQL ALTER TABLE fktest
    ADD CONSTRAINT FK_fktest_fktarget FOREIGN KEY (fktarget_id) REFERENCES fktarget (fktarget_id)
	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(
	at org.apache.ddlutils.platform.PlatformImplBase.createModel(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at junit.framework.TestCase.runTest(
	at junit.framework.TestCase.runBare(
	at junit.framework.TestResult$1.protect(
	at junit.framework.TestResult.runProtected(
	at junit.framework.TestSuite.runTest(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
Caused by: Incorrect syntax near the keyword
	at Source)
	at Source)
	at Source)
	at$StmtExecCmd.doExecute(Unknown Source)
	at Source)
	at Source)
	at Source)
	at Source)
	at Source)
	at org.apache.ddlutils.platform.PlatformImplBase.evaluateBatch(
	... 21 more

This is clearly because SQL Server 2005 does not recognise "RESTRICT" as a valid ON UPDATE
value. Essentially the problem is that the methods writeForeignKeyOnDeleteAction and writeForeignKeyOnUpdateAction
for the class automatically use the RESTRICT value while writing the SQL for the ALTER TABLE.

So, there seem to be 2 parts to the  solution here:

1. Writing the schema XML for ON UPDATE and ON DELETE for MSSQL Servers should probably default
to "NO ACTION" rather than "RESTRICT"

2. When read in a schema if the onDelete and onUpdate values are "restrict" the MSSQLBuilder
should Interpret these as "NO ACTION"

I am new to the code base, but I would like to propose the following fixes for 1 and 2:

  * Override method in in JdbcModelReader: protected CascadeActionEnum convertAction(Short
jdbcActionValue) in the subclass MSSqlModelReader so that it returns the value CascadeActionEnum.NONE
by default for MSSsql 

  * Change the methods writeForeignKeyOnDeleteAction and writeForeignKeyOnUpdateAction from
private to protected so that MSSqlBuilder can override them to provide a correct implementation
of "RESTRICT"(throw error or interpret to "NO ACTION"

I notice that the methods writeForeignKeyOnDeleteAction and writeForeignKeyOnUpdateAction
are private methods and so cannot be overriden.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message