Tab/WS crusade
[dbsrgits/SQL-Translator.git] / t / 02mysql-parser.t
index 4dd921c..2b4bfa1 100644 (file)
@@ -69,10 +69,10 @@ BEGIN {
 
 {
     my $tr = SQL::Translator->new;
-    my $data = parse($tr, 
+    my $data = parse($tr,
         q[
             CREATE TABLE `check` (
-              check_id int(7) unsigned zerofill NOT NULL default '0000000' 
+              check_id int(7) unsigned zerofill NOT NULL default '0000000'
                 auto_increment primary key,
               successful date NOT NULL default '0000-00-00',
               unsuccessful date default '0000-00-00',
@@ -92,7 +92,7 @@ BEGIN {
             ) TYPE=MyISAM PACK_KEYS=1;
         ]
     );
-    
+
     my $schema = $tr->schema;
     is( $schema->is_valid, 1, 'Schema is valid' );
     my @tables = $schema->get_tables;
@@ -240,7 +240,7 @@ BEGIN {
 
 {
     my $tr = SQL::Translator->new;
-    my $data = parse($tr, 
+    my $data = parse($tr,
         q[
             CREATE TABLE orders (
               order_id                  integer NOT NULL auto_increment,
@@ -307,13 +307,13 @@ BEGIN {
     is( $f2->default_value, undef, 'Default value is undefined' );
 
     my $f3 = shift @fields;
-    is( $f3->name, 'billing_address_id', 
+    is( $f3->name, 'billing_address_id',
         'Third field name is "billing_address_id"' );
     is( $f3->data_type, 'int', 'Type is "int"' );
     is( $f3->size, 11, 'Size is "11"' );
 
     my $f4 = shift @fields;
-    is( $f4->name, 'shipping_address_id', 
+    is( $f4->name, 'shipping_address_id',
         'Fourth field name is "shipping_address_id"' );
     is( $f4->data_type, 'int', 'Type is "int"' );
     is( $f4->size, 11, 'Size is "11"' );
@@ -363,17 +363,17 @@ BEGIN {
 
     my $i2 = shift @indices;
     is( $i2->type, NORMAL, 'Second index is normal' );
-    is( join(',', $i2->fields), 'billing_address_id', 
+    is( join(',', $i2->fields), 'billing_address_id',
         'Index is on "billing_address_id"' );
 
     my $i3 = shift @indices;
     is( $i3->type, NORMAL, 'Third index is normal' );
-    is( join(',', $i3->fields), 'shipping_address_id', 
+    is( join(',', $i3->fields), 'shipping_address_id',
         'Index is on "shipping_address_id"' );
 
     my $i4 = shift @indices;
     is( $i4->type, NORMAL, 'Third index is normal' );
-    is( join(',', $i4->fields), 'member_id,store_id', 
+    is( join(',', $i4->fields), 'member_id,store_id',
         'Index is on "member_id,store_id"' );
 
     my @constraints = $t1->get_constraints;
@@ -391,25 +391,25 @@ BEGIN {
 
     my $c3 = shift @constraints;
     is( $c3->type, FOREIGN_KEY, 'Constraint is a FK' );
-    is( join(',', $c3->fields), 'billing_address_id', 
+    is( join(',', $c3->fields), 'billing_address_id',
         'Constraint is on "billing_address_id"' );
     is( $c3->reference_table, 'address', 'To table "address"' );
-    is( join(',', $c3->reference_fields), 'address_id', 
+    is( join(',', $c3->reference_fields), 'address_id',
         'To field "address_id"' );
 
     my $c4 = shift @constraints;
     is( $c4->type, FOREIGN_KEY, 'Constraint is a FK' );
-    is( join(',', $c4->fields), 'shipping_address_id', 
+    is( join(',', $c4->fields), 'shipping_address_id',
         'Constraint is on "shipping_address_id"' );
     is( $c4->reference_table, 'address', 'To table "address"' );
-    is( join(',', $c4->reference_fields), 'address_id', 
+    is( join(',', $c4->reference_fields), 'address_id',
         'To field "address_id"' );
 
     my $c5 = shift @constraints;
     is( $c5->type, FOREIGN_KEY, 'Constraint is a FK' );
     is( join(',', $c5->fields), 'store_id', 'Constraint is on "store_id"' );
     is( $c5->reference_table, 'store', 'To table "store"' );
-    is( join(',', map { $_ || '' } $c5->reference_fields), '', 
+    is( join(',', map { $_ || '' } $c5->reference_fields), '',
         'No reference fields defined' );
 
     my $t2  = shift @tables;
@@ -427,7 +427,7 @@ BEGIN {
 #
 {
     my $tr = SQL::Translator->new;
-    my $data = parse($tr, 
+    my $data = parse($tr,
         q[
             USE database_name;
 
@@ -500,98 +500,98 @@ BEGIN {
 #
 {
     my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003});
-    my $data = parse($tr, 
+    my $data = parse($tr,
         q[
-               DELIMITER ;;
+            DELIMITER ;;
             /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;;
-                       /*!50003 CREATE */ /*!50017 DEFINER=`cmdomain`@`localhost` */
-                       /*!50003 TRIGGER `acl_entry_insert` BEFORE INSERT ON `acl_entry`
-                               FOR EACH ROW SET NEW.dateCreated = CONVERT_TZ(SYSDATE(),'SYSTEM','+0:00'),
-                               NEW.dateModified = CONVERT_TZ(SYSDATE(),'SYSTEM','+0:00') */;;
+            /*!50003 CREATE */ /*!50017 DEFINER=`cmdomain`@`localhost` */
+            /*!50003 TRIGGER `acl_entry_insert` BEFORE INSERT ON `acl_entry`
+                FOR EACH ROW SET NEW.dateCreated = CONVERT_TZ(SYSDATE(),'SYSTEM','+0:00'),
+                NEW.dateModified = CONVERT_TZ(SYSDATE(),'SYSTEM','+0:00') */;;
 
-                       DELIMITER ;
+            DELIMITER ;
             CREATE TABLE one (
               `op` varchar(255) character set latin1 collate latin1_bin default NULL,
               `last_modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
             ) TYPE=INNODB DEFAULT CHARSET=latin1;
 
-                       /*!50001 CREATE ALGORITHM=UNDEFINED */
-                       /*!50013 DEFINER=`cmdomain`@`localhost` SQL SECURITY DEFINER */
-                       /*! VIEW `vs_asset` AS 
-                               select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
-                               `cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
-                               `cfgmgmt_mig`.`ap_extract_asset`(`a`.`fq_name`) AS `asset_name`,
-                               `a`.`annotation` AS `annotation`,`a`.`asset_type` AS `asset_type`,
-                               `a`.`foreign_asset_id` AS `foreign_asset_id`,
-                               `a`.`foreign_asset_id2` AS `foreign_asset_id2`,`a`.`dateCreated` AS `date_created`,
-                               `a`.`dateModified` AS `date_modified`,`a`.`container_id` AS `container_id`,
-                               `a`.`creator_id` AS `creator_id`,`a`.`modifier_id` AS `modifier_id`,
-                               `m`.`user_id` AS `user_access` 
-                               from (`asset` `a` join `M_ACCESS_CONTROL` `m` on((`a`.`acl_id` = `m`.`acl_id`))) */;
-                       DELIMITER ;;
-                       /*!50001 CREATE */
-                       /*! VIEW `vs_asset2` AS 
-                               select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
-                               `cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
-                               `cfgmgmt_mig`.`ap_extract_asset`(`a`.`fq_name`) AS `asset_name`,
-                               `a`.`annotation` AS `annotation`,`a`.`asset_type` AS `asset_type`,
-                               `a`.`foreign_asset_id` AS `foreign_asset_id`,
-                               `a`.`foreign_asset_id2` AS `foreign_asset_id2`,`a`.`dateCreated` AS `date_created`,
-                               `a`.`dateModified` AS `date_modified`,`a`.`container_id` AS `container_id`,
-                               `a`.`creator_id` AS `creator_id`,`a`.`modifier_id` AS `modifier_id`,
-                               `m`.`user_id` AS `user_access` 
-                               from (`asset` `a` join `M_ACCESS_CONTROL` `m` on((`a`.`acl_id` = `m`.`acl_id`))) */;
-                       DELIMITER ;;
-                       /*!50001 CREATE OR REPLACE */
-                       /*! VIEW `vs_asset3` AS 
-                               select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
-                               `cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
-                               `cfgmgmt_mig`.`ap_extract_asset`(`a`.`fq_name`) AS `asset_name`,
-                               `a`.`annotation` AS `annotation`,`a`.`asset_type` AS `asset_type`,
-                               `a`.`foreign_asset_id` AS `foreign_asset_id`,
-                               `a`.`foreign_asset_id2` AS `foreign_asset_id2`,`a`.`dateCreated` AS `date_created`,
-                               `a`.`dateModified` AS `date_modified`,`a`.`container_id` AS `container_id`,
-                               `a`.`creator_id` AS `creator_id`,`a`.`modifier_id` AS `modifier_id`,
-                               `m`.`user_id` AS `user_access` 
-                               from (`asset` `a` join `M_ACCESS_CONTROL` `m` on((`a`.`acl_id` = `m`.`acl_id`))) */;
-                       DELIMITER ;;
-                       /*!50003 CREATE*/ /*!50020 DEFINER=`cmdomain`@`localhost`*/ /*!50003 FUNCTION `ap_from_millitime_nullable`( millis_since_1970 BIGINT ) RETURNS timestamp
-                       DETERMINISTIC
-                               BEGIN
-                               DECLARE rval TIMESTAMP;
-                                   IF ( millis_since_1970 = 0 )
-                                   THEN
-                                       SET rval = NULL;
-                                   ELSE
-                                       SET rval = FROM_UNIXTIME( millis_since_1970 / 1000 );
-                                   END IF;
-                                   RETURN rval;
-                               END */;;
-                       /*!50003 CREATE*/ /*!50020 DEFINER=`cmdomain`@`localhost`*/ /*!50003 PROCEDURE `sp_update_security_acl`(IN t_acl_id INTEGER)
-                       BEGIN
-                               DECLARE hasMoreRows BOOL DEFAULT TRUE;
-                               DECLARE t_group_id INT;
-                               DECLARE t_user_id INT ;
-                               DECLARE t_user_name VARCHAR (512) ;
-                               DECLARE t_message VARCHAR (512) ;
-
-                               DROP TABLE IF EXISTS group_acl;
-                               DROP TABLE IF EXISTS user_group;
-                               DELETE FROM M_ACCESS_CONTROL WHERE acl_id = t_acl_id;
-
-                               CREATE TEMPORARY TABLE group_acl SELECT DISTINCT p.id group_id, d.acl_id acl_id
-                                       FROM  asset d, acl_entry e, alterpoint_principal p
-                                       WHERE d.acl_id = e.acl
-                                       AND p.id = e.principal AND d.acl_id = t_acl_id;
-
-                               CREATE TEMPORARY TABLE user_group  SELECT a.id user_id, a.name user_name, c.id group_id
-                                       FROM alterpoint_principal a, groups_for_user b, alterpoint_principal c
-                                       WHERE a.id = b.user_ref AND b.elt = c.id;
-
-                               INSERT INTO M_ACCESS_CONTROL SELECT DISTINCT group_acl.group_id, group_acl.acl_id, user_group.user_id, user_group.user_name
-                                       FROM group_acl, user_group
-                                       WHERE group_acl.group_id = user_group.group_id ;
-                       END */;;
+            /*!50001 CREATE ALGORITHM=UNDEFINED */
+            /*!50013 DEFINER=`cmdomain`@`localhost` SQL SECURITY DEFINER */
+            /*! VIEW `vs_asset` AS
+                select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
+                `cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
+                `cfgmgmt_mig`.`ap_extract_asset`(`a`.`fq_name`) AS `asset_name`,
+                `a`.`annotation` AS `annotation`,`a`.`asset_type` AS `asset_type`,
+                `a`.`foreign_asset_id` AS `foreign_asset_id`,
+                `a`.`foreign_asset_id2` AS `foreign_asset_id2`,`a`.`dateCreated` AS `date_created`,
+                `a`.`dateModified` AS `date_modified`,`a`.`container_id` AS `container_id`,
+                `a`.`creator_id` AS `creator_id`,`a`.`modifier_id` AS `modifier_id`,
+                `m`.`user_id` AS `user_access`
+                from (`asset` `a` join `M_ACCESS_CONTROL` `m` on((`a`.`acl_id` = `m`.`acl_id`))) */;
+            DELIMITER ;;
+            /*!50001 CREATE */
+            /*! VIEW `vs_asset2` AS
+                select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
+                `cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
+                `cfgmgmt_mig`.`ap_extract_asset`(`a`.`fq_name`) AS `asset_name`,
+                `a`.`annotation` AS `annotation`,`a`.`asset_type` AS `asset_type`,
+                `a`.`foreign_asset_id` AS `foreign_asset_id`,
+                `a`.`foreign_asset_id2` AS `foreign_asset_id2`,`a`.`dateCreated` AS `date_created`,
+                `a`.`dateModified` AS `date_modified`,`a`.`container_id` AS `container_id`,
+                `a`.`creator_id` AS `creator_id`,`a`.`modifier_id` AS `modifier_id`,
+                `m`.`user_id` AS `user_access`
+                from (`asset` `a` join `M_ACCESS_CONTROL` `m` on((`a`.`acl_id` = `m`.`acl_id`))) */;
+            DELIMITER ;;
+            /*!50001 CREATE OR REPLACE */
+            /*! VIEW `vs_asset3` AS
+                select `a`.`asset_id` AS `asset_id`,`a`.`fq_name` AS `fq_name`,
+                `cfgmgmt_mig`.`ap_extract_folder`(`a`.`fq_name`) AS `folder_name`,
+                `cfgmgmt_mig`.`ap_extract_asset`(`a`.`fq_name`) AS `asset_name`,
+                `a`.`annotation` AS `annotation`,`a`.`asset_type` AS `asset_type`,
+                `a`.`foreign_asset_id` AS `foreign_asset_id`,
+                `a`.`foreign_asset_id2` AS `foreign_asset_id2`,`a`.`dateCreated` AS `date_created`,
+                `a`.`dateModified` AS `date_modified`,`a`.`container_id` AS `container_id`,
+                `a`.`creator_id` AS `creator_id`,`a`.`modifier_id` AS `modifier_id`,
+                `m`.`user_id` AS `user_access`
+                from (`asset` `a` join `M_ACCESS_CONTROL` `m` on((`a`.`acl_id` = `m`.`acl_id`))) */;
+            DELIMITER ;;
+            /*!50003 CREATE*/ /*!50020 DEFINER=`cmdomain`@`localhost`*/ /*!50003 FUNCTION `ap_from_millitime_nullable`( millis_since_1970 BIGINT ) RETURNS timestamp
+                DETERMINISTIC
+                BEGIN
+                    DECLARE rval TIMESTAMP;
+                    IF ( millis_since_1970 = 0 )
+                    THEN
+                        SET rval = NULL;
+                    ELSE
+                        SET rval = FROM_UNIXTIME( millis_since_1970 / 1000 );
+                    END IF;
+                    RETURN rval;
+                END */;;
+            /*!50003 CREATE*/ /*!50020 DEFINER=`cmdomain`@`localhost`*/ /*!50003 PROCEDURE `sp_update_security_acl`(IN t_acl_id INTEGER)
+                BEGIN
+                    DECLARE hasMoreRows BOOL DEFAULT TRUE;
+                    DECLARE t_group_id INT;
+                    DECLARE t_user_id INT ;
+                    DECLARE t_user_name VARCHAR (512) ;
+                    DECLARE t_message VARCHAR (512) ;
+
+                    DROP TABLE IF EXISTS group_acl;
+                    DROP TABLE IF EXISTS user_group;
+                    DELETE FROM M_ACCESS_CONTROL WHERE acl_id = t_acl_id;
+
+                    CREATE TEMPORARY TABLE group_acl SELECT DISTINCT p.id group_id, d.acl_id acl_id
+                        FROM  asset d, acl_entry e, alterpoint_principal p
+                        WHERE d.acl_id = e.acl
+                        AND p.id = e.principal AND d.acl_id = t_acl_id;
+
+                    CREATE TEMPORARY TABLE user_group  SELECT a.id user_id, a.name user_name, c.id group_id
+                        FROM alterpoint_principal a, groups_for_user b, alterpoint_principal c
+                        WHERE a.id = b.user_ref AND b.elt = c.id;
+
+                    INSERT INTO M_ACCESS_CONTROL SELECT DISTINCT group_acl.group_id, group_acl.acl_id, user_group.user_id, user_group.user_name
+                        FROM group_acl, user_group
+                        WHERE group_acl.group_id = user_group.group_id ;
+                END */;;
         ]
     ) or die $tr->error;
 
@@ -606,18 +606,18 @@ BEGIN {
     is(scalar @fields, 2, 'Right number of fields (2) on table one');
     my $tableTypeFound = 0;
     my $charsetFound = 0;
-       for my $t1_option_ref ( $table1->options ) {
-               my($key, $value) = %{$t1_option_ref};
-               if ( $key eq 'TYPE' ) {
-                       is($value, 'INNODB', 'Table has right table type option' );
-                       $tableTypeFound = 1;
-               } elsif ( $key eq 'CHARACTER SET' ) {
-                       is($value, 'latin1', 'Table has right character set option' );
-                       $charsetFound = 1;
-               }
-       }
-       fail('Table did not have a type option') unless $tableTypeFound;
-       fail('Table did not have a character set option') unless $charsetFound;
+    for my $t1_option_ref ( $table1->options ) {
+        my($key, $value) = %{$t1_option_ref};
+        if ( $key eq 'TYPE' ) {
+            is($value, 'INNODB', 'Table has right table type option' );
+            $tableTypeFound = 1;
+        } elsif ( $key eq 'CHARACTER SET' ) {
+            is($value, 'latin1', 'Table has right character set option' );
+            $charsetFound = 1;
+        }
+    }
+    fail('Table did not have a type option') unless $tableTypeFound;
+    fail('Table did not have a character set option') unless $charsetFound;
 
     my $t1f1 = shift @fields;
     is( $t1f1->data_type, 'varchar', 'Field is a varchar' );
@@ -632,7 +632,7 @@ BEGIN {
     is_deeply(
       $t1f2->default_value,
       \'CURRENT_TIMESTAMP',
-      'Field has right default value' 
+      'Field has right default value'
     );
     is( $t1f2->extra('on update'), 'CURRENT_TIMESTAMP', 'Field has right on update qualifier' );
 
@@ -651,19 +651,19 @@ BEGIN {
     is( scalar @procs, 2, 'Right number of procedures (2)' );
     my $proc1 = shift @procs;
     is( $proc1->name, 'ap_from_millitime_nullable', 'Found "ap_from_millitime_nullable" procedure' );
-       like($proc1->sql, qr/CREATE FUNCTION ap_from_millitime_nullable/, "Detected procedure ap_from_millitime_nullable");
+    like($proc1->sql, qr/CREATE FUNCTION ap_from_millitime_nullable/, "Detected procedure ap_from_millitime_nullable");
     my $proc2 = shift @procs;
     is( $proc2->name, 'sp_update_security_acl', 'Found "sp_update_security_acl" procedure' );
-       like($proc2->sql, qr/CREATE PROCEDURE sp_update_security_acl/, "Detected procedure sp_update_security_acl");
+    like($proc2->sql, qr/CREATE PROCEDURE sp_update_security_acl/, "Detected procedure sp_update_security_acl");
 }
 
 # Tests for collate table option
 {
     my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003});
-    my $data = parse($tr, 
+    my $data = parse($tr,
         q[
           CREATE TABLE test ( id int ) DEFAULT CHARACTER SET latin1 COLLATE latin1_bin;
-         ] ); 
+         ] );
 
     my $schema = $tr->schema;
     is( $schema->is_valid, 1, 'Schema is valid' );
@@ -862,7 +862,7 @@ ok ($@, 'Exception thrown on invalid version string');
     is( $f2->is_primary_key, 0, 'Field is not PK' );
 
     # this is more of a sanity test because the original sqlt regex for default looked for an escaped quote represented as \'
-    # however in mysql 5.x (and probably other previous versions) still actually outputs that as '' 
+    # however in mysql 5.x (and probably other previous versions) still actually outputs that as ''
     is( $f3->name, 'user', 'Second field name is "user"' );
     is( $f3->data_type, 'varchar', 'Type is "varchar"' );
     is( $f3->size, 20, 'Size is "20"' );