From: Rafael Kitover Date: Thu, 13 May 2010 17:12:45 +0000 (-0400) Subject: Pg: preserve_case mode X-Git-Tag: 0.07000~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c930f78be67718446858647b878b1e4c590538f3;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Pg: preserve_case mode --- diff --git a/TODO b/TODO index e95c244..73abcd0 100644 --- a/TODO +++ b/TODO @@ -30,11 +30,13 @@ - add hashref form of generate_pod to control which POD is generated - add hashref form of components to control which components are added to which classes - - add common tests for preserve_case option + - add common tests for preserve_case option where it must be exclusive + (Oracle, Firebird) - check rel accessors for method conflicts - add an option to add extra code to Result classes - redo in-memory schema as an @INC coderef rather than temp files - add option to filter out views + - support columns with names like "ro'd p/n" - Relationships - Re-scan relations/tables after initial relation setup to find @@ -56,7 +58,6 @@ - Pg - introspect on_update/on_delete/is_deferrable - introspect view SQL - - preserve_case mode - domains - DB2 - data_type tests diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index 7e9a7a7..ac16b43 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -252,15 +252,15 @@ sub _table_fk_info { my $i = 1; # for unnamed rels, which hopefully have only 1 column ... while(my $raw_rel = $sth->fetchrow_arrayref) { my $uk_tbl = $raw_rel->[2]; - my $uk_col = lc $raw_rel->[3]; - my $fk_col = lc $raw_rel->[7]; + my $uk_col = $self->_lc($raw_rel->[3]); + my $fk_col = $self->_lc($raw_rel->[7]); my $relid = ($raw_rel->[11] || ( "__dcsld__" . $i++ )); $uk_tbl =~ s/\Q$self->{_quoter}\E//g; $uk_col =~ s/\Q$self->{_quoter}\E//g; $fk_col =~ s/\Q$self->{_quoter}\E//g; $relid =~ s/\Q$self->{_quoter}\E//g; $rels{$relid}->{tbl} = $uk_tbl; - $rels{$relid}->{cols}->{$uk_col} = $fk_col; + $rels{$relid}->{cols}{$uk_col} = $fk_col; } $sth->finish; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm index 19f332f..f6d2d42 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm @@ -63,13 +63,13 @@ EOF $self->preserve_case(1); } - $self->schema->storage->sql_maker->name_sep('.'); - if ($self->preserve_case) { $self->schema->storage->sql_maker->quote_char('"'); + $self->schema->storage->sql_maker->name_sep('.'); } else { $self->schema->storage->sql_maker->quote_char(undef); + $self->schema->storage->sql_maker->name_sep(undef); } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index 7c4ea38..b03b91b 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -41,8 +41,8 @@ sub _setup { $self->preserve_case(0); } elsif ($self->preserve_case) { - $self->schema->storage->quote_char('"'); - $self->schema->storage->name_sep('.'); + $self->schema->storage->sql_maker->quote_char('"'); + $self->schema->storage->sql_maker->name_sep('.'); } } diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index e92fbaf..ccf6690 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -41,6 +41,10 @@ sub _setup { if (not defined $self->preserve_case) { $self->preserve_case(0); } + elsif ($self->preserve_case) { + $self->schema->storage->sql_maker->quote_char('"'); + $self->schema->storage->sql_maker->name_sep('.'); + } } sub _table_uniq_info { diff --git a/t/12pg_common.t b/t/12pg_common.t index e70e914..564a20b 100644 --- a/t/12pg_common.t +++ b/t/12pg_common.t @@ -14,6 +14,8 @@ my $tester = dbixcsl_common_tests->new( dsn => $dsn, user => $user, password => $password, + loader_options => { preserve_case => 1 }, + quote_char => '"', data_types => { # http://www.postgresql.org/docs/7.4/interactive/datatype.html # diff --git a/t/14ora_common.t b/t/14ora_common.t index 0f8b6ae..60c5645 100644 --- a/t/14ora_common.t +++ b/t/14ora_common.t @@ -29,6 +29,7 @@ my $tester = dbixcsl_common_tests->new( my ($table, $col) = @_; return qq{ DROP SEQUENCE ${table}_${col}_seq }; }, + quote_char => '"', dsn => $dsn, user => $user, password => $password, diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 2ac6097..eb86ceb 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -1131,6 +1131,16 @@ sub create { }, ); + # some DBs require mixed case identifiers to be quoted + # XXX should get quote_char from the storage of an initialized loader. + my ($oqt, $cqt); # open quote, close quote + if (ref $self->{quote_char}) { + ($oqt, $cqt) = @{ $self->{quote_char} }; + } + else { + $oqt = $cqt = $self->{quote_char} || ''; + } + @statements_reltests = ( qq{ CREATE TABLE loader_test3 ( @@ -1158,33 +1168,33 @@ sub create { q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(125,3,'ccc') }, q{ INSERT INTO loader_test4 (id,fkid,dat) VALUES(126,4,'ddd') }, - qq{ + qq| CREATE TABLE loader_test5 ( id1 INTEGER NOT NULL, - iD2 INTEGER NOT NULL, + ${oqt}iD2${cqt} INTEGER NOT NULL, dat VARCHAR(8), from_id INTEGER $self->{null}, to_id INTEGER $self->{null}, - PRIMARY KEY (id1,iD2), + PRIMARY KEY (id1,${oqt}iD2${cqt}), FOREIGN KEY (from_id) REFERENCES loader_test4 (id), FOREIGN KEY (to_id) REFERENCES loader_test4 (id) ) $self->{innodb} - }, + |, - q{ INSERT INTO loader_test5 (id1,iD2,dat) VALUES (1,1,'aaa') }, + qq| INSERT INTO loader_test5 (id1,${oqt}iD2${cqt},dat) VALUES (1,1,'aaa') |, - qq{ + qq| CREATE TABLE loader_test6 ( id INTEGER NOT NULL PRIMARY KEY, - Id2 INTEGER, + ${oqt}Id2${cqt} INTEGER, loader_test2_id INTEGER, dat VARCHAR(8), FOREIGN KEY (loader_test2_id) REFERENCES loader_test2 (id), - FOREIGN KEY(id,Id2) REFERENCES loader_test5 (id1,iD2) + FOREIGN KEY(id,${oqt}Id2${cqt}) REFERENCES loader_test5 (id1,${oqt}iD2${cqt}) ) $self->{innodb} - }, + |, - (q{ INSERT INTO loader_test6 (id, Id2,loader_test2_id,dat) } . + (qq| INSERT INTO loader_test6 (id, ${oqt}Id2${cqt},loader_test2_id,dat) | . q{ VALUES (1, 1,1,'aaa') }), qq{