Showing 3 changed files with 46 additions and 39 deletions
+1
Changes
... ...
@@ -1,4 +1,5 @@
1 1
 0.1740
2
+    - added EXPERIMENTAL q method
2 3
     - execute method id option is DEPRECATED!
3 4
 0.1739
4 5
     - insert timestamp option is DEPRECATED!
+44 -38
lib/DBIx/Custom.pm
... ...
@@ -131,7 +131,7 @@ sub assign_clause {
131 131
     
132 132
     my $wrap = $opts->{wrap} || {};
133 133
     my $safety = $self->{safety_character} || $self->safety_character;
134
-    my $qp = $self->_q('');
134
+    my $qp = $self->q('');
135 135
     my $q = substr($qp, 0, 1) || '';
136 136
     my $p = substr($qp, 1, 1) || '';
137 137
     
... ...
@@ -172,8 +172,8 @@ sub column {
172 172
     # Column clause
173 173
     my @column;
174 174
     $columns ||= [];
175
-    push @column, $self->_q($table) . "." . $self->_q($_) .
176
-      " as " . $self->_q("${table}${separator}$_")
175
+    push @column, $self->q($table) . "." . $self->q($_) .
176
+      " as " . $self->q("${table}${separator}$_")
177 177
       for @$columns;
178 178
     
179 179
     return join (', ', @column);
... ...
@@ -257,7 +257,7 @@ sub delete {
257 257
     # Delete statement
258 258
     my $sql = "delete ";
259 259
     $sql .= "$opt{prefix} " if defined $opt{prefix};
260
-    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
260
+    $sql .= "from " . $self->q($opt{table}) . " $w->{clause} ";
261 261
     
262 262
     # Execute query
263 263
     $opt{statement} = 'delete';
... ...
@@ -661,7 +661,7 @@ sub insert {
661 661
     # Insert statement
662 662
     my $sql = "insert ";
663 663
     $sql .= "$opt{prefix} " if defined $opt{prefix};
664
-    $sql .= "into " . $self->_q($opt{table}) . " "
664
+    $sql .= "into " . $self->q($opt{table}) . " "
665 665
       . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
666 666
 
667 667
     # Remove id from parameter
... ...
@@ -814,8 +814,8 @@ sub mycolumn {
814 814
     # Create column clause
815 815
     my @column;
816 816
     $columns ||= [];
817
-    push @column, $self->_q($table) . "." . $self->_q($_) .
818
-      " as " . $self->_q($_)
817
+    push @column, $self->q($table) . "." . $self->q($_) .
818
+      " as " . $self->q($_)
819 819
       for @$columns;
820 820
     
821 821
     return join (', ', @column);
... ...
@@ -856,6 +856,29 @@ sub order {
856 856
     return DBIx::Custom::Order->new(dbi => $self, @_);
857 857
 }
858 858
 
859
+sub q {
860
+    my ($self, $value, $quotemeta) = @_;
861
+    
862
+    my $quote = $self->{reserved_word_quote}
863
+      || $self->{quote} || $self->quote || '';
864
+    return "$quote$value$quote"
865
+      if !$quotemeta && ($quote eq '`' || $quote eq '"');
866
+    
867
+    my $q = substr($quote, 0, 1) || '';
868
+    my $p;
869
+    if (defined $quote && length $quote > 1) {
870
+        $p = substr($quote, 1, 1);
871
+    }
872
+    else { $p = $q }
873
+    
874
+    if ($quotemeta) {
875
+        $q = quotemeta($q);
876
+        $p = quotemeta($p);
877
+    }
878
+    
879
+    return "$q$value$p";
880
+}
881
+
859 882
 sub register_filter {
860 883
     my $self = shift;
861 884
     
... ...
@@ -904,7 +927,7 @@ sub select {
904 927
                     splice @$column, 1, 1;
905 928
                 }
906 929
                 
907
-                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
930
+                $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
908 931
             }
909 932
             unshift @$tables, @{$self->_search_tables($column)};
910 933
             $sql .= "$column, ";
... ...
@@ -918,11 +941,11 @@ sub select {
918 941
     if ($opt{relation}) {
919 942
         my $found = {};
920 943
         for my $table (@$tables) {
921
-            $sql .= $self->_q($table) . ', ' unless $found->{$table};
944
+            $sql .= $self->q($table) . ', ' unless $found->{$table};
922 945
             $found->{$table} = 1;
923 946
         }
924 947
     }
925
-    else { $sql .= $self->_q($tables->[-1] || '') . ' ' }
948
+    else { $sql .= $self->q($tables->[-1] || '') . ' ' }
926 949
     $sql =~ s/, $/ /;
927 950
     croak "select method table option must be specified " . _subname
928 951
       unless defined $tables->[-1];
... ...
@@ -1119,7 +1142,7 @@ sub update {
1119 1142
     # Update statement
1120 1143
     my $sql = "update ";
1121 1144
     $sql .= "$opt{prefix} " if defined $opt{prefix};
1122
-    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
1145
+    $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
1123 1146
     
1124 1147
     # Execute query
1125 1148
     $opt{statement} = 'update';
... ...
@@ -1187,7 +1210,7 @@ sub values_clause {
1187 1210
     
1188 1211
     # Create insert parameter tag
1189 1212
     my $safety = $self->{safety_character} || $self->safety_character;
1190
-    my $qp = $self->_q('');
1213
+    my $qp = $self->q('');
1191 1214
     my $q = substr($qp, 0, 1) || '';
1192 1215
     my $p = substr($qp, 1, 1) || '';
1193 1216
     
... ...
@@ -1531,29 +1554,6 @@ sub _quote {
1531 1554
     return $self->{reserved_word_quote} || $self->quote || '';
1532 1555
 }
1533 1556
 
1534
-sub _q {
1535
-    my ($self, $value, $quotemeta) = @_;
1536
-    
1537
-    my $quote = $self->{reserved_word_quote}
1538
-      || $self->{quote} || $self->quote || '';
1539
-    return "$quote$value$quote"
1540
-      if !$quotemeta && ($quote eq '`' || $quote eq '"');
1541
-    
1542
-    my $q = substr($quote, 0, 1) || '';
1543
-    my $p;
1544
-    if (defined $quote && length $quote > 1) {
1545
-        $p = substr($quote, 1, 1);
1546
-    }
1547
-    else { $p = $q }
1548
-    
1549
-    if ($quotemeta) {
1550
-        $q = quotemeta($q);
1551
-        $p = quotemeta($p);
1552
-    }
1553
-    
1554
-    return "$q$value$p";
1555
-}
1556
-
1557 1557
 sub _remove_duplicate_table {
1558 1558
     my ($self, $tables, $main_table) = @_;
1559 1559
     
... ...
@@ -1577,7 +1577,7 @@ sub _search_tables {
1577 1577
     my $tables = [];
1578 1578
     my $safety_character = $self->safety_character;
1579 1579
     my $q = $self->_quote;
1580
-    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1580
+    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
1581 1581
     my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
1582 1582
                       : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
1583 1583
     while ($source =~ /$table_re/g) {
... ...
@@ -1617,8 +1617,8 @@ sub _where_clause_and_param {
1617 1617
                 }
1618 1618
                 
1619 1619
                 my $table_quote;
1620
-                $table_quote = $self->_q($table) if defined $table;
1621
-                my $column_quote = $self->_q($c);
1620
+                $table_quote = $self->q($table) if defined $table;
1621
+                my $column_quote = $self->q($c);
1622 1622
                 $column_quote = $table_quote . '.' . $column_quote
1623 1623
                   if defined $table_quote;
1624 1624
                 push @$clause, "$column_quote = :$column" for keys %$where;
... ...
@@ -2944,6 +2944,12 @@ This is used in C<param> of L<DBIx::Custom::Where> .
2944 2944
 
2945 2945
 Create a new L<DBIx::Custom::Order> object.
2946 2946
 
2947
+=head2 C<q EXPERIMENTAL>
2948
+
2949
+    my $quooted = $dbi->q("title");
2950
+
2951
+Quote string by value of C<quote>.
2952
+
2947 2953
 =head2 C<register_filter>
2948 2954
 
2949 2955
     $dbi->register_filter(
+1 -1
lib/DBIx/Custom/Order.pm
... ...
@@ -14,7 +14,7 @@ sub prepend {
14 14
     for my $order (reverse @_) {
15 15
         if (ref $order eq 'ARRAY') {
16 16
             my $column = shift @$order;
17
-            $column = $self->dbi->_q($column) if defined $column;
17
+            $column = $self->dbi->q($column) if defined $column;
18 18
             my $derection = shift @$order;
19 19
             $order = $column;
20 20
             $order .= " $derection" if $derection;