Return-Path: Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 92440 invoked from network); 8 Apr 2003 22:53:43 -0000 Received: from unknown (HELO bravenet.com) (24.69.160.230) by daedalus.apache.org with SMTP; 8 Apr 2003 22:53:43 -0000 Received: from [192.168.40.157] (HELO bravenet.com) by bravenet.com (CommuniGate Pro SMTP 4.0.5) with ESMTP id 1793385 for torque-dev@db.apache.org; Tue, 08 Apr 2003 15:53:33 -0700 Message-ID: <3E935307.5040902@bravenet.com> Date: Tue, 08 Apr 2003 15:53:59 -0700 From: Gabriel Bauman Organization: Bravenet Web Services User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3b) Gecko/20030313 Minotaur/0.1a X-Accept-Language: en-us, en MIME-Version: 1.0 To: torque-dev@db.apache.org Subject: Patch for src/templates/sql/base/mysql/foreignkey.vm Content-Type: multipart/mixed; boundary="------------060908010803000900050506" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --------------060908010803000900050506 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi, not sure where to send this, so here you go. I have patched the VelociMacro file that handles SQL generation for foreign keys under MySql. Basically, I've made it tableType sensitive. The patch is against cvs head. If you do not have a tableType specified in your db.props, the template assumes no support for constraints and simply generates an index: # Foreign Key: service_id -> ftp_service.id INDEX ftp_account_subscription_FK_1 (service_id) In this case, a comment containing a warning message about the missing features is injected as well. I feel that this warning may clear up some confusion among new users. If, on the other hand, you are using InnoDB tables, an index is generated as above (mysql and InnoDB require this) and the proper FOREIGN KEY is generated as well: # Foreign Key: service_id -> ftp_service.id INDEX ftp_account_subscription_FK_1 (service_id)), FOREIGN KEY (service_id) REFERENCES ftp_service (id) ON DELETE CASCADE I have taken pains to keep the output pretty at the expense of template readability. I've tested as many cases as I could come up with. Comments? Gabe --------------060908010803000900050506 Content-Type: text/plain; name="mysql-fk-tabletype.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mysql-fk-tabletype.patch" Index: src/generator/src/templates/sql/base/mysql/foreignkey.vm =================================================================== RCS file: /home/cvspublic/db-torque/src/generator/src/templates/sql/base/mysql/foreignkey.vm,v retrieving revision 1.1 diff -u -r1.1 foreignkey.vm --- src/generator/src/templates/sql/base/mysql/foreignkey.vm 10 Feb 2003 13:18:49 -0000 1.1 +++ src/generator/src/templates/sql/base/mysql/foreignkey.vm 8 Apr 2003 22:40:27 -0000 @@ -1,3 +1,18 @@ +## Please do not reformat this file. It is formatted to give neat OUTPUT. #foreach ($fk in $table.ForeignKeys) - FOREIGN KEY ($fk.LocalColumnNames) REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames), + + # Foreign Key: $fk.LocalColumnNames -> $fk.ForeignTableName.$fk.ForeignColumnNames +#if (!($dbprops.get("tableType") == "InnoDB")) + # Constraints not supported for this table type! Consider using InnoDB tables. + # To do this, set tableType to InnoDB in db.props, and recreate your tables. + # More information is available at http://www.mysql.com/doc/en/InnoDB.html +#end + INDEX $fk.Name ($fk.LocalColumnNames)#if (($dbprops.get("tableType") == "InnoDB"))), + 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 --------------060908010803000900050506--