| 1 | package DBIx::Connection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use DBI::Const::GetInfoType; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Abstract::Meta::Class ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use DBIx::SQLHandler; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use DBIx::QueryCursor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use vars qw($VERSION $CONNECTION_POOLING $IDLE_THRESHOLD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Time::HiRes qw(gettimeofday tv_interval); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | $VERSION = 0.08; | |||||||||||||||||||||||||||
| 15 | 6 | $IDLE_THRESHOLD = 300; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | DBIx::Connection - Simple database interface. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | use DBIx::Connection; | ||||||||||||||||||||||||||||
| 24 | my $connection = DBIx::Connection->new( | ||||||||||||||||||||||||||||
| 25 | name => 'my_connection_name', | ||||||||||||||||||||||||||||
| 26 | dsn => 'dbi:Oracle:localhost:1521/ORCL', | ||||||||||||||||||||||||||||
| 27 | username => 'user', | ||||||||||||||||||||||||||||
| 28 | password => 'password', | ||||||||||||||||||||||||||||
| 29 | db_session_variables => { | ||||||||||||||||||||||||||||
| 30 | NLS_DATE_FORMAT => 'DD.MM.YYYY' | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | or | ||||||||||||||||||||||||||||
| 35 | my $dbh = DBI->connect(...); | ||||||||||||||||||||||||||||
| 36 | my $connection = DBIx::Connection->new( | ||||||||||||||||||||||||||||
| 37 | name => 'my_connection_name', | ||||||||||||||||||||||||||||
| 38 | dbh => $dbh, | ||||||||||||||||||||||||||||
| 39 | db_session_variables => { | ||||||||||||||||||||||||||||
| 40 | NLS_DATE_FORMAT => 'DD.MM.YYYY' | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my $cursor = $connection->query_cursor(sql => "select * from emp where deptno > ?", name => 'emp_select'); | ||||||||||||||||||||||||||||
| 46 | my $dataset = $cursor->execute(20); | ||||||||||||||||||||||||||||
| 47 | while ($cursor->fetch) { | ||||||||||||||||||||||||||||
| 48 | #do some stuff ... | ||||||||||||||||||||||||||||
| 49 | print $_ . " => " . $dataset->{$_} | ||||||||||||||||||||||||||||
| 50 | for keys %$dataset; | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | my $cursor = $connection->find_query_cursor('emp_select'); | ||||||||||||||||||||||||||||
| 55 | my $dataset = $cursor->execute(20); | ||||||||||||||||||||||||||||
| 56 | ... | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | my $record = $connection->record("select * from emp where empno = ?", 'xxx'); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | my $sql_handler = $connection->sql_handler(sql => "INSERT INTO emp(empno, ename) VALUES(?, ?)", name => 'emp_ins'); | ||||||||||||||||||||||||||||
| 63 | $sql_handler->execute(1, 'Smith'); | ||||||||||||||||||||||||||||
| 64 | $sql_handler->execute(2, 'Witek'); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | my $sql_handler= $connection->find_sql_handler('emp_ins'); | ||||||||||||||||||||||||||||
| 68 | $sql_handler->execute(3, 'Zzz'); | ||||||||||||||||||||||||||||
| 69 | ... | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | #or | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | $connection->execute_statement("INSERT INTO emp(empno, ename) VALUES(?, ?)", 1, 'Smith'); | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | #gets connection by name. | ||||||||||||||||||||||||||||
| 79 | my $connection = DBIx::Connection->connection('my_connection_name'); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | do stuff | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # returns connection to connection pool | ||||||||||||||||||||||||||||
| 84 | $connection->close(); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | #turn on connection pooling | ||||||||||||||||||||||||||||
| 88 | $DBIx::Connection::CONNECTION_POOLING = 1; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | In this mode only connection may have the following states : in_use and NOT in_use, | ||||||||||||||||||||||||||||
| 91 | Only connection that is "NOT in use" state can be retrieve by invoking DBIx::Connection->connection, and | ||||||||||||||||||||||||||||
| 92 | state changes to "in use". Close method change state back to NOT in_use. | ||||||||||||||||||||||||||||
| 93 | If in connection pool there are not connections in "NOT in use" state, then the new connection is cloned. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | my $connection = DBIx::Connection->connection('my_connection_name'); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # do stuff ... | ||||||||||||||||||||||||||||
| 99 | $connection->close(); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | #preserving resource by physical disconnecting all connection that are idle by defined threshold (sec). | ||||||||||||||||||||||||||||
| 102 | $DBIx::Connection::IDLE_THRESHOLD = 300; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Represents a database connection handler. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | It provides simple interface to managing database connections with the all related operations wrapped in the | ||||||||||||||||||||||||||||
| 110 | different sql handlers. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | $connection = DBIx::Connection->connection('my_connection_name'); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | eval { | ||||||||||||||||||||||||||||
| 115 | $connection->begin_work(); | ||||||||||||||||||||||||||||
| 116 | my $sql_handler = $connection->sql_handler(sql => "INSERT INTO emp(empno, ename) VALUES(?, ?)"); | ||||||||||||||||||||||||||||
| 117 | $sql_handler->execute(1, 'Smith'); | ||||||||||||||||||||||||||||
| 118 | ... | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | $connection->commit(); | ||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | if($@) { | ||||||||||||||||||||||||||||
| 124 | $connection->rollback(); | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | $connection->close(); | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | It supports: | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sql handlers(dml) -(INSERT/UDPDATE/DELETE) | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | my $sql_handler = $connection->sql_handler(sql => "INSERT INTO emp(empno, ename) VALUES(?, ?)"); | ||||||||||||||||||||||||||||
| 134 | $sql_handler->execute(1, 'Smith'); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | query cursors - SELECT ... FROM ... | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | my $query_cursor = $connection->query_cursor( | ||||||||||||||||||||||||||||
| 139 | sql => " | ||||||||||||||||||||||||||||
| 140 | SELECT t.* FROM ( | ||||||||||||||||||||||||||||
| 141 | SELECT 1 AS col1, 'text 1' AS col2 " . ($dialect eq 'oracle' ? ' FROM dual' : '') . " | ||||||||||||||||||||||||||||
| 142 | UNION ALL | ||||||||||||||||||||||||||||
| 143 | SELECT 2 AS col1, 'text 2' AS col2 " . ($dialect eq 'oracle' ? ' FROM dual' : '') . " | ||||||||||||||||||||||||||||
| 144 | ) t | ||||||||||||||||||||||||||||
| 145 | WHERE 1 = ? " | ||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||
| 147 | my $resultset = $cursor->execute([1]); | ||||||||||||||||||||||||||||
| 148 | while($cursor->fetch()) { | ||||||||||||||||||||||||||||
| 149 | # do some stuff | ||||||||||||||||||||||||||||
| 150 | # $resultset | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | plsql handlers - BEGIN ... END | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | my $plsql_handler = $connection->plsql_handler( | ||||||||||||||||||||||||||||
| 156 | name => 'test_block', | ||||||||||||||||||||||||||||
| 157 | connection => $connection, | ||||||||||||||||||||||||||||
| 158 | plsql => "BEGIN | ||||||||||||||||||||||||||||
| 159 | :var1 := :var2 + :var3; | ||||||||||||||||||||||||||||
| 160 | END;", | ||||||||||||||||||||||||||||
| 161 | bind_variables => { | ||||||||||||||||||||||||||||
| 162 | var1 => {type => 'SQL_INTEGER'}, | ||||||||||||||||||||||||||||
| 163 | var2 => {type => 'SQL_INTEGER'}, | ||||||||||||||||||||||||||||
| 164 | var3 => {type => 'SQL_INTEGER'} | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||
| 167 | my $resultset = $plsql_handler->execute(var2 => 12, var3 => 8); | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Connection is cached by its name. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | DBIx::Connection->new( | ||||||||||||||||||||||||||||
| 173 | name => 'my_connection_name', | ||||||||||||||||||||||||||||
| 174 | dsn => 'dbi:Oracle:localhost:1521/ORCL', | ||||||||||||||||||||||||||||
| 175 | username => 'user', | ||||||||||||||||||||||||||||
| 176 | password => 'password', | ||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | $connection = DBIx::Connection->connection('my_connection_name'); | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | RDBMS session variables supports. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | my $databaseHandler = DBIx::Connection->new( | ||||||||||||||||||||||||||||
| 184 | name => 'my_connection_name', | ||||||||||||||||||||||||||||
| 185 | dsn => 'dbi:Oracle:localhost:1521/ORCL', | ||||||||||||||||||||||||||||
| 186 | username => 'user', | ||||||||||||||||||||||||||||
| 187 | password => 'password', | ||||||||||||||||||||||||||||
| 188 | db_session_variables => { | ||||||||||||||||||||||||||||
| 189 | NLS_DATE_FORMAT => 'DD.MM.YYYY' | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | ) | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | It caches sql statements based on handler's name. | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | $connection->sql_handler(name => 'emp_ins', sql => "INSERT INTO emp(empno, ename) VALUES(?, ?)"); | ||||||||||||||||||||||||||||
| 196 | my $sql_handler = $connection->find_sql_handler('emp_ins'); | ||||||||||||||||||||||||||||
| 197 | $sql_handler->execute(1, 'Smith'); | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | Database usage: | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | This module allows gathering sql statistics issued by application | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | Automatic reporting: | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | $connection->set_collect_statistics(1); | ||||||||||||||||||||||||||||
| 207 | $connection->set_statistics_dir('/sql_usage'); | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Error handler customization: | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | It supports eroror handler customization. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | my $error_handler = sub { | ||||||||||||||||||||||||||||
| 215 | my (self, $message, $sql_handler) = @_; | ||||||||||||||||||||||||||||
| 216 | #do some stuff | ||||||||||||||||||||||||||||
| 217 | }; | ||||||||||||||||||||||||||||
| 218 | $connection->set_custom_error_handler($error_handler); | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | Sequences support: | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | $connection->sequence_value('emp_seq'); | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | Large Object support; | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | $connection->update_lob(lob_test => 'blob_content', $lob_content, {id => 1}, 'doc_size'); | ||||||||||||||||||||||||||||
| 228 | my $lob = $connection->fetch_lob(lob_test => 'blob_content', {id => 1}, 'doc_size'); | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =over | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =item name | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | Connection name. | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 6 | has '$.name'; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =item dsn | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | Database source name. | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 6 | has '$.dsn'; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =item username | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =cut | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 6 | has '$.username'; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =item password | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | =cut | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 6 | has '$.password'; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =item database handler | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 6 | has '$.dbh'; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | =item db_session_variables | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 6 | has '%.db_session_variables'; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =item query_cursors | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =cut | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 6 | has '%.query_cursors' => (item_accessor => '_query_cursor'); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =item sql_handlers | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 6 | has '%.sql_handlers' => (item_accessor => '_sql_handler'); | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | =item plsql_handlers | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 6 | has '%.plsql_handlers' => (item_accessor => '_plsql_handler'); | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =item custom_error_handler | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Callback that overwrites default error_handler on SQLHandler object. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 6 | has '&.custom_error_handler'; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =item stats | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =cut | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 6 | has '%.tracking'; | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | =item action_start_time | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | =cut | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 6 | has '$.action_start_time'; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | =item collect_statistics | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | Flag that indicate if statisitcs are collected. | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =cut | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 6 | has '$.collect_statistics' => (default => 0); | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | =item statistics_dir | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 6 | has '$.statistics_dir'; | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =item in_use | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =cut | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 6 | has '$.in_use'; | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =item is_connected | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | =cut | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 6 | has '$.is_connected'; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =item last_in_use | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | =cut | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 6 | has '$.last_in_use'; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =item no_cache | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | Prepares statements each time, otherwise use prepare statement once and reuse it | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | =cut | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 6 | has '$.no_cache'; | |||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =item _active_transaction | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Flag that indicate that connection has pending transaction | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =cut | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 6 | has '$._active_transaction'; | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | =back | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | =head2 METHODS | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =over | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | =item load_module | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | Loads specyfic rdbms module. | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | { | ||||||||||||||||||||||||||||
| 396 | 6 | my %loaded_modules = (); | |||||||||||||||||||||||||||
| 397 | 0 | ▶ | sub load_module { | ||||||||||||||||||||||||||
|
Subroutine
load_module: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | 0 | my ($self, $module) = @_; | |||||||||||||||||||||||||||
| 399 | 0 | my $rdbms_module = $self->dbms_name . "::" . $module; | |||||||||||||||||||||||||||
| 400 | 0 | ▶ | return $loaded_modules{$rdbms_module} if $loaded_modules{$rdbms_module}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 0 | my $module_name = __PACKAGE__ . "::\u$rdbms_module"; | |||||||||||||||||||||||||||
| 402 | 0 | my $module_to_load = $module_name; | |||||||||||||||||||||||||||
| 403 | 0 | $module_to_load =~ s/::/\//g; | |||||||||||||||||||||||||||
| 404 | 0 | eval { require "${module_to_load}.pm" }; | |||||||||||||||||||||||||||
| 405 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | 0 | $loaded_modules{$rdbms_module} = $module_name; | |||||||||||||||||||||||||||
| 407 | 0 | $module_name; | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | =item connect | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | Connects to the database. | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | =cut | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 6 | ▶ | sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=2 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||||||||
| 418 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 419 | 0 | ▶ | my $dbh = DBI->connect( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | $self->dsn, | ||||||||||||||||||||||||||||
| 421 | $self->username, | ||||||||||||||||||||||||||||
| 422 | $self->password, | ||||||||||||||||||||||||||||
| 423 | { PrintError => 0, AutoCommit => 1}, | ||||||||||||||||||||||||||||
| 424 | ) or $self->error_handler("Cannot connect to database " . $self->dsn . " " . $DBI::errstr); | ||||||||||||||||||||||||||||
| 425 | 0 | $dbh->{Warn} = 0; | |||||||||||||||||||||||||||
| 426 | 0 | $self->set_dbh($dbh); | |||||||||||||||||||||||||||
| 427 | 0 | $self->is_connected(1); | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =item check_connection | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | Checks the database connection and reconnects if necessary. | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =cut | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub check_connection { | ||||||||||||||||||||||||||
|
Subroutine
check_connection: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 438 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 439 | 0 | ▶ | unless (eval { $self->dbh->ping }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 0 | warn "Database disconnected, reconnecting\n"; | |||||||||||||||||||||||||||
| 441 | 0 | $self->connect; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | =item do | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | Executes passed in sql statement. | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =cut | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub do { | ||||||||||||||||||||||||||
|
Subroutine
do: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 453 | 0 | my ($self, $sql) = @_; | |||||||||||||||||||||||||||
| 454 | 0 | $self->record_action_start_time; | |||||||||||||||||||||||||||
| 455 | 0 | ▶ | $self->dbh->do($sql) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | or $self->error_handler($sql); | ||||||||||||||||||||||||||||
| 457 | 0 | $self->record_action_end_time($sql, 'execute'); | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | =item sql_handler | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | Returns a new sql handeler instance. | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | my $sql_handler = $connection->sql_handler( | ||||||||||||||||||||||||||||
| 466 | name => 'emp_ins' | ||||||||||||||||||||||||||||
| 467 | sql => "INSERT INTO emp(empno, ename) VALUES(?, ?)", | ||||||||||||||||||||||||||||
| 468 | ); | ||||||||||||||||||||||||||||
| 469 | $sql_handler->execute(1, 'Smith'); | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | =cut | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 0 | ▶ | sub sql_handler { | ||||||||||||||||||||||||||
|
Subroutine
sql_handler: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 474 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 475 | 0 | ▶ | my $name = $args{name} || $args{sql}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'name'} || $args{'sql'}
MC/DC0%0/2
$args{'name'} || $args{'sql'}
$args{'name'}
$args{'sql'}
Truth table0%0/3
A || B
A= $args{'name'}B= $args{'sql'}
| |||||||||||||||||||||||||||||
| 476 | 0 | my $result = $self->_sql_handler($name); | |||||||||||||||||||||||||||
| 477 | 0 | ▶ | if(! $result || $self->no_cache) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $result or $self->no_cache
MC/DC0%0/2
not $result or $self->no_cache
not $result
$self->no_cache
Truth table0%0/3
not(A) or B
A= not $resultB= $self->no_cache
| |||||||||||||||||||||||||||||
| 478 | 0 | $result = DBIx::SQLHandler->new(connection => $self, %args); | |||||||||||||||||||||||||||
| 479 | 0 | $self->_sql_handler($name, $result); | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | 0 | $result; | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =item find_sql_handler | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | Returns cached sql handler. | ||||||||||||||||||||||||||||
| 488 | Takes sql handler name as parameter. | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | my $sql_handler = $connection->find_sql_handler('emp_ins'); | ||||||||||||||||||||||||||||
| 492 | $sql_handler->execute(1, 'Scott'); | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | =cut | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 0 | ▶ | sub find_sql_handler { | ||||||||||||||||||||||||||
|
Subroutine
find_sql_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 498 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 499 | 0 | $self->_sql_handler($name); | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | =item execute_statement | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | Executes passed in statement. | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | $connection->execute_statement("INSERT INTO emp(empno, ename) VALUES(?, ?)", 1, 'Smith'); | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | =cut | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 0 | ▶ | sub execute_statement { | ||||||||||||||||||||||||||
|
Subroutine
execute_statement: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 512 | 0 | my ($self, $sql, @bind_variables) = @_; | |||||||||||||||||||||||||||
| 513 | 0 | my $sql_handler = $self->sql_handler(sql => $sql); | |||||||||||||||||||||||||||
| 514 | 0 | $sql_handler->execute(@bind_variables); | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | =item query_cursor | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | my $cursor = $connection->query_cursor(sql => "SELECT * FROM emp WHERE empno = ?"); | ||||||||||||||||||||||||||||
| 521 | my @result_set; | ||||||||||||||||||||||||||||
| 522 | $cursor->execute([1], \@result_set); | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | or # my $result_set = $cursor->execute([1]); | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | my $iterator = $cursor->iterator; | ||||||||||||||||||||||||||||
| 527 | while($iterator->()) { | ||||||||||||||||||||||||||||
| 528 | #do some stuff | ||||||||||||||||||||||||||||
| 529 | #@result_set | ||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | # or | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | while($cusor->fetch()) { | ||||||||||||||||||||||||||||
| 535 | #do some stuff | ||||||||||||||||||||||||||||
| 536 | #@result_set | ||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | =cut | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 0 | ▶ | sub query_cursor { | ||||||||||||||||||||||||||
|
Subroutine
query_cursor: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 542 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 543 | 0 | ▶ | my $name = $args{name} || $args{sql}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'name'} || $args{'sql'}
MC/DC0%0/2
$args{'name'} || $args{'sql'}
$args{'name'}
$args{'sql'}
Truth table0%0/3
A || B
A= $args{'name'}B= $args{'sql'}
| |||||||||||||||||||||||||||||
| 544 | 0 | my $result = $self->_query_cursor($name); | |||||||||||||||||||||||||||
| 545 | 0 | ▶ | if(! $result || $self->no_cache) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $result or $self->no_cache
MC/DC0%0/2
not $result or $self->no_cache
not $result
$self->no_cache
Truth table0%0/3
not(A) or B
A= not $resultB= $self->no_cache
| |||||||||||||||||||||||||||||
| 546 | 0 | $result = DBIx::QueryCursor->new(connection => $self, %args); | |||||||||||||||||||||||||||
| 547 | 0 | $self->_query_cursor($name, $result); | |||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||
| 549 | 0 | $result; | |||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | =item find_query_cursor | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | Returns cached query cursor. | ||||||||||||||||||||||||||||
| 556 | Takes query cursor name as parmeter. | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | my $cursor = $connection->find_query_cursor('my_cusror'); | ||||||||||||||||||||||||||||
| 559 | my $result_set = $cursor->execute([1]); | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | =cut | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | 0 | ▶ | sub find_query_cursor { | ||||||||||||||||||||||||||
|
Subroutine
find_query_cursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 564 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 565 | 0 | $self->_query_cursor($name); | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | =item plsql_handler | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | Returns a new plsql handeler instance <DBIx::PLSQLHandler>. | ||||||||||||||||||||||||||||
| 572 | Takes DBIx::PLSQLHandler constructor parameters. | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | my $plsql_handler = $connection->plsql_handler( | ||||||||||||||||||||||||||||
| 575 | name => 'my_plsql', | ||||||||||||||||||||||||||||
| 576 | plsql => "DECLARE | ||||||||||||||||||||||||||||
| 577 | debit_amt CONSTANT NUMBER(5,2) := 500.00; | ||||||||||||||||||||||||||||
| 578 | BEGIN | ||||||||||||||||||||||||||||
| 579 | SELECT a.bal INTO :acct_balance FROM accounts a | ||||||||||||||||||||||||||||
| 580 | WHERE a.account_id = :acct AND a.debit > debit_amt; | ||||||||||||||||||||||||||||
| 581 | :extra_info := 'debit_amt: ' || debit_amt; | ||||||||||||||||||||||||||||
| 582 | END;"); | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | my $result_set = $plsql_handler->execute(acct => 000212); | ||||||||||||||||||||||||||||
| 585 | print $result_set->{acct_balance}; | ||||||||||||||||||||||||||||
| 586 | print $result_set->{extra_info}; | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | =cut | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | 0 | ▶ | sub plsql_handler { | ||||||||||||||||||||||||||
|
Subroutine
plsql_handler: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 591 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 592 | 0 | ▶ | my $name = $args{name} || $args{sql}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{'name'} || $args{'sql'}
MC/DC0%0/2
$args{'name'} || $args{'sql'}
$args{'name'}
$args{'sql'}
Truth table0%0/3
A || B
A= $args{'name'}B= $args{'sql'}
| |||||||||||||||||||||||||||||
| 593 | 0 | my $result = $self->_plsql_handler($name); | |||||||||||||||||||||||||||
| 594 | 0 | ▶ | if(! $result || $self->no_cache) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $result or $self->no_cache
MC/DC0%0/2
not $result or $self->no_cache
not $result
$self->no_cache
Truth table0%0/3
not(A) or B
A= not $resultB= $self->no_cache
| |||||||||||||||||||||||||||||
| 595 | 0 | $result = DBIx::PLSQLHandler->new(connection => $self, %args); | |||||||||||||||||||||||||||
| 596 | 0 | $self->_plsql_handler($name, $result); | |||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||
| 598 | 0 | $result; | |||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | =item find_plsql_handler | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | Returns cached plsql handler, takes name of handler. | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | my $plsql_handler = $connection->find_plsql_handler('my_plsql'); | ||||||||||||||||||||||||||||
| 608 | my $result_set = $plsql_handler->execute(acct => 000212); | ||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | =cut | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | 0 | ▶ | sub find_plsql_handler { | ||||||||||||||||||||||||||
|
Subroutine
find_plsql_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 613 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 614 | 0 | $self->_plsql_handler($name); | |||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | =item record | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | Returns resultset record. Takes sql statement, and bind variables parameters as list. | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | my $resultset = $connection->record("SELECT * FROM emp WHERE ename = ? AND deptno = ? ", 'scott', 10); | ||||||||||||||||||||||||||||
| 623 | #$resultset->{ename} | ||||||||||||||||||||||||||||
| 624 | # do some stuff | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | =cut | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 0 | ▶ | sub record { | ||||||||||||||||||||||||||
|
Subroutine
record: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 629 | 0 | my ($self, $sql, @bind_variables) = @_; | |||||||||||||||||||||||||||
| 630 | 0 | my $query_cursor = $self->query_cursor(sql => $sql); | |||||||||||||||||||||||||||
| 631 | 0 | my $result = $query_cursor->execute(\@bind_variables); | |||||||||||||||||||||||||||
| 632 | 0 | $query_cursor->fetch(); | |||||||||||||||||||||||||||
| 633 | 0 | $result; | |||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | =item begin_work | ||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | Begins transaction. | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | =cut | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | 0 | ▶ | sub begin_work { | ||||||||||||||||||||||||||
|
Subroutine
begin_work: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 644 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 645 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 646 | 0 | ▶ | confess "connection has allready active transaction " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 647 | if $self->_active_transaction; | ||||||||||||||||||||||||||||
| 648 | 0 | $self->_active_transaction(1); | |||||||||||||||||||||||||||
| 649 | 0 | ▶ | my $result = $dbh->begin_work() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 650 | or $self->error_handler("Could not start transaction"); | ||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | =item commit | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | Commits current transaction. | ||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | =cut | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | 0 | ▶ | sub commit { | ||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 661 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 662 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 663 | 0 | $self->_active_transaction(0); | |||||||||||||||||||||||||||
| 664 | 0 | ▶ | $dbh->commit() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 665 | or $self->error_handler("Could not commit current transaction"); | ||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | =item rollback | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | Rollbacks current transaction. | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | =cut | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 0 | ▶ | sub rollback { | ||||||||||||||||||||||||||
|
Subroutine
rollback: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 676 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 677 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 678 | 0 | $self->_active_transaction(0); | |||||||||||||||||||||||||||
| 679 | 0 | ▶ | $dbh->rollback() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 680 | or $self->error_handler("Could not rollback current transaction"); | ||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | { | ||||||||||||||||||||||||||||
| 686 | 6 | my %connections; | |||||||||||||||||||||||||||
| 687 | 6 | my %connections_counter; | |||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | =item initialise | ||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | Initialises connection. | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | =cut | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | 0 | ▶ | sub initialise { | ||||||||||||||||||||||||||
|
Subroutine
initialise: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 697 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 698 | 0 | ▶ | $self->set_name($self->dsn . " " . $self->username) unless $self->name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 699 | 0 | ▶ | if($self->dbh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 700 | 0 | $self->is_connected(1); | |||||||||||||||||||||||||||
| 701 | } else { | ||||||||||||||||||||||||||||
| 702 | 0 | $self->connect; | |||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||
| 704 | $self->set_session_variables($self->db_session_variables) | ||||||||||||||||||||||||||||
| 705 | 0 | ▶ | if (keys %{$self->db_session_variables}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 706 | 0 | $self->_cache_connection; | |||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | =item connection | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | Returns connection object for passed in connection name. | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | =cut | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 0 | ▶ | sub connection { | ||||||||||||||||||||||||||
|
Subroutine
connection: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 718 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||
| 719 | 0 | ▶ | if(!exists($connections_counter{$name})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 720 | 0 | die "connection $name does not exist"; | |||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||
| 722 | 0 | my $result; | |||||||||||||||||||||||||||
| 723 | 0 | ▶ | if ($CONNECTION_POOLING) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 724 | 0 | $result = $connections{"${name}_0"}->_find_connection; | |||||||||||||||||||||||||||
| 725 | 0 | $result->_check_connection; | |||||||||||||||||||||||||||
| 726 | 0 | $result->last_in_use(time); | |||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | } else { | ||||||||||||||||||||||||||||
| 729 | 0 | $result = $connections{"${name}_0"}; | |||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||
| 731 | 0 | $class->check_connnections; | |||||||||||||||||||||||||||
| 732 | 0 | $result; | |||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||
| 736 | =item has_autocomit_mode | ||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | Returns true if connection has autocommit mode | ||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | =cut | ||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | 0 | ▶ | sub has_autocomit_mode { | ||||||||||||||||||||||||||
|
Subroutine
has_autocomit_mode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 743 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 744 | 0 | !! $self->dbh->{AutoCommit}; | |||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | =item _find_connection | ||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||
| 750 | Finds connections | ||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||
| 752 | =cut | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | 0 | ▶ | sub _find_connection { | ||||||||||||||||||||||||||
|
Subroutine
_find_connection: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 755 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 756 | 0 | my $name = $self->name; | |||||||||||||||||||||||||||
| 757 | 0 | ▶ | unless ($self->in_use) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 758 | 0 | $self->set_in_use(1); | |||||||||||||||||||||||||||
| 759 | 0 | return $self; | |||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||
| 761 | 0 | my $counter = $connections_counter{$name}; | |||||||||||||||||||||||||||
| 762 | 0 | for my $i(0 .. $counter) { | |||||||||||||||||||||||||||
| 763 | 0 | my $connection = $connections{"${name}_$i"}; | |||||||||||||||||||||||||||
| 764 | 0 | ▶ | unless ($connection->in_use) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 765 | 0 | $connection->set_in_use(1); | |||||||||||||||||||||||||||
| 766 | 0 | return $connection; | |||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||
| 769 | 0 | $self->_clone_connection(); | |||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||
| 773 | =item _cache_connection | ||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||
| 775 | Checks connection | ||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||
| 777 | =cut | ||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | 0 | ▶ | sub _cache_connection { | ||||||||||||||||||||||||||
|
Subroutine
_cache_connection: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 780 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 781 | 0 | my $name = $self->name; | |||||||||||||||||||||||||||
| 782 | 0 | ▶ | my $counter = exists $connections_counter{$name} ? $connections_counter{$name} + 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 783 | 0 | $connections_counter{$name} = $counter; | |||||||||||||||||||||||||||
| 784 | 0 | $connections{"${name}_${counter}"} = $self; | |||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | =item _clone_connection | ||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||
| 790 | Clones current connection. Returns a new connection object. | ||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||
| 792 | =cut | ||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub _clone_connection { | ||||||||||||||||||||||||||
|
Subroutine
_clone_connection: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 795 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 796 | 0 | my $connection = __PACKAGE__->new( | |||||||||||||||||||||||||||
| 797 | name => $self->name, | ||||||||||||||||||||||||||||
| 798 | dsn => $self->dsn, | ||||||||||||||||||||||||||||
| 799 | username => $self->username, | ||||||||||||||||||||||||||||
| 800 | password => $self->password, | ||||||||||||||||||||||||||||
| 801 | ); | ||||||||||||||||||||||||||||
| 802 | 0 | $connection->set_in_use(1); | |||||||||||||||||||||||||||
| 803 | 0 | $connection; | |||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||
| 807 | =item _check_connection | ||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||
| 809 | Checks connection state. | ||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||
| 811 | =cut | ||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||
| 813 | 0 | ▶ | sub _check_connection { | ||||||||||||||||||||||||||
|
Subroutine
_check_connection: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 814 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 815 | 0 | ▶ | return $self->connect unless $self->is_connected; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 816 | 0 | ▶ | if($self->_is_idled) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 817 | 0 | $self->check_connection; | |||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||
| 822 | =item _is_idled | ||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||
| 824 | returns true if connection is idle. | ||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||
| 826 | =cut | ||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | 0 | ▶ | sub _is_idled { | ||||||||||||||||||||||||||
|
Subroutine
_is_idled: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 830 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 831 | 0 | ▶ | !! (time - ($self->last_in_use || time) > $IDLE_THRESHOLD); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->last_in_use || time
MC/DC0%0/1
$self->last_in_use || time
$self->last_in_use
Truth table0%0/2
A
A= $self->last_in_use
| |||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||
| 835 | =item check_connnections | ||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | Checks all connection and disconnects all inactive for longer the 5 mins | ||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||
| 839 | =cut | ||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | 0 | ▶ | sub check_connnections { | ||||||||||||||||||||||||||
|
Subroutine
check_connnections: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 842 | 0 | my ($class) = @_; | |||||||||||||||||||||||||||
| 843 | 0 | for my $k(keys %connections) { | |||||||||||||||||||||||||||
| 844 | 0 | my $connection = $connections{$k}; | |||||||||||||||||||||||||||
| 845 | 0 | ▶ | $connection->disconnect() if(! $connection->in_use && $connection->_is_idled); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $connection->in_use and $connection->_is_idled
MC/DC0%0/2
not $connection->in_use and $connection->_is_idled
not $connection->in_use
$connection->_is_idled
Truth table0%0/3
not(A) and B
A= not $connection->in_useB= $connection->_is_idled
| |||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | =item close | ||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | Returns connection to the connection pool, | ||||||||||||||||||||||||||||
| 853 | so that connection may be reused by another call Connection->connection('connection_name') | ||||||||||||||||||||||||||||
| 854 | rather then its clone. | ||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | =cut | ||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||
| 858 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 859 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 860 | 0 | ▶ | if ($CONNECTION_POOLING) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 861 | 0 | $self->set_in_use(0); | |||||||||||||||||||||||||||
| 862 | 0 | $self->last_in_use(time); | |||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||
| 869 | =item disconnect | ||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||
| 871 | Disconnects from current database. | ||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||
| 873 | =cut | ||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||
| 875 | 6 | ▶ | sub disconnect { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=3 SCAR=22.8
Pod
documented
| |||||||||||||||||||||||||||||
| 876 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 877 | 0 | ▶ | my $dbh = $self->dbh or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 878 | 0 | $self->set_query_cursors({}); | |||||||||||||||||||||||||||
| 879 | 0 | $self->sql_handlers({}); | |||||||||||||||||||||||||||
| 880 | 0 | $self->is_connected(0); | |||||||||||||||||||||||||||
| 881 | 0 | ▶ | $self->dbh->disconnect | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 882 | or $self->error_handler("Can not disconnect from database: $DBI::errstr"); | ||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||
| 887 | =item dbms_name | ||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | Returns database name | ||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||
| 891 | =cut | ||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||
| 893 | 0 | ▶ | sub dbms_name { | ||||||||||||||||||||||||||
|
Subroutine
dbms_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 894 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 895 | 0 | $self->dbh->get_info($GetInfoType{SQL_DBMS_NAME}); | |||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||
| 899 | =item dbms_version | ||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | Returns database version | ||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | =cut | ||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||
| 905 | 0 | ▶ | sub dbms_version { | ||||||||||||||||||||||||||
|
Subroutine
dbms_version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 906 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 907 | 0 | $self->dbh->get_info($GetInfoType{SQL_DBMS_VER}); | |||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||
| 911 | =item primary_key_info | ||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||
| 913 | Returns primary key information, takes table name | ||||||||||||||||||||||||||||
| 914 | Return array ref (DBI::primary_key_info) | ||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||
| 916 | TABLE_CAT: The catalog identifier. This field is NULL (undef) if not applicable to the data source, which is often the case. This field is empty if not applicable to the table. | ||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||
| 918 | TABLE_SCHEM: The schema identifier. This field is NULL (undef) if not applicable to the data source, and empty if not applicable to the table. | ||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||
| 920 | TABLE_NAME: The table identifier. | ||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||
| 922 | COLUMN_NAME: The column identifier. | ||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||
| 924 | KEY_SEQ: The column sequence number (starting with 1). Note: This field is named ORDINAL_POSITION in SQL/CLI. | ||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||
| 926 | PK_NAME The primary key constraint identifier. This field is NULL (undef) if not applicable to the data source. | ||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||
| 928 | =cut | ||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||
| 930 | 0 | ▶ | sub primary_key_info { | ||||||||||||||||||||||||||
|
Subroutine
primary_key_info: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 931 | 0 | my ($self, $table_name, $schema) = @_; | |||||||||||||||||||||||||||
| 932 | 0 | my $sth = $self->dbh->primary_key_info(undef, $schema, $table_name); | |||||||||||||||||||||||||||
| 933 | 0 | ▶ | my $result = $sth ? $sth->fetchall_arrayref : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 934 | 0 | ▶ | if($result && ! @$result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$result and not @$result
MC/DC0%0/2
$result and not @$result
$result
not @$result
Truth table0%0/3
A and not(B)
A= $resultB= not @$result
| |||||||||||||||||||||||||||||
| 935 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 936 | 0 | ▶ | if($module_name && $module_name->can('primary_key_info')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("primary_key_info")
MC/DC0%0/2
$module_name and $module_name->can("primary_key_info")
$module_name
$module_name->can("primary_key_info")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("primary_key_info")
| |||||||||||||||||||||||||||||
| 937 | 0 | my $sql = $module_name->primary_key_info($schema); | |||||||||||||||||||||||||||
| 938 | 0 | my $cursor = $self->query_cursor(sql => $sql); | |||||||||||||||||||||||||||
| 939 | 0 | ▶ | my $resultset = $cursor->execute([$table_name, ($schema ? $schema : ())]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 940 | 0 | $result = []; | |||||||||||||||||||||||||||
| 941 | 0 | ▶ | while ($cursor->fetch()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 942 | 0 | push @$result, [undef, $schema, $resultset->{table_name}, $resultset->{column_name}, undef, $resultset->{pk_name}]; | |||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||
| 946 | 0 | $result; | |||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||
| 950 | =item primary_key_columns | ||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||
| 952 | Returns primary key columns | ||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||
| 954 | my @primary_key_columns = $connection->primary_key_columns('emp'); | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | =cut | ||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||
| 958 | 0 | ▶ | sub primary_key_columns { | ||||||||||||||||||||||||||
|
Subroutine
primary_key_columns: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 959 | 0 | my ($self, $table_name) = @_; | |||||||||||||||||||||||||||
| 960 | 0 | my ($schema, $table) = ($table_name =~ m/([^\.]+)\.(.+)/); | |||||||||||||||||||||||||||
| 961 | 0 | ▶ | my $info = $self->primary_key_info($schema ? ($schema, $table) : ($table_name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 962 | 0 | map { $_->[3] } @$info; | |||||||||||||||||||||||||||
| 963 | } | ||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||
| 966 | =item table_info | ||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||
| 968 | Returns table info. | ||||||||||||||||||||||||||||
| 969 | See also DBI::table_info | ||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||
| 971 | =cut | ||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||
| 973 | 0 | ▶ | sub table_info { | ||||||||||||||||||||||||||
|
Subroutine
table_info: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 974 | 0 | my ($self, $table_name) = @_; | |||||||||||||||||||||||||||
| 975 | 0 | my $sth = $self->dbh->table_info(undef, undef, $table_name, 'TABLE'); | |||||||||||||||||||||||||||
| 976 | 0 | my $result = $sth->fetchall_arrayref; | |||||||||||||||||||||||||||
| 977 | 0 | ▶ | unless (@$result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 978 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 979 | 0 | ▶ | if ($module_name && $module_name->can('has_table')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("has_table")
MC/DC0%0/2
$module_name and $module_name->can("has_table")
$module_name
$module_name->can("has_table")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("has_table")
| |||||||||||||||||||||||||||||
| 980 | 0 | $result = $module_name->has_table($self, $table_name); | |||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||
| 984 | 0 | $result; | |||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||
| 987 | =item set_session_variables | ||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||
| 989 | =cut | ||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||
| 991 | 0 | ▶ | sub set_session_variables { | ||||||||||||||||||||||||||
|
Subroutine
set_session_variables: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 992 | 0 | my ($self, $db_session_variables) = @_; | |||||||||||||||||||||||||||
| 993 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 994 | 0 | ▶ | if ($module_name && $module_name->can('set_session_variables')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("set_session_variables")
MC/DC0%0/2
$module_name and $module_name->can("set_session_variables")
$module_name
$module_name->can("set_session_variables")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("set_session_variables")
| |||||||||||||||||||||||||||||
| 995 | 0 | $module_name->set_session_variables($self, $db_session_variables); | |||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||
| 1000 | =item has_table | ||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||
| 1002 | Returns true if table exists in database schema | ||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||
| 1004 | =cut | ||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||
| 1006 | 0 | ▶ | sub has_table { | ||||||||||||||||||||||||||
|
Subroutine
has_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1007 | 0 | my ($self, $table_name) = @_; | |||||||||||||||||||||||||||
| 1008 | 0 | my $result = $self->table_info($table_name); | |||||||||||||||||||||||||||
| 1009 | 0 | !! @$result; | |||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||
| 1013 | =item has_sequence | ||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||
| 1015 | Returns true if has sequence | ||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||
| 1017 | =cut | ||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||
| 1019 | 0 | ▶ | sub has_sequence { | ||||||||||||||||||||||||||
|
Subroutine
has_sequence: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1020 | 0 | my ($self, $sequence_name) = @_; | |||||||||||||||||||||||||||
| 1021 | 0 | my $result; | |||||||||||||||||||||||||||
| 1022 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 1023 | 0 | ▶ | if($module_name && $module_name->can('has_sequence')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("has_sequence")
MC/DC0%0/2
$module_name and $module_name->can("has_sequence")
$module_name
$module_name->can("has_sequence")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("has_sequence")
| |||||||||||||||||||||||||||||
| 1024 | 0 | my $record = $self->record($module_name->has_sequence($self->username), $sequence_name); | |||||||||||||||||||||||||||
| 1025 | 0 | $result = $record->{sequence_name}; | |||||||||||||||||||||||||||
| 1026 | } else { | ||||||||||||||||||||||||||||
| 1027 | 0 | warn "not implemented ${module_name}::has_sequence"; | |||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||
| 1029 | 0 | $result; | |||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||
| 1033 | =item sequence_value | ||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||
| 1035 | Returns sequence's value. Takes seqence name. | ||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||
| 1037 | $connection->sequence_value('emp_seq'); | ||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||
| 1039 | =cut | ||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | sub sequence_value { | ||||||||||||||||||||||||||
|
Subroutine
sequence_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1042 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 1043 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 1044 | 0 | my $sql = $module_name->sequence_value($name); | |||||||||||||||||||||||||||
| 1045 | 0 | my ($result) = $self->record($sql); | |||||||||||||||||||||||||||
| 1046 | 0 | $result->{val}; | |||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||
| 1050 | =item reset_sequence | ||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||
| 1052 | Restart sequence. Takes sequence name, initial sequence value, incremental sequence value. | ||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||
| 1054 | $connection->reset_sequence('emp_seq', 1, 1); | ||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||
| 1056 | =cut | ||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||
| 1058 | 0 | ▶ | sub reset_sequence { | ||||||||||||||||||||||||||
|
Subroutine
reset_sequence: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 1059 | 0 | my ($self, $name, $start_with, $increment_by) = @_; | |||||||||||||||||||||||||||
| 1060 | 0 | ▶ | $start_with ||= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$start_with ||= 1
MC/DC0%0/1
$start_with ||= 1
$start_with
Truth table0%0/2
A
A= $start_with
| |||||||||||||||||||||||||||||
| 1061 | 0 | ▶ | $increment_by ||= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$increment_by ||= 1
MC/DC0%0/1
$increment_by ||= 1
$increment_by
Truth table0%0/2
A
A= $increment_by
| |||||||||||||||||||||||||||||
| 1062 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 1063 | 0 | ▶ | if($module_name && $module_name->can('reset_sequence')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("reset_sequence")
MC/DC0%0/2
$module_name and $module_name->can("reset_sequence")
$module_name
$module_name->can("reset_sequence")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("reset_sequence")
| |||||||||||||||||||||||||||||
| 1064 | 0 | my @sqls = $module_name->reset_sequence($name, $start_with, $increment_by, $self); | |||||||||||||||||||||||||||
| 1065 | 0 | $self->do($_) for @sqls; | |||||||||||||||||||||||||||
| 1066 | } else { | ||||||||||||||||||||||||||||
| 1067 | 0 | warn "not implemented ${module_name}::reset_sequence"; | |||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||
| 1072 | =item record_action_start_time | ||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||
| 1074 | Records database operation start time. | ||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||
| 1076 | =cut | ||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||
| 1078 | 0 | ▶ | sub record_action_start_time { | ||||||||||||||||||||||||||
|
Subroutine
record_action_start_time: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1079 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1080 | 0 | ▶ | return unless $self->collect_statistics; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1081 | 0 | $self->action_start_time([gettimeofday]) | |||||||||||||||||||||||||||
| 1082 | } | ||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||
| 1085 | =item record_action_end_time | ||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||
| 1087 | Records database operation end time. | ||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||
| 1089 | =cut | ||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||
| 1091 | 0 | ▶ | sub record_action_end_time { | ||||||||||||||||||||||||||
|
Subroutine
record_action_end_time: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1092 | 0 | my ($self, $name, $method) = @_; | |||||||||||||||||||||||||||
| 1093 | 0 | ▶ | return unless $self->collect_statistics; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1094 | 0 | ▶ | $method ||= [split /::/, [caller(1)]->[3]]->[-1]; | ||||||||||||||||||||||||||
|
Condition0%0/3
$method ||= [split(/::/, [caller 1]->[3], 0)]->[-1]
MC/DC0%0/2
$method ||= [split(/::/, [caller 1]->[3], 0)]->[-1]
$method
[split(/::/, [caller 1]->[3], 0)]->[-1]
Truth table0%0/3
A ||= B
A= $methodB= [split(/::/, [caller 1]->[3], 0)]->[-1]
| |||||||||||||||||||||||||||||
| 1095 | 0 | my $duration = tv_interval($self->action_start_time, [gettimeofday]); | |||||||||||||||||||||||||||
| 1096 | 0 | my $tracking = $self->tracking; | |||||||||||||||||||||||||||
| 1097 | 0 | ▶ | my $info = $tracking->{$name} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$tracking->{$name} ||= {}
MC/DC0%0/1
$tracking->{$name} ||= {}
$tracking->{$name}
Truth table0%0/2
A
A= $tracking->{$name}
| |||||||||||||||||||||||||||||
| 1098 | 0 | ▶ | my $stats = $info->{$method} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$info->{$method} ||= {}
MC/DC0%0/1
$info->{$method} ||= {}
$info->{$method}
Truth table0%0/2
A
A= $info->{$method}
| |||||||||||||||||||||||||||||
| 1099 | 0 | ▶ | unless (exists($info->{" called"})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1100 | 0 | $stats->{" called"} = 1; | |||||||||||||||||||||||||||
| 1101 | 0 | $stats->{min} = $duration; | |||||||||||||||||||||||||||
| 1102 | 0 | $stats->{max} = $duration; | |||||||||||||||||||||||||||
| 1103 | 0 | $stats->{avg} = $duration; | |||||||||||||||||||||||||||
| 1104 | } else { | ||||||||||||||||||||||||||||
| 1105 | 0 | $stats->{" called"}++; | |||||||||||||||||||||||||||
| 1106 | 0 | ▶ | $stats->{min} = $duration if $info->{min} > $duration; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1107 | 0 | ▶ | $stats->{max} = $duration if $info->{max} < $duration; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1108 | 0 | $stats->{avg} = ($info->{avg} + $duration) / 2.0 | |||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||
| 1113 | =item format_usage_report | ||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||
| 1115 | Formats usage report. | ||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||
| 1117 | =cut | ||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||
| 1119 | 0 | ▶ | sub format_usage_report { | ||||||||||||||||||||||||||
|
Subroutine
format_usage_report: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1120 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 1121 | 0 | ▶ | return unless $self->collect_statistics; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1122 | 0 | my $tracking = $self->tracking; | |||||||||||||||||||||||||||
| 1123 | 0 | my $footer = ""; | |||||||||||||||||||||||||||
| 1124 | 0 | my $body = ""; | |||||||||||||||||||||||||||
| 1125 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 1126 | 0 | foreach my $k (sort keys %$tracking) { | |||||||||||||||||||||||||||
| 1127 | 0 | $footer .= "$i: \n " . $k; | |||||||||||||||||||||||||||
| 1128 | 0 | $body .= "SQL id $i:\n"; | |||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | 0 | my $item = $tracking->{$k}; | |||||||||||||||||||||||||||
| 1131 | 0 | foreach my $j(sort keys %$item) { | |||||||||||||||||||||||||||
| 1132 | 0 | $body .= " $j => " ; | |||||||||||||||||||||||||||
| 1133 | 0 | my $details = $item->{$j}; | |||||||||||||||||||||||||||
| 1134 | 0 | foreach my $m (sort keys %$details) { | |||||||||||||||||||||||||||
| 1135 | 0 | $body .= " $m = " . $details->{$m} | |||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||
| 1137 | 0 | $body .= "\n"; | |||||||||||||||||||||||||||
| 1138 | } | ||||||||||||||||||||||||||||
| 1139 | 0 | $body .= "\n"; | |||||||||||||||||||||||||||
| 1140 | 0 | $i++; | |||||||||||||||||||||||||||
| 1141 | } | ||||||||||||||||||||||||||||
| 1142 | 0 | return $self->name . " USAGE REPORT\n" . $body . "SQL:\n" . $footer; | |||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||
| 1147 | =item print_usage_report | ||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||
| 1149 | Prints usage report to stander output. | ||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||
| 1151 | =cut | ||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||
| 1153 | 0 | ▶ | sub print_usage_report { | ||||||||||||||||||||||||||
|
Subroutine
print_usage_report: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1154 | 0 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||
| 1155 | 0 | print $fh $self->format_usage_report; | |||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||
| 1159 | =item print_usage_report_to_file | ||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||
| 1161 | Prints usage report to file | ||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||
| 1163 | =cut | ||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||
| 1165 | 0 | ▶ | sub print_usage_report_to_file { | ||||||||||||||||||||||||||
|
Subroutine
print_usage_report_to_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1166 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 1167 | 0 | my $dir = $self->statistics_dir; | |||||||||||||||||||||||||||
| 1168 | 0 | ▶ | if($self->collect_statistics && -d $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->collect_statistics and -d $dir
MC/DC0%0/2
$self->collect_statistics and -d $dir
$self->collect_statistics
-d $dir
Truth table0%0/3
A and B
A= $self->collect_statisticsB= -d $dir
| |||||||||||||||||||||||||||||
| 1169 | 0 | my $file = $dir . $self->name . "." . $$; | |||||||||||||||||||||||||||
| 1170 | 0 | ▶ | open my $fh, '>>', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1171 | or die "cant open file $file"; | ||||||||||||||||||||||||||||
| 1172 | 0 | $self->print_usage_report; | |||||||||||||||||||||||||||
| 1173 | 0 | ::close($fh); | |||||||||||||||||||||||||||
| 1174 | } | ||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||
| 1177 | =item error_handler | ||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||
| 1179 | Returns error message, takes error message, and optionally bind variables. | ||||||||||||||||||||||||||||
| 1180 | If bind variables are passed in the sql's place holders are replaced with the bind_variables. | ||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||
| 1182 | =cut | ||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||
| 1184 | 0 | ▶ | sub error_handler { | ||||||||||||||||||||||||||
|
Subroutine
error_handler: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1185 | 0 | my ($self, $sql, $sql_handler) = @_; | |||||||||||||||||||||||||||
| 1186 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 1187 | 0 | ▶ | my $message = "[" . $self->name ."]: " . $sql . '\': ' .($dbh ? $dbh->errstr : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1188 | 0 | ▶ | if ($self->custom_error_handler) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1189 | 0 | $self->custom_error_handler->($self, $message, $sql_handler); | |||||||||||||||||||||||||||
| 1190 | } else { | ||||||||||||||||||||||||||||
| 1191 | 0 | confess $message; | |||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||
| 1193 | } | ||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||
| 1196 | =item update_lob | ||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||
| 1198 | Updates lob. | ||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||
| 1200 | Takes table_name, lob column name, lob content, hash_ref to primary key values. optionally lob size column name. | ||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||
| 1202 | $connection->update_lob(lob_test => 'blob_content', $lob_content, {id => 1}, 'doc_size'); | ||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||
| 1204 | =cut | ||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||
| 1206 | 0 | ▶ | sub update_lob { | ||||||||||||||||||||||||||
|
Subroutine
update_lob: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1207 | 0 | my ($self, $table_name, $lob_column_name, $lob, $primary_key_values, $lob_size_column_name) = @_; | |||||||||||||||||||||||||||
| 1208 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 1209 | 0 | ▶ | if($module_name && $module_name->can('update_lob')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("update_lob")
MC/DC0%0/2
$module_name and $module_name->can("update_lob")
$module_name
$module_name->can("update_lob")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("update_lob")
| |||||||||||||||||||||||||||||
| 1210 | 0 | $module_name->update_lob($self, $table_name, $lob_column_name, $lob, $primary_key_values, $lob_size_column_name); | |||||||||||||||||||||||||||
| 1211 | } else { | ||||||||||||||||||||||||||||
| 1212 | 0 | warn "not implemented ${module_name}::update_lob"; | |||||||||||||||||||||||||||
| 1213 | } | ||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | =item fetch_lob | ||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||
| 1218 | Returns lob, takes table name, lob column name, hash ref of primary key values, lob size column name | ||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||
| 1220 | my $lob = $connection->fetch_lob(lob_test => 'blob_content', {id => 1}, 'doc_size'); | ||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||
| 1222 | =cut | ||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||
| 1224 | 0 | ▶ | sub fetch_lob { | ||||||||||||||||||||||||||
|
Subroutine
fetch_lob: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1225 | 0 | my ($self, $table_name, $lob_column_name, $primary_key_values, $lob_size_column_name) = @_; | |||||||||||||||||||||||||||
| 1226 | 0 | my $result; | |||||||||||||||||||||||||||
| 1227 | 0 | my $module_name = $self->load_module('SQL'); | |||||||||||||||||||||||||||
| 1228 | 0 | ▶ | if($module_name && $module_name->can('fetch_lob')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module_name and $module_name->can("fetch_lob")
MC/DC0%0/2
$module_name and $module_name->can("fetch_lob")
$module_name
$module_name->can("fetch_lob")
Truth table0%0/3
A and B
A= $module_nameB= $module_name->can("fetch_lob")
| |||||||||||||||||||||||||||||
| 1229 | 0 | $result = $module_name->fetch_lob($self, $table_name, $lob_column_name, $primary_key_values, $lob_size_column_name); | |||||||||||||||||||||||||||
| 1230 | } else { | ||||||||||||||||||||||||||||
| 1231 | 0 | warn "not implemented ${module_name}::fetch_lob"; | |||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||
| 1233 | 0 | $result; | |||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||
| 1237 | =item _where_clause | ||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||
| 1239 | Returns Where caluse sql fragment, takes hash ref of fields values. | ||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||
| 1241 | =cut | ||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||
| 1243 | 0 | ▶ | sub _where_clause { | ||||||||||||||||||||||||||
|
Subroutine
_where_clause: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 1244 | 0 | my ($self, $field_values) = @_; | |||||||||||||||||||||||||||
| 1245 | 0 | " WHERE " . join(" AND ", map {( $_ . ' = ? ')} sort keys %$field_values); | |||||||||||||||||||||||||||
| 1246 | } | ||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||
| 1249 | =item DESTORY | ||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||
| 1251 | =cut | ||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||
| 1253 | 0 | ▶ | sub DESTORY { | ||||||||||||||||||||||||||
|
Subroutine
DESTORY: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1254 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 1255 | 0 | $self->print_usage_report_to_file; | |||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||
| 1259 | 6 | 1; | |||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||
| 1261 | __END__ | ||||||||||||||||||||||||||||