View | Details | Raw Unified | Return to bug 21281
Collapse All | Expand All

(-)a/C4/Creators/Lib.pm (-4 / +17 lines)
Lines 67-73 C4::Creators::Lib Link Here
67
67
68
sub _SELECT {
68
sub _SELECT {
69
    my @params = @_;
69
    my @params = @_;
70
    my $query = "SELECT `$params[0]` FROM $params[1]";
70
    my $fields_list = $params[0];
71
    if (index($fields_list, ' ')==-1 && index($fields_list,',')==-1 && $fields_list ne '*') {
72
        $fields_list = "`$fields_list`";
73
    }
74
    my $query = "SELECT $fields_list FROM $params[1]";
71
    $params[2] ? $query .= " WHERE $params[2];" : $query .= ';';
75
    $params[2] ? $query .= " WHERE $params[2];" : $query .= ';';
72
    my $sth = C4::Context->dbh->prepare($query);
76
    my $sth = C4::Context->dbh->prepare($query);
73
#    $sth->{'TraceLevel'} = 3;
77
#    $sth->{'TraceLevel'} = 3;
Lines 145-160 my $output_formats = [ Link Here
145
sub _build_query {
149
sub _build_query {
146
    my ( $params, $table ) = @_;
150
    my ( $params, $table ) = @_;
147
    my @fields = exists $params->{fields} ? @{ $params->{fields} } : ();
151
    my @fields = exists $params->{fields} ? @{ $params->{fields} } : ();
148
    my $query = "SELECT " . ( @fields ? join(', ', map {"`$_`"} @fields ) : '*' ) . " FROM $table";
152
    my @fields2 = ();
153
    foreach my $field_name (@fields) {
154
        if (index($field_name,' ')==-1 && $field_name ne '*') {
155
            push @fields2, "`$field_name`";
156
        } else {
157
            push @fields2, $field_name;
158
        }
159
    }
160
    @fields = @fields2;
161
    my $query = "SELECT " . ( @fields ? join(', ', @fields ) : '*' ) . " FROM $table";
149
    my @where_args;
162
    my @where_args;
150
    if ( exists $params->{filters} ) {
163
    if ( exists $params->{filters} ) {
151
        $query .= ' WHERE 1 ';
164
        $query .= ' WHERE 1 ';
152
        while ( my ( $field, $values ) = each %{ $params->{filters} } ) {
165
        while ( my ( $field, $values ) = each %{ $params->{filters} } ) {
153
            if ( ref( $values ) ) {
166
            if ( ref( $values ) ) {
154
                $query .= " AND $field IN ( " . ( ('?,') x (@$values-1) ) . "? ) "; # a comma separates elements in a list...
167
                $query .= " AND `$field` IN ( " . ( ('?,') x (@$values-1) ) . "? ) "; # a comma separates elements in a list...
155
                push @where_args, @$values;
168
                push @where_args, @$values;
156
            } else {
169
            } else {
157
                $query .= " AND $field = ? ";
170
                $query .= " AND `$field` = ? ";
158
                push @where_args, $values;
171
                push @where_args, $values;
159
            }
172
            }
160
        }
173
        }
(-)a/t/db_dependent/Creators/Lib.t (-2 / +1 lines)
Lines 398-404 is( $templates->[0]->{creator}, 'Labels', 'creator is good Link Here
398
$templates = get_all_templates( { filters => { rows => [-42, 7]} } );
398
$templates = get_all_templates( { filters => { rows => [-42, 7]} } );
399
is( @$templates, $count, 'There is 1 template matching' );
399
is( @$templates, $count, 'There is 1 template matching' );
400
# With orderby param ------------------
400
# With orderby param ------------------
401
$templates = get_all_templates( { orderby => 'rows DESC' } );
401
$templates = get_all_templates( { orderby => '`rows` DESC' } );
402
402
403
$query = '
403
$query = '
404
  SELECT    count(*)
404
  SELECT    count(*)
405
- 

Return to bug 21281