|
Lines 67-77
C4::Creators::Lib
Link Here
|
| 67 |
|
67 |
|
| 68 |
sub _SELECT { |
68 |
sub _SELECT { |
| 69 |
my @params = @_; |
69 |
my @params = @_; |
| 70 |
my $fields_list = $params[0]; |
70 |
my $fieldname = _add_backtics($params[0]); |
| 71 |
if (index($fields_list, ' ')==-1 && index($fields_list,',')==-1 && $fields_list ne '*') { |
71 |
my $query = "SELECT $fieldname FROM $params[1]"; |
| 72 |
$fields_list = "`$fields_list`"; |
|
|
| 73 |
} |
| 74 |
my $query = "SELECT $fields_list FROM $params[1]"; |
| 75 |
$params[2] ? $query .= " WHERE $params[2];" : $query .= ';'; |
72 |
$params[2] ? $query .= " WHERE $params[2];" : $query .= ';'; |
| 76 |
my $sth = C4::Context->dbh->prepare($query); |
73 |
my $sth = C4::Context->dbh->prepare($query); |
| 77 |
# $sth->{'TraceLevel'} = 3; |
74 |
# $sth->{'TraceLevel'} = 3; |
|
Lines 87-92
sub _SELECT {
Link Here
|
| 87 |
return $record_set; |
84 |
return $record_set; |
| 88 |
} |
85 |
} |
| 89 |
|
86 |
|
|
|
87 |
sub _add_backtics { |
| 88 |
my ( @args ) = @_; |
| 89 |
s/(?:^|\b)(\w+)(?:\b|$)/`$1`/g for @args; |
| 90 |
# Too bad that we need to correct a few exceptions: aggregate functions |
| 91 |
my @aggregates = ( 'COUNT', 'MAX', 'MIN', 'SUM' ); # add when needed.. |
| 92 |
foreach my $aggr (@aggregates) { |
| 93 |
s/`$aggr`\(/$aggr\(/gi for @args; |
| 94 |
} |
| 95 |
# And correct aliases |
| 96 |
s/(`|\))\s+`AS`\s+`/$1 AS `/gi for @args; |
| 97 |
return wantarray ? @args : $args[0]; |
| 98 |
} |
| 99 |
|
| 90 |
my $barcode_types = [ |
100 |
my $barcode_types = [ |
| 91 |
{type => 'CODE39', name => 'Code 39', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern.', selected => 0}, |
101 |
{type => 'CODE39', name => 'Code 39', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern.', selected => 0}, |
| 92 |
{type => 'CODE39MOD', name => 'Code 39 + Modulo43', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 43 checksum.', selected => 0}, |
102 |
{type => 'CODE39MOD', name => 'Code 39 + Modulo43', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 43 checksum.', selected => 0}, |
|
Lines 148-164
my $output_formats = [
Link Here
|
| 148 |
|
158 |
|
| 149 |
sub _build_query { |
159 |
sub _build_query { |
| 150 |
my ( $params, $table ) = @_; |
160 |
my ( $params, $table ) = @_; |
| 151 |
my @fields = exists $params->{fields} ? @{ $params->{fields} } : (); |
161 |
my @fields = exists $params->{fields} ? _add_backtics( @{ $params->{fields} } ) : ('*'); |
| 152 |
my @fields2 = (); |
162 |
my $query = "SELECT " . join(', ', @fields ) . " FROM $table"; |
| 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"; |
| 162 |
my @where_args; |
163 |
my @where_args; |
| 163 |
if ( exists $params->{filters} ) { |
164 |
if ( exists $params->{filters} ) { |
| 164 |
$query .= ' WHERE 1 '; |
165 |
$query .= ' WHERE 1 '; |