+*** INCOMPATIBLE CHANGES:
+* SQLT no longer supports setting separate conflicting values for the now
+ deprecated 'quote_table_names' and 'quote_field_names'. Instead their values
+ are proxied to the new 'quote_identifiers'. If 'quote_identifiers' is
+ supplied, the legacy settings are ignored (with a warning). If nothing is
+ specified the default is TRUE as before. If only one is specified - default
+ to its value for everything, and if both are specified with a conflicting
+ value an exception is thrown.
+
* Fixes to SQLite foreign keys production (patch from Johan Viklund)
closes RT#16412, RT#44769
* ON DELETE/UPDATE actions for SQLite (patch from Lukas Thiemeier)
$DEBUG = 0 unless defined $DEBUG;
$ERROR = "";
-use Carp qw(carp);
+use Carp qw(carp croak);
use Data::Dumper;
use File::Find;
$self->validate( $config->{'validate'} );
- $self->quote_table_names( (defined $config->{'quote_table_names'}
- ? $config->{'quote_table_names'} : 1) );
- $self->quote_field_names( (defined $config->{'quote_field_names'}
- ? $config->{'quote_field_names'} : 1) );
+ my $quote;
+ if (defined $config->{quote_identifiers}) {
+ $quote = $config->{quote_identifiers};
+
+ for (qw/quote_table_names quote_field_names/) {
+ carp "Ignoring deprecated parameter '$_', since 'quote_identifiers' is supplied"
+ if defined $config->{$_}
+ }
+ }
+ # Legacy one set the other is not
+ elsif (
+ defined $config->{'quote_table_names'}
+ xor
+ defined $config->{'quote_field_names'}
+ ) {
+ if (defined $config->{'quote_table_names'}) {
+ carp "Explicitly disabling the deprecated 'quote_table_names' implies disabling 'quote_identifiers' which in turn implies disabling 'quote_field_names'"
+ unless $config->{'quote_table_names'};
+ $quote = $config->{'quote_table_names'} ? 1 : 0;
+ }
+ else {
+ carp "Explicitly disabling the deprecated 'quote_field_names' implies disabling 'quote_identifiers' which in turn implies disabling 'quote_table_names'"
+ unless $config->{'quote_field_names'};
+ $quote = $config->{'quote_field_names'} ? 1 : 0;
+ }
+ }
+ # Legacy both are set
+ elsif(defined $config->{'quote_table_names'}) {
+ croak 'Setting quote_table_names and quote_field_names to conflicting values is no longer supported'
+ if ($config->{'quote_table_names'} xor $config->{'quote_field_names'});
+
+ $quote = $config->{'quote_table_names'} ? 1 : 0;
+ }
+ # none are set - on by default, use a 0-but-true as indicator
+ # so we can allow individual producers to change the default
+ else {
+ $quote = '0E0';
+ }
+
+ $self->quote_identifiers($quote);
return $self;
}
}
sub quote_table_names {
- my $self = shift;
- if ( defined (my $arg = shift) ) {
- $self->{'quote_table_names'} = $arg ? 1 : 0;
- }
- return $self->{'quote_table_names'} || 0;
+ (@_ > 1 and ($_[1] xor $_[0]->{quote_identifiers}) )
+ ? croak 'Using quote_table_names as a setter is no longer supported'
+ : $_[0]->{quote_identifiers} ? 1 : 0
}
sub quote_field_names {
- my $self = shift;
- if ( defined (my $arg = shift) ) {
- $self->{'quote_field_names'} = $arg ? 1 : 0;
- }
- return $self->{'quote_field_names'} || 0;
+ (@_ > 1 and ($_[1] xor $_[0]->{quote_identifiers}) )
+ ? croak 'Using quote_field_names as a setter is no longer supported'
+ : $_[0]->{quote_identifiers} ? 1 : 0
+}
+
+sub quote_identifiers {
+ @_ > 1
+ ? # synchronize for old code reaching directly into guts
+ $_[0]->{quote_table_names}
+ = $_[0]->{quote_field_names}
+ = $_[0]->{quote_identifiers}
+ = $_[1] ? $_[1] : 0
+ : $_[0]->{quote_identifiers}
}
sub producer {
# Add "drop table" statements
add_drop_table => 1,
# to quote or not to quote, thats the question
- quote_table_names => 1,
- quote_field_names => 1,
+ quote_identifiers => 1,
# Validate schema object
validate => 1,
# Make all table names CAPS in producers which support this option
=item *
-quote_table_names
+quote_identifiers
=item *
-quote_field_names
+quote_table_names (DEPRECATED)
+
+=item *
+
+quote_field_names (DEPRECATED)
=item *
Toggles whether or not to add "DROP TABLE" statements just before the
create definitions.
+=head2 quote_identifiers
+
+Toggles whether or not to quote identifiers (table, column, constraint, etc.)
+with a quoting mechanism suitable for the chosen Producer. The default (true)
+is to quote them.
+
=head2 quote_table_names
-Toggles whether or not to quote table names with " in DROP and CREATE
-statements. The default (true) is to quote them.
+DEPRECATED - A legacy proxy to L</quote_identifiers>
=head2 quote_field_names
-Toggles whether or not to quote field names with " in most
-statements. The default (true), is to quote them.
+DEPRECATED - A legacy proxy to L</quote_identifiers>
=head2 no_comments
or die "Translat eerror:".$sqlt->error;
is_deeply \@out, \@stmts_no_drop, "Array output looks right with quoting";
+ $sqlt->quote_identifiers(0);
- @{$sqlt}{qw/quote_table_names quote_field_names/} = (0,0);
$out = $sqlt->translate(\$yaml_in)
or die "Translate error:".$sqlt->error;
eq_or_diff $out, $mysql_out, "Output looks right without quoting";
is_deeply \@out, \@unquoted_stmts, "Array output looks right without quoting";
- @{$sqlt}{qw/add_drop_table quote_field_names quote_table_names/} = (1,1,1);
+ $sqlt->quote_identifiers(1);
+ $sqlt->add_drop_table(1);
+
@out = $sqlt->translate(\$yaml_in)
or die "Translat eerror:".$sqlt->error;
$out = $sqlt->translate(\$yaml_in)