line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Connection::MySQL::SQL; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3998
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Abstract::Meta::Class ':all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
181
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp 'confess'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
653
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub sequence_value { |
42
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub reset_sequence { |
54
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub set_session_variables { |
70
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub update_lob { |
86
|
0
|
|
|
0
|
1
|
|
my ($class, $connection, $table_name, $lob_column_name, $lob, $primary_key_values, $lob_size_column_name) = @_; |
87
|
0
|
0
|
0
|
|
|
|
confess "missing primary key for lob update on ${table_name}.${lob_column_name}" |
88
|
|
|
|
|
|
|
if (!$primary_key_values || ! (%$primary_key_values)); |
89
|
0
|
0
|
|
|
|
|
confess "missing lob size column name" unless $lob_size_column_name; |
90
|
0
|
|
|
|
|
|
my $sql = "UPDATE ${table_name} SET ${lob_column_name} = ? "; |
91
|
0
|
0
|
|
|
|
|
$sql .= ($lob_size_column_name ? ", ${lob_size_column_name} = ? " : '') |
92
|
|
|
|
|
|
|
. $connection->_where_clause($primary_key_values); |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
$connection->dbh->{max_allowed_packet} = length($lob) if $lob; |
95
|
0
|
|
|
|
|
|
my $bind_counter = 1; |
96
|
0
|
|
|
|
|
|
my $sth = $connection->dbh->prepare($sql); |
97
|
0
|
|
|
|
|
|
$sth->bind_param($bind_counter++ ,$lob); |
98
|
0
|
0
|
|
|
|
|
$sth->bind_param($bind_counter++ , ($lob ? length($lob) : 0)) if $lob_size_column_name; |
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub fetch_lob { |
116
|
0
|
|
|
0
|
1
|
|
my ($class, $connection, $table_name, $lob_column_name, $primary_key_values) = @_; |
117
|
0
|
0
|
0
|
|
|
|
confess "missing primary key for lob update on ${table_name}.${lob_column_name}" |
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); |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$record->{lob_content}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |