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