| 1 | package DBIx::Connection::MySQL::SQL; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Abstract::Meta::Class ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | $VERSION = 0.03; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | DBIx::Connection::MySQL::SQL - MySQL catalog sql abstractaction layer. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | use DBIx::Connection::MySQL::SQL; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Represents sql abstractaction layer | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 EXPORT | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | None | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head2 METHODS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =over | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =item sequence_value | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Returns sql statement that returns next sequence value | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub sequence_value { | ||||||||||||||||||||||||||
|
Subroutine
sequence_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 43 | 0 | confess "not supported"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item reset_sequence | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Returns sql statement that restarts sequence. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub reset_sequence { | ||||||||||||||||||||||||||
|
Subroutine
reset_sequence: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($class, $name, $start_with, $increment_by, $connection) = @_; | |||||||||||||||||||||||||||
| 55 | 0 | $connection->do("ALTER TABLE $name AUTO_INCREMENT = ${start_with}"); | |||||||||||||||||||||||||||
| 56 | 0 | (); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item set_session_variables | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Iniitialise session variable. | ||||||||||||||||||||||||||||
| 63 | It uses the following command pattern: | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | SET @@local.variable = value; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =cut | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub set_session_variables { | ||||||||||||||||||||||||||
|
Subroutine
set_session_variables: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($class, $connection, $db_session_variables) = @_; | |||||||||||||||||||||||||||
| 71 | 0 | my $sql = ""; | |||||||||||||||||||||||||||
| 72 | $sql .= 'SET @@local.' . $_ . " = " . $db_session_variables->{$_} . ";" | ||||||||||||||||||||||||||||
| 73 | 0 | for keys %$db_session_variables; | |||||||||||||||||||||||||||
| 74 | 0 | $connection->do($sql); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =item update_lob | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Updates lob. (Large Object) | ||||||||||||||||||||||||||||
| 81 | Takes connection object, table name, lob column_name, lob conetent, hash_ref to primary key values. optionally lob size column name. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub update_lob { | ||||||||||||||||||||||||||
|
Subroutine
update_lob: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($class, $connection, $table_name, $lob_column_name, $lob, $primary_key_values, $lob_size_column_name) = @_; | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | confess "missing primary key for lob update on ${table_name}.${lob_column_name}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$primary_key_values and %$primary_key_values
MC/DC0%0/2
$primary_key_values and %$primary_key_values
$primary_key_values
%$primary_key_values
Truth table0%0/3
A and B
A= $primary_key_valuesB= %$primary_key_values
| |||||||||||||||||||||||||||||
| 88 | if (!$primary_key_values || ! (%$primary_key_values)); | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | confess "missing lob size column name" unless $lob_size_column_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | my $sql = "UPDATE ${table_name} SET ${lob_column_name} = ? "; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | $sql .= ($lob_size_column_name ? ", ${lob_size_column_name} = ? " : '') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | . $connection->_where_clause($primary_key_values); | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $connection->dbh->{max_allowed_packet} = length($lob) if $lob; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | my $bind_counter = 1; | |||||||||||||||||||||||||||
| 96 | 0 | my $sth = $connection->dbh->prepare($sql); | |||||||||||||||||||||||||||
| 97 | 0 | $sth->bind_param($bind_counter++ ,$lob); | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | $sth->bind_param($bind_counter++ , ($lob ? length($lob) : 0)) if $lob_size_column_name; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 99 | 0 | for my $k (sort keys %$primary_key_values) { | |||||||||||||||||||||||||||
| 100 | 0 | $sth->bind_param($bind_counter++ , $primary_key_values->{$k}); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | $sth->execute(); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =item fetch_lob | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Retrieves lob. | ||||||||||||||||||||||||||||
| 111 | Takes connection object, table name, lob column_name, hash_ref to primary key values | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub fetch_lob { | ||||||||||||||||||||||||||
|
Subroutine
fetch_lob: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my ($class, $connection, $table_name, $lob_column_name, $primary_key_values) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | confess "missing primary key for lob update on ${table_name}.${lob_column_name}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$primary_key_values and %$primary_key_values
MC/DC0%0/2
$primary_key_values and %$primary_key_values
$primary_key_values
%$primary_key_values
Truth table0%0/3
A and B
A= $primary_key_valuesB= %$primary_key_values
| |||||||||||||||||||||||||||||
| 118 | if (! $primary_key_values || ! (%$primary_key_values)); | ||||||||||||||||||||||||||||
| 119 | 0 | my $sql = "SELECT ${lob_column_name} as lob_content FROM ${table_name} " . $connection->_where_clause($primary_key_values); | |||||||||||||||||||||||||||
| 120 | 0 | my $record = $connection->record($sql, map { $primary_key_values->{$_}} sort keys %$primary_key_values); | |||||||||||||||||||||||||||
| 121 | 0 | $record->{lob_content}; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||