blib/lib/DBIx/DBO/DBD/mysql.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 118 CC 7 SCAR 16.9
CC
7
Cov
0%
_calc_found_rows
12.0
_get_table_schema
6.0
_set_table_key_info
6.0
CRAP 5.4
1 use 5.014;
2 use warnings;
3  
4 package # hide from PAUSE
5 DBIx::DBO::DBD::mysql;
6 use Carp qw(croak);
7  
8 sub _get_table_schema {
9 my($class, $me, $table) = @_;
10  
11 my($schema) = $me->selectrow_array('SELECT DATABASE()');
12 croak 'Invalid table: '.$class->_qi($me, $table).' (No database selected)' unless defined $schema;
13 return $schema;
14 }
15  
16 sub _set_table_key_info {
17 my($class, $me, $schema, $table, $h) = @_;
18  
19 if (my $keys = $me->rdbh->primary_key_info(undef, $schema, $table)) {
20 $h->{PrimaryKeys}[$_->{KEY_SEQ} - 1] = $_->{COLUMN_NAME} for @{$keys->fetchall_arrayref({})};
21 } else {
22 # Support for older DBD::mysql - Simulate primary_key_info()
23 local $me->rdbh->{FetchHashKeyName} = 'NAME_lc';
24 my $info = $me->rdbh->selectall_arrayref('SHOW KEYS FROM '.$class->_qi($me, $schema, $table), {Columns => {}});
25 $_->{key_name} eq 'PRIMARY' and $h->{PrimaryKeys}[$_->{seq_in_index} - 1] = $_->{column_name} for @$info;
26 }
27 }
28  
29 sub _unquote_table {
30 $_[2] =~ /^(?:(`|"|)(.+)\1\.|)(`|"|)(.+)\3$/ or croak "Invalid table: \"$_[2]\"";
31 return ($2, $4);
32 }
33  
34 sub _save_last_insert_id {
35 my($class, $me, $sth) = @_;
36  
37 return $sth->{mysql_insertid};
38 }
39  
40 sub _get_config {
41 my $class = shift;
42 my $val = $class->SUPER::_get_config(@_);
43 # In MySQL support for LIMIT on UPDATE/DELETE is on by default
44 $val // ($_[0] eq 'LimitRowUpdate' || $_[0] eq 'LimitRowDelete' || undef);
45 }
46  
47 # Query
48 sub _calc_found_rows {
49 my($class, $me) = @_;
50  
51 # If sth and sql =~ SQL_CALC_FOUND_ROWS, then SELECT FOUND_ROWS
52 # If no sth and CalcFoundRows, then run, and SELECT FOUND_ROWS
53 if ($me->{sth}
54 ? $me->{sql} =~ / SQL_CALC_FOUND_ROWS /
55 : ($me->config('CalcFoundRows') and $me->run or croak $me->rdbh->errstr)) {
56 return $me->{Found_Rows} = ($class->_selectrow_array($me, 'SELECT FOUND_ROWS()'))[0];
57 }
58 $class->SUPER::_calc_found_rows($me);
59 }
60  
61 sub _build_sql_select {
62 my($class, $me) = @_;
63  
64 my $sql = $class->SUPER::_build_sql_select($me);
65 $sql =~ s/^SELECT /SELECT SQL_CALC_FOUND_ROWS / if $me->config('CalcFoundRows') and not $me->{build_data}{_super_query};
66 return $sql;
67 }
68  
69 # MySQL doesn't allow the use of aliases in the WHERE clause
70 sub _alias_preference {
71 my($class, $me, $method) = @_;
72 $method ||= ((caller(2))[3] =~ /\b(\w+)$/)[0];
73 return 0 if $method eq 'join_on' or $method eq 'where';
74 return 1;
75 }
76  
77 sub _bulk_insert {
78 shift->_fast_bulk_insert(@_);
79 }
80  
81 1;