reserved_word_quote is DEPRECATED! this is renamed...
...to quote
... | ... |
@@ -1,4 +1,5 @@ |
1 | 1 |
0.1694 |
2 |
+ - reserved_word_quote is DEPRECATED! this is renamed to quote |
|
2 | 3 |
- DBIx::Custom::Model type attribute is DEPRECATED! |
3 | 4 |
this is renamed to bind_type. |
4 | 5 |
0.1693 |
... | ... |
@@ -22,7 +22,7 @@ use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8'; |
22 | 22 |
our @COMMON_ARGS = qw/bind_type table query filter id primary_key |
23 | 23 |
type_rule_off type/; |
24 | 24 |
|
25 |
-has [qw/connector dsn password user/], |
|
25 |
+has [qw/connector dsn password quote user/], |
|
26 | 26 |
cache => 0, |
27 | 27 |
cache_method => sub { |
28 | 28 |
sub { |
... | ... |
@@ -55,7 +55,6 @@ has [qw/connector dsn password user/], |
55 | 55 |
models => sub { {} }, |
56 | 56 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
57 | 57 |
result_class => 'DBIx::Custom::Result', |
58 |
- reserved_word_quote => '', |
|
59 | 58 |
safety_character => '\w', |
60 | 59 |
stash => sub { {} }; |
61 | 60 |
|
... | ... |
@@ -86,7 +85,7 @@ sub assign_param { |
86 | 85 |
# Create set tag |
87 | 86 |
my @params; |
88 | 87 |
my $safety = $self->safety_character; |
89 |
- my $q = $self->reserved_word_quote; |
|
88 |
+ my $q = $self->_quote; |
|
90 | 89 |
foreach my $column (keys %$param) { |
91 | 90 |
croak qq{"$column" is not safety column name } . _subname |
92 | 91 |
unless $column =~ /^[$safety\.]+$/; |
... | ... |
@@ -112,7 +111,7 @@ sub column { |
112 | 111 |
} |
113 | 112 |
|
114 | 113 |
# Reserved word quote |
115 |
- my $q = $self->reserved_word_quote; |
|
114 |
+ my $q = $self->_quote; |
|
116 | 115 |
|
117 | 116 |
# Separator |
118 | 117 |
my $separator = $self->separator; |
... | ... |
@@ -165,7 +164,7 @@ sub create_query { |
165 | 164 |
$query = $builder->build_query($source); |
166 | 165 |
|
167 | 166 |
# Remove reserved word quote |
168 |
- if (my $q = $self->reserved_word_quote) { |
|
167 |
+ if (my $q = $self->_quote) { |
|
169 | 168 |
$_ =~ s/$q//g for @{$query->columns} |
170 | 169 |
} |
171 | 170 |
|
... | ... |
@@ -222,12 +221,12 @@ sub dbh { |
222 | 221 |
$self->{dbh} ||= $self->_connect; |
223 | 222 |
|
224 | 223 |
# Quote |
225 |
- unless ($self->reserved_word_quote) { |
|
224 |
+ if (!defined $self->reserved_word_quote && !defined $self->quote) { |
|
226 | 225 |
my $driver = $self->{dbh}->{Driver}->{Name}; |
227 | 226 |
my $quote = $driver eq 'mysql' ? '`' : '"'; |
228 |
- $self->reserved_word_quote($quote); |
|
227 |
+ $self->quote($quote); |
|
229 | 228 |
} |
230 |
- |
|
229 |
+ |
|
231 | 230 |
return $self->{dbh}; |
232 | 231 |
} |
233 | 232 |
} |
... | ... |
@@ -277,7 +276,7 @@ sub delete { |
277 | 276 |
|
278 | 277 |
# Delete statement |
279 | 278 |
my @sql; |
280 |
- my $q = $self->reserved_word_quote; |
|
279 |
+ my $q = $self->_quote; |
|
281 | 280 |
push @sql, "delete from $q$table$q $where_clause"; |
282 | 281 |
push @sql, $append if $append; |
283 | 282 |
my $sql = join(' ', @sql); |
... | ... |
@@ -380,7 +379,7 @@ sub execute { |
380 | 379 |
unshift @$tables, @{$query->tables}; |
381 | 380 |
my $main_table = pop @$tables; |
382 | 381 |
$tables = $self->_remove_duplicate_table($tables, $main_table); |
383 |
- if (my $q = $self->reserved_word_quote) { |
|
382 |
+ if (my $q = $self->_quote) { |
|
384 | 383 |
$_ =~ s/$q//g for @$tables; |
385 | 384 |
} |
386 | 385 |
|
... | ... |
@@ -541,7 +540,7 @@ sub insert { |
541 | 540 |
} |
542 | 541 |
|
543 | 542 |
# Reserved word quote |
544 |
- my $q = $self->reserved_word_quote; |
|
543 |
+ my $q = $self->_quote; |
|
545 | 544 |
|
546 | 545 |
# Insert statement |
547 | 546 |
my @sql; |
... | ... |
@@ -563,7 +562,7 @@ sub insert_param { |
563 | 562 |
|
564 | 563 |
# Create insert parameter tag |
565 | 564 |
my $safety = $self->safety_character; |
566 |
- my $q = $self->reserved_word_quote; |
|
565 |
+ my $q = $self->_quote; |
|
567 | 566 |
my @columns; |
568 | 567 |
my @placeholders; |
569 | 568 |
foreach my $column (keys %$param) { |
... | ... |
@@ -700,7 +699,7 @@ sub mycolumn { |
700 | 699 |
|
701 | 700 |
# Create column clause |
702 | 701 |
my @column; |
703 |
- my $q = $self->reserved_word_quote; |
|
702 |
+ my $q = $self->_quote; |
|
704 | 703 |
$columns ||= []; |
705 | 704 |
push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns; |
706 | 705 |
|
... | ... |
@@ -796,7 +795,7 @@ sub select { |
796 | 795 |
push @sql, 'select'; |
797 | 796 |
|
798 | 797 |
# Reserved word quote |
799 |
- my $q = $self->reserved_word_quote; |
|
798 |
+ my $q = $self->_quote; |
|
800 | 799 |
|
801 | 800 |
# Prefix |
802 | 801 |
push @sql, $prefix if defined $prefix; |
... | ... |
@@ -1066,7 +1065,7 @@ sub update { |
1066 | 1065 |
|
1067 | 1066 |
# Update statement |
1068 | 1067 |
my @sql; |
1069 |
- my $q = $self->reserved_word_quote; |
|
1068 |
+ my $q = $self->_quote; |
|
1070 | 1069 |
push @sql, "update $q$table$q $update_clause $where_clause"; |
1071 | 1070 |
push @sql, $append if $append; |
1072 | 1071 |
|
... | ... |
@@ -1103,7 +1102,7 @@ sub where { |
1103 | 1102 |
return DBIx::Custom::Where->new( |
1104 | 1103 |
query_builder => $self->query_builder, |
1105 | 1104 |
safety_character => $self->safety_character, |
1106 |
- reserved_word_quote => $self->reserved_word_quote, |
|
1105 |
+ quote => $self->_quote, |
|
1107 | 1106 |
@_ |
1108 | 1107 |
); |
1109 | 1108 |
} |
... | ... |
@@ -1318,7 +1317,7 @@ sub _push_join { |
1318 | 1317 |
|
1319 | 1318 |
# Push join clause |
1320 | 1319 |
my $tree = {}; |
1321 |
- my $q = $self->reserved_word_quote; |
|
1320 |
+ my $q = $self->_quote; |
|
1322 | 1321 |
for (my $i = 0; $i < @$join; $i++) { |
1323 | 1322 |
|
1324 | 1323 |
# Search table in join clause |
... | ... |
@@ -1352,6 +1351,14 @@ sub _push_join { |
1352 | 1351 |
} |
1353 | 1352 |
} |
1354 | 1353 |
|
1354 |
+sub _quote { |
|
1355 |
+ my $self = shift; |
|
1356 |
+ |
|
1357 |
+ return defined $self->reserved_word_quote ? $self->reserved_word_quote |
|
1358 |
+ : defined $self->quote ? $self->quote |
|
1359 |
+ : ''; |
|
1360 |
+} |
|
1361 |
+ |
|
1355 | 1362 |
sub _remove_duplicate_table { |
1356 | 1363 |
my ($self, $tables, $main_table) = @_; |
1357 | 1364 |
|
... | ... |
@@ -1368,7 +1375,7 @@ sub _search_tables { |
1368 | 1375 |
# Search tables |
1369 | 1376 |
my $tables = []; |
1370 | 1377 |
my $safety_character = $self->safety_character; |
1371 |
- my $q = $self->reserved_word_quote; |
|
1378 |
+ my $q = $self->_quote; |
|
1372 | 1379 |
my $q_re = quotemeta($q); |
1373 | 1380 |
my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./ |
1374 | 1381 |
: qr/(?:^|[^$safety_character])([$safety_character]+)\./; |
... | ... |
@@ -1387,7 +1394,7 @@ sub _where_to_obj { |
1387 | 1394 |
# Hash |
1388 | 1395 |
if (ref $where eq 'HASH') { |
1389 | 1396 |
my $clause = ['and']; |
1390 |
- my $q = $self->reserved_word_quote; |
|
1397 |
+ my $q = $self->_quote; |
|
1391 | 1398 |
foreach my $column (keys %$where) { |
1392 | 1399 |
my $column_quote = "$q$column$q"; |
1393 | 1400 |
$column_quote =~ s/\./$q.$q/; |
... | ... |
@@ -1553,11 +1560,9 @@ sub register_tag { |
1553 | 1560 |
|
1554 | 1561 |
# DEPRECATED! |
1555 | 1562 |
has 'data_source'; |
1556 |
- |
|
1557 |
-# DEPRECATED! |
|
1558 |
-has dbi_options => sub { {} }, |
|
1559 |
- filter_check => 1; |
|
1560 |
- |
|
1563 |
+has dbi_options => sub { {} }; |
|
1564 |
+has filter_check => 1; |
|
1565 |
+has 'reserved_word_quote'; |
|
1561 | 1566 |
|
1562 | 1567 |
# DEPRECATED! |
1563 | 1568 |
sub default_bind_filter { |
... | ... |
@@ -1785,7 +1790,7 @@ L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> |
1785 | 1790 |
=head2 C<connector> |
1786 | 1791 |
|
1787 | 1792 |
my $connector = $dbi->connector; |
1788 |
- $dbi = $dbi->connector(DBIx::Connector->new(...)); |
|
1793 |
+ $dbi = $dbi->connector(DBIx::Connector->new(...)); |
|
1789 | 1794 |
|
1790 | 1795 |
Connection manager object. if connector is set, you can get C<dbh()> |
1791 | 1796 |
from connection manager. conection manager object must have dbh() mehtod. |
... | ... |
@@ -1805,14 +1810,14 @@ C<default_dbi_option> to L<DBIx::Connector>. |
1805 | 1810 |
=head2 C<dsn> |
1806 | 1811 |
|
1807 | 1812 |
my $dsn = $dbi->dsn; |
1808 |
- $dbi = $dbi->dsn("DBI:mysql:database=dbname"); |
|
1813 |
+ $dbi = $dbi->dsn("DBI:mysql:database=dbname"); |
|
1809 | 1814 |
|
1810 | 1815 |
Data source name, used when C<connect()> is executed. |
1811 | 1816 |
|
1812 | 1817 |
=head2 C<dbi_option> |
1813 | 1818 |
|
1814 | 1819 |
my $dbi_option = $dbi->dbi_option; |
1815 |
- $dbi = $dbi->dbi_option($dbi_option); |
|
1820 |
+ $dbi = $dbi->dbi_option($dbi_option); |
|
1816 | 1821 |
|
1817 | 1822 |
L<DBI> option, used when C<connect()> is executed. |
1818 | 1823 |
Each value in option override the value of C<default_dbi_option>. |
... | ... |
@@ -1820,7 +1825,7 @@ Each value in option override the value of C<default_dbi_option>. |
1820 | 1825 |
=head2 C<default_dbi_option> |
1821 | 1826 |
|
1822 | 1827 |
my $default_dbi_option = $dbi->default_dbi_option; |
1823 |
- $dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1828 |
+ $dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1824 | 1829 |
|
1825 | 1830 |
L<DBI> default option, used when C<connect()> is executed, |
1826 | 1831 |
default to the following values. |
... | ... |
@@ -1837,35 +1842,35 @@ the value is used to check if the process is in transaction. |
1837 | 1842 |
=head2 C<filters> |
1838 | 1843 |
|
1839 | 1844 |
my $filters = $dbi->filters; |
1840 |
- $dbi = $dbi->filters(\%filters); |
|
1845 |
+ $dbi = $dbi->filters(\%filters); |
|
1841 | 1846 |
|
1842 | 1847 |
Filters, registered by C<register_filter()>. |
1843 | 1848 |
|
1844 | 1849 |
=head2 C<models> |
1845 | 1850 |
|
1846 | 1851 |
my $models = $dbi->models; |
1847 |
- $dbi = $dbi->models(\%models); |
|
1852 |
+ $dbi = $dbi->models(\%models); |
|
1848 | 1853 |
|
1849 | 1854 |
Models, included by C<include_model()>. |
1850 | 1855 |
|
1851 | 1856 |
=head2 C<password> |
1852 | 1857 |
|
1853 | 1858 |
my $password = $dbi->password; |
1854 |
- $dbi = $dbi->password('lkj&le`@s'); |
|
1859 |
+ $dbi = $dbi->password('lkj&le`@s'); |
|
1855 | 1860 |
|
1856 | 1861 |
Password, used when C<connect()> is executed. |
1857 | 1862 |
|
1858 | 1863 |
=head2 C<query_builder> |
1859 | 1864 |
|
1860 | 1865 |
my $sql_class = $dbi->query_builder; |
1861 |
- $dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
1866 |
+ $dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
1862 | 1867 |
|
1863 | 1868 |
Query builder, default to L<DBIx::Custom::QueryBuilder> object. |
1864 | 1869 |
|
1865 |
-=head2 C<reserved_word_quote> |
|
1870 |
+=head2 C<quote> |
|
1866 | 1871 |
|
1867 |
- my reserved_word_quote = $dbi->reserved_word_quote; |
|
1868 |
- $dbi = $dbi->reserved_word_quote('"'); |
|
1872 |
+ my quote = $dbi->quote; |
|
1873 |
+ $dbi = $dbi->quote('"'); |
|
1869 | 1874 |
|
1870 | 1875 |
Reserved word quote. |
1871 | 1876 |
Default to double quote '"' except for mysql. |
... | ... |
@@ -1874,14 +1879,14 @@ In mysql, default to back quote '`' |
1874 | 1879 |
=head2 C<result_class> |
1875 | 1880 |
|
1876 | 1881 |
my $result_class = $dbi->result_class; |
1877 |
- $dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
1882 |
+ $dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
1878 | 1883 |
|
1879 | 1884 |
Result class, default to L<DBIx::Custom::Result>. |
1880 | 1885 |
|
1881 | 1886 |
=head2 C<safety_character> |
1882 | 1887 |
|
1883 | 1888 |
my $safety_character = $self->safety_character; |
1884 |
- $dbi = $self->safety_character($character); |
|
1889 |
+ $dbi = $self->safety_character($character); |
|
1885 | 1890 |
|
1886 | 1891 |
Regex of safety character for table and column name, default to '\w'. |
1887 | 1892 |
Note that you don't have to specify like '[\w]'. |
... | ... |
@@ -1889,7 +1894,7 @@ Note that you don't have to specify like '[\w]'. |
1889 | 1894 |
=head2 C<user> |
1890 | 1895 |
|
1891 | 1896 |
my $user = $dbi->user; |
1892 |
- $dbi = $dbi->user('Ken'); |
|
1897 |
+ $dbi = $dbi->user('Ken'); |
|
1893 | 1898 |
|
1894 | 1899 |
User name, used when C<connect()> is executed. |
1895 | 1900 |
|
... | ... |
@@ -9,9 +9,8 @@ use overload '""' => sub { shift->to_string }, fallback => 1; |
9 | 9 |
# Carp trust relationship |
10 | 10 |
push @DBIx::Custom::CARP_NOT, __PACKAGE__; |
11 | 11 |
|
12 |
-has [qw/param query_builder safety_character/], |
|
13 |
- clause => sub { [] }, |
|
14 |
- reserved_word_quote => ''; |
|
12 |
+has [qw/param query_builder quote safety_character /], |
|
13 |
+ clause => sub { [] }; |
|
15 | 14 |
|
16 | 15 |
sub new { |
17 | 16 |
my $self = shift->SUPER::new(@_); |
... | ... |
@@ -103,7 +102,7 @@ sub _parse { |
103 | 102 |
|
104 | 103 |
# Remove quote |
105 | 104 |
my $column = $columns->[0]; |
106 |
- if (my $q = $self->reserved_word_quote) { |
|
105 |
+ if (my $q = $self->quote) { |
|
107 | 106 |
$column =~ s/$q//g; |
108 | 107 |
} |
109 | 108 |
|
... | ... |
@@ -283,7 +283,7 @@ eval{$dbi->insert(table => 'table', param => {';' => 1})}; |
283 | 283 |
like($@, qr/safety/); |
284 | 284 |
|
285 | 285 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
286 |
-$dbi->reserved_word_quote('"'); |
|
286 |
+$dbi->quote('"'); |
|
287 | 287 |
$dbi->execute('create table "table" ("select")'); |
288 | 288 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
289 | 289 |
$dbi->insert(table => 'table', param => {select => 1}); |
... | ... |
@@ -389,7 +389,7 @@ eval{$dbi->update(table => 'table1', param => {'key1' => 1}, where => {';' => 1} |
389 | 389 |
like($@, qr/safety/); |
390 | 390 |
|
391 | 391 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
392 |
-$dbi->reserved_word_quote('"'); |
|
392 |
+$dbi->quote('"'); |
|
393 | 393 |
$dbi->execute('create table "table" ("select", "update")'); |
394 | 394 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
395 | 395 |
$dbi->apply_filter('table', update => {out => sub { $_[0] * 3}}); |
... | ... |
@@ -505,7 +505,7 @@ eval{$dbi->delete(table => 'table1', where => {';' => 1})}; |
505 | 505 |
like($@, qr/safety/); |
506 | 506 |
|
507 | 507 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
508 |
-$dbi->reserved_word_quote('"'); |
|
508 |
+$dbi->quote('"'); |
|
509 | 509 |
$dbi->execute('create table "table" ("select", "update")'); |
510 | 510 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
511 | 511 |
$dbi->insert(table => 'table', param => {select => 1}); |
... | ... |
@@ -572,7 +572,7 @@ eval{$dbi->select(table => 'table1', noexist => 1)}; |
572 | 572 |
like($@, qr/noexist/, "invalid"); |
573 | 573 |
|
574 | 574 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
575 |
-$dbi->reserved_word_quote('"'); |
|
575 |
+$dbi->quote('"'); |
|
576 | 576 |
$dbi->execute('create table "table" ("select", "update")'); |
577 | 577 |
$dbi->apply_filter('table', select => {out => sub { $_[0] * 2}}); |
578 | 578 |
$dbi->insert(table => 'table', param => {select => 1, update => 2}); |
... | ... |
@@ -1974,7 +1974,7 @@ is($dbi->select(table => 'table1')->one->{key1}, 1); |
1974 | 1974 |
is($dbi->select(table => 'table1')->one->{key2}, 2); |
1975 | 1975 |
|
1976 | 1976 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
1977 |
-$dbi->reserved_word_quote('"'); |
|
1977 |
+$dbi->quote('"'); |
|
1978 | 1978 |
$dbi->execute($CREATE_TABLE->{1}); |
1979 | 1979 |
$param = {key1 => 1, key2 => 2}; |
1980 | 1980 |
$insert_param = $dbi->insert_param($param); |
... | ... |
@@ -2050,7 +2050,7 @@ $rows = $dbi->select( |
2050 | 2050 |
is_deeply($rows, [{table1__key1 => 1}]); |
2051 | 2051 |
|
2052 | 2052 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
2053 |
-$dbi->reserved_word_quote('"'); |
|
2053 |
+$dbi->quote('"'); |
|
2054 | 2054 |
$dbi->execute($CREATE_TABLE->{0}); |
2055 | 2055 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
2056 | 2056 |
$dbi->execute($CREATE_TABLE->{2}); |
... | ... |
@@ -2062,7 +2062,7 @@ $rows = $dbi->select( |
2062 | 2062 |
join => ['left outer join "table2" on "table1"."key1" = "table2"."key1"'], |
2063 | 2063 |
)->all; |
2064 | 2064 |
is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], |
2065 |
- 'reserved_word_quote'); |
|
2065 |
+ 'quote'); |
|
2066 | 2066 |
|
2067 | 2067 |
{ |
2068 | 2068 |
package MyDBI8; |