line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE |
2
|
|
|
|
|
|
|
CellBIS::SQL::Abstract::Util; |
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
53
|
use Mojo::Base -base; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
43
|
|
5
|
10
|
|
|
10
|
|
1053
|
use Mojo::Util 'dumper'; |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
8084
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# For "column" with "value" : |
8
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
9
|
|
|
|
|
|
|
sub col_with_val { |
10
|
3
|
|
|
3
|
0
|
25
|
my $self = shift; |
11
|
3
|
|
|
|
|
7
|
my ($column, $value) = @_; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
|
|
7
|
my @data_col = @{$column}; |
|
3
|
|
|
|
|
10
|
|
14
|
3
|
|
|
|
|
7
|
my @data_val = @{$value}; |
|
3
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
my @data |
16
|
3
|
|
|
|
|
12
|
= map { $data_col[$_] . '=\'' . $data_val[$_] . '\'' } 0 .. $#data_col; |
|
9
|
|
|
|
|
36
|
|
17
|
3
|
|
|
|
|
15
|
return @data; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# For onjoin clause : |
21
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
22
|
|
|
|
|
|
|
sub for_onjoin { |
23
|
3
|
|
|
3
|
0
|
17
|
my $self = shift; |
24
|
3
|
|
|
|
|
6
|
my ($options, $table_name) = @_; |
25
|
3
|
|
|
|
|
5
|
my $data = "FROM " . $table_name->[0]->{name}; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
4
|
my %type = %{$options->{typejoin}}; |
|
3
|
|
|
|
|
9
|
|
28
|
3
|
|
|
|
|
5
|
my $join = $options->{join}; |
29
|
3
|
|
|
|
|
3
|
my $size_join = @{$join}; |
|
3
|
|
|
|
|
4
|
|
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
3
|
my @table_list = @{$table_name}; |
|
3
|
|
|
|
|
6
|
|
32
|
3
|
|
|
|
|
4
|
my %list_table = map { $_->{name} => $_ } @{$table_name}; |
|
6
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
4
|
|
33
|
3
|
100
|
|
|
|
6
|
my @get_primaryTbl = grep { $_->{primary} && $_->{primary} == 1 } @table_list; |
|
6
|
|
|
|
|
19
|
|
34
|
3
|
50
|
|
|
|
7
|
@get_primaryTbl = @get_primaryTbl ? @get_primaryTbl : ($table_list[0]); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Check IF founded primary table : |
37
|
3
|
50
|
|
|
|
5
|
if (@get_primaryTbl) { |
38
|
3
|
|
|
|
|
4
|
my $tbl_name = ''; |
39
|
3
|
|
|
|
|
5
|
my $tbl_alias = ''; |
40
|
3
|
|
|
|
|
4
|
my $get_table_data = ''; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# For "FROM TABLE" |
43
|
3
|
|
|
|
|
6
|
$data = "\nFROM $get_primaryTbl[0]->{name}"; |
44
|
3
|
50
|
|
|
|
4
|
if (exists $get_primaryTbl[0]->{alias}) { |
45
|
3
|
|
|
|
|
7
|
$data |
46
|
|
|
|
|
|
|
= "\nFROM $get_primaryTbl[0]->{name} AS $get_primaryTbl[0]->{alias}"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
4
|
my $i = 0; |
50
|
3
|
|
|
|
|
3
|
my $table_join = ''; |
51
|
3
|
|
|
|
|
4
|
my $type_join = ''; |
52
|
3
|
|
|
|
|
6
|
while ($i < $size_join) { |
53
|
3
|
|
|
|
|
5
|
my $get_table = $join->[$i]; |
54
|
3
|
|
|
|
|
4
|
$tbl_name = $get_table->{name}; |
55
|
3
|
|
|
|
|
5
|
$table_join = $get_table->{onjoin}; |
56
|
3
|
|
|
|
|
4
|
$get_table_data = $list_table{$tbl_name}; |
57
|
3
|
|
|
|
|
8
|
$type_join = $self->type_join($type{$tbl_name}); |
58
|
|
|
|
|
|
|
|
59
|
3
|
50
|
|
|
|
5
|
if (exists $get_table_data->{alias}) { |
60
|
3
|
|
|
|
|
5
|
$tbl_alias = $get_table_data->{alias}; |
61
|
3
|
|
|
|
|
7
|
$data .= " $type_join $tbl_name AS $tbl_alias "; |
62
|
3
|
50
|
33
|
|
|
13
|
$data .= "\nON " if ($i > 1 or $i <= ($size_join - 1)); |
63
|
3
|
|
|
|
|
8
|
$data .= join " = ", @$table_join; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
0
|
$data .= " $type_join $tbl_name "; |
67
|
0
|
0
|
0
|
|
|
0
|
$data .= 'ON ' if ($i > 1 or $i <= ($size_join - 1)); |
68
|
0
|
|
|
|
|
0
|
$data .= join " = ", @$table_join; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
5
|
$i++; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
3
|
|
|
|
|
10
|
return $data; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# For create clause query : |
78
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
79
|
|
|
|
|
|
|
sub create_clause { |
80
|
17
|
|
|
17
|
0
|
114
|
my ($self, $clause) = @_; |
81
|
17
|
|
|
|
|
27
|
my $data = ''; |
82
|
17
|
100
|
|
|
|
41
|
if (exists $clause->{'where'}) { |
83
|
12
|
|
|
|
|
39
|
$data .= 'WHERE ' . $clause->{'where'}; |
84
|
|
|
|
|
|
|
} |
85
|
17
|
100
|
100
|
|
|
70
|
if (exists $clause->{'orderby'} and not exists $clause->{'groupby'}) { |
86
|
11
|
|
|
|
|
28
|
$data .= ' ORDER BY ' . $clause->{'orderby'}; |
87
|
|
|
|
|
|
|
} |
88
|
17
|
100
|
100
|
|
|
61
|
if (exists $clause->{'orderby'} and exists $clause->{'groupby'}) { |
89
|
|
|
|
|
|
|
$data |
90
|
|
|
|
|
|
|
.= ' GROUP BY ' |
91
|
|
|
|
|
|
|
. $clause->{'groupby'} |
92
|
|
|
|
|
|
|
. ' ORDER BY ' |
93
|
1
|
|
|
|
|
4
|
. $clause->{'orderby'}; |
94
|
|
|
|
|
|
|
} |
95
|
17
|
50
|
66
|
|
|
51
|
if (exists $clause->{'order'} and exists $clause->{orderby}) { |
96
|
9
|
|
|
|
|
22
|
$data .= ' ' . (uc $clause->{'order'}); |
97
|
|
|
|
|
|
|
} |
98
|
17
|
100
|
|
|
|
40
|
if (exists $clause->{'limit'}) { |
99
|
11
|
|
|
|
|
20
|
$data .= ' LIMIT ' . $clause->{'limit'}; |
100
|
|
|
|
|
|
|
} |
101
|
17
|
|
|
|
|
43
|
return $data; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# for Type Join : |
105
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
106
|
|
|
|
|
|
|
sub type_join { |
107
|
3
|
|
|
3
|
0
|
4
|
my ($self, $type) = @_; |
108
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
8
|
my %data_type = ('left' => "\nLEFT JOIN", 'inner' => "\nINNER JOIN",); |
110
|
3
|
50
|
|
|
|
11
|
return $data_type{$type} if exists $data_type{$type}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# For replace data values "insert" : |
114
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
115
|
|
|
|
|
|
|
sub replace_data_value_insert { |
116
|
1
|
|
|
1
|
0
|
11
|
my $self = shift; |
117
|
1
|
|
|
|
|
2
|
my ($data_value) = @_; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
3
|
my @data = @{$data_value}; |
|
1
|
|
|
|
|
2
|
|
120
|
1
|
100
|
|
|
|
3
|
my @result = map { $_ =~ qr/(date|datetime|now|NOW)/ ? $_ : '?' } @data; |
|
3
|
|
|
|
|
30
|
|
121
|
1
|
|
|
|
|
5
|
@result = grep (defined, @result); |
122
|
1
|
|
|
|
|
3
|
return @result; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# For replace data values "insert" in no prepare statement : |
126
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
127
|
|
|
|
|
|
|
sub replace_data_value_insert_no_pre_st { |
128
|
1
|
|
|
1
|
0
|
7
|
my $self = shift; |
129
|
1
|
|
|
|
|
2
|
my ($data_value) = @_; |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
2
|
my @data = @{$data_value}; |
|
1
|
|
|
|
|
3
|
|
132
|
|
|
|
|
|
|
my @result |
133
|
1
|
50
|
|
|
|
3
|
= map { $_ =~ qr/(date|datetime|now|NOW)/ ? $_ : "'" . $_ . "'" } @data; |
|
3
|
|
|
|
|
20
|
|
134
|
1
|
|
|
|
|
4
|
@result = grep (defined, @result); |
135
|
1
|
|
|
|
|
5
|
return @result; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |