line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jifty::DBI::Handle::mysql; |
2
|
1
|
|
|
1
|
|
1175
|
use Jifty::DBI::Handle; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
|
|
|
|
|
|
@ISA = qw(Jifty::DBI::Handle); |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
37
|
use vars qw($VERSION @ISA $DBIHandle $DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
6
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
542
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Jifty::DBI::Handle::mysql - A mysql specific Handle object |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module provides a subclass of L that |
18
|
|
|
|
|
|
|
compensates for some of the idiosyncrasies of MySQL. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 insert |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Takes a table name as the first argument and assumes that the rest of |
27
|
|
|
|
|
|
|
the arguments are an array of key-value pairs to be inserted. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
If the insert succeeds, returns the id of the insert, otherwise, |
30
|
|
|
|
|
|
|
returns a L object with the error reported. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub insert { |
35
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $sth = $self->SUPER::insert(@_); |
38
|
0
|
0
|
|
|
|
|
if ( !$sth ) { |
39
|
0
|
|
|
|
|
|
return ($sth); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->{'id'} = $self->dbh->{'mysql_insertid'}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Yay. we get to work around mysql_insertid being null some of the time :/ |
45
|
0
|
0
|
|
|
|
|
unless ( $self->{'id'} ) { |
46
|
0
|
|
|
|
|
|
$self->{'id'} = $self->fetch_result('SELECT LAST_INSERT_ID()'); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
warn "$self no row id returned on row creation" unless ( $self->{'id'} ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return ( $self->{'id'} ); #Add Succeded. return the id |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 database_version |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Returns the mysql version, trimming off any -foo identifier |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub database_version { |
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
my $v = $self->SUPER::database_version(@_); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$v =~ s/\-.*$//; |
64
|
0
|
|
|
|
|
|
return ($v); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 case_sensitive |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Returns undef, since mysql's searches are not case sensitive by default |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub case_sensitive { |
74
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
return (undef); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _optimize_joins { |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
0
|
0
|
|
|
|
|
return $self->SUPER::_optimize_joins if $self->database_version =~ /^[34]/; |
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 rename_column ( table => $table, column => $old_column, to => $new_column ) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
rename column, die if fails |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub rename_column { |
91
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my %args = ( |
93
|
|
|
|
|
|
|
table => undef, |
94
|
|
|
|
|
|
|
column => undef, |
95
|
|
|
|
|
|
|
to => undef, |
96
|
|
|
|
|
|
|
@_ |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my ($table, $column, $to) = @args{'table', 'column', 'to'}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# XXX, FIXME, TODO: this is stupid parser of CREATE TABLE, this should be something based on |
102
|
|
|
|
|
|
|
# column_info, schema tables and show fields. The closest thing is RT 3.8/etc/upgrade/upgrade-mysql-schema.pl |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $create_table = ($self->simple_query("SHOW CREATE TABLE $table")->fetchrow_array)[1]; |
105
|
0
|
0
|
|
|
|
|
$create_table =~ /create\s+table\s+\S+\s*\((.*)\)/ims |
106
|
|
|
|
|
|
|
or die "Cannot find 'CREATE TABLE' statement in schema for '$table': $create_table"; |
107
|
0
|
|
|
|
|
|
$create_table = $1; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
my ($column_info) = ($create_table =~ /`$column`(.*?)(?:,|$)/i) |
110
|
|
|
|
|
|
|
or die "Cannot find column '$column' in $create_table"; |
111
|
0
|
|
|
|
|
|
my $sth = $self->simple_query("ALTER TABLE $table CHANGE $column $to $column_info"); |
112
|
0
|
0
|
|
|
|
|
die "Cannot rename column '$column' in table '$table' to '$to': ". $self->dbh->errstr |
113
|
|
|
|
|
|
|
unless $sth; |
114
|
0
|
|
|
|
|
|
return $sth; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |