Showing 6 changed files with 122 additions and 57 deletions
+4
Changes
... ...
@@ -1,4 +1,8 @@
1 1
 0.1745
2
+    - DBIx::Custom::QueryBuilder class is DEPRECATED!
3
+    - added DBIX_CUSTOM_DISABLE_MODEL_EXECUTE environment variable
4
+    - added DBIX_CUSTOM_TAG_PARSE environment variable
5
+    - tag_parse attribute is DEPRECATED! 
2 6
     - show_datatype method return lower case string
3 7
     - show_typename method return lower case string
4 8
     - DBIx::Custom::Result filter_on method is DEPRECATED!
+32 -15
lib/DBIx/Custom.pm
... ...
@@ -1,7 +1,7 @@
1 1
 package DBIx::Custom;
2 2
 use Object::Simple -base;
3 3
 
4
-our $VERSION = '0.1744';
4
+our $VERSION = '0.1745';
5 5
 use 5.008001;
6 6
 
7 7
 use Carp 'croak';
... ...
@@ -71,8 +71,7 @@ has [qw/connector dsn password quote user exclude_table user_table_info
71 71
     result_class  => 'DBIx::Custom::Result',
72 72
     safety_character => '\w',
73 73
     separator => '.',
74
-    stash => sub { {} },
75
-    tag_parse => 1;
74
+    stash => sub { {} };
76 75
 
77 76
 sub available_datatype {
78 77
     my $self = shift;
... ...
@@ -838,6 +837,9 @@ sub new {
838 837
         'update_param' => \&DBIx::Custom::Tag::update_param
839 838
     };
840 839
     
840
+    # DEPRECATED!
841
+    $self->{tag_parse} = 1;
842
+    
841 843
     return $self;
842 844
 }
843 845
 
... ...
@@ -1705,6 +1707,18 @@ has default_dbi_option => sub {
1705 1707
     return shift->default_option;
1706 1708
 };
1707 1709
 
1710
+# DEPRECATED
1711
+sub tag_parse {
1712
+   my $self = shift;
1713
+   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1714
+         "environment variable";
1715
+    if (@_) {
1716
+        $self->{tag_parse} = $_[0];
1717
+        return $self;
1718
+    }
1719
+    return $self->{tag_parse};
1720
+}
1721
+
1708 1722
 # DEPRECATED!
1709 1723
 sub method {
1710 1724
     warn "method is DEPRECATED! use helper instead";
... ...
@@ -2612,6 +2626,18 @@ You can check SQL, column, or get statment handle.
2612 2626
     my $sth = $query->sth;
2613 2627
     my $columns = $query->columns;
2614 2628
     
2629
+=item C<reuse>
2630
+    
2631
+    reuse => $hash_ref
2632
+
2633
+Reuse query object if the hash reference variable is set.
2634
+    
2635
+    my $queries = {};
2636
+    $dbi->execute($sql, $param, reuse => $queries);
2637
+
2638
+This will improved performance when you want to execute same query repeatedly
2639
+because generally creating query object is slow.
2640
+
2615 2641
 =item C<primary_key>
2616 2642
 
2617 2643
     primary_key => 'id'
... ...
@@ -2643,18 +2669,6 @@ Table alias. Key is real table name, value is alias table name.
2643 2669
 If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2644 2670
 on alias table name.
2645 2671
 
2646
-=item C<reuse>
2647
-    
2648
-    reuse => $hash_ref
2649
-
2650
-Reuse query object if the hash reference variable is set.
2651
-    
2652
-    my $queries = {};
2653
-    $dbi->execute($sql, $param, reuse => $queries);
2654
-
2655
-This will improved performance when you want to execute same query repeatedly
2656
-because generally creating query object is slow.
2657
-
2658 2672
 =item C<type_rule_off>
2659 2673
 
2660 2674
     type_rule_off => 1
... ...
@@ -3392,6 +3406,7 @@ DEBUG output encoding. Default to UTF-8.
3392 3406
 L<DBIx::Custom>
3393 3407
 
3394 3408
     # Attribute methods
3409
+    tag_parse # will be removed 2017/1/1
3395 3410
     default_dbi_option # will be removed 2017/1/1
3396 3411
     dbi_option # will be removed 2017/1/1
3397 3412
     data_source # will be removed at 2017/1/1
... ...
@@ -3464,6 +3479,8 @@ L<DBIx::Custom::Query>
3464 3479
     filter # will be removed at 2017/1/1
3465 3480
 
3466 3481
 L<DBIx::Custom::QueryBuilder>
3482
+
3483
+This module is DEPRECATED! # will be removed at 2017/1/1
3467 3484
     
3468 3485
     # Attribute methods
3469 3486
     tags # will be removed at 2017/1/1
+20 -10
lib/DBIx/Custom/Model.pm
... ...
@@ -87,17 +87,27 @@ sub update_or_insert {
87 87
 }
88 88
 
89 89
 sub execute {
90
-    warn "DBIx::Custom::Model execute method is DEPRECATED!";
91 90
     my $self = shift;
92
-    return $self->dbi->execute(
93
-        shift,
94
-        shift,
95
-        table => $self->table,
96
-        bind_type => $self->bind_type,
97
-        primary_key => $self->primary_key,
98
-        type => $self->type,
99
-        @_
100
-    );
91
+    
92
+    if ($ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE}) {
93
+        $self->dbi->execute(@_);
94
+    }
95
+    else {
96
+        warn "DBIx::Custom::Model execute method is DEPRECATED! " .
97
+             "use DBIx::Custom execute method. " .
98
+             "If you want to call DBIx::Custom execute method directory from model, " .
99
+             "set \$ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} to 1 " .
100
+             "until DBIx::Custom::Model execute method is removed in the future." ;
101
+        return $self->dbi->execute(
102
+            shift,
103
+            shift,
104
+            table => $self->table,
105
+            bind_type => $self->bind_type,
106
+            primary_key => $self->primary_key,
107
+            type => $self->type,
108
+            @_
109
+        );    
110
+    }
101 111
 }
102 112
 
103 113
 sub DESTROY { }
+13 -30
lib/DBIx/Custom/QueryBuilder.pm
... ...
@@ -10,13 +10,16 @@ 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
-has 'dbi';
14
-
15 13
 sub build_query {
16 14
     my ($self, $sql) = @_;
17 15
     
18 16
     # Parse tag. tag is DEPRECATED!
19
-    if ($sql =~ /(\s|^)\{/ && $self->dbi->tag_parse) {
17
+    my $tag_parse;
18
+    $tag_parse = $ENV{DBIX_CUSTOM_TAG_PARSE}
19
+      if exists $ENV{DBIX_CUSTOM_TAG_PARSE};
20
+    $tag_parse = $self->dbi->{tag_parse} unless defined $tag_parse;
21
+    
22
+    if ($tag_parse && $sql =~ /(\s|^)\{/) {
20 23
         my $query = $self->_parse_tag($sql);
21 24
         my $tag_count = delete $query->{tag_count};
22 25
         warn qq/Tag system such as {? name} is DEPRECATED! / .
... ...
@@ -77,7 +80,10 @@ sub _parse_parameter {
77 80
     
78 81
     return $query;
79 82
 }
80
-    
83
+
84
+# DEPRECATED
85
+has 'dbi';
86
+
81 87
 # DEPRECATED!
82 88
 has tags => sub { {} };
83 89
 
... ...
@@ -286,33 +292,10 @@ sub register_tag_processor {
286 292
 
287 293
 =head1 NAME
288 294
 
289
-DBIx::Custom::QueryBuilder - Query builder
295
+DBIx::Custom::QueryBuilder - DEPRECATED!
290 296
 
291
-=head1 SYNOPSIS
292
-    
293
-    my $builder = DBIx::Custom::QueryBuilder->new;
294
-    my $query = $builder->build_query(
295
-        "select from table title = :title and author = :author"
296
-    );
297
-
298
-=head1 ATTRIBUTES
299
-
300
-=head2 C<dbi>
301
-
302
-    my $dbi = $builder->dbi;
303
-    $builder = $builder->dbi($dbi);
304
-
305
-L<DBIx::Custom> object.
306
-
307
-=head1 METHODS
308
-
309
-L<DBIx::Custom::QueryBuilder> inherits all methods from L<Object::Simple>
310
-and implements the following new ones.
311
-
312
-=head2 C<build_query>
313
-    
314
-    my $query = $builder->build_query($source);
297
+=head1 DESCRIPTION
315 298
 
316
-Create a new L<DBIx::Custom::Query> object from SQL source.
299
+This module functionality will be moved to DBIx::Custom
317 300
 
318 301
 =cut
+2 -2
lib/DBIx/Custom/Where.pm
... ...
@@ -39,14 +39,14 @@ sub to_string {
39 39
     $self->{_query_builder} = $self->dbi->query_builder;
40 40
     $self->{_safety_character} = $self->dbi->safety_character;
41 41
     $self->{_quote} = $self->dbi->_quote;
42
-    $self->{_tag_parse} = $self->dbi->tag_parse;
42
+    $self->{_tag_parse} = $self->dbi->{tag_parse};
43 43
     $self->_parse($clause, $where, $count, 'and');
44 44
 
45 45
     # Stringify
46 46
     unshift @$where, 'where' if @$where;
47 47
     return join(' ', @$where);
48 48
 }
49
-
49
+    
50 50
 our %VALID_OPERATIONS = map { $_ => 1 } qw/and or/;
51 51
 sub _parse {
52 52
     my ($self, $clause, $where, $count, $op, $info) = @_;
+51
t/common.t
... ...
@@ -3024,6 +3024,28 @@ $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3024 3024
 eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3025 3025
 ok($@);
3026 3026
 
3027
+test 'DBIX_CUSTOM_TAG_PARSE environment variable';
3028
+{
3029
+    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3030
+    $dbi = DBIx::Custom->connect;
3031
+    eval { $dbi->execute("drop table $table1") };
3032
+    $dbi->execute($create_table1);
3033
+    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3034
+    eval {$dbi->execute("select * from $table1 where {= $key1}", {$key1 => 1})};
3035
+    ok($@);
3036
+    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3037
+}
3038
+
3039
+{
3040
+    $ENV{DBIX_CUSTOM_TAG_PARSE} = 0;
3041
+    $dbi = DBIx::Custom->connect;
3042
+    eval { $dbi->execute("drop table $table1") };
3043
+    $dbi->execute($create_table1);
3044
+    $dbi->insert({$key1 => 1, $key2 => 1}, table => $table1);
3045
+    is($dbi->select(table => $table1)->one->{$key1}, 1);
3046
+    delete$ENV{DBIX_CUSTOM_TAG_PARSE};
3047
+}
3048
+
3027 3049
 test 'last_sql';
3028 3050
 $dbi = DBIx::Custom->connect;
3029 3051
 eval { $dbi->execute("drop table $table1") };
... ...
@@ -3135,6 +3157,35 @@ $rows = [
3135 3157
     );
3136 3158
 }
3137 3159
 
3160
+eval { $dbi->execute("drop table $table1") };
3161
+$dbi->execute($create_table1);
3162
+{
3163
+    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3164
+    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3165
+    eval {$model->execute("select * from $table1 where :${key1}{=}", id => 1)};
3166
+    like($@, qr/primary_key/);
3167
+    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3168
+}
3169
+
3170
+{
3171
+    $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE} = 1;
3172
+    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3173
+    $model->insert({$key1 => 1});
3174
+    $result = $model->execute("select * from $table1 where :${key1}{=}", id => 1,
3175
+      table => $table1, primary_key => $key1);
3176
+    is($result->one->{$key1}, 1);
3177
+    delete $ENV{DBIX_CUSTOM_DISABLE_MODEL_EXECUTE};
3178
+}
3179
+
3180
+eval { $dbi->execute("drop table $table1") };
3181
+$dbi->execute($create_table1);
3182
+{
3183
+    $model = $dbi->create_model(table => $table1, primary_key => $key1);
3184
+    $model->insert({$key1 => 1});
3185
+    eval {$result = $model->execute("select * from $table1 where :${key1}{=}", {}, id => 1)};
3186
+    is($result->one->{$key1}, 1);
3187
+}
3188
+
3138 3189
 test 'id option more';
3139 3190
 eval { $dbi->execute("drop table $table1") };
3140 3191
 $dbi->execute($create_table1_highperformance);