Filename | /usr/share/perl5/CGI/Session/Driver/DBI.pm |
Statements | Executed 48 statements in 4.53ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 551µs | 654µs | BEGIN@9 | CGI::Session::Driver::DBI::
3 | 3 | 2 | 117µs | 3.12ms | DESTROY | CGI::Session::Driver::DBI::
3 | 1 | 1 | 34µs | 34µs | init | CGI::Session::Driver::DBI::
3 | 1 | 1 | 23µs | 23µs | table_name | CGI::Session::Driver::DBI::
1 | 1 | 1 | 21µs | 26µs | BEGIN@5 | CGI::Session::Driver::DBI::
1 | 1 | 1 | 18µs | 43µs | BEGIN@7 | CGI::Session::Driver::DBI::
1 | 1 | 1 | 13µs | 36µs | BEGIN@48 | CGI::Session::Driver::DBI::
1 | 1 | 1 | 9µs | 51µs | BEGIN@8 | CGI::Session::Driver::DBI::
0 | 0 | 0 | 0s | 0s | remove | CGI::Session::Driver::DBI::
0 | 0 | 0 | 0s | 0s | retrieve | CGI::Session::Driver::DBI::
0 | 0 | 0 | 0s | 0s | store | CGI::Session::Driver::DBI::
0 | 0 | 0 | 0s | 0s | traverse | CGI::Session::Driver::DBI::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package CGI::Session::Driver::DBI; | ||||
2 | |||||
3 | # $Id: DBI.pm 447 2008-11-01 03:46:08Z markstos $ | ||||
4 | |||||
5 | 3 | 35µs | 2 | 30µs | # spent 26µs (21+4) within CGI::Session::Driver::DBI::BEGIN@5 which was called:
# once (21µs+4µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 5 # spent 26µs making 1 call to CGI::Session::Driver::DBI::BEGIN@5
# spent 4µs making 1 call to strict::import |
6 | |||||
7 | 3 | 35µs | 2 | 68µs | # spent 43µs (18+25) within CGI::Session::Driver::DBI::BEGIN@7 which was called:
# once (18µs+25µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 7 # spent 43µs making 1 call to CGI::Session::Driver::DBI::BEGIN@7
# spent 25µs making 1 call to Exporter::import |
8 | 3 | 28µs | 2 | 93µs | # spent 51µs (9+42) within CGI::Session::Driver::DBI::BEGIN@8 which was called:
# once (9µs+42µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 8 # spent 51µs making 1 call to CGI::Session::Driver::DBI::BEGIN@8
# spent 42µs making 1 call to Exporter::import |
9 | 3 | 371µs | 2 | 658µs | # spent 654µs (551+104) within CGI::Session::Driver::DBI::BEGIN@9 which was called:
# once (551µs+104µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 9 # spent 654µs making 1 call to CGI::Session::Driver::DBI::BEGIN@9
# spent 3µs making 1 call to UNIVERSAL::import |
10 | |||||
11 | 1 | 16µs | @CGI::Session::Driver::DBI::ISA = ( "CGI::Session::Driver" ); | ||
12 | 1 | 600ns | $CGI::Session::Driver::DBI::VERSION = '4.38'; | ||
13 | |||||
14 | |||||
15 | # spent 34µs within CGI::Session::Driver::DBI::init which was called 3 times, avg 11µs/call:
# 3 times (34µs+0s) by CGI::Session::Driver::mysql::init at line 41 of CGI/Session/Driver/mysql.pm, avg 11µs/call | ||||
16 | 9 | 46µs | my $self = shift; | ||
17 | if ( defined $self->{Handle} ) { | ||||
18 | if (ref $self->{Handle} eq 'CODE') { | ||||
19 | $self->{Handle} = $self->{Handle}->(); | ||||
20 | } | ||||
21 | else { | ||||
22 | # We assume the handle is working, and there is nothing to do. | ||||
23 | } | ||||
24 | } | ||||
25 | else { | ||||
26 | $self->{Handle} = DBI->connect( | ||||
27 | $self->{DataSource}, $self->{User}, $self->{Password}, | ||||
28 | { RaiseError=>1, PrintError=>1, AutoCommit=>1 } | ||||
29 | ); | ||||
30 | unless ( $self->{Handle} ) { | ||||
31 | return $self->set_error( "init(): couldn't connect to database: " . DBI->errstr ); | ||||
32 | } | ||||
33 | $self->{_disconnect} = 1; | ||||
34 | } | ||||
35 | return 1; | ||||
36 | } | ||||
37 | |||||
38 | # A setter/accessor method for the table name, defaulting to 'sessions' | ||||
39 | |||||
40 | # spent 23µs within CGI::Session::Driver::DBI::table_name which was called 3 times, avg 8µs/call:
# 3 times (23µs+0s) by CGI::Session::Driver::mysql::table_name at line 61 of CGI/Session/Driver/mysql.pm, avg 8µs/call | ||||
41 | 9 | 30µs | my $self = shift; | ||
42 | my $class = ref( $self ) || $self; | ||||
43 | |||||
44 | if ( (@_ == 0) && ref($self) && ($self->{TableName}) ) { | ||||
45 | return $self->{TableName}; | ||||
46 | } | ||||
47 | |||||
48 | 3 | 841µs | 2 | 59µs | # spent 36µs (13+23) within CGI::Session::Driver::DBI::BEGIN@48 which was called:
# once (13µs+23µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 48 # spent 36µs making 1 call to CGI::Session::Driver::DBI::BEGIN@48
# spent 23µs making 1 call to strict::unimport |
49 | if ( @_ ) { | ||||
50 | $self->{TableName} = shift; | ||||
51 | } | ||||
52 | |||||
53 | unless (defined $self->{TableName}) { | ||||
54 | $self->{TableName} = "sessions"; | ||||
55 | } | ||||
56 | |||||
57 | return $self->{TableName}; | ||||
58 | } | ||||
59 | |||||
60 | |||||
61 | sub retrieve { | ||||
62 | my $self = shift; | ||||
63 | my ($sid) = @_; | ||||
64 | croak "retrieve(): usage error" unless $sid; | ||||
65 | |||||
66 | |||||
67 | my $dbh = $self->{Handle}; | ||||
68 | my $sth = $dbh->prepare_cached("SELECT $self->{DataColName} FROM " . $self->table_name . " WHERE $self->{IdColName}=?", undef, 3); | ||||
69 | unless ( $sth ) { | ||||
70 | return $self->set_error( "retrieve(): DBI->prepare failed with error message " . $dbh->errstr ); | ||||
71 | } | ||||
72 | $sth->execute( $sid ) or return $self->set_error( "retrieve(): \$sth->execute failed with error message " . $sth->errstr); | ||||
73 | |||||
74 | my ($row) = $sth->fetchrow_array(); | ||||
75 | |||||
76 | $sth->finish; | ||||
77 | |||||
78 | return 0 unless $row; | ||||
79 | return $row; | ||||
80 | } | ||||
81 | |||||
82 | |||||
83 | sub store { | ||||
84 | # die; | ||||
85 | my $self = shift; | ||||
86 | my ($sid, $datastr) = @_; | ||||
87 | croak "store(): usage error" unless $sid && $datastr; | ||||
88 | |||||
89 | |||||
90 | my $dbh = $self->{Handle}; | ||||
91 | my $sth = $dbh->prepare_cached("SELECT $self->{IdColName} FROM " . $self->table_name . " WHERE $self->{IdColName}=?", undef, 3); | ||||
92 | unless ( defined $sth ) { | ||||
93 | return $self->set_error( "store(): \$dbh->prepare failed with message " . $sth->errstr ); | ||||
94 | } | ||||
95 | |||||
96 | $sth->execute( $sid ) or return $self->set_error( "store(): \$sth->execute failed with message " . $sth->errstr ); | ||||
97 | my $rc = $sth->fetchrow_array; | ||||
98 | $sth->finish; | ||||
99 | |||||
100 | my $action_sth; | ||||
101 | if ( $rc ) { | ||||
102 | $action_sth = $dbh->prepare_cached("UPDATE " . $self->table_name . " SET $self->{DataColName}=? WHERE $self->{IdColName}=?", undef, 3); | ||||
103 | } else { | ||||
104 | $action_sth = $dbh->prepare_cached("INSERT INTO " . $self->table_name . " ($self->{DataColName}, $self->{IdColName}) VALUES(?, ?)", undef, 3); | ||||
105 | } | ||||
106 | |||||
107 | unless ( defined $action_sth ) { | ||||
108 | return $self->set_error( "store(): \$dbh->prepare failed with message " . $dbh->errstr ); | ||||
109 | } | ||||
110 | $action_sth->execute($datastr, $sid) | ||||
111 | or return $self->set_error( "store(): \$action_sth->execute failed " . $action_sth->errstr ); | ||||
112 | |||||
113 | $action_sth->finish; | ||||
114 | |||||
115 | return 1; | ||||
116 | } | ||||
117 | |||||
118 | |||||
119 | sub remove { | ||||
120 | my $self = shift; | ||||
121 | my ($sid) = @_; | ||||
122 | croak "remove(): usage error" unless $sid; | ||||
123 | |||||
124 | my $rc = $self->{Handle}->do( 'DELETE FROM ' . $self->table_name . " WHERE $self->{IdColName}= ?", {}, $sid ); | ||||
125 | unless ( $rc ) { | ||||
126 | croak "remove(): \$dbh->do failed!"; | ||||
127 | } | ||||
128 | |||||
129 | return 1; | ||||
130 | } | ||||
131 | |||||
132 | |||||
133 | # spent 3.12ms (117µs+3.00) within CGI::Session::Driver::DBI::DESTROY which was called 3 times, avg 1.04ms/call:
# once (37µs+1.07ms) by main::RUNTIME at line 690 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
# once (39µs+989µs) by C4::Auth::checkauth at line 805 of /usr/share/koha/lib/C4/Auth.pm
# once (41µs+936µs) by C4::Auth::get_template_and_user at line 365 of /usr/share/koha/lib/C4/Auth.pm | ||||
134 | 12 | 3.12ms | my $self = shift; | ||
135 | |||||
136 | 3 | 2.97ms | unless ( defined $self->{Handle} && $self->{Handle} -> ping ) { # spent 2.97ms making 3 calls to DBI::db::ping, avg 991µs/call | ||
137 | $self->set_error(__PACKAGE__ . '::DESTROY(). Database handle has gone away'); | ||||
138 | return; | ||||
139 | } | ||||
140 | |||||
141 | 3 | 28µs | unless ( $self->{Handle}->{AutoCommit} ) { # spent 28µs making 3 calls to DBI::common::FETCH, avg 9µs/call | ||
142 | $self->{Handle}->commit; | ||||
143 | } | ||||
144 | if ( $self->{_disconnect} ) { | ||||
145 | $self->{Handle}->disconnect; | ||||
146 | } | ||||
147 | } | ||||
148 | |||||
149 | |||||
150 | sub traverse { | ||||
151 | my $self = shift; | ||||
152 | my ($coderef) = @_; | ||||
153 | |||||
154 | unless ( $coderef && ref( $coderef ) && (ref $coderef eq 'CODE') ) { | ||||
155 | croak "traverse(): usage error"; | ||||
156 | } | ||||
157 | |||||
158 | my $tablename = $self->table_name(); | ||||
159 | my $sth = $self->{Handle}->prepare_cached("SELECT $self->{IdColName} FROM $tablename", undef, 3) | ||||
160 | or return $self->set_error("traverse(): couldn't prepare SQL statement. " . $self->{Handle}->errstr); | ||||
161 | $sth->execute() or return $self->set_error("traverse(): couldn't execute statement $sth->{Statement}. " . $sth->errstr); | ||||
162 | |||||
163 | while ( my ($sid) = $sth->fetchrow_array ) { | ||||
164 | $coderef->($sid); | ||||
165 | } | ||||
166 | |||||
167 | $sth->finish; | ||||
168 | |||||
169 | return 1; | ||||
170 | } | ||||
171 | |||||
172 | |||||
173 | 1 | 4µs | 1; | ||
174 | |||||
175 | =pod | ||||
176 | |||||
- - |