dbsrgits / dbix-class-schema-loader

Official GitHub remote for git.shadowcat.co.uk DBIx-Class-Schema-Loader.git
http://dbix-class.org/
11 stars 34 forks source link

Use hashref (not hash) for connection info options #15

Open sillitoe opened 6 years ago

sillitoe commented 6 years ago

Trying to specify DBI connection options in dbicdump config.

I may have misunderstood usage, but it looks like connect allows DBI connection options to be given as a hashref, eg

$options = { LongTrunkOk => 1 };
My::Schema->connect($dsn, $user, $pass, $options);

However, I think dbicdump is currently passing them in as a (de-referenced) hash:

     make_schema_at(
         $c->{schema_class},
         $c->{loader_options} || {},
         [ $dsn, $user, $pass, %{$options} ],
     );

This PR changes %{$options} to $options, which allows DBI connection options to be specified in the config as:

<connect_info>
    dsn     dbi:Oracle:host=xxx;sid=xxx
    user    xxx
    pass    xxx
    <options>
        LongReadLen         100000000
        LongTrunkOk         1
    </options>
</connect_info>

Full details appended.


I was having difficulty passing connect options through to dbicdump (via Config::Any), e.g trying to dump the schema from an Oracle database requires the following connection options:

      LongReadLen         100000000
      LongTrunkOk         1

Based on the DBIx::Class::Storage::DBI docs, I thought the best way to do this in dbic.conf was:

<connect_info>
    dsn     dbi:Oracle:host=xxx;sid=xxx
    user    xxx
    pass    xxx
    LongReadLen         100000000
    LongTrunkOk         1
</connect_info>

However this came up with an error that seemed to suggest these options weren't being used.

DBIx::Class::Schema::Loader::DBI::Oracle::_view_definition(): DBI Exception: DBD::Oracle::db selectrow_array failed: ORA-24345: A Truncation or null fetch error occurred (DBD ERROR: ORA-01406 error on field 1 of 1, ora_type 8, LongReadLen too small and/or LongTruncOk not set)

From the code, it looks like dbicdump allows a config key options within connect_info so I tried:

<connect_info>
    dsn     dbi:Oracle:host=xxx;sid=xxx
    user    xxx
    pass    xxx
    <options>
        LongReadLen         100000000
        LongTrunkOk         1
    </options>
</connect_info>

However, this gave the error:

Can't use string ("LongTrunkOk") as a HASH ref while "strict refs" in use at /cath/homes2/ucbcisi/.plenv/versions/5.12.5/lib/perl5/site_perl/5.12.5/DBIx/Class/Storage/DBI.pm line 733.

It looks like DBIC->connect can accept these options as a hashref, but dbicdump is currently passing them in as a (de-referenced) hash. Applying the change in this PR seemed to make everything work for me.

Existing tests all pass. I've added a test to make sure the new config with options parses okay (fails prior to this PR). It currently throws out a warning though (I think because the test database isn't DBD::Oracle).