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

(-)a/C4/Context.pm (-19 / +14 lines)
Lines 292-311 sub memcached { Link Here
292
    }
292
    }
293
}
293
}
294
294
295
# db_scheme2dbi
295
=head2 db_schema2dbi
296
# Translates the full text name of a database into de appropiate dbi name
296
297
# 
297
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
298
299
This routines translates a database type to part of the name
300
of the appropriate DBD driver to use when establishing a new
301
database connection.  It recognizes 'mysql' and 'Pg'; if any
302
other scheme is supplied it defaults to 'mysql'.
303
304
=cut
305
298
sub db_scheme2dbi {
306
sub db_scheme2dbi {
299
    my $name = shift;
307
    my $scheme = shift // '';
300
    # for instance, we support only mysql, so don't care checking
308
    return $scheme eq 'Pg' ? $scheme : 'mysql';
301
    return "mysql";
302
    for ($name) {
303
# FIXME - Should have other databases. 
304
        if (/mysql/) { return("mysql"); }
305
        if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
306
        if (/oracle/) { return("Oracle"); }
307
    }
308
    return;         # Just in case
309
}
309
}
310
310
311
sub import {
311
sub import {
Lines 793-804 sub _new_dbh Link Here
793
793
794
    ## $context
794
    ## $context
795
    ## correct name for db_schme        
795
    ## correct name for db_schme        
796
    my $db_driver;
796
    my $db_driver = db_scheme2dbi($context->config("db_scheme"));
797
    if ($context->config("db_scheme")){
798
        $db_driver=db_scheme2dbi($context->config("db_scheme"));
799
    }else{
800
        $db_driver="mysql";
801
    }
802
797
803
    my $db_name   = $context->config("database");
798
    my $db_name   = $context->config("database");
804
    my $db_host   = $context->config("hostname");
799
    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-10 Link Here
2
use strict;
2
use strict;
3
use warnings;
3
use warnings;
4
use DBI;
4
use DBI;
5
use Test::More tests => 1;
5
use Test::More tests => 5;
6
use Test::MockModule;
6
use Test::MockModule;
7
7
8
BEGIN {
8
BEGIN {
9
    use_ok('C4::Context');
9
    use_ok('C4::Context');
10
}
10
}
11
- 
11
12
is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql');
13
is(C4::Context::db_scheme2dbi('Pg'),    'Pg',    'ask for Pg, get Pg');
14
is(C4::Context::db_scheme2dbi('xxx'),   'mysql', 'ask for unsupported DBMS, get mysql');
15
is(C4::Context::db_scheme2dbi(),        'mysql', 'ask for nothing, get mysql');

Return to bug 11389