use Test::SQL::Translator qw(maybe_plan);
BEGIN {
- maybe_plan(293, "SQL::Translator::Parser::MySQL");
+ maybe_plan(317, "SQL::Translator::Parser::MySQL");
SQL::Translator::Parser::MySQL->import('parse');
}
`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
is( $t1f2->extra('on update'), 'CURRENT_TIMESTAMP', 'Field has right on update qualifier' );
my @views = $schema->get_views;
- is( scalar @views, 1, 'Right number of views (1)' );
- my $view1 = shift @views;
+ is( scalar @views, 3, 'Right number of views (3)' );
+ my ($view3, $view1, $view2) = @views;
is( $view1->name, 'vs_asset', 'Found "vs_asset" view' );
+ is( $view2->name, 'vs_asset2', 'Found "vs_asset2" view' );
+ is( $view3->name, 'vs_asset3', 'Found "vs_asset3" view' );
like($view1->sql, qr/ALGORITHM=UNDEFINED/, "Detected algorithm");
like($view1->sql, qr/vs_asset/, "Detected view vs_asset");
unlike($view1->sql, qr/cfgmgmt_mig/, "Did not detect cfgmgmt_mig");
}
}
+{
+ my $tr = SQL::Translator->new;
+ my $data = q|create table "sessions" (
+ id char(32) not null default '0' primary key,
+ ssn varchar(12) NOT NULL default 'test single quotes like in you''re',
+ user varchar(20) NOT NULL default 'test single quotes escaped like you\'re',
+ key using btree (ssn)
+ );|;
+
+ my $val = parse($tr, $data);
+ my $schema = $tr->schema;
+ is( $schema->is_valid, 1, 'Schema is valid' );
+ my @tables = $schema->get_tables;
+ is( scalar @tables, 1, 'Right number of tables (1)' );
+ my $table = shift @tables;
+ is( $table->name, 'sessions', 'Found "sessions" table' );
+
+ my @fields = $table->get_fields;
+ is( scalar @fields, 3, 'Right number of fields (3)' );
+ my $f1 = shift @fields;
+ my $f2 = shift @fields;
+ my $f3 = shift @fields;
+ is( $f1->name, 'id', 'First field name is "id"' );
+ is( $f1->data_type, 'char', 'Type is "char"' );
+ is( $f1->size, 32, 'Size is "32"' );
+ is( $f1->is_nullable, 0, 'Field cannot be null' );
+ is( $f1->default_value, '0', 'Default value is "0"' );
+ is( $f1->is_primary_key, 1, 'Field is PK' );
+
+ is( $f2->name, 'ssn', 'Second field name is "ssn"' );
+ is( $f2->data_type, 'varchar', 'Type is "varchar"' );
+ is( $f2->size, 12, 'Size is "12"' );
+ is( $f2->is_nullable, 0, 'Field can not be null' );
+ is( $f2->default_value, "test single quotes like in you''re", "Single quote in default value is escaped properly" );
+ 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 ''
+ is( $f3->name, 'user', 'Second field name is "user"' );
+ is( $f3->data_type, 'varchar', 'Type is "varchar"' );
+ is( $f3->size, 20, 'Size is "20"' );
+ is( $f3->is_nullable, 0, 'Field can not be null' );
+ is( $f3->default_value, "test single quotes escaped like you\\'re", "Single quote in default value is escaped properly" );
+ is( $f3->is_primary_key, 0, 'Field is not PK' );
+}