From: Chris W. <la...@us...> - 2005-02-19 04:27:17
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Datasource In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9313/OpenInteract2/Datasource Modified Files: LDAP.pm DBI.pm Log Message: OIN-54: add 'resolve_datasource_info()' that setup calls which does datasource configuration rewriting Index: LDAP.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Datasource/LDAP.pm,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** LDAP.pm 18 Feb 2004 05:25:27 -0000 1.8 --- LDAP.pm 19 Feb 2005 04:27:07 -0000 1.9 *************** *** 117,120 **** --- 117,127 ---- } + # no-op... + + sub resolve_datasource_info { + my ( $self, $name, $ds_info ) = @_; + return { %{ $ds_info } }; + } + 1; *************** *** 259,261 **** =head1 AUTHORS ! Chris Winters E<lt>ch...@cw...E<gt> \ No newline at end of file --- 266,268 ---- =head1 AUTHORS ! Chris Winters E<lt>ch...@cw...E<gt> Index: DBI.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Datasource/DBI.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DBI.pm 17 Oct 2004 20:07:18 -0000 1.14 --- DBI.pm 19 Feb 2005 04:27:07 -0000 1.15 *************** *** 30,34 **** } ! unless ( $ds_info->{driver_name} ) { $log->error( "Required configuration key undefined ", "'datasource.$ds_name.driver_name'" ); --- 30,36 ---- } ! my $full = $class->resolve_datasource_info( $ds_name, $ds_info ); ! ! unless ( $full->{driver_name} ) { $log->error( "Required configuration key undefined ", "'datasource.$ds_name.driver_name'" ); *************** *** 40,49 **** # it happens ! my $dsn = "DBI:$ds_info->{driver_name}:$ds_info->{dsn}"; ! my $username = $ds_info->{username}; ! my $password = $ds_info->{password}; if ( $log->is_debug ) { ! my %dumpable = %{ $ds_info }; $dumpable{password} = '*' x length $password; $log->debug( "Trying to connect to DBI with: ", --- 42,51 ---- # it happens ! my $dsn = join( ':', 'DBI', $full->{driver_name}, $full->{dsn} ); ! my $username = $full->{username}; ! my $password = $full->{password}; if ( $log->is_debug ) { ! my %dumpable = %{ $full }; $dumpable{password} = '*' x length $password; $log->debug( "Trying to connect to DBI with: ", *************** *** 56,67 **** unless ( $db ) { oi_datasource_error ! "Error connecting to DBI database '$ds_name': $DBI::errstr", ! { datasource_name => $ds_name, ! datasource_type => 'DBI', ! connect_params => "$dsn , $username , $password" }; } ! # We don't set this until here so we can control the format of the ! # error... $db->{RaiseError} = 1; --- 58,69 ---- unless ( $db ) { oi_datasource_error ! "Error connecting to DBI database '$ds_name': $DBI::errstr", ! { datasource_name => $ds_name, ! datasource_type => 'DBI', ! connect_params => "$dsn , $username , $password" }; } ! # We don't set these until here (esp RaiseError) so we can control ! # the format of the error... $db->{RaiseError} = 1; *************** *** 69,76 **** $db->{ChopBlanks} = 1; $db->{AutoCommit} = 1; ! $db->{LongReadLen} = $ds_info->{long_read_len} || DEFAULT_READ_LEN; ! $db->{LongTruncOk} = $ds_info->{long_trunc_ok} || DEFAULT_TRUNC_OK; ! my $trace_level = $ds_info->{trace_level} || '0'; $db->trace( $trace_level ); --- 71,78 ---- $db->{ChopBlanks} = 1; $db->{AutoCommit} = 1; ! $db->{LongReadLen} = $full->{long_read_len} || DEFAULT_READ_LEN; ! $db->{LongTruncOk} = $full->{long_trunc_ok} || DEFAULT_TRUNC_OK; ! my $trace_level = $full->{trace_level} || '0'; $db->trace( $trace_level ); *************** *** 93,96 **** --- 95,136 ---- } + # OIN-54: resolve user-friendly configuration items + + my %DBI_INFO = ( + pg => [ 'SPOPS::DBI::Pg', 'Pg' ], + mysql => [ 'SPOPS::DBI::MySQL', 'mysql' ], + sqlite => [ 'SPOPS::DBI::SQLite', 'SQLite' ], + oracle => [ 'SPOPS::DBI::Oracle', 'Oracle' ], + asany => [ 'SPOPS::DBI::Sybase', 'ASAny' ], + mssql => [ 'SPOPS::DBI::Sybase', 'Sybase' ], + sybase => [ 'SPOPS::DBI::Sybase', 'Sybase' ], + ); + + sub resolve_datasource_info { + my ( $self, $name, $ds_info ) = @_; + + # backwards compatibility - if 'spops' key exists just return as-is + if ( $ds_info->{spops} ) { + return { %{ $ds_info } }; + } + + my @copy_properties = qw( + type dsn username password long_read_len long_trunc_ok trace_level + ); + my %info = map { $_ => $ds_info->{ $_ } } @copy_properties; + + my $dbi_type = lc $ds_info->{dbi_type}; + unless ( $dbi_type or $DBI_INFO{ $dbi_type } ) { + oi_error "DBI datasource configuration '$name' has an invalid ", + "'dbi_type'; allowed values: ", + join( ', ', sort keys %DBI_INFO ); + } + my $dbi_info = $DBI_INFO{ $dbi_type }; + $info{spops} = $dbi_info->[0]; + $info{driver_name} = ( 'yes' eq lc $ds_info->{use_odbc} ) + ? 'ODBC' : $dbi_info->[1]; + return \%info; + } + 1; *************** *** 103,117 **** =head1 SYNOPSIS ! # Define the parameters for a database handle 'main' ! [datasource main] type = DBI ! db_owner = username = webuser password = urkelnut - dsn = dbname=urkelweb - driver_name = Pg - long_read_len = 65536 - long_trunc_ok = 0 # Request the datasource 'main' from the context object (which in --- 143,165 ---- =head1 SYNOPSIS ! # Define the parameters for a database handle 'main' using PostgreSQL ! [datasource main] type = DBI ! dbi_type = Pg ! dsn = dbname=urkelweb ! username = webuser ! password = urkelnut ! ! # Define a handle 'win32' that uses Microsoft SQL Server and connects ! # with ODBC ! ! [datasource win32] ! type = DBI ! dbi_type = MSSQL ! use_odbc = yes ! dsn = MyDSN username = webuser password = urkelnut # Request the datasource 'main' from the context object (which in *************** *** 149,157 **** ChopBlanks: 1 AutoCommit: 1 (for now...) ! LongReadLen: 32768 (or as set in \%datasource_info) ! LongTruncOk: 0 (or as set in \%datasource_info) The parameter C<\%datasource_info> defines how we connect to the ! database. =over 4 --- 197,206 ---- ChopBlanks: 1 AutoCommit: 1 (for now...) ! LongReadLen: 32768 (or from 'long_read_len' of \%datasource_info) ! LongTruncOk: 0 (or from 'long_trunc_ok' of \%datasource_info) The parameter C<\%datasource_info> defines how we connect to the ! database and is pulled from your 'datasource.$name' server ! configuration. =over 4 *************** *** 166,175 **** Full DBI DSN: DBI:mysql:webdb OpenInteract DSN: webdb ! Full DBI DSN: DBI:Pg:dbname=web OpenInteract DSN: dbname=web ! Full DBI DSN: DBI:Sybase:server=SYBASE;database=web OpenInteract DSN: server=SYBASE;database=web So the OpenInteract DSN string only includes the database-specific items --- 215,227 ---- Full DBI DSN: DBI:mysql:webdb OpenInteract DSN: webdb ! Full DBI DSN: DBI:Pg:dbname=web OpenInteract DSN: dbname=web ! Full DBI DSN: DBI:Sybase:server=SYBASE;database=web OpenInteract DSN: server=SYBASE;database=web + + Full DBI DSN: DBI:ODBC:MyDSN + OpenInteract DSN: MyDSN So the OpenInteract DSN string only includes the database-specific items *************** *** 181,188 **** =item * ! B<driver_name> ($) ! What DBD driver is used to connect to your database? (Examples: ! 'Pg', 'Sybase', 'mysql', 'Oracle') =item * --- 233,240 ---- =item * ! B<dbi_type> ($) ! What database type are you using? Available values are: 'MySQL', ! 'Pg', 'Sybase', 'ASAny', 'Oracle', 'SQLite' and 'MSSQL'. =item * *************** *** 201,208 **** =item * ! B<db_owner> ($) (optional) ! Who owns this database? Only use if your database uses the database ! owner to differentiate different tables. =item * --- 253,259 ---- =item * ! B<use_odbc> (yes/no; default no) ! Whether to use ODBC as a DBI driver. =item * *************** *** 244,247 **** --- 295,321 ---- variety. + B<resolve_datasource_info( $name, \%datasource_info )> + + Internal method used to resolve some shortcuts we allow for + usability. This will look at the 'dbi_type' and add keys to the + datasource information: + + =over 4 + + =item B<spops> + + Lists the SPOPS class to use. + + =item B<driver_name> + + Lists the DBI driver name to use -- this is what you'd use in the + second ':' place in the DBI C<connect()> call. + + =back + + Returns a new hashref of information. For backwards compatibility, if + we see the key C<spops> in C<\%datasource_info> we just return a new + hashref with the same data. + =head1 SEE ALSO |