I've been using DBIC ResultSource table definition classes built for
Oracle with SQLite during testing.

I ran into a snag when the table name includes a schema name and
unique constraints are added.

This patch fixes the SQL generated for SQLite index creation.

I looked for a place to add a test for schema names in index creation,
but did not see any obvious place.

-kolibrie

diff -rN -u old-SQL-Translator-0.08001/lib/SQL/Translator/Producer/SQLite.pm new-SQL-Translator-0.08001/lib/SQL/Translator/Producer/SQLite.pm
--- old-SQL-Translator-0.08001/lib/SQL/Translator/Producer/SQLite.pm	2007-12-19 11:00:43.000000000 -0500
+++ new-SQL-Translator-0.08001/lib/SQL/Translator/Producer/SQLite.pm	2007-12-19 11:00:43.000000000 -0500
@@ -87,6 +87,7 @@
                         : $max_id_length;
     $basename         = substr( $basename, 0, $max_name ) 
                         if length( $basename ) > $max_name;
+    $basename         =~ s/\./_/g;
     my $name          = $type ? "${type}_$basename" : $basename;
 
     if ( $basename ne $basename_orig and $critical ) {
@@ -282,8 +283,10 @@
 
     # strip any field size qualifiers as SQLite doesn't like these
     my @fields = map { s/\(\d+\)$//; $_ } $index->fields;
+    (my $index_table_name = $index->table->name) =~ s/^.+?\.//; # table name may not specify schema
+    warn "removing schema name from '" . $index->table->name . "' to make '$index_table_name'\n" if $WARN;
     my $index_def =  
-    "CREATE INDEX $name on " . $index->table->name .
+    "CREATE INDEX $name on " . $index_table_name .
         ' (' . join( ', ', @fields ) . ');';
 
     return $index_def;
@@ -296,9 +299,11 @@
     my $name   = $c->name;
     $name      = mk_name($c->table->name, $name); # || ++$idx_name_default);
     my @fields = $c->fields;
+    (my $index_table_name = $c->table->name) =~ s/^.+?\.//; # table name may not specify schema
+    warn "removing schema name from '" . $c->table->name . "' to make '$index_table_name'\n" if $WARN;
 
     my $c_def =  
-    "CREATE UNIQUE INDEX $name on " . $c->table->name .
+    "CREATE UNIQUE INDEX $name on " . $index_table_name .
         ' (' . join( ', ', @fields ) . ');';
 
     return $c_def;

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
-- 
sqlfairy-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlfairy-developers

Reply via email to