View | Details | Raw Unified | Return to bug 11389
Collapse All | Expand All

(-)a/C4/Context.pm (-19 / +14 lines)
Lines 293-312 sub memcached { Link Here
293
    }
293
    }
294
}
294
}
295
295
296
# db_scheme2dbi
296
=head2 db_schema2dbi
297
# Translates the full text name of a database into de appropiate dbi name
297
298
# 
298
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
299
300
This routines translates a database type to part of the name
301
of the appropriate DBD driver to use when establishing a new
302
database connection.  It recognizes 'mysql' and 'Pg'; if any
303
other scheme is supplied it defaults to 'mysql'.
304
305
=cut
306
299
sub db_scheme2dbi {
307
sub db_scheme2dbi {
300
    my $name = shift;
308
    my $scheme = shift // '';
301
    # for instance, we support only mysql, so don't care checking
309
    return $scheme eq 'Pg' ? $scheme : 'mysql';
302
    return "mysql";
303
    for ($name) {
304
# FIXME - Should have other databases. 
305
        if (/mysql/) { return("mysql"); }
306
        if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
307
        if (/oracle/) { return("Oracle"); }
308
    }
309
    return;         # Just in case
310
}
310
}
311
311
312
sub import {
312
sub import {
Lines 794-805 sub _new_dbh Link Here
794
794
795
    ## $context
795
    ## $context
796
    ## correct name for db_schme        
796
    ## correct name for db_schme        
797
    my $db_driver;
797
    my $db_driver = db_scheme2dbi($context->config("db_scheme"));
798
    if ($context->config("db_scheme")){
799
        $db_driver=db_scheme2dbi($context->config("db_scheme"));
800
    }else{
801
        $db_driver="mysql";
802
    }
803
798
804
    my $db_name   = $context->config("database");
799
    my $db_name   = $context->config("database");
805
    my $db_host   = $context->config("hostname");
800
    my $db_host   = $context->config("hostname");
(-)a/Koha/Database.pm (-7 / +1 lines)
Lines 45-58 __PACKAGE__->mk_accessors(qw( )); Link Here
45
# database connection from the data given in the current context, and
45
# database connection from the data given in the current context, and
46
# returns it.
46
# returns it.
47
sub _new_schema {
47
sub _new_schema {
48
    my $db_driver;
49
    my $context = C4::Context->new();
48
    my $context = C4::Context->new();
50
    if ( $context->config("db_scheme") ) {
49
    my $db_driver = C4::Context::db_scheme2dbi($context->config("db_scheme"));
51
        $db_driver = $context->db_scheme2dbi( $context->config("db_scheme") );
52
    }
53
    else {
54
        $db_driver = "mysql";
55
    }
56
50
57
    my $db_name   = $context->config("database");
51
    my $db_name   = $context->config("database");
58
    my $db_host   = $context->config("hostname");
52
    my $db_host   = $context->config("hostname");
(-)a/etc/koha-conf.xml (+1 lines)
Lines 264-269 __PAZPAR2_TOGGLE_XML_POST__ Link Here
264
264
265
<!-- ADDITIONAL KOHA CONFIGURATION DIRECTIVE -->
265
<!-- ADDITIONAL KOHA CONFIGURATION DIRECTIVE -->
266
<!-- db_scheme should follow the DBD driver name --> 
266
<!-- db_scheme should follow the DBD driver name --> 
267
<!-- the DBD drivers supported by Koha are mysql and Pg -->
267
<!-- port info: mysql:3306 Pg:5432 (5433 on Debian) -->
268
<!-- port info: mysql:3306 Pg:5432 (5433 on Debian) -->
268
<config>
269
<config>
269
 <db_scheme>__DB_TYPE__</db_scheme>
270
 <db_scheme>__DB_TYPE__</db_scheme>
(-)a/t/Context.t (-2 / +6 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use DBI;
4
use DBI;
5
use Test::More tests => 6;
5
use Test::More tests => 10;
6
use Test::MockModule;
6
use Test::MockModule;
7
7
8
BEGIN {
8
BEGIN {
Lines 30-32 $userenv->{flags} = 421; Link Here
30
$is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
30
$is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
31
is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
31
is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
32
is ( $is_super_librarian, 1, "With flag=1, it is a super librarian" );
32
is ( $is_super_librarian, 1, "With flag=1, it is a super librarian" );
33
- 
33
34
is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql');
35
is(C4::Context::db_scheme2dbi('Pg'),    'Pg',    'ask for Pg, get Pg');
36
is(C4::Context::db_scheme2dbi('xxx'),   'mysql', 'ask for unsupported DBMS, get mysql');
37
is(C4::Context::db_scheme2dbi(),        'mysql', 'ask for nothing, get mysql');

Return to bug 11389