Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I know this isn't exactly what you're asking, but here's an example of using two different data sources on a single schema in the same script. The example uses SQLite and AnyData but any DBI source should work.
#!perl -w use strict; sub run { for my $source( qw(sqlite anydata)){ Schema->db_connect( $source ); Schema->db_drop_table; Schema->db_make_table; Schema->create({c1=>9,c2=>'Hi From'}); printf "%s %s!\n", Schema->retrieve(9)->c2 , Schema->db_Main->{Driver}->{Name}; } } package My::DBI; use base 'Class::DBI'; my $source_name; Ima::DBI->set_db ( 'anydata','DBI:AnyData(AutoCommit=1):','','' ); Ima::DBI->set_db ( 'sqlite' ,'DBI:SQLite:dbname=cdbi' ,'','' ); sub db_Main { my $db = 'db_'.$source_name; __PACKAGE__->$db } sub db_connect { $source_name = lc $_[1] } sub db_drop_table{ eval{ $_[0]->db_Main->do('DROP TABLE '.$_[0]->table +)} } sub db_make_table{ $_[0]->db_drop_table; $_[0]->sql_create->execute } package Schema; use base 'My::DBI'; __PACKAGE__->table ( 't1' ); __PACKAGE__->columns( All=>qw(c1 c2) ); __PACKAGE__->columns( Primary => qw(c1) ); __PACKAGE__->set_sql( 'create' => "CREATE TABLE t1 (c1 INT, c2 CHAR(9) +)"); package main; run(); __END__

In reply to Re: Dynamic DSN w/ Class::DBI Example by jZed
in thread Dynamic DSN w/ Class::DBI Example by gryphon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2021-02-26 13:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?