From: Jonathan C. Otsuka Date: Wed, 30 Oct 2013 00:29:55 +0000 (-0500) Subject: Quote table_name to fix tables using reserve words as their name X-Git-Tag: v0.011017~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=45f19683cbecba08bf68f7e7559a0eb411821b25;p=dbsrgits%2FSQL-Translator.git Quote table_name to fix tables using reserve words as their name --- diff --git a/Changes b/Changes index 02ab2c6..57d4b01 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ - +* Apply quotes to fix tables that are reserved words, DBI::SQLServer (Jonathan C. Otsuka) * De-linkify XML namespace in docs (RT#81838) * Allow both single and double quotes for values in MySQL parser * Fix diff for altering two things per column - add ; at the end diff --git a/lib/SQL/Translator/Parser/DBI/SQLServer.pm b/lib/SQL/Translator/Parser/DBI/SQLServer.pm index 729b7ff..072def8 100644 --- a/lib/SQL/Translator/Parser/DBI/SQLServer.pm +++ b/lib/SQL/Translator/Parser/DBI/SQLServer.pm @@ -212,7 +212,7 @@ $table_info->{TABLE_TYPE}, # add in primary key my $h = $dbh->selectall_hashref("sp_pkeys -$table_info->{TABLE_NAME}", 'COLUMN_NAME'); +[$table_info->{TABLE_NAME}]", 'COLUMN_NAME'); if (scalar keys %{$h} >= 1) { my @c = map { $_->{COLUMN_NAME} @@ -226,7 +226,7 @@ $table_info->{TABLE_NAME}", 'COLUMN_NAME'); # add in foreign keys $h = $dbh->selectall_hashref("sp_fkeys NULL, -\@fktable_name = '$table_info->{TABLE_NAME}'", 'FK_NAME'); +\@fktable_name = '[$table_info->{TABLE_NAME}]'", 'FK_NAME'); foreach my $fk ( values %{$h} ) { my $constraint = $table->add_constraint( name => $fk->{FK_NAME}, fields => [$fk->{FKCOLUMN_NAME}], @@ -249,7 +249,7 @@ $table_info->{TABLE_NAME}", 'COLUMN_NAME'); if (defined($stuff->{indexes}->{$table_info->{TABLE_NAME}})){ my $h = $dbh->selectall_hashref("sp_helpindex -$table_info->{TABLE_NAME}", 'INDEX_NAME'); +[$table_info->{TABLE_NAME}]", 'INDEX_NAME'); foreach (values %{$h}) { my $fields = $_->{'INDEX_KEYS'}; $fields =~ s/\s*//g; diff --git a/lib/SQL/Translator/Parser/DBI/Sybase.pm b/lib/SQL/Translator/Parser/DBI/Sybase.pm index 708a080..f3bfe74 100644 --- a/lib/SQL/Translator/Parser/DBI/Sybase.pm +++ b/lib/SQL/Translator/Parser/DBI/Sybase.pm @@ -212,7 +212,7 @@ $table_info->{TABLE_TYPE}, # add in primary key my $h = $dbh->selectall_hashref("sp_pkeys -$table_info->{TABLE_NAME}", 'COLUMN_NAME'); +[$table_info->{TABLE_NAME}]", 'COLUMN_NAME'); if (scalar keys %{$h} > 1) { my @c = map { $_->{COLUMN_NAME} @@ -230,7 +230,7 @@ $table_info->{TABLE_NAME}", 'COLUMN_NAME'); if (defined($stuff->{indexes}->{$table_info->{TABLE_NAME}})){ my $h = $dbh->selectall_hashref("sp_helpindex -$table_info->{TABLE_NAME}", 'INDEX_NAME'); +[$table_info->{TABLE_NAME}]", 'INDEX_NAME'); foreach (values %{$h}) { my $fields = $_->{'INDEX_KEYS'}; $fields =~ s/\s*//g;