... | ... |
@@ -1,3 +1,5 @@ |
1 |
+0.1704 |
|
2 |
+ - added EXPERIMENTAL parameter new syntax :name(operator) |
|
1 | 3 |
0.1703 |
2 | 4 |
- added EXPERIMENTAL join new syntax. |
3 | 5 |
0.1702 |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.1703'; |
|
4 |
+our $VERSION = '0.1704'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -1126,6 +1126,7 @@ sub _create_query { |
1126 | 1126 |
# Create query |
1127 | 1127 |
my $builder = $self->query_builder; |
1128 | 1128 |
$builder->{_tag_parse} = $self->tag_parse; |
1129 |
+ $builder->safety_character($self->safety_character); |
|
1129 | 1130 |
$query = $builder->build_query($source); |
1130 | 1131 |
|
1131 | 1132 |
# Remove reserved word quote |
... | ... |
@@ -10,8 +10,7 @@ use DBIx::Custom::Util '_subname'; |
10 | 10 |
push @DBIx::Custom::CARP_NOT, __PACKAGE__; |
11 | 11 |
push @DBIx::Custom::Where::CARP_NOT, __PACKAGE__; |
12 | 12 |
|
13 |
-# Parameter regex |
|
14 |
-our $PARAM_RE = qr/(^|[^\.\w]):([\.\w]+)([^\.\w]|$)/sm; |
|
13 |
+has 'safety_character'; |
|
15 | 14 |
|
16 | 15 |
sub build_query { |
17 | 16 |
my ($self, $source) = @_; |
... | ... |
@@ -69,14 +68,17 @@ sub _placeholder_count { |
69 | 68 |
|
70 | 69 |
sub _parse_parameter { |
71 | 70 |
my ($self, $source) = @_; |
72 |
- |
|
71 |
+ |
|
73 | 72 |
# Get and replace parameters |
74 | 73 |
my $sql = $source || ''; |
75 | 74 |
my $columns = []; |
76 |
- while ($source =~ /$PARAM_RE/g) { |
|
75 |
+ my $c = $self->safety_character; |
|
76 |
+ # Parameter regex |
|
77 |
+ my $re = qr/^(.*?):([$c\.]+)(.*)/s; |
|
78 |
+ while ($sql =~ /$re/g) { |
|
77 | 79 |
push @$columns, $2; |
80 |
+ $sql = "$1?$3"; |
|
78 | 81 |
} |
79 |
- $sql =~ s/$PARAM_RE/$1?$3/g; |
|
80 | 82 |
|
81 | 83 |
# Create query |
82 | 84 |
my $query = DBIx::Custom::Query->new( |
... | ... |
@@ -57,6 +57,7 @@ $datas = [ |
57 | 57 |
for (my $i = 0; $i < @$datas; $i++) { |
58 | 58 |
my $data = $datas->[$i]; |
59 | 59 |
my $builder = DBIx::Custom->new->query_builder; |
60 |
+ $builder->safety_character('\w'); |
|
60 | 61 |
my $query = $builder->build_query($data->{source}); |
61 | 62 |
is($query->{sql}, $data->{sql_expected}, "$data->{name} : sql"); |
62 | 63 |
is_deeply($query->columns, $data->{columns_expected}, "$data->{name} : columns"); |
... | ... |
@@ -65,6 +66,7 @@ for (my $i = 0; $i < @$datas; $i++) { |
65 | 66 |
|
66 | 67 |
test 'Original tag'; |
67 | 68 |
$builder = DBIx::Custom->new->query_builder; |
69 |
+$builder->safety_character('\w'); |
|
68 | 70 |
|
69 | 71 |
$ret_val = $builder->register_tag( |
70 | 72 |
p => sub { |
... | ... |
@@ -84,6 +86,7 @@ isa_ok($ret_val, 'DBIx::Custom::QueryBuilder'); |
84 | 86 |
|
85 | 87 |
test "Tag error case"; |
86 | 88 |
$builder = DBIx::Custom->new->query_builder; |
89 |
+$builder->safety_character('\w'); |
|
87 | 90 |
|
88 | 91 |
eval{$builder->build_query('{? }')}; |
89 | 92 |
like($@, qr/\QColumn name must be specified in tag "{? }"/, "? not arguments"); |
... | ... |
@@ -119,6 +122,7 @@ $builder->register_tag( |
119 | 122 |
|
120 | 123 |
test 'General error case'; |
121 | 124 |
$builder = DBIx::Custom->new->query_builder; |
125 |
+$builder->safety_character('\w'); |
|
122 | 126 |
$builder->register_tag( |
123 | 127 |
a => sub { |
124 | 128 |
return ["? ? ?", ['']]; |