You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2005/11/22 21:28:48 UTC

svn commit: r348240 - in /db/torque: runtime/trunk/xdocs/ templates/trunk/src/templates/sql/base/mysql/ test/trunk/test-project/src/schema/

Author: tfischer
Date: Tue Nov 22 12:28:39 2005
New Revision: 348240

URL: http://svn.apache.org/viewcvs?rev=348240&view=rev
Log:
Fixed foreign key support in mysql to allow the referenced table to be declared before the referencing table.
This is done by defining the foreign keys in an extra "CREATE TABLE" statement instead of defining them in the "CREATE TABLE" statement. 
Note that foreign keys are ignored by mysql except in InnoDB tables. 

Thanks to Thoralf Rickert for suggesting the patch.
Fixes also TRQS278
(Added an index in the test-schema to check that)

Modified:
    db/torque/runtime/trunk/xdocs/changes.xml
    db/torque/templates/trunk/src/templates/sql/base/mysql/foreignkey.vm
    db/torque/templates/trunk/src/templates/sql/base/mysql/table.vm
    db/torque/templates/trunk/src/templates/sql/base/mysql/tablefk.vm
    db/torque/test/trunk/test-project/src/schema/test-schema.xml

Modified: db/torque/runtime/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/xdocs/changes.xml?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- db/torque/runtime/trunk/xdocs/changes.xml (original)
+++ db/torque/runtime/trunk/xdocs/changes.xml Tue Nov 22 12:28:39 2005
@@ -25,6 +25,20 @@
 
   <body>
 
+  <release version="3.2-rc4-dev" date="in SVN">
+    <action type="fix" dev="tfischer">
+      Fixed foreign key support in mysql to allow the referenced table to
+      be declared before the referencing table.
+      This is done by defining the foreign keys in an extra 
+      &quot;CREATE TABLE&quot; statement instead of defining them in the 
+      &quot;CREATE TABLE&quot; statement. 
+      Note that foreign keys are ignored by mysql except in InnoDB tables. 
+      <br />
+      Thanks to Thoralf Rickert for suggesting the patch.
+      Fixes also TRQS278.
+    </action>
+  </release>
+
   <release version="3.2-rc3" date="2005-11-13">
     <action type="fix" dev="tfischer">
       Fixed support for limit and offset for Derby in the runtime.

Modified: db/torque/templates/trunk/src/templates/sql/base/mysql/foreignkey.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/sql/base/mysql/foreignkey.vm?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/sql/base/mysql/foreignkey.vm (original)
+++ db/torque/templates/trunk/src/templates/sql/base/mysql/foreignkey.vm Tue Nov 22 12:28:39 2005
@@ -12,12 +12,16 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 #foreach ($fk in $table.ForeignKeys)
-    FOREIGN KEY ($fk.LocalColumnNames) REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames)
+ALTER TABLE $table.Name
+    ADD CONSTRAINT $fk.Name
+    FOREIGN KEY ($fk.LocalColumnNames)
+    REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames)
   #if ($fk.hasOnUpdate())
     ON UPDATE $fk.OnUpdate
   #end
   #if ($fk.hasOnDelete())
     ON DELETE $fk.OnDelete
   #end
-,
-#end
+;
+
+#end
\ No newline at end of file

Modified: db/torque/templates/trunk/src/templates/sql/base/mysql/table.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/sql/base/mysql/table.vm?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/sql/base/mysql/table.vm (original)
+++ db/torque/templates/trunk/src/templates/sql/base/mysql/table.vm Tue Nov 22 12:28:39 2005
@@ -20,12 +20,11 @@
 (
 #set ( $cols = $generator.parse("$basepath/columns.vm", '', "table", $tbl) )
 #set ( $pk = $generator.parse("$basepath/primarykey.vm", '', "table", $tbl) )
-#set ( $fk = $generator.parse("$basepath/foreignkey.vm", '', "table", $tbl) )
 #set ( $unique = $generator.parse("$basepath/unique.vm", '', "table", $tbl) )
 #set ( $index = $generator.parse("$basepath/index.vm", '', "table", $tbl) )
 #if($strings.allEmpty([$pk,$fk,$unique,$index]))$strings.chop($cols,2)#else$cols#end
 #if($strings.allEmpty([$fk,$unique,$index]) && $pk.length()>0)$strings.chop($pk,2)#else$pk#end
-#if($strings.allEmpty([$unique,$index]) && $fk.length() >0)$strings.chop($fk,2)#else$fk#end
 #if($strings.allEmpty([$index]) && $unique.length()>0)$strings.chop($unique,2)#else$unique#end
 #if($index.length() > 0)$strings.chop($index,2)#end
 );
+

Modified: db/torque/templates/trunk/src/templates/sql/base/mysql/tablefk.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/sql/base/mysql/tablefk.vm?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/sql/base/mysql/tablefk.vm (original)
+++ db/torque/templates/trunk/src/templates/sql/base/mysql/tablefk.vm Tue Nov 22 12:28:39 2005
@@ -11,4 +11,5 @@
 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
-
+#set ( $fk = $generator.parse("$basepath/foreignkey.vm", "", "table", $tbl) )
+#if ($fk.length()>0)$fk#end
\ No newline at end of file

Modified: db/torque/test/trunk/test-project/src/schema/test-schema.xml
URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/schema/test-schema.xml?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- db/torque/test/trunk/test-project/src/schema/test-schema.xml (original)
+++ db/torque/test/trunk/test-project/src/schema/test-schema.xml Tue Nov 22 12:28:39 2005
@@ -78,6 +78,9 @@
     <column name="ext_id" type="INTEGER"/>
     <column name="test" required="true" type="INTEGER"/>
 
+    <index name="index_ext_id">
+      <index-column name="ext_id"/>
+    </index>
     <foreign-key foreignTable="ext">
       <reference local="ext_id" foreign="ext_id"/>
     </foreign-key>



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org