Filename | /usr/share/perl5/CGI/Session/Driver/DBI.pm |
Statements | Executed 48 statements in 4.91ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 877µs | 1.14ms | BEGIN@9 | CGI::Session::Driver::DBI::
3 | 3 | 2 | 147µs | 2.78ms | DESTROY | CGI::Session::Driver::DBI::
3 | 1 | 1 | 38µs | 38µs | table_name | CGI::Session::Driver::DBI::
1 | 1 | 1 | 37µs | 77µs | BEGIN@7 | CGI::Session::Driver::DBI::
1 | 1 | 1 | 30µs | 37µs | BEGIN@5 | CGI::Session::Driver::DBI::
3 | 1 | 1 | 30µs | 30µs | init | CGI::Session::Driver::DBI::
1 | 1 | 1 | 19µs | 58µs | BEGIN@48 | CGI::Session::Driver::DBI::
1 | 1 | 1 | 17µs | 91µ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 | 57µs | 2 | 45µs | # spent 37µs (30+7) within CGI::Session::Driver::DBI::BEGIN@5 which was called:
# once (30µs+7µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 5 # spent 37µs making 1 call to CGI::Session::Driver::DBI::BEGIN@5
# spent 7µs making 1 call to strict::import |
6 | |||||
7 | 3 | 61µs | 2 | 118µs | # spent 77µs (37+41) within CGI::Session::Driver::DBI::BEGIN@7 which was called:
# once (37µs+41µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 7 # spent 77µs making 1 call to CGI::Session::Driver::DBI::BEGIN@7
# spent 41µs making 1 call to Exporter::import |
8 | 3 | 50µs | 2 | 165µs | # spent 91µs (17+74) within CGI::Session::Driver::DBI::BEGIN@8 which was called:
# once (17µs+74µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 8 # spent 91µs making 1 call to CGI::Session::Driver::DBI::BEGIN@8
# spent 74µs making 1 call to Exporter::import |
9 | 3 | 526µs | 1 | 1.14ms | # spent 1.14ms (877µs+262µs) within CGI::Session::Driver::DBI::BEGIN@9 which was called:
# once (877µs+262µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 9 # spent 1.14ms making 1 call to CGI::Session::Driver::DBI::BEGIN@9 |
10 | |||||
11 | 1 | 22µs | @CGI::Session::Driver::DBI::ISA = ( "CGI::Session::Driver" ); | ||
12 | 1 | 2µs | $CGI::Session::Driver::DBI::VERSION = '4.38'; | ||
13 | |||||
14 | |||||
15 | # spent 30µs within CGI::Session::Driver::DBI::init which was called 3 times, avg 10µs/call:
# 3 times (30µs+0s) by CGI::Session::Driver::mysql::init at line 41 of CGI/Session/Driver/mysql.pm, avg 10µs/call | ||||
16 | 9 | 40µ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 38µs within CGI::Session::Driver::DBI::table_name which was called 3 times, avg 13µs/call:
# 3 times (38µs+0s) by CGI::Session::Driver::mysql::table_name at line 61 of CGI/Session/Driver/mysql.pm, avg 13µs/call | ||||
41 | 9 | 46µ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 | 1.31ms | 2 | 98µs | # spent 58µs (19+39) within CGI::Session::Driver::DBI::BEGIN@48 which was called:
# once (19µs+39µs) by CGI::Session::Driver::mysql::BEGIN@7 at line 48 # spent 58µs making 1 call to CGI::Session::Driver::DBI::BEGIN@48
# spent 39µ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 2.78ms (147µs+2.63) within CGI::Session::Driver::DBI::DESTROY which was called 3 times, avg 926µs/call:
# once (58µs+891µs) by C4::Auth::checkauth at line 806 of /usr/share/koha/lib/C4/Auth.pm
# once (38µs+894µs) by C4::Auth::get_template_and_user at line 365 of /usr/share/koha/lib/C4/Auth.pm
# once (52µs+845µs) by main::RUNTIME at line 690 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
134 | 12 | 2.79ms | my $self = shift; | ||
135 | |||||
136 | 3 | 2.60ms | unless ( defined $self->{Handle} && $self->{Handle} -> ping ) { # spent 2.60ms making 3 calls to DBI::db::ping, avg 866µs/call | ||
137 | $self->set_error(__PACKAGE__ . '::DESTROY(). Database handle has gone away'); | ||||
138 | return; | ||||
139 | } | ||||
140 | |||||
141 | 3 | 31µs | unless ( $self->{Handle}->{AutoCommit} ) { # spent 31µs making 3 calls to DBI::common::FETCH, avg 10µ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 | 6µs | 1; | ||
174 | |||||
175 | =pod | ||||
176 | |||||
- - |