DBBrowser/Table/Extensions/ScalarFunctions.pm untested

filter: Statementstmt 0.0% 0 / 318 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 408 CC 22 SCAR 53.2
CC
22
Cov
0%
scalar_function
380.0
__available_functions
20.0
new
2.0
CRAP 203.5
1 package # hide from PAUSE
2 App::DBBrowser::Table::Extensions::ScalarFunctions;
3  
4 use warnings;
5 use strict;
6 use 5.016;
7  
8 use Term::Choose qw();
9  
10 use App::DBBrowser::Auxil;
11 use App::DBBrowser::Table::Extensions;
12 use App::DBBrowser::Table::Extensions::ScalarFunctions::Date;
13 use App::DBBrowser::Table::Extensions::ScalarFunctions::Numeric;
14 use App::DBBrowser::Table::Extensions::ScalarFunctions::Other;
15 use App::DBBrowser::Table::Extensions::ScalarFunctions::String;
16 use App::DBBrowser::Table::Extensions::ScalarFunctions::To;
17 use App::DBBrowser::Table::Extensions::ScalarFunctions::GetArguments;
18  
19 my $charindex = 'CHARINDEX';
20 my $char_length = 'CHAR_LENGTH';
21 my $concat = 'CONCAT';
22 my $datalength = 'DATALENGTH';
23 my $instr = 'INSTR';
24 my $left = 'LEFT';
25 my $len = 'LEN';
26 my $length = 'LENGTH';
27 my $lengthb = 'LENGTHB';
28 my $locate = 'LOCATE';
29 my $lower = 'LOWER';
30 my $lpad = 'LPAD';
31 my $ltrim = 'LTRIM';
32 my $octet_length = 'OCTET_LENGTH';
33 my $position = 'POSITION';
34 my $replace = 'REPLACE';
35 my $reverse = 'REVERSE';
36 my $right = 'RIGHT';
37 my $rpad = 'RPAD';
38 my $rtrim = 'RTRIM';
39 my $substring = 'SUBSTRING';
40 my $substr = 'SUBSTR';
41 my $trim = 'TRIM';
42 my $truncate = 'TRUNCATE';
43 my $trunc = 'TRUNC';
44 my $upper = 'UPPER';
45  
46 my $abs = 'ABS';
47 my $ceil = 'CEIL';
48 my $ceiling = 'CEILING';
49 my $exp = 'EXP';
50 my $floor = 'FLOOR';
51 my $ln = 'LN';
52 my $log = 'LOG';
53 my $mod = 'MOD';
54 my $power = 'POWER';
55 my $rand = 'RAND';
56 my $round = 'ROUND';
57 my $sign = 'SIGN';
58 my $sqrt = 'SQRT';
59  
60 my $age = 'AGE';
61 my $current = 'CURRENT';
62 my $current_date = 'CURRENT_DATE';
63 my $current_timestamp = 'CURRENT_TIMESTAMP';
64 my $current_time = 'CURRENT_TIME';
65 my $date = 'DATE';
66 my $datediff = 'DATEDIFF';
67 my $datetime = 'DATETIME';
68 my $date_add = 'DATE_ADD';
69 my $date_part = 'DATE_PART';
70 my $date_subtract = 'DATE_SUBTRACT';
71 my $date_trunc = 'DATE_TRUNC';
72 my $day = 'DAY';
73 my $days = 'DAYS';
74 my $dayname = 'DAYNAME';
75 my $dayofweek = 'DAYOFWEEK';
76 my $dayofweek_iso = 'DAYOFWEEK_ISO';
77 my $dayofyear = 'DAYOFYEAR';
78 my $extract = 'EXTRACT';
79 my $julian_day = 'JULIAN_DAY';
80 my $last_day = 'LAST_DAY';
81 my $month = 'MONTH';
82 my $monthname = 'MONTHNAME';
83 my $months_between = 'MONTHS_BETWEEN';
84 my $now = 'NOW';
85 my $quarter = 'QUARTER';
86 my $timediff = 'TIMEDIFF';
87 my $timestampdiff = 'TIMESTAMPDIFF';
88 my $time = 'TIME';
89 my $week = 'WEEK';
90 my $weekday = 'WEEKDAY';
91 my $week_iso = 'WEEK_ISO';
92 my $year = 'YEAR';
93  
94 my $date_format = 'DATE_FORMAT';
95 my $epoch_to_date = 'EPOCH_TO_DATE';
96 my $epoch_to_datetime = 'EPOCH_TO_DATETIME';
97 my $epoch_to_timestamp = 'EPOCH_TO_TIMESTAMP';
98 my $format = 'FORMAT';
99 my $str = 'STR';
100 my $strftime = 'STRFTIME';
101 my $strptime = 'STRPTIME';
102 my $str_to_date = 'STR_TO_DATE';
103 my $to_char = 'TO_CHAR';
104 my $to_date = 'TO_DATE';
105 my $to_epoch = 'TO_EPOCH';
106 my $to_number = 'TO_NUMBER';
107 my $to_timestamp = 'TO_TIMESTAMP';
108 my $to_timestamp_tz = 'TO_TIMESTAMP_TZ';
109 my $unixepoch = 'UNIXEPOCH';
110  
111 my $cast = 'CAST';
112 my $coalesce = 'COALESCE';
113  
114  
115 sub new {
116 my ( $class, $info, $options, $d ) = @_;
117 bless {
118 i => $info,
119 o => $options,
120 d => $d
121 }, $class;
122 }
123  
124  
125 sub __available_functions {
126 my ( $sf, $type ) = @_;
127 my $functions = {
128 string => {
129 $charindex => [ undef , undef , undef , undef, undef , undef , undef, undef , undef , 'MSSQL' ],
130 $char_length => [ undef , 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', undef , undef ],
131 $concat => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
132 $datalength => [ undef , undef , undef , undef, undef , undef , undef, undef , undef , 'MSSQL' ],
133 $instr => [ 'SQLite', undef , undef , undef, undef , undef , 'DB2' , 'Informix', 'Oracle', undef ], # DuckDB
134 $left => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', undef , 'MSSQL' ],
135 $len => [ undef , undef , undef , undef, undef , undef , undef, undef , undef , 'MSSQL' ],
136 $length => [ 'SQLite', undef , undef , undef, undef , undef , undef, undef , 'Oracle', undef ], # Pg, DuckDB
137 $lengthb => [ undef , undef , undef , undef, undef , undef , undef, undef , 'Oracle', undef ],
138 $locate => [ undef , 'mysql', 'MariaDB', undef, undef , undef , undef, undef , undef , undef ], # DB2
139 $lower => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
140 $lpad => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', undef ],
141 $ltrim => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', undef , 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
142 $octet_length => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , undef , 'Firebird', 'DB2' , 'Informix', undef , undef ], # DuckDB: bit_length('abc')
143 $position => [ undef , 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , undef , undef ],
144 $replace => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
145 $reverse => [ undef , 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', undef, 'Informix', 'Oracle', 'MSSQL' ],
146 $right => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', undef , 'MSSQL' ],
147 $rpad => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', undef ],
148 $rtrim => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', undef , 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
149 $substring => [ undef , undef , undef , undef, undef , 'Firebird', undef, undef , undef , 'MSSQL' ], # mysql, MariaDB, Pg, DB2, Informix, DuckDB
150 $substr => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', undef , 'DB2' , 'Informix', 'Oracle', undef ],
151 $trim => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
152 $upper => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
153 },
154 numeric => {
155 $abs => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
156 $ceil => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', undef ],
157 $ceiling => [ undef , undef , undef , undef, undef , undef , undef, undef , undef , 'MSSQL' ],
158 $exp => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
159 $floor => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
160 $ln => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', undef ],
161 $log => [ undef , undef , undef , undef, undef , undef , undef, undef , undef , 'MSSQL' ],
162 $mod => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
163 $power => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
164 $rand => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , 'Oracle', 'MSSQL' ],
165 $round => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
166 $sign => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
167 $sqrt => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
168 $truncate => [ undef , 'mysql', 'MariaDB', undef, undef , undef , 'DB2' , undef , undef , undef ],
169 $trunc => [ 'SQLite', undef , undef , 'Pg' , 'DuckDB', 'Firebird', undef, 'Informix', 'Oracle', 'MSSQL' ], # DB2
170 },
171 date => {
172 $age => [ undef , undef , undef , 'Pg' , 'DuckDB', undef , 'DB2' , undef , undef , undef ],
173 $current => [ undef , undef , undef , undef, undef , undef , undef, 'Informix', undef , undef ],
174 $current_date => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , 'Oracle', 'MSSQL' ],
175 $current_time => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , 'Oracle', undef ],
176 $current_timestamp => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , 'Oracle', 'MSSQL' ],
177 $date => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', undef , 'DB2' , 'Informix', undef , undef ],
178 $datediff => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , undef , 'MSSQL' ],
179 $datetime => [ 'SQLite', undef , undef , undef, undef , undef , 'DB2' , undef , undef , undef ],
180 $date_add => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
181 $date_part => [ undef , undef , undef , 'Pg' , 'DuckDB', undef , undef, undef , undef , 'MSSQL' ], # DB2
182 $date_subtract => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
183 $date_trunc => [ undef , undef , undef , 'Pg' , 'DuckDB', undef , 'DB2' , undef , undef , 'MSSQL' ],
184 $day => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , 'Informix', undef , 'MSSQL' ],
185 $dayname => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
186 $dayofweek => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
187 $dayofweek_iso => [ undef , undef , undef , undef, undef , undef , 'DB2' , undef , undef , undef ],
188 $dayofyear => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
189 $days => [ undef , undef , undef , undef, undef , undef , 'DB2' , undef , undef , undef ],
190 $extract => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', undef ],
191 $julian_day => [ 'SQLite', undef , undef , undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
192 $last_day => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , 'Informix', 'Oracle', undef ], # firebird 4.0
193 $month => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , 'Informix', undef , 'MSSQL' ],
194 $monthname => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
195 $months_between => [ undef , undef , undef , undef, undef , undef , 'DB2' , 'Informix', 'Oracle', undef ],
196 $quarter => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
197 $time => [ 'SQLite', 'mysql', 'MariaDB', undef, undef , undef , 'DB2' , undef , undef , undef ],
198 $timediff => [ 'SQLite', 'mysql', 'MariaDB', undef, undef , undef , undef, undef , undef , undef ],
199 $timestampdiff => [ undef , 'mysql', 'MariaDB', undef, undef , undef , undef, undef , undef , undef ], # DB2
200 $week => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , undef , undef , undef ],
201 $weekday => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , undef, undef , undef , undef ],
202 $week_iso => [ undef , undef , undef , undef, undef , undef , 'DB2' , undef , undef , undef ],
203 $year => [ undef , 'mysql', 'MariaDB', undef, 'DuckDB', undef , 'DB2' , 'Informix', undef , 'MSSQL' ],
204 },
205 to => {
206 $epoch_to_date => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
207 $epoch_to_datetime => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ], ##
208 $epoch_to_timestamp => [ undef , undef , undef , 'Pg' , 'DuckDB', 'Firebird', undef, undef , 'Oracle', 'MSSQL' ],
209 $to_char => [ undef , undef , undef , 'Pg' , undef , undef , 'DB2' , 'Informix', 'Oracle', undef ], # MariaDB
210 $to_date => [ undef , undef , undef , 'Pg' , undef , undef , 'DB2' , 'Informix', 'Oracle', undef ], # MariaDB
211 $to_timestamp => [ undef , undef , undef , 'Pg' , 'DuckDB', undef , undef, undef , 'Oracle', undef ], # DB2 # DuckDB: epoch to timestamp
212 $to_timestamp_tz => [ undef , undef , undef , undef, undef , undef , undef, undef , 'Oracle', undef ],
213 $to_number => [ undef , undef , 'MariaDB', 'Pg' , undef , undef , 'DB2' , 'Informix', 'Oracle', undef ],
214 $to_epoch => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , undef , 'Oracle', 'MSSQL' ],
215 $str => [ undef , undef , undef , undef, undef , undef , undef, undef , undef , 'MSSQL' ],
216 $strftime => [ 'SQLite', undef , undef , undef, 'DuckDB', undef , undef, undef , undef , undef ],
217 $strptime => [ undef , undef , undef , undef, 'DuckDB', undef , undef, undef , undef , undef ],
218 $date_format => [ undef , 'mysql', 'MariaDB', undef, undef , undef , undef, undef , undef , undef ],
219 $format => [ undef , 'mysql', 'MariaDB', undef, undef , undef , undef, undef , undef , 'MSSQL' ], # DuckDB: construct formatted strings
220 $str_to_date => [ undef , 'mysql', 'MariaDB', undef, undef , undef , undef, undef , undef , undef ],
221 $unixepoch => [ 'SQLite', undef , undef , undef, undef , undef , undef, undef , undef , undef ],
222 },
223 other => {
224 $cast => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
225 $coalesce => [ 'SQLite', 'mysql', 'MariaDB', 'Pg' , 'DuckDB', 'Firebird', 'DB2' , 'Informix', 'Oracle', 'MSSQL' ],
226 },
227 };
228  
229 my $dbms = $sf->{i}{dbms};
230 my $index = {
231 SQLite => 0, mysql => 1, MariaDB => 2, Pg => 3, DuckDB => 4, Firebird => 5, DB2 => 6, Informix => 7, Oracle => 8, MSSQL => 9,
232 };
233 my $avail_functions = [];
234 for my $func ( sort keys %{$functions->{$type}} ) {
235 if ( ! exists $index->{$dbms} ) {
236 # return all functions
237 push @$avail_functions, $func;
238 }
239 elsif ( $functions->{$type}{$func}[$index->{$dbms}] ) {
240 push @$avail_functions, $func;
241 }
242 }
243 if ( $sf->{i}{driver} eq 'ODBC' && $dbms eq 'SQLite' ) {
244 $avail_functions = [ grep { ! /^(?:$trunc|$octet_length)\z/ } @$avail_functions ]; # sqlite_create_functions
245 }
246 return $avail_functions;
247 }
248  
249  
250 sub scalar_function {
251 my ( $sf, $sql, $clause, $cols, $r_data ) = @_;
252 my $tc = Term::Choose->new( $sf->{i}{tc_default} );
253 my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, $sf->{d} );
254 my $ext = App::DBBrowser::Table::Extensions->new( $sf->{i}, $sf->{o}, $sf->{d} );
255 my $dbms = $sf->{i}{dbms};
256 my $hidden = 'Scalar functions:';
257 my $info_sql = $ax->get_sql_info( $sql );
258 my $old_idx_cat = 1;
259  
260 CATEGORY: while( 1 ) {
261 my $info = $info_sql . $ext->nested_func_info( $r_data );
262 my @pre = ( $hidden, undef );
263 my $menu = [ @pre, '- String', '- Numeric', '- Date', '- To', '- Other' ];
264 # Choose
265 my $idx_cat = $tc->choose(
266 $menu,
267 { %{$sf->{i}{lyt_v}}, info => $info, prompt => '', index => 1, default => $old_idx_cat, undef => '<=' }
268 );
269 if ( ! defined $idx_cat || ! defined $menu->[$idx_cat] ) {
270 return;
271 }
272 if ( $sf->{o}{G}{menu_memory} ) {
273 if ( $old_idx_cat == $idx_cat && ! $ENV{TC_RESET_AUTO_UP} ) {
274 $old_idx_cat = 1;
275 next CATEGORY;
276 }
277 $old_idx_cat = $idx_cat;
278 }
279 my $choice = $menu->[$idx_cat];
280 if ( $choice eq $hidden ) {
281 $ext->enable_extended_arguments( $info );
282 next CATEGORY;
283 }
284 my $old_idx_func = 0;
285  
286 FUNCTION: while( 1 ) {
287 my $type = lc( $choice =~ s/^-\s//r );
288 @pre = ( undef );
289 my $avail_functions = $sf->__available_functions( $type );
290 $menu = [ @pre, map { '- ' . $_ } @$avail_functions ];
291 my $prompt = ucfirst( $type ). ' function:';
292 # Choose
293 my $idx_func = $tc->choose(
294 $menu,
295 { %{$sf->{i}{lyt_v}}, info => $info, prompt => $prompt, index => 1, default => $old_idx_func, undef => '<=' }
296 );
297 if ( ! defined $idx_func || ! defined $menu->[$idx_func] ) {
298 next CATEGORY;
299 }
300 if ( $sf->{o}{G}{menu_memory} ) {
301 if ( $old_idx_func == $idx_func && ! $ENV{TC_RESET_AUTO_UP} ) {
302 $old_idx_func = 0;
303 next FUNCTION;
304 }
305 $old_idx_func = $idx_func;
306 }
307 my $func = $menu->[$idx_func] =~ s/^-\s//r;
308 push @$r_data, [ 'scalar', $func ];
309 $cols = [ grep { ! /^${func}\(/i } @$cols ];
310 my $new_func;
311 if ( $type eq 'string' ) {
312 $new_func = App::DBBrowser::Table::Extensions::ScalarFunctions::String->new( $sf->{i}, $sf->{o}, $sf->{d} );
313 }
314 elsif( $type eq 'numeric' ) {
315 $new_func = App::DBBrowser::Table::Extensions::ScalarFunctions::Numeric->new( $sf->{i}, $sf->{o}, $sf->{d} );
316 }
317 elsif( $type eq 'date' ) {
318 $new_func = App::DBBrowser::Table::Extensions::ScalarFunctions::Date->new( $sf->{i}, $sf->{o}, $sf->{d} );
319 }
320 elsif ( $type eq 'to' ) {
321 $new_func = App::DBBrowser::Table::Extensions::ScalarFunctions::To->new( $sf->{i}, $sf->{o}, $sf->{d} );
322 }
323 elsif ( $type eq 'other' ) {
324 $new_func = App::DBBrowser::Table::Extensions::ScalarFunctions::Other->new( $sf->{i}, $sf->{o}, $sf->{d} );
325 }
326 my $method = 'function_' . lc( $func ); ##
327 my $function_stmt;
328 if ( $new_func->can( $method ) ) {
329 $function_stmt = $new_func->$method( $sql, $clause, $func, $cols, $r_data );
330 if ( ! defined $function_stmt ) {
331 pop @$r_data;
332 if ( ! @$r_data ) { # no parent
333 next FUNCTION;
334 }
335 return; # return to the parent
336 }
337 }
338 else {
339 my $ga = App::DBBrowser::Table::Extensions::ScalarFunctions::GetArguments->new( $sf->{i}, $sf->{o}, $sf->{d} );
340 my $col = $ga->choose_a_column( $sql, $clause, $cols, $r_data );
341 if ( ! defined $col ) {
342 pop @$r_data;
343 if ( ! @$r_data ) {
344 next FUNCTION;
345 }
346 return;
347 }
348 if ( $dbms eq 'Pg' && $type eq 'string' ) {
349 $col = $ax->pg_column_to_text( $sql, $col );
350 }
351 $function_stmt = uc( $func ) . "($col)";
352 }
353 pop @$r_data;
354 return $function_stmt;
355 }
356 }
357 }
358  
359  
360  
361 1;
362 __END__