Showing 3 changed files with 7 additions and 9 deletions
+2 -2
lib/DBIx/Custom.pm
... ...
@@ -1252,7 +1252,7 @@ sub _create_query {
1252 1252
         my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1253 1253
           ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1254 1254
 
1255
-        my $sql = $source || '';
1255
+        my $sql = " " . $source || '';
1256 1256
         if ($tag_parse && ($sql =~ /\s\{/ || $sql =~ /^\{/)) {
1257 1257
             $query = $self->query_builder->build_query($sql);
1258 1258
         }
... ...
@@ -1263,7 +1263,7 @@ sub _create_query {
1263 1263
             my $duplicate;
1264 1264
             # Parameter regex
1265 1265
             $sql =~ s/([0-9]):/$1\\:/g;
1266
-            while ($sql =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) {
1266
+            while ($sql =~ /(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) {
1267 1267
                 push @columns, $2;
1268 1268
                 $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1269 1269
                 $sql = defined $3 ? "$1$2 $3 ?$4" : "$1?$4";
+2 -4
lib/DBIx/Custom/Where.pm
... ...
@@ -98,11 +98,9 @@ sub _parse {
98 98
             $column = $columns->[0];
99 99
         }
100 100
         else {
101
-            my $sql = $clause;
101
+            my $sql = " " . $clause || '';
102 102
             $sql =~ s/([0-9]):/$1\\:/g;
103
-            if ($sql =~ /[^\\]:([$c\.]+)/s || $sql =~ /^:([$c\.]+)/s) {
104
-                ($column) = $1;
105
-            }
103
+            ($column) = $sql =~ /[^\\]:([$c\.]+)/s
106 104
         }
107 105
         unless (defined $column) {
108 106
             push @$where, $clause;
+3 -3
t/common.t
... ...
@@ -1270,7 +1270,7 @@ $dbi->execute($create_table1);
1270 1270
 $source = "select * from $table1 where $key1 = :$key1 and $key2 = :$key2";
1271 1271
 $dbi->execute($source, {}, query => 1);
1272 1272
 is_deeply($dbi->{_cached}->{$source}, 
1273
-          {sql => "select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
1273
+          {sql => " select * from $table1 where $key1 = ? and $key2 = ?", columns => [$key1, $key2], tables => []}, "cache");
1274 1274
 
1275 1275
 eval { $dbi->execute("drop table $table1") };
1276 1276
 $dbi->execute($create_table1);
... ...
@@ -3112,10 +3112,10 @@ $dbi = DBIx::Custom->connect;
3112 3112
 eval { $dbi->execute("drop table $table1") };
3113 3113
 $dbi->execute($create_table1);
3114 3114
 $dbi->execute("select * from $table1");
3115
-is($dbi->last_sql, "select * from $table1");
3115
+is($dbi->last_sql, " select * from $table1");
3116 3116
 
3117 3117
 eval{$dbi->execute("aaa")};
3118
-is($dbi->last_sql, 'aaa');
3118
+is($dbi->last_sql, ' aaa');
3119 3119
 
3120 3120
 test 'DBIx::Custom header';
3121 3121
 $dbi = DBIx::Custom->connect;