-#!/usr/bin/perl
use strict;
-
+use warnings;
use Test::More;
use SQL::Translator;
-#use SQL::Translator::Schema::Constants;
use SQL::Translator::Constants qw(:sqlt_types :sqlt_constants);
-#use SQL::Translator::Utils qw//;
-use Test::SQL::Translator qw(maybe_plan);
-
-BEGIN {
- maybe_plan(317, "SQL::Translator::Parser::DDL::MySQL");
-# SQL::Translator::Parser::DDL::MySQL->import('parse');
-}
{
my $tr = SQL::Translator->new({ from => 'MySQL' });
fulltext key `session_fulltext` (a_session)
);|;
- #my $val = $tr->parse();
-# my $val = $tr->parse($data);
- my $schema = $tr->parse($data);
+ my $val = $tr->parse($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)' );
is( $f2->name, 'a_session', 'Second field name is "a_session"' );
is( $f2->data_type, 'text', 'Type is "text"' );
- is( $f2->size, 65_535, 'Size is "65,535"' );
+ is( $f2->size, 0, 'Size is "0"' );
is( $f2->is_nullable, 1, 'Field can be null' );
is( $f2->default_value, undef, 'Default value is undefined' );
is( $f2->is_primary_key, 0, 'Field is not PK' );
{
my $tr = SQL::Translator->new({ from => 'MySQL' });
- my $schema = $tr->parse(
+ my $val = $tr->parse(
q[
CREATE TABLE `check` (
check_id int(7) unsigned zerofill NOT NULL default '0000000'
KEY (i1),
UNIQUE (date, i1),
KEY date_idx (date),
- KEY name_idx (name(10))
+ KEY name_idx (name)
) TYPE=MyISAM PACK_KEYS=1;
]
- );
+ ); ## KEY name_idx (name(10))
-# my $schema = $tr->schema;
+ 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 $f5 = shift @fields;
is( $f5->name, 's1', 'Fifth field name is "s1"' );
is( $f5->data_type, 'set', 'Type is "set"' );
- is( $f5->size, 1, 'Size is "1"' );
+ is( $f5->size, 0, 'Size is "0"' );
is( $f5->is_nullable, 1, 'Field can be null' );
is( $f5->default_value, 'b', 'Default value is "b"' );
is( $f5->is_primary_key, 0, 'Field is not PK' );
my $f6 = shift @fields;
is( $f6->name, 'e1', 'Sixth field name is "e1"' );
is( $f6->data_type, 'enum', 'Type is "enum"' );
- is( $f6->size, 1, 'Size is "1"' );
+ is( $f6->size, 0, 'Size is "0"' );
is( $f6->is_nullable, 1, 'Field can be null' );
is( $f6->default_value, 'c', 'Default value is "c"' );
is( $f6->is_primary_key, 0, 'Field is not PK' );
my $f8 = shift @fields;
is( $f8->name, 'foo_type', 'Eighth field name is "foo_type"' );
is( $f8->data_type, 'enum', 'Type is "enum"' );
- is( $f8->size, 2, 'Size is "2"' );
+ is( $f8->size, 0, 'Size is "0"' );
is( $f8->is_nullable, 0, 'Field cannot be null' );
is( $f8->default_value, 'vk', 'Default value is "vk"' );
is( $f8->is_primary_key, 0, 'Field is not PK' );
my $i3 = shift @indices;
is( $i3->name, 'name_idx', 'Name is "name_idx"' );
is( $i3->type, NORMAL, 'Normal index' );
- is( join(',', $i3->fields ), 'name(10)', 'Index is on field "name(10)"' );
+ is( join(',', $i3->fields ), 'name', 'Index is on field "name(10)"' ); ## FIX ME
my @constraints = $table->get_constraints;
is( scalar @constraints, 2, 'Right number of constraints (2)' );
}
{
- my $tr = SQL::Translator->new;
- my $data = parse($tr,
+ my $tr = SQL::Translator->new({ from => 'MySQL' });
+ my $val = $tr->parse(
q[
CREATE TABLE orders (
order_id integer NOT NULL auto_increment,
my $f1 = shift @fields;
is( $f1->name, 'order_id', 'First field name is "order_id"' );
- is( $f1->data_type, 'int', 'Type is "int"' );
- is( $f1->size, 11, 'Size is "11"' );
+ is( $f1->data_type, 'integer', 'Type is "integer"' );
+ is( $f1->size, 0, 'Size is "0"' );
is( $f1->is_nullable, 0, 'Field cannot be null' );
is( $f1->default_value, undef, 'Default value is undefined' );
is( $f1->is_primary_key, 1, 'Field is PK' );
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"' );
+ is( $f3->size, 0, 'Size is "0"' );
my $f4 = shift @fields;
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"' );
+ is( $f4->size, 0, 'Size is "0"' );
my $f5 = shift @fields;
is( $f5->name, 'credit_card_id', 'Fifth field name is "credit_card_id"' );
is( $f5->data_type, 'int', 'Type is "int"' );
- is( $f5->size, 11, 'Size is "11"' );
+ is( $f5->size, 0, 'Size is "0"' );
my $f6 = shift @fields;
is( $f6->name, 'status', 'Sixth field name is "status"' );
is( $f6->data_type, 'smallint', 'Type is "smallint"' );
- is( $f6->size, 6, 'Size is "6"' );
+ is( $f6->size, 0, 'Size is "0"' );
is( $f6->is_nullable, 0, 'Field cannot be null' );
my $f7 = shift @fields;
is( $f7->is_nullable, 0, 'Field cannot be null' );
is( $f7->is_foreign_key, 1, 'Field is a FK' );
my $fk_ref = $f7->foreign_key_reference;
- isa_ok( $fk_ref, 'SQL::Translator::Schema::Constraint', 'FK' );
+ isa_ok( $fk_ref, 'SQL::Translator::Object::Constraint', 'FK' );
is( $fk_ref->reference_table, 'store', 'FK is to "store" table' );
my $f8 = shift @fields;
# Ignoring INSERT statements
#
{
- my $tr = SQL::Translator->new;
- my $data = parse($tr,
+ my $tr = SQL::Translator->new({ from => 'MySQL' });
+ my $data = $tr->parse(
q[
USE database_name;
# charset table option
#
{
- my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003});
- my $data = parse($tr,
- q[
+ my $tr = SQL::Translator->new({ from => 'MySQL', parser_args => { mysql_parser_version => 50003 } });
+ my $data = $tr->parse(
+ q[
DELIMITER ;;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;;
/*!50003 CREATE */ /*!50017 DEFINER=`cmdomain`@`localhost` */
# Tests for collate table option
{
- my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003});
- my $data = parse($tr,
+ my $tr = SQL::Translator->new({ from => 'MySQL', parser_args => { mysql_parser_version => 50003 } });
+ my $data = $tr->parse(
q[
CREATE TABLE test ( id int ) DEFAULT CHARACTER SET latin1 COLLATE latin1_bin;
] );
},
};
+my $tr = SQL::Translator->new;
for my $target (keys %$parse_as) {
for my $str (keys %{$parse_as->{$target}}) {
cmp_ok (
- SQL::Translator::Utils::parse_mysql_version ($str, $target),
+ $tr->engine_version($str, $target),
'==',
$parse_as->{$target}{$str},
"'$str' parsed as $target version '$parse_as->{$target}{$str}'",
}
}
-eval { SQL::Translator::Utils::parse_mysql_version ('bogus5.1') };
+eval { $tr->engine_version ('bogus5.1') };
ok ($@, 'Exception thrown on invalid version string');
{
- my $tr = SQL::Translator->new;
+ my $tr = SQL::Translator->new({ from => 'MySQL' });
my $data = q|create table merge_example (
id int(11) NOT NULL auto_increment,
shape_field geometry NOT NULL,
SPATIAL KEY shape_field (shape_field)
) ENGINE=MRG_MyISAM UNION=(`sometable_0`,`sometable_1`,`sometable_2`);|;
- my $val = parse($tr, $data);
+ my $val = $tr->parse($data);
my $schema = $tr->schema;
is( $schema->is_valid, 1, 'Schema is valid' );
my @tables = $schema->get_tables;
) ENGINE=innodb;|,
);
for my $data (@data) {
- my $tr = SQL::Translator->new;
+ my $tr = SQL::Translator->new({ from => 'MySQL' });
- my $val = parse($tr, $data);
+ my $val = $tr->parse($data);
my $schema = $tr->schema;
is( $schema->is_valid, 1, 'Schema is valid' );
my @tables = $schema->get_tables;
}
{
- my $tr = SQL::Translator->new;
+ my $tr = SQL::Translator->new({ from => 'MySQL' });
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',
);|;
- my $val = parse($tr, $data);
+ my $val = $tr->parse($data);
my $schema = $tr->schema;
is( $schema->is_valid, 1, 'Schema is valid' );
my @tables = $schema->get_tables;
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' );
}
+
+done_testing;