Showing 3 changed files with 80 additions and 7 deletions
+10 -7
lib/DBIx/Custom.pm
... ...
@@ -937,8 +937,6 @@ sub q {
937 937
   
938 938
   my $quote = $self->{reserved_word_quote}
939 939
     || $self->{quote} || $self->quote || '';
940
-  return "$quote$value$quote"
941
-    if !$quotemeta && ($quote eq '`' || $quote eq '"');
942 940
   
943 941
   my $q = substr($quote, 0, 1) || '';
944 942
   my $p;
... ...
@@ -952,7 +950,12 @@ sub q {
952 950
     $p = quotemeta($p);
953 951
   }
954 952
   
955
-  return "$q$value$p";
953
+  if ($value =~ /\./) {
954
+    my @values = split /\./, $value;
955
+    for my $v (@values) { $v = "$q$v$p" }
956
+    return join '.', @values;
957
+  }
958
+  else { return "$q$value$p" }
956 959
 }
957 960
 
958 961
 sub register_filter {
... ...
@@ -2049,8 +2052,8 @@ sub _push_relation {
2049 2052
   if (keys %{$relation || {}}) {
2050 2053
     $$sql .= $need_where ? 'where ' : 'and ';
2051 2054
     for my $rcolumn (keys %$relation) {
2052
-      my $table1 = (split (/\./, $rcolumn))[0];
2053
-      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2055
+      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2056
+      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
2054 2057
       push @$tables, ($table1, $table2);
2055 2058
       $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
2056 2059
     }
... ...
@@ -2064,8 +2067,8 @@ sub _add_relation_table {
2064 2067
   
2065 2068
   if (keys %{$relation || {}}) {
2066 2069
     for my $rcolumn (keys %$relation) {
2067
-      my $table1 = (split (/\./, $rcolumn))[0];
2068
-      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2070
+      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2071
+      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
2069 2072
       my $table1_exists;
2070 2073
       my $table2_exists;
2071 2074
       for my $table (@$tables) {
+69
t/common-sqlite-fullqualified.t
... ...
@@ -0,0 +1,69 @@
1
+use strict;
2
+use warnings;
3
+
4
+use FindBin;
5
+use lib "$FindBin::Bin/common";
6
+$ENV{DBIX_CUSTOM_TEST_RUN} = 1;
7
+
8
+use DBIx::Custom;
9
+{
10
+  package DBIx::Custom;
11
+  no warnings 'redefine';
12
+  
13
+  my $table1 = 'main.table1';
14
+  my $table2 = 'main.table2';
15
+  my $table2_alias = 'main.table2_alias';
16
+  my $table3 = 'main.table3';
17
+  my $key1 = 'key1';
18
+  my $key2 = 'key2';
19
+  my $key3 = 'key3';
20
+  my $key4 = 'key4';
21
+  my $key5 = 'key5';
22
+  my $key6 = 'key6';
23
+  my $key7 = 'key7';
24
+  my $key8 = 'key8';
25
+  my $key9 = 'key9';
26
+  my $key10 = 'key10';
27
+  
28
+  has table1 => $table1;
29
+  has table2 => $table2;
30
+  has table2_alias => $table2_alias;
31
+  has table3 => $table3;
32
+  has key1 => $key1;
33
+  has key2 => $key2;
34
+  has key3 => $key3;
35
+  has key4 => $key4;
36
+  has key5 => $key5;
37
+  has key6 => $key6;
38
+  has key7 => $key7;
39
+  has key8 => $key8;
40
+  has key9 => $key9;
41
+  has key10 => $key10;
42
+  
43
+  my $date_typename = 'Date';
44
+  my $datetime_typename = 'Datetime';
45
+  
46
+  sub date_typename { lc $date_typename }
47
+  sub datetime_typename { lc $datetime_typename }
48
+
49
+  my $date_datatype = 'Date';
50
+  my $datetime_datatype = 'Datetime';
51
+  
52
+  sub date_datatype { lc $date_datatype }
53
+  sub datetime_datatype { lc $datetime_datatype }
54
+
55
+  has dsn => 'dbi:SQLite:dbname=:memory:';
56
+  sub create_table1 { "create table $table1 ($key1 varchar, $key2 varchar)" }
57
+  sub create_table1_2 {"create table $table1 ($key1 varchar, $key2 varchar, $key3 varchar, key4 varchar, key5 varchar)" }
58
+  sub create_table1_type { "create table $table1 ($key1 $date_typename, $key2 $datetime_typename)" }
59
+  
60
+  sub create_table1_highperformance { "create table $table1 (key1 varchar, key2 varchar, key3 varchar, key4 varchar, key5 varchar, key6 varchar, key7 varchar)" }
61
+  
62
+  sub create_table2 { "create table $table2 ($key1 varchar, $key3 varchar)" }
63
+  sub create_table2_2 { "create table $table2 ($key1 varchar, $key2 varchar, $key3 varchar)" }
64
+  sub create_table3 { "create table $table3 ($key1 varchar, $key2 varchar, $key3 varchar)" }
65
+  sub create_table_reserved { 'create table "table" ("select" varchar, "update" varchar)' }
66
+  
67
+}
68
+
69
+require "$FindBin::Bin/common.t";
+1
t/common.t
... ...
@@ -1318,6 +1318,7 @@ is_deeply($rows, [{$key1 => 1, $key2 => 2}], "filter");
1318 1318
 eval { $dbi->execute("drop table $table2") };
1319 1319
 $dbi->execute($create_table2);
1320 1320
 $dbi->insert({$key1 => 1, $key3 => 5}, table => $table2);
1321
+$DB::single = 1;
1321 1322
 $rows = $dbi->select(
1322 1323
   table => [$table1, $table2],
1323 1324
   column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",