+* Added support for proper booleans in the mysql producer, when a mysql version of at least 4.x is supplied
* Added support for proper enums under pg (as of 8.3), with pg version check, and deferrable constraints
# ----------------------------------------------------------
--mysql-parser-version Target MySQL parser version for dealing with
/*! comments; default = 30000
+ MySQL Producer Options:
+
+ --mysql-version MySQL server version
+
General Producer Options
--producer-db-user Database user for producer
my $add_truncate;
my $mysql_parser_version; # MySQL parser arg for /*! comments
my $postgres_version; # PostgreSQL version
+my $mysql_version; # MySQL version
GetOptions(
'add-drop-table' => \$add_drop_table,
'version' => \$show_version,
'mysql-parser-version=i' => \$mysql_parser_version,
'postgres-version=f' => \$postgres_version,
+ 'mysql-version=f' => \$mysql_version,
) or pod2usage(2);
if ($use_same_auth) {
indent => $indent,
newlines => $newlines,
postgres_version => $postgres_version,
+ mysql_version => $mysql_version,
package_name => $package_name,
},
);
=item * Ying Zhang <zyolive@yahoo.com>
+=item * Daniel Ruoso <daniel@ruoso.com>
+
=back
If you would like to contribute to the project, you can send patches
my $add_drop_table = $translator->add_drop_table;
my $schema = $translator->schema;
my $show_warnings = $translator->show_warnings || 0;
+ my $producer_args = $translator->producer_args;
+ my $mysql_version = $producer_args->{mysql_version} || 0;
my ($qt, $qf, $qc) = ('','', '');
$qt = '`' if $translator->quote_table_names;
show_warnings => $show_warnings,
no_comments => $no_comments,
quote_table_names => $qt,
- quote_field_names => $qf
+ quote_field_names => $qf,
+ mysql_version => $mysql_version
});
}
@size = ();
}
elsif ( $data_type =~ /boolean/i ) {
- $data_type = 'enum';
- $commalist = "'0','1'";
+ my $mysql_version = $options->{mysql_version} || 0;
+ if ($mysql_version >= 4) {
+ $data_type = 'boolean';
+ } else {
+ $data_type = 'enum';
+ $commalist = "'0','1'";
+ }
}
elsif ( exists $translate{ lc $data_type } ) {
$data_type = $translate{ lc $data_type };
#=============================================================================
BEGIN {
- maybe_plan(11,
+ maybe_plan(14,
'YAML',
'SQL::Translator::Producer::MySQL',
'Test::Differences',
my $drop_field = SQL::Translator::Producer::MySQL::drop_field($field2);
is($drop_field, 'ALTER TABLE mytable DROP COLUMN myfield', 'Drop field works');
+
+my $field3 = SQL::Translator::Schema::Field->new( name => 'myfield',
+ table => $table,
+ data_type => 'boolean',
+ is_nullable => 0,
+ is_foreign_key => 0,
+ is_unique => 0 );
+
+my $field3_sql = SQL::Translator::Producer::MySQL::create_field($field3, { mysql_version => 4.1 });
+is($field3_sql, 'myfield boolean NOT NULL', 'For Mysql >= 4, use boolean type');
+$field3_sql = SQL::Translator::Producer::MySQL::create_field($field3, { mysql_version => 3.22 });
+is($field3_sql, "myfield enum('0','1') NOT NULL", 'For Mysql < 4, use enum for boolean type');
+$field3_sql = SQL::Translator::Producer::MySQL::create_field($field3,);
+is($field3_sql, "myfield enum('0','1') NOT NULL", 'When no version specified, use enum for boolean type');