... | ... |
@@ -21,7 +21,7 @@ use Scalar::Util qw/weaken/; |
21 | 21 |
|
22 | 22 |
|
23 | 23 |
has [qw/connector dsn password quote user exclude_table user_table_info |
24 |
- user_column_info/], |
|
24 |
+ user_column_info safety_character/], |
|
25 | 25 |
cache => 0, |
26 | 26 |
cache_method => sub { |
27 | 27 |
sub { |
... | ... |
@@ -70,7 +70,6 @@ has [qw/connector dsn password quote user exclude_table user_table_info |
70 | 70 |
return $builder; |
71 | 71 |
}, |
72 | 72 |
result_class => 'DBIx::Custom::Result', |
73 |
- safety_character => '\w', |
|
74 | 73 |
separator => '.', |
75 | 74 |
stash => sub { {} }; |
76 | 75 |
|
... | ... |
@@ -395,12 +394,12 @@ sub execute { |
395 | 394 |
else { |
396 | 395 |
$query = $opt{reuse}->{$sql} if $opt{reuse}; |
397 | 396 |
unless ($query) { |
398 |
- my $safety = $self->{safety_character} || $self->safety_character; |
|
397 |
+ my $c = $self->{safety_character}; |
|
399 | 398 |
# Check unsafety keys |
400 |
- unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) { |
|
399 |
+ unless ((join('', keys %$param) || '') =~ /^[$c\.]+$/) { |
|
401 | 400 |
for my $column (keys %$param) { |
402 | 401 |
croak qq{"$column" is not safety column name } . _subname |
403 |
- unless $column =~ /^[$safety\.]+$/; |
|
402 |
+ unless $column =~ /^[$c\.]+$/; |
|
404 | 403 |
} |
405 | 404 |
} |
406 | 405 |
$query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter}); |
... | ... |
@@ -829,6 +828,9 @@ sub new { |
829 | 828 |
croak qq{Invalid attribute: "$attr" } . _subname |
830 | 829 |
unless $self->can($attr); |
831 | 830 |
} |
831 |
+ |
|
832 |
+ $self->{safety_character} = 'a-zA-Z0-9_' |
|
833 |
+ unless exists $self->{safety_character}; |
|
832 | 834 |
|
833 | 835 |
# DEPRECATED |
834 | 836 |
$self->{_tags} = { |
... | ... |
@@ -1256,7 +1258,7 @@ sub _create_query { |
1256 | 1258 |
} |
1257 | 1259 |
else { |
1258 | 1260 |
my @columns; |
1259 |
- my $c = $self->{safety_character} || $self->safety_character; |
|
1261 |
+ my $c = $self->{safety_character}; |
|
1260 | 1262 |
my %duplicate; |
1261 | 1263 |
my $duplicate; |
1262 | 1264 |
# Parameter regex |
... | ... |
@@ -1501,8 +1503,8 @@ sub _push_join { |
1501 | 1503 |
$j_clause =~ s/[$q_re]//g; |
1502 | 1504 |
|
1503 | 1505 |
my @j_clauses = reverse split /\s(and|on)\s/, $j_clause; |
1504 |
- my $c = $self->safety_character; |
|
1505 |
- my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm; |
|
1506 |
+ my $c = $self->{safety_character}; |
|
1507 |
+ my $join_re = qr/([$c]+)\.[$c]+[^$c].*?([$c]+)\.[$c]+/sm; |
|
1506 | 1508 |
for my $clause (@j_clauses) { |
1507 | 1509 |
if ($clause =~ $join_re) { |
1508 | 1510 |
$table1 = $1; |
... | ... |
@@ -1559,7 +1561,7 @@ sub _search_tables { |
1559 | 1561 |
|
1560 | 1562 |
# Search tables |
1561 | 1563 |
my $tables = []; |
1562 |
- my $safety_character = $self->safety_character; |
|
1564 |
+ my $safety_character = $self->{safety_character}; |
|
1563 | 1565 |
my $q = $self->_quote; |
1564 | 1566 |
my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1); |
1565 | 1567 |
my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./ |
... | ... |
@@ -1604,7 +1606,7 @@ sub _where_clause_and_param { |
1604 | 1606 |
} |
1605 | 1607 |
|
1606 | 1608 |
# Check unsafety column |
1607 |
- my $safety = $self->safety_character; |
|
1609 |
+ my $safety = $self->{safety_character}; |
|
1608 | 1610 |
unless ($column_join =~ /^[$safety\.]+$/) { |
1609 | 1611 |
for my $column (keys %$where) { |
1610 | 1612 |
croak qq{"$column" is not safety column name } . _subname |
... | ... |
@@ -1,3 +1,4 @@ |
1 |
+# DEPRECATED! |
|
1 | 2 |
package DBIx::Custom::QueryBuilder; |
2 | 3 |
|
3 | 4 |
use Object::Simple -base; |
... | ... |
@@ -10,44 +11,27 @@ use DBIx::Custom::Util '_subname'; |
10 | 11 |
push @DBIx::Custom::CARP_NOT, __PACKAGE__; |
11 | 12 |
push @DBIx::Custom::Where::CARP_NOT, __PACKAGE__; |
12 | 13 |
|
14 |
+# DEPRECATED! |
|
13 | 15 |
sub build_query { |
14 | 16 |
my ($self, $sql) = @_; |
15 |
- |
|
16 |
- # Parse tag. tag is DEPRECATED! |
|
17 |
- if ($self->dbi->{tag_parse} && $sql =~ /(\s|^)\{/) { |
|
18 |
- my $query = $self->_parse_tag($sql); |
|
19 |
- my $tag_count = delete $query->{tag_count}; |
|
20 |
- warn qq/Tag system such as {? name} is DEPRECATED! / . |
|
21 |
- qq/use parameter system such as :name instead/ |
|
22 |
- if $tag_count; |
|
23 |
- my $query2 = $self->_parse_parameter($query->sql); |
|
24 |
- $query->sql($query2->sql); |
|
25 |
- for (my $i =0; $i < @{$query->columns}; $i++) { |
|
26 |
- my $column = $query->columns->[$i]; |
|
27 |
- if ($column eq 'RESERVED_PARAMETER') { |
|
28 |
- my $column2 = shift @{$query2->columns}; |
|
29 |
- croak ":name syntax is wrong" |
|
30 |
- unless defined $column2; |
|
31 |
- $query->columns->[$i] = $column2; |
|
32 |
- } |
|
17 |
+ |
|
18 |
+ my $query = $self->_parse_tag($sql); |
|
19 |
+ my $tag_count = delete $query->{tag_count}; |
|
20 |
+ warn qq/Tag system such as {? name} is DEPRECATED! / . |
|
21 |
+ qq/use parameter system such as :name instead/ |
|
22 |
+ if $tag_count; |
|
23 |
+ my $query2 = $self->_parse_parameter($query->sql); |
|
24 |
+ $query->sql($query2->sql); |
|
25 |
+ for (my $i =0; $i < @{$query->columns}; $i++) { |
|
26 |
+ my $column = $query->columns->[$i]; |
|
27 |
+ if ($column eq 'RESERVED_PARAMETER') { |
|
28 |
+ my $column2 = shift @{$query2->columns}; |
|
29 |
+ croak ":name syntax is wrong" |
|
30 |
+ unless defined $column2; |
|
31 |
+ $query->columns->[$i] = $column2; |
|
33 | 32 |
} |
34 |
- return $query; |
|
35 |
- } |
|
36 |
- |
|
37 |
- $sql ||= ''; |
|
38 |
- my $columns = []; |
|
39 |
- my $c = ($self->{dbi} || {})->{safety_character} |
|
40 |
- || $self->dbi->safety_character; |
|
41 |
- # Parameter regex |
|
42 |
- $sql =~ s/([0-9]):/$1\\:/g; |
|
43 |
- while ($sql =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) { |
|
44 |
- push @$columns, $2; |
|
45 |
- $sql = defined $3 ? "$1$2 $3 ?$4" : "$1?$4"; |
|
46 | 33 |
} |
47 |
- $sql =~ s/\\:/:/g if index($sql, "\\:") != -1; |
|
48 |
- |
|
49 |
- # Create query |
|
50 |
- return {sql => $sql, columns => $columns, duplicate => 1}; |
|
34 |
+ return $query; |
|
51 | 35 |
} |
52 | 36 |
|
53 | 37 |
# DEPRECATED! |
... | ... |
@@ -289,8 +273,4 @@ sub register_tag_processor { |
289 | 273 |
|
290 | 274 |
DBIx::Custom::QueryBuilder - DEPRECATED! |
291 | 275 |
|
292 |
-=head1 DESCRIPTION |
|
293 |
- |
|
294 |
-This module functionality will be moved to DBIx::Custom |
|
295 |
- |
|
296 | 276 |
=cut |