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

(-)a/C4/Context.pm (-4 / +4 lines)
Lines 284-296 sub memcached { Link Here
284
# 
284
# 
285
sub db_scheme2dbi {
285
sub db_scheme2dbi {
286
    my $name = shift;
286
    my $name = shift;
287
    # for instance, we support only mysql, so don't care checking
288
    return "mysql";
289
    for ($name) {
287
    for ($name) {
290
# FIXME - Should have other databases. 
288
# FIXME - Should have other databases. 
291
        if (/mysql/) { return("mysql"); }
289
        if (/mysql/) { return("mysql"); }
292
        if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
290
        elsif (/Postgres|Pg|pgsql|PostgresSQL/i) { return("Pg"); }
293
        if (/oracle/) { return("Oracle"); }
291
        elsif (/oracle/) { return("Oracle"); }
292
        else { return("mysql"); }
294
    }
293
    }
295
    return undef;         # Just in case
294
    return undef;         # Just in case
296
}
295
}
Lines 1103-1108 sub get_versions { Link Here
1103
    {
1102
    {
1104
        no warnings qw(exec); # suppress warnings if unable to find a program in $PATH
1103
        no warnings qw(exec); # suppress warnings if unable to find a program in $PATH
1105
        $versions{mysqlVersion}  = `mysql -V`;
1104
        $versions{mysqlVersion}  = `mysql -V`;
1105
        $versions{psqlVersion}   = `psql -V`;
1106
        $versions{apacheVersion} = `httpd -v`;
1106
        $versions{apacheVersion} = `httpd -v`;
1107
        $versions{apacheVersion} = `httpd2 -v`            unless  $versions{apacheVersion} ;
1107
        $versions{apacheVersion} = `httpd2 -v`            unless  $versions{apacheVersion} ;
1108
        $versions{apacheVersion} = `apache2 -v`           unless  $versions{apacheVersion} ;
1108
        $versions{apacheVersion} = `apache2 -v`           unless  $versions{apacheVersion} ;
(-)a/C4/DBQ.pm (+65 lines)
Line 0 Link Here
1
package C4::DBQ;
2
3
# Copyright 2012 BibLibre and Marc Balmer
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use C4::Context;
22
use vars qw(@ISA @EXPORT $state);
23
24
@ISA = qw(Exporter);
25
26
@EXPORT = qw(
27
  &dbq
28
);
29
30
$state = {};
31
32
sub dbq {
33
    my ( $self, $dbtype ) = @_;
34
    $dbtype //= C4::Context->config("db_scheme");
35
    if ( !$$state{"dbtype"} or $$state{"dbtype"} ne $dbtype ) {
36
        if ( $dbtype eq "mysql" ) {
37
            require C4::DBQ::MySQL;
38
            $$state{"obj"} = C4::DBQ::MySQL->new();
39
        }
40
        elsif ( $dbtype =~ /Postgres|Pg|PostgresSQL|pgsql/i ) {
41
            require C4::DBQ::PostgreSQL;
42
            $$state{"obj"} = C4::DBQ::PostgreSQL->new();
43
        }
44
        else {
45
            die "unsupported database type " . $dbtype;
46
        }
47
        $$state{"dbtype"} = $dbtype;
48
    }
49
    return $$state{"obj"};
50
}
51
52
1;
53
__END__
54
55
=head1 AUTHOR
56
57
Koha Development Team <http://koha-community.org/>
58
59
Stephane Delaune <stephane.delaune at biblibre dot com>
60
61
Marc Balmer <marc at msys dot ch>
62
63
Christophe Croullebois <christophe.croullebois at biblibre dot com>
64
65
=cut
(-)a/C4/DBQ/MySQL.pm (+64 lines)
Line 0 Link Here
1
package C4::DBQ::MySQL;
2
3
# Copyright 2012 BibLibre and Marc Balmer
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use C4::Context;
22
use vars qw(@ISA @EXPORT);
23
24
@ISA = qw(Exporter);
25
26
@EXPORT = qw(
27
  &new
28
  &tableColumns
29
);
30
31
sub new {
32
    my $class = shift;
33
    my $self  = {};
34
    bless $self, $class;
35
    return $self;
36
}
37
38
=head2 tableColumns
39
40
$value = $sql->tableColumns($tablename);
41
42
Returns a string containing request to get a table's columns 
43
44
=cut
45
46
sub tableColumns {
47
    my ( $self, $table ) = @_;
48
    return "SHOW COLUMNS FROM $table";
49
}
50
51
1;
52
__END__
53
54
=head1 AUTHOR
55
56
Koha Development Team <http://koha-community.org/>
57
58
Stephane Delaune <stephane.delaune at biblibre dot com>
59
60
Marc Balmer <marc at msys dot ch>
61
62
Christophe Croullebois <christophe.croullebois at biblibre dot com>
63
64
=cut
(-)a/C4/DBQ/PostgreSQL.pm (+65 lines)
Line 0 Link Here
1
package C4::DBQ::PostgreSQL;
2
3
# Copyright 2012 BibLibre and Marc Balmer
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use C4::Context;
22
use vars qw(@ISA @EXPORT);
23
24
@ISA = qw(Exporter);
25
26
@EXPORT = qw(
27
  &new
28
  &tableColumns
29
);
30
31
sub new {
32
    my $class = shift;
33
    my $self  = {};
34
    bless $self, $class;
35
    return $self;
36
}
37
38
=head2 tableColumns
39
40
$value = $sql->tableColumns($tablename);
41
42
Returns a string containing request to get a table's columns 
43
44
=cut
45
46
sub tableColumns {
47
    my ( $self, $table ) = @_;
48
    return
49
"SELECT column_name as \"Field\", data_type as \"Type\" FROM information_schema.columns WHERE table_name ='$table'";
50
}
51
52
1;
53
__END__
54
55
=head1 AUTHOR
56
57
Koha Development Team <http://koha-community.org/>
58
59
Stephane Delaune <stephane.delaune at biblibre dot com>
60
61
Marc Balmer <marc at msys dot ch>
62
63
Christophe Croullebois <christophe.croullebois at biblibre dot com>
64
65
=cut
(-)a/C4/ImportExportFramework.pm (-16 / +13 lines)
Lines 25-30 use Digest::MD5 qw(md5_base64); Link Here
25
use POSIX qw(strftime);
25
use POSIX qw(strftime);
26
26
27
use C4::Context;
27
use C4::Context;
28
use C4::DBQ;
28
use C4::Debug;
29
use C4::Debug;
29
30
30
31
Lines 266-273 sub _export_table_sql Link Here
266
267
267
    eval {
268
    eval {
268
        # First row with the name of the columns
269
        # First row with the name of the columns
269
        my $query = 'SHOW COLUMNS FROM ' . $table;
270
        my $dbq = C4::DBQ->dbq;
270
        my $sth = $dbh->prepare($query);
271
        my $sth = $dbh->prepare($dbq->tableColumns($table));
271
        $sth->execute();
272
        $sth->execute();
272
        my @fields = ();
273
        my @fields = ();
273
        while (my $hashRef = $sth->fetchrow_hashref) {
274
        while (my $hashRef = $sth->fetchrow_hashref) {
Lines 305-312 sub _export_table_csv Link Here
305
306
306
    eval {
307
    eval {
307
        # First row with the name of the columns
308
        # First row with the name of the columns
308
        my $query = 'SHOW COLUMNS FROM ' . $table;
309
        my $dbq = C4::DBQ->dbq;
309
        my $sth = $dbh->prepare($query);
310
        my $sth = $dbh->prepare($dbq->tableColumns($table));
310
        $sth->execute();
311
        $sth->execute();
311
        my @fields = ();
312
        my @fields = ();
312
        while (my $hashRef = $sth->fetchrow_hashref) {
313
        while (my $hashRef = $sth->fetchrow_hashref) {
Lines 361-368 sub _export_table_ods Link Here
361
        my $elementCell;
362
        my $elementCell;
362
        my $elementData;
363
        my $elementData;
363
        # First row with the name of the columns
364
        # First row with the name of the columns
364
        my $query = 'SHOW COLUMNS FROM ' . $table;
365
        my $dbq = C4::DBQ->dbq;
365
        my $sth = $dbh->prepare($query);
366
        my $sth = $dbh->prepare($dbq->tableColumns($table));
366
        $sth->execute();
367
        $sth->execute();
367
        my @fields = ();
368
        my @fields = ();
368
        while (my $hashRef = $sth->fetchrow_hashref) {
369
        while (my $hashRef = $sth->fetchrow_hashref) {
Lines 426-433 sub _export_table_excel Link Here
426
        # First row with the name of the columns
427
        # First row with the name of the columns
427
        my $elementCell;
428
        my $elementCell;
428
        my $elementData;
429
        my $elementData;
429
        my $query = 'SHOW COLUMNS FROM ' . $table;
430
        my $dbq = C4::DBQ->dbq;
430
        my $sth = $dbh->prepare($query);
431
        my $sth = $dbh->prepare($dbq->tableColumns($table));
431
        $sth->execute();
432
        $sth->execute();
432
        my @fields = ();
433
        my @fields = ();
433
        while (my $hashRef = $sth->fetchrow_hashref) {
434
        while (my $hashRef = $sth->fetchrow_hashref) {
Lines 946-957 sub _check_validity_worksheet Link Here
946
947
947
    my $ret = 0;
948
    my $ret = 0;
948
    eval {
949
    eval {
949
        my $query = 'DESCRIBE ' . $table;
950
        my $dbq = C4::DBQ->dbq;
950
        my $sth = $dbh->prepare($query);
951
        my $sth = $dbh->prepare($dbq->tableColumns($table));
951
        $sth->execute();
952
        $sth->finish;
953
        $query = 'SHOW COLUMNS FROM ' . $table;
954
        $sth = $dbh->prepare($query);
955
        $sth->execute();
952
        $sth->execute();
956
        my $fields = {};
953
        my $fields = {};
957
        while (my $hashRef = $sth->fetchrow_hashref) {
954
        while (my $hashRef = $sth->fetchrow_hashref) {
Lines 1004-1011 sub _import_table Link Here
1004
    if ($format eq 'csv') {
1001
    if ($format eq 'csv') {
1005
        my @fieldsName = ();
1002
        my @fieldsName = ();
1006
        eval {
1003
        eval {
1007
            my $query = 'SHOW COLUMNS FROM ' . $table;
1004
            my $dbq = C4::DBQ->dbq;
1008
            my $sth = $dbh->prepare($query);
1005
            my $sth = $dbh->prepare($dbq->tableColumns($table));
1009
            $sth->execute();
1006
            $sth->execute();
1010
            while (my $hashRef = $sth->fetchrow_hashref) {
1007
            while (my $hashRef = $sth->fetchrow_hashref) {
1011
                push @fieldsName, $hashRef->{Field};
1008
                push @fieldsName, $hashRef->{Field};
(-)a/C4/Installer/PerlDependencies.pm (+5 lines)
Lines 79-84 our $PERL_DEPS = { Link Here
79
        'required' => '1',
79
        'required' => '1',
80
        'min_ver'  => '4.004'
80
        'min_ver'  => '4.004'
81
    },
81
    },
82
    'DBD::Pg' => {
83
        'usage'    => 'Core',
84
        'required' => '1',
85
        'min_ver'  => '2.19.2'
86
    },
82
    'XML::LibXML' => {
87
    'XML::LibXML' => {
83
        'usage'    => 'Core',
88
        'usage'    => 'Core',
84
        'required' => '1',
89
        'required' => '1',
(-)a/t/DBQ.t (-1 / +58 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!
4
# Add more tests here!!!
5
6
use Modern::Perl;
7
use Data::Dumper;
8
use Test::More tests => 4;
9
10
BEGIN {
11
    use_ok('C4::DBQ');
12
}
13
14
#check if all files in C4/DBQ/ have the same sub's names
15
my $dirname = C4::Context->intranetdir . "/C4/DBQ/";
16
my %sublists;
17
opendir my ($dh), $dirname or die "Couldn't open dir '$dirname': $!";
18
my @files = readdir $dh;
19
foreach my $file (@files) {
20
    my @sublist    = ();
21
    my $stringlist = "";
22
23
    open my $f, '<', $dirname . $file;
24
    while ( my $line = <$f> ) {
25
        if ( $line =~ /^(\s*)sub(\s*)([^{|\s]+)(\s*){/ ) {
26
            push( @sublist, $3 );
27
        }
28
    }
29
    close $f;
30
    my @sortlist = sort( { $a cmp $b } @sublist );
31
    foreach my $subname (@sortlist) {
32
        $stringlist .= "$subname|";
33
    }
34
    $sublists{$stringlist} = 1 if $stringlist;
35
36
    #print $file;
37
}
38
closedir $dh;
39
my $countdiffsubs = 0;
40
foreach my $sublists ( keys(%sublists) ) {
41
    $countdiffsubs++;
42
}
43
is( $countdiffsubs, '1', "check sub's list into C4/DBQ/ files" );
44
45
#check each sub
46
my $mysql = C4::DBQ->dbq('mysql');
47
my $pgsql = C4::DBQ->dbq('pgsql');
48
is(
49
    $mysql->tableColumns("foo"),
50
    "SHOW COLUMNS FROM foo",
51
    "check C4::DBQ::MySQL->tableColumns"
52
);
53
is(
54
    $pgsql->tableColumns("foo"),
55
"SELECT column_name as \"Field\", data_type as \"Type\" FROM information_schema.columns WHERE table_name ='foo'",
56
    "check C4::DBQ::PostgreSQL->tableColumns"
57
);
58

Return to bug 7365