|
Lines 25-31
use vars qw(@ISA @EXPORT);
Link Here
|
| 25 |
BEGIN { |
25 |
BEGIN { |
| 26 |
|
26 |
|
| 27 |
@ISA = qw(Exporter); |
27 |
@ISA = qw(Exporter); |
| 28 |
@EXPORT = qw(dt_build_orderby dt_build_having dt_get_params dt_build_query); |
28 |
@EXPORT = qw(dt_build_orderby dt_build_having dt_get_params); |
| 29 |
} |
29 |
} |
| 30 |
|
30 |
|
| 31 |
=head1 NAME |
31 |
=head1 NAME |
|
Lines 209-283
sub dt_get_params {
Link Here
|
| 209 |
return %dtparam; |
209 |
return %dtparam; |
| 210 |
} |
210 |
} |
| 211 |
|
211 |
|
| 212 |
=head2 dt_build_query_simple |
|
|
| 213 |
|
| 214 |
my ( $query, $params )= dt_build_query_simple( $value, $field ) |
| 215 |
|
| 216 |
This function takes a value and a field (table.field). |
| 217 |
|
| 218 |
It returns (undef, []) if not $value. |
| 219 |
Else, returns a SQL where string and an arrayref containing parameters |
| 220 |
for the execute method of the statement. |
| 221 |
|
| 222 |
=cut |
| 223 |
sub dt_build_query_simple { |
| 224 |
my ( $value, $field ) = @_; |
| 225 |
my $query; |
| 226 |
my @params; |
| 227 |
if( $value ) { |
| 228 |
$query .= " AND $field = ? "; |
| 229 |
push @params, $value; |
| 230 |
} |
| 231 |
return ( $query, \@params ); |
| 232 |
} |
| 233 |
|
| 234 |
=head2 dt_build_query_dates |
| 235 |
|
| 236 |
my ( $query, $params )= dt_build_query_dates( $datefrom, $dateto, $field) |
| 237 |
|
| 238 |
This function takes a datefrom, dateto and a field (table.field). |
| 239 |
|
| 240 |
It returns (undef, []) if not $value. |
| 241 |
Else, returns a SQL where string and an arrayref containing parameters |
| 242 |
for the execute method of the statement. |
| 243 |
|
| 244 |
=cut |
| 245 |
sub dt_build_query_dates { |
| 246 |
my ( $datefrom, $dateto, $field ) = @_; |
| 247 |
my $query; |
| 248 |
my @params; |
| 249 |
if ( $datefrom ) { |
| 250 |
$query .= " AND $field >= ? "; |
| 251 |
push @params, eval { output_pref( { dt => dt_from_string( $datefrom ), dateonly => 1, dateformat => 'iso' } ); }; |
| 252 |
} |
| 253 |
if ( $dateto ) { |
| 254 |
$query .= " AND $field <= ? "; |
| 255 |
push @params, eval { output_pref( { dt => dt_from_string( $dateto ), dateonly => 1, dateformat => 'iso' } ); }; |
| 256 |
} |
| 257 |
return ( $query, \@params ); |
| 258 |
} |
| 259 |
|
| 260 |
=head2 dt_build_query |
| 261 |
|
| 262 |
my ( $query, $filter ) = dt_build_query( $type, @params ) |
| 263 |
|
| 264 |
This function takes a value and a list of parameters. |
| 265 |
|
| 266 |
It calls dt_build_query_dates or dt_build_query_simple function of $type. |
| 267 |
|
| 268 |
$type can contain 'simple' or 'range_dates'. |
| 269 |
if $type is not matched it returns undef |
| 270 |
|
| 271 |
=cut |
| 272 |
sub dt_build_query { |
| 273 |
my ( $type, @params ) = @_; |
| 274 |
if ( $type =~ m/simple/ ) { |
| 275 |
return dt_build_query_simple(@params); |
| 276 |
} |
| 277 |
elsif ( $type =~ m/range_dates/ ) { |
| 278 |
return dt_build_query_dates(@params); |
| 279 |
} |
| 280 |
return; |
| 281 |
} |
| 282 |
|
| 283 |
1; |
212 |
1; |
| 284 |
- |
|
|