}
}
-# db_scheme2dbi
-# Translates the full text name of a database into de appropiate dbi name
-#
+=head2 db_schema2dbi
+
+ my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
+
+This routines translates a database type to part of the name
+of the appropriate DBD driver to use when establishing a new
+database connection. It recognizes 'mysql' and 'Pg'; if any
+other scheme is supplied it defaults to 'mysql'.
+
+=cut
+
sub db_scheme2dbi {
- my $name = shift;
- # for instance, we support only mysql, so don't care checking
- return "mysql";
- for ($name) {
-# FIXME - Should have other databases.
- if (/mysql/) { return("mysql"); }
- if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
- if (/oracle/) { return("Oracle"); }
- }
- return; # Just in case
+ my $scheme = shift // '';
+ return $scheme eq 'Pg' ? $scheme : 'mysql';
}
sub import {
## $context
## correct name for db_schme
- my $db_driver;
- if ($context->config("db_scheme")){
- $db_driver=db_scheme2dbi($context->config("db_scheme"));
- }else{
- $db_driver="mysql";
- }
+ my $db_driver = db_scheme2dbi($context->config("db_scheme"));
my $db_name = $context->config("database");
my $db_host = $context->config("hostname");
# database connection from the data given in the current context, and
# returns it.
sub _new_schema {
- my $db_driver;
my $context = C4::Context->new();
- if ( $context->config("db_scheme") ) {
- $db_driver = $context->db_scheme2dbi( $context->config("db_scheme") );
- }
- else {
- $db_driver = "mysql";
- }
+ my $db_driver = C4::Context::db_scheme2dbi($context->config("db_scheme"));
my $db_name = $context->config("database");
my $db_host = $context->config("hostname");
<!-- ADDITIONAL KOHA CONFIGURATION DIRECTIVE -->
<!-- db_scheme should follow the DBD driver name -->
+<!-- the DBD drivers supported by Koha are mysql and Pg -->
<!-- port info: mysql:3306 Pg:5432 (5433 on Debian) -->
<config>
<db_scheme>__DB_TYPE__</db_scheme>
use Modern::Perl;
use DBI;
-use Test::More tests => 6;
+use Test::More tests => 10;
use Test::MockModule;
BEGIN {
$is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
is ( $is_super_librarian, 1, "With flag=1, it is a super librarian" );
+
+is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql');
+is(C4::Context::db_scheme2dbi('Pg'), 'Pg', 'ask for Pg, get Pg');
+is(C4::Context::db_scheme2dbi('xxx'), 'mysql', 'ask for unsupported DBMS, get mysql');
+is(C4::Context::db_scheme2dbi(), 'mysql', 'ask for nothing, get mysql');