line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Sakai::Stats::Database; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
19
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
305
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
9
|
1
|
|
|
1
|
|
14411
|
use DBI; |
|
1
|
|
|
|
|
37584
|
|
|
1
|
|
|
|
|
83
|
|
10
|
1
|
|
|
1
|
|
805
|
use DBD::mysql; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use base qw(Exporter); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#{{{sub new |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
my ( $class, $stats ) = @_; |
24
|
|
|
|
|
|
|
if ( !defined $stats ) { croak 'no stats object provided!'; } |
25
|
|
|
|
|
|
|
my $dsn; |
26
|
|
|
|
|
|
|
my $conn; |
27
|
|
|
|
|
|
|
my $queryhandle; |
28
|
|
|
|
|
|
|
my $database = { |
29
|
|
|
|
|
|
|
Conn => $conn, |
30
|
|
|
|
|
|
|
DSN => $dsn, |
31
|
|
|
|
|
|
|
QueryHandle => $queryhandle, |
32
|
|
|
|
|
|
|
Stats => $stats, |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
bless $database, $class; |
35
|
|
|
|
|
|
|
return $database; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#}}} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#{{{sub connect |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub make_connection { |
43
|
|
|
|
|
|
|
my ($database) = @_; |
44
|
|
|
|
|
|
|
$database->{'DSN'} = |
45
|
|
|
|
|
|
|
q{dbi:} |
46
|
|
|
|
|
|
|
. q{mysql} . q{:} |
47
|
|
|
|
|
|
|
. ${ $database->{'Stats'} }->{'DBName'} . q{:} |
48
|
|
|
|
|
|
|
. ${ $database->{'Stats'} }->{'DBHost'} . q{:} |
49
|
|
|
|
|
|
|
. ${ $database->{'Stats'} }->{'DBPort'}; |
50
|
|
|
|
|
|
|
$database->{'Conn'} = DBI->connect( |
51
|
|
|
|
|
|
|
$database->{'DSN'}, |
52
|
|
|
|
|
|
|
${ $database->{'Stats'} }->{'DBUser'}, |
53
|
|
|
|
|
|
|
${ $database->{'Stats'} }->{'DBPass'} |
54
|
|
|
|
|
|
|
) || croak 'Problem accessing stats database'; |
55
|
|
|
|
|
|
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#}}} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#{{{sub inst_users_per_month |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub inst_users_per_month { |
63
|
|
|
|
|
|
|
my ( $database, $year, $month ) = @_; |
64
|
|
|
|
|
|
|
my $query = |
65
|
|
|
|
|
|
|
q{select SESSION_USER FROM SAKAI_SESSION WHERE SESSION_START LIKE '} |
66
|
|
|
|
|
|
|
. $year . q{-} |
67
|
|
|
|
|
|
|
. $month . q{%'}; |
68
|
|
|
|
|
|
|
$database->{'QueryHandle'} = $database->{'Conn'}->prepare($query); |
69
|
|
|
|
|
|
|
$database->{'QueryHandle'}->execute(); |
70
|
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#}}} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |