DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3059 lines | 79.017kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
4
our $VERSION = '0.1698';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
17
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
19
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
20
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
21

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
22
our @COMMON_ARGS = qw/bind_type table query filter id primary_key
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
23
  type_rule_off type_rule1_off type_rule2_off type table_alias/;
cleanup
Yuki Kimoto authored on 2011-03-21
24

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
25
has [qw/connector dsn password quote user/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
26
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
27
    cache_method => sub {
28
        sub {
29
            my $self = shift;
30
            
31
            $self->{_cached} ||= {};
32
            
33
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
34
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
35
            }
36
            else {
update pod
Yuki Kimoto authored on 2011-03-13
37
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
38
            }
39
        }
update pod
Yuki Kimoto authored on 2011-03-13
40
    },
41
    dbi_option => sub { {} },
42
    default_dbi_option => sub {
43
        {
44
            RaiseError => 1,
45
            PrintError => 0,
46
            AutoCommit => 1
47
        }
48
    },
fix tests
Yuki Kimoto authored on 2011-01-13
49
    filters => sub {
50
        {
51
            encode_utf8 => sub { encode_utf8($_[0]) },
52
            decode_utf8 => sub { decode_utf8($_[0]) }
53
        }
update pod
Yuki Kimoto authored on 2011-03-13
54
    },
55
    models => sub { {} },
56
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
57
    result_class  => 'DBIx::Custom::Result',
58
    safety_character => '\w',
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
59
    stash => sub { {} },
60
    tag_parse => 1;
cleanup
yuki-kimoto authored on 2010-10-17
61

            
added helper method
yuki-kimoto authored on 2010-10-17
62
our $AUTOLOAD;
63
sub AUTOLOAD {
64
    my $self = shift;
65

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
66
    # Method name
67
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
68

            
cleanup
Yuki Kimoto authored on 2011-04-02
69
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
70
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
71
    if (my $method = $self->{_methods}->{$mname}) {
72
        return $self->$method(@_)
73
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
74
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
75
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
76
    }
77
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
78
        croak qq{Can't locate object method "$mname" via "$package" }
79
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
80
    }
added helper method
yuki-kimoto authored on 2010-10-17
81
}
82

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
83
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
84
    my ($self, $param) = @_;
85
    
86
    # Create set tag
87
    my @params;
88
    my $safety = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
89
    my $q = $self->_quote;
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
90
    foreach my $column (keys %$param) {
91
        croak qq{"$column" is not safety column name } . _subname
92
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
93
        my $column_quote = "$q$column$q";
94
        $column_quote =~ s/\./$q.$q/;
95
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
96
    }
97
    my $tag = join(', ', @params);
98
    
99
    return $tag;
100
}
101

            
cleanup
Yuki Kimoto authored on 2011-03-21
102
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
103
    my $self = shift;
104
    my $option = pop if ref $_[-1] eq 'HASH';
105
    my $real_table = shift;
106
    my $columns = shift;
107
    my $table = $option->{alias} || $real_table;
108
    
109
    # Columns
110
    unless ($columns) {
111
        $columns ||= $self->model($real_table)->columns;
112
    }
added helper method
yuki-kimoto authored on 2010-10-17
113
    
cleanup
Yuki Kimoto authored on 2011-04-02
114
    # Reserved word quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
115
    my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
116
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
117
    # Separator
118
    my $separator = $self->separator;
119
    
cleanup
Yuki Kimoto authored on 2011-04-02
120
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
121
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
122
    $columns ||= [];
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
123
    push @column, "$q$table$q.$q$_$q as $q${table}${separator}$_$q"
124
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
125
    
126
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
127
}
128

            
packaging one directory
yuki-kimoto authored on 2009-11-16
129
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
130
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
131
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
132
    # Connect
133
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
134
    
packaging one directory
yuki-kimoto authored on 2009-11-16
135
    return $self;
136
}
137

            
update pod
Yuki Kimoto authored on 2011-03-13
138
sub dbh {
139
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
140
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
141
    # Set
142
    if (@_) {
143
        $self->{dbh} = $_[0];
144
        
145
        return $self;
146
    }
147
    
148
    # Get
149
    else {
150
        # From Connction manager
151
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
152
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
153
              unless ref $connector && $connector->can('dbh');
154
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
155
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
156
        }
157
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
158
        # Connect
159
        $self->{dbh} ||= $self->_connect;
160
        
161
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
162
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
163
            my $driver = $self->{dbh}->{Driver}->{Name};
164
            my $quote = $driver eq 'mysql' ? '`' : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
165
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
166
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
167
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
168
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
169
    }
170
}
171

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
172
our %DELETE_ARGS = map { $_ => 1 } @COMMON_ARGS,
173
  qw/where append allow_delete_all where_param prefix/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
174

            
cleanup
yuki-kimoto authored on 2010-10-17
175
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
176
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
177

            
cleanup
Yuki Kimoto authored on 2011-04-02
178
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
179
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
180
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
181
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
182
    }
183
    
184
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
185
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
186
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
187
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
188
    my $where            = delete $args{where} || {};
189
    my $append           = delete $args{append};
190
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
191
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
192
    my $id = delete $args{id};
193
    my $primary_key = delete $args{primary_key};
194
    croak "update method primary_key option " .
195
          "must be specified when id is specified " . _subname
196
      if defined $id && !defined $primary_key;
197
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
198
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
199
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
200
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
201
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
202
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
203
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
204
        $where_clause = "where " . $where->[0];
205
        $where_param = $where->[1];
206
    }
207
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
208
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
209
        $where_param = keys %$where_param
210
                     ? $self->merge_param($where_param, $where->param)
211
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
212
        
213
        # String where
214
        $where_clause = $where->to_string;
215
    }
216
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
217
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
218
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
219

            
cleanup
Yuki Kimoto authored on 2011-04-02
220
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
221
    my @sql;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
222
    my $q = $self->_quote;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
223
    push @sql, "delete";
224
    push @sql, $prefix if defined $prefix;
225
    push @sql, "from $q$table$q $where_clause";
226
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
227
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
228
    
229
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
230
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
231
}
232

            
cleanup
yuki-kimoto authored on 2010-10-17
233
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
234

            
added helper method
yuki-kimoto authored on 2010-10-17
235
sub DESTROY { }
236

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
237
sub create_model {
238
    my $self = shift;
239
    
cleanup
Yuki Kimoto authored on 2011-04-02
240
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
241
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
242
    $args->{dbi} = $self;
243
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
244
    my $model_name  = delete $args->{name};
245
    my $model_table = delete $args->{table};
246
    $model_name ||= $model_table;
247
    
cleanup
Yuki Kimoto authored on 2011-04-02
248
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
249
    my $model = $model_class->new($args);
250
    $model->name($model_name) unless $model->name;
251
    $model->table($model_table) unless $model->table;
252
    
253
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
254
    my $filter = ref $model->filter eq 'HASH'
255
               ? [%{$model->filter}]
256
               : $model->filter;
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
257
    warn "DBIx::Custom::Model filter method is DEPRECATED!"
258
      if @$filter;
cleanup
Yuki Kimoto authored on 2011-06-13
259
    $self->_apply_filter($model->table, @$filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
260

            
261
    # Set model
262
    $self->model($model->name, $model);
263
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
264
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
265
}
266

            
267
sub each_column {
268
    my ($self, $cb) = @_;
269
    
270
    # Iterate all tables
271
    my $sth_tables = $self->dbh->table_info;
272
    while (my $table_info = $sth_tables->fetchrow_hashref) {
273
        
274
        # Table
275
        my $table = $table_info->{TABLE_NAME};
276
        
277
        # Iterate all columns
278
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
279
        while (my $column_info = $sth_columns->fetchrow_hashref) {
280
            my $column = $column_info->{COLUMN_NAME};
281
            $self->$cb($table, $column, $column_info);
282
        }
283
    }
284
}
285

            
cleanup
Yuki Kimoto authored on 2011-04-02
286
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param';
287

            
288
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
289
    my $self = shift;
290
    my $query = shift;
291
    my $param;
292
    $param = shift if @_ % 2;
293
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
294
    
cleanup
Yuki Kimoto authored on 2011-04-02
295
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
296
    my $p = delete $args{param} || {};
297
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
298
    my $tables = delete $args{table} || [];
299
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
300
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
301
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
302
    my $bind_type = delete $args{bind_type} || delete $args{type};
303
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
304
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
305
    my $type_rule_off_parts = {
306
        1 => delete $args{type_rule1_off},
307
        2 => delete $args{type_rule2_off}
308
    };
cleanup
Yuki Kimoto authored on 2011-06-09
309
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
310
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
311
    
cleanup
Yuki Kimoto authored on 2011-03-09
312
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
313
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
314
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
315
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
316
    }
317
    
cleanup
Yuki Kimoto authored on 2011-04-02
318
    # Create query
updated pod
Yuki Kimoto authored on 2011-06-21
319
    $query = $self->_create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
320
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
321
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
322
    
cleanup
Yuki Kimoto authored on 2011-04-02
323
    # Tables
324
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
325
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
326
    $tables = $self->_remove_duplicate_table($tables, $main_table);
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
327
    if (my $q = $self->_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
328
        $_ =~ s/$q//g for @$tables;
329
    }
cleanup
Yuki Kimoto authored on 2011-04-02
330
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
331
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
332
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
333
    unless ($type_rule_off) {
334
        foreach my $name (keys %$param) {
335
            my $table;
336
            my $column;
337
            if ($name =~ /(?:(.+)\.)?(.+)/) {
338
                $table = $1;
339
                $column = $2;
340
            }
341
            $table ||= $main_table;
342
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
343
            foreach my $i (1 .. 2) {
344
                unless ($type_rule_off_parts->{$i}) {
345
                    my $into = $self->{"_into$i"} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
346
                    
347
                    my $alias = $table;
348
                    $table = $table_alias->{$alias}
349
                      if defined $alias && $table_alias->{$alias};
350
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
351
                    if (defined $table && $into->{$table} &&
352
                        (my $rule = $into->{$table}->{$column}))
353
                    {
354
                        $type_filters->{$i}->{$column} = $rule;
355
                        $type_filters->{$i}->{"$table.$column"} = $rule;
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
356
                        $type_filters->{$i}->{"$alias.$column"} = $rule if $alias ne $table;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
357
                    }
358
                }
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
359
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
360
        }
361
    }
cleanup
Yuki Kimoto authored on 2011-04-02
362
    
363
    # Applied filter
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
364
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
365
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
366
        $applied_filter = {
367
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
368
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
369
        }
370
    }
cleanup
Yuki Kimoto authored on 2011-04-02
371
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
372
    
cleanup
Yuki Kimoto authored on 2011-04-02
373
    # Replace filter name to code
374
    foreach my $column (keys %$filter) {
375
        my $name = $filter->{$column};
376
        if (!defined $name) {
377
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
378
        }
cleanup
Yuki Kimoto authored on 2011-04-02
379
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
380
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
381
            unless exists $self->filters->{$name};
382
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
383
        }
384
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
385
    
cleanup
Yuki Kimoto authored on 2011-04-02
386
    # Create bind values
387
    my $bind = $self->_create_bind_values(
388
        $param,
389
        $query->columns,
390
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
391
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
392
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
393
    );
cleanup
yuki-kimoto authored on 2010-10-17
394
    
395
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
396
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
397
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
398
    eval {
399
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
400
            my $bind_type = $bind->[$i]->{bind_type};
401
            $sth->bind_param(
402
                $i + 1,
403
                $bind->[$i]->{value},
404
                $bind_type ? $bind_type : ()
405
            );
cleanup
Yuki Kimoto authored on 2011-03-21
406
        }
407
        $affected = $sth->execute;
408
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
409
    
410
    if ($@) {
411
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
412
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
413
    }
cleanup
yuki-kimoto authored on 2010-10-17
414
    
improved debug message
Yuki Kimoto authored on 2011-05-23
415
    # DEBUG message
416
    if (DEBUG) {
417
        print STDERR "SQL:\n" . $query->sql . "\n";
418
        my @output;
419
        foreach my $b (@$bind) {
420
            my $value = $b->{value};
421
            $value = 'undef' unless defined $value;
422
            $value = encode(DEBUG_ENCODING(), $value)
423
              if utf8::is_utf8($value);
424
            push @output, $value;
425
        }
426
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
427
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
428
    
cleanup
Yuki Kimoto authored on 2011-04-02
429
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
430
    if ($sth->{NUM_OF_FIELDS}) {
431
        
cleanup
Yuki Kimoto authored on 2011-04-02
432
        # Filter
433
        my $filter = {};
434
        $filter->{in}  = {};
435
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
436
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
437
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
438
            foreach my $way (qw/in end/) {
439
                $filter->{$way} = {
440
                    %{$filter->{$way}},
441
                    %{$self->{filter}{$way}{$table} || {}}
442
                };
443
            }
cleanup
Yuki Kimoto authored on 2011-01-12
444
        }
445
        
446
        # Result
447
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
448
            sth => $sth,
449
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
450
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
451
            filter => $filter->{in} || {},
452
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
453
            type_rule => {
454
                from1 => $self->type_rule->{from1},
455
                from2 => $self->type_rule->{from2}
456
            },
cleanup
yuki-kimoto authored on 2010-10-17
457
        );
458

            
459
        return $result;
460
    }
cleanup
Yuki Kimoto authored on 2011-04-02
461
    
462
    # Not select statement
463
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
464
}
465

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
466
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param/;
update pod
Yuki Kimoto authored on 2011-03-13
467

            
cleanup
yuki-kimoto authored on 2010-10-17
468
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
469
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
470
    
cleanup
yuki-kimoto authored on 2010-10-17
471
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
472
    my $param;
473
    $param = shift if @_ % 2;
474
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
475
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
476
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
477
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
478
    my $p = delete $args{param} || {};
479
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
480
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
481
    my $id = delete $args{id};
482
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
483
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
484
          "must be specified when id is specified " . _subname
485
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
486
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
487
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
488

            
489
    # Check arguments
490
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
491
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
492
          unless $INSERT_ARGS{$name};
493
    }
494

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
495
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
496
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
497
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
498
        $param = $self->merge_param($id_param, $param);
499
    }
500

            
cleanup
Yuki Kimoto authored on 2011-04-02
501
    # Reserved word quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
502
    my $q = $self->_quote;
cleanup
yuki-kimoto authored on 2010-10-17
503
    
cleanup
Yuki Kimoto authored on 2011-04-02
504
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
505
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
506
    push @sql, "insert";
507
    push @sql, $prefix if defined $prefix;
508
    push @sql, "into $q$table$q " . $self->insert_param($param);
509
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
510
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
511
    
512
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
513
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
514
}
515

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
516
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
517
    my ($self, $param) = @_;
518
    
cleanup
Yuki Kimoto authored on 2011-04-02
519
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
520
    my $safety = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
521
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
522
    my @columns;
523
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
524
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
525
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
526
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
527
        my $column_quote = "$q$column$q";
528
        $column_quote =~ s/\./$q.$q/;
529
        push @columns, $column_quote;
530
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
531
    }
532
    
cleanup
Yuki Kimoto authored on 2011-04-02
533
    return '(' . join(', ', @columns) . ') ' . 'values ' .
534
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
535
}
536

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
537
sub include_model {
538
    my ($self, $name_space, $model_infos) = @_;
539
    
cleanup
Yuki Kimoto authored on 2011-04-02
540
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
541
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
542
    
543
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
544
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
545

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
546
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
547
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
548
          if $name_space =~ /[^\w:]/;
549
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
550
        croak qq{Name space module "$name_space.pm" is needed. $@ }
551
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
552
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
553
        
554
        # Search model modules
555
        my $path = $INC{"$name_space.pm"};
556
        $path =~ s/\.pm$//;
557
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
558
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
559
        $model_infos = [];
560
        while (my $module = readdir $dh) {
561
            push @$model_infos, $module
562
              if $module =~ s/\.pm$//;
563
        }
564
        close $dh;
565
    }
566
    
cleanup
Yuki Kimoto authored on 2011-04-02
567
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
568
    foreach my $model_info (@$model_infos) {
569
        
cleanup
Yuki Kimoto authored on 2011-04-02
570
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
571
        my $model_class;
572
        my $model_name;
573
        my $model_table;
574
        if (ref $model_info eq 'HASH') {
575
            $model_class = $model_info->{class};
576
            $model_name  = $model_info->{name};
577
            $model_table = $model_info->{table};
578
            
579
            $model_name  ||= $model_class;
580
            $model_table ||= $model_name;
581
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
582
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
583
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
584
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
585
          if $mclass =~ /[^\w:]/;
586
        unless ($mclass->can('isa')) {
587
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
588
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
589
        }
590
        
cleanup
Yuki Kimoto authored on 2011-04-02
591
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
592
        my $args = {};
593
        $args->{model_class} = $mclass if $mclass;
594
        $args->{name}        = $model_name if $model_name;
595
        $args->{table}       = $model_table if $model_table;
596
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
597
    }
598
    
599
    return $self;
600
}
601

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
602
sub map_param {
603
    my $self = shift;
604
    my $param = shift;
605
    my %map = @_;
606
    
607
    # Mapping
608
    my $map_param = {};
609
    foreach my $key (keys %map) {
610
        my $value_cb;
611
        my $condition;
612
        my $map_key;
613
        
614
        # Get mapping information
615
        if (ref $map{$key} eq 'ARRAY') {
616
            foreach my $some (@{$map{$key}}) {
617
                $map_key = $some unless ref $some;
618
                $condition = $some->{if} if ref $some eq 'HASH';
619
                $value_cb = $some if ref $some eq 'CODE';
620
            }
621
        }
622
        else {
623
            $map_key = $map{$key};
624
        }
625
        $value_cb ||= sub { $_[0] };
626
        $condition ||= sub { defined $_[0] && length $_[0] };
627

            
628
        # Map parameter
629
        my $value;
630
        if (ref $condition eq 'CODE') {
631
            $map_param->{$map_key} = $value_cb->($param->{$key})
632
              if $condition->($param->{$key});
633
        }
634
        elsif ($condition eq 'exists') {
635
            $map_param->{$map_key} = $value_cb->($param->{$key})
636
              if exists $param->{$key};
637
        }
638
        else { croak qq/Condition must be code reference or "exists" / . _subname }
639
    }
640
    
641
    return $map_param;
642
}
643

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
644
sub merge_param {
645
    my ($self, @params) = @_;
646
    
cleanup
Yuki Kimoto authored on 2011-04-02
647
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
648
    my $merge = {};
649
    foreach my $param (@params) {
650
        foreach my $column (keys %$param) {
651
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
652
            
653
            if (exists $merge->{$column}) {
654
                $merge->{$column} = [$merge->{$column}]
655
                  unless ref $merge->{$column} eq 'ARRAY';
656
                push @{$merge->{$column}},
657
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
658
            }
659
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
660
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
661
            }
662
        }
663
    }
664
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
665
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
666
}
667

            
cleanup
Yuki Kimoto authored on 2011-03-21
668
sub method {
669
    my $self = shift;
670
    
cleanup
Yuki Kimoto authored on 2011-04-02
671
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
672
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
673
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
674
    
675
    return $self;
676
}
677

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
678
sub model {
679
    my ($self, $name, $model) = @_;
680
    
cleanup
Yuki Kimoto authored on 2011-04-02
681
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
682
    if ($model) {
683
        $self->models->{$name} = $model;
684
        return $self;
685
    }
686
    
687
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
688
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
689
      unless $self->models->{$name};
690
    
cleanup
Yuki Kimoto authored on 2011-04-02
691
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
692
    return $self->models->{$name};
693
}
694

            
cleanup
Yuki Kimoto authored on 2011-03-21
695
sub mycolumn {
696
    my ($self, $table, $columns) = @_;
697
    
cleanup
Yuki Kimoto authored on 2011-04-02
698
    # Create column clause
699
    my @column;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
700
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
701
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
702
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
703
    
704
    return join (', ', @column);
705
}
706

            
added dbi_options attribute
kimoto authored on 2010-12-20
707
sub new {
708
    my $self = shift->SUPER::new(@_);
709
    
cleanup
Yuki Kimoto authored on 2011-04-02
710
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
711
    my @attrs = keys %$self;
712
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
713
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
714
          unless $self->can($attr);
715
    }
cleanup
Yuki Kimoto authored on 2011-04-02
716
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
717
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
718
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
719
        '?'     => \&DBIx::Custom::Tag::placeholder,
720
        '='     => \&DBIx::Custom::Tag::equal,
721
        '<>'    => \&DBIx::Custom::Tag::not_equal,
722
        '>'     => \&DBIx::Custom::Tag::greater_than,
723
        '<'     => \&DBIx::Custom::Tag::lower_than,
724
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
725
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
726
        'like'  => \&DBIx::Custom::Tag::like,
727
        'in'    => \&DBIx::Custom::Tag::in,
728
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
729
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
730
    };
added dbi_options attribute
kimoto authored on 2010-12-20
731
    
732
    return $self;
733
}
734

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
735
sub not_exists { bless {}, 'DBIx::Custom::NotExists' }
736

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
737
sub order {
738
    my $self = shift;
739
    return DBIx::Custom::Order->new(@_);
740
}
741

            
cleanup
yuki-kimoto authored on 2010-10-17
742
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
743
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
744
    
745
    # Register filter
746
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
747
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
748
    
cleanup
Yuki Kimoto authored on 2011-04-02
749
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
750
}
packaging one directory
yuki-kimoto authored on 2009-11-16
751

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
752
our %SELECT_ARGS = map { $_ => 1 } @COMMON_ARGS,
753
  qw/column where relation join param where_param wrap prefix/;
refactoring select
yuki-kimoto authored on 2010-04-28
754

            
packaging one directory
yuki-kimoto authored on 2009-11-16
755
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
756
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
757

            
refactoring select
yuki-kimoto authored on 2010-04-28
758
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
759
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
760
    my $tables = ref $table eq 'ARRAY' ? $table
761
               : defined $table ? [$table]
762
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
763
    my $columns   = delete $args{column};
764
    my $where     = delete $args{where} || {};
765
    my $append    = delete $args{append};
766
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
767
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
768
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
769
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
770
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
771
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
772
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
773
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
774
      if keys %$param;
775
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
776
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
777
    my $id = delete $args{id};
778
    my $primary_key = delete $args{primary_key};
779
    croak "update method primary_key option " .
780
          "must be specified when id is specified " . _subname
781
      if defined $id && !defined $primary_key;
782
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
783
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
784
    
cleanup
Yuki Kimoto authored on 2011-04-02
785
    # Check arguments
786
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
787
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
788
          unless $SELECT_ARGS{$name};
789
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
790
    
cleanup
Yuki Kimoto authored on 2011-03-09
791
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
792
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
793
    
cleanup
Yuki Kimoto authored on 2011-04-02
794
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
795
    my @sql;
796
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
797
    
- select() column option can...
Yuki Kimoto authored on 2011-06-08
798
    # Reserved word quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
799
    my $q = $self->_quote;
- select() column option can...
Yuki Kimoto authored on 2011-06-08
800
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
801
    # Prefix
802
    push @sql, $prefix if defined $prefix;
803
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
804
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
805
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
806
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
807
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
808
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
809
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
810
            }
811
            elsif (ref $column eq 'ARRAY') {
812
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
813
                  unless @$column == 3 && $column->[1] eq 'as';
814
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
815
            }
cleanup
Yuki Kimoto authored on 2011-04-02
816
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
817
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
818
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
819
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
820
    }
821
    else { push @sql, '*' }
822
    
823
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
824
    push @sql, 'from';
825
    if ($relation) {
826
        my $found = {};
827
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
828
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
829
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
830
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
831
    }
cleanup
Yuki Kimoto authored on 2011-03-30
832
    else {
833
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
834
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
835
    }
836
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
837
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
838
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
839

            
cleanup
Yuki Kimoto authored on 2011-04-02
840
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
841
    unshift @$tables,
842
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
843
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
844
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
845
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
846
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
847
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
848
        $where_clause = "where " . $where->[0];
849
        $where_param = $where->[1];
850
    }
851
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
852
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
853
        $where_param = keys %$where_param
854
                     ? $self->merge_param($where_param, $where->param)
855
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
856
        
857
        # String where
858
        $where_clause = $where->to_string;
859
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
860
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
861
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
862
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
863
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
864
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
865
    # Push join
866
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
867
    
cleanup
Yuki Kimoto authored on 2011-03-09
868
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
869
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
870
    
cleanup
Yuki Kimoto authored on 2011-03-08
871
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
872
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
873
    
cleanup
Yuki Kimoto authored on 2011-04-02
874
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
875
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
876
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
877
    # Wrap
878
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
879
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
880
          unless ref $wrap eq 'ARRAY';
881
        unshift @sql, $wrap->[0];
882
        push @sql, $wrap->[1];
883
    }
884
    
cleanup
Yuki Kimoto authored on 2011-01-27
885
    # SQL
886
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
887
    
888
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
889
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
890
    
891
    return $result;
892
}
893

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
894
sub separator {
895
    my $self = shift;
896
    
897
    if (@_) {
898
        my $separator = $_[0] || '';
899
        croak qq{Separator must be "." or "__" or "-" } . _subname
900
          unless $separator eq '.' || $separator eq '__'
901
              || $separator eq '-';
902
        
903
        $self->{separator} = $separator;
904
    
905
        return $self;
906
    }
907
    return $self->{separator} ||= '.';
908
}
909

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
910
sub setup_model {
911
    my $self = shift;
912
    
cleanup
Yuki Kimoto authored on 2011-04-02
913
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
914
    $self->each_column(
915
        sub {
916
            my ($self, $table, $column, $column_info) = @_;
917
            if (my $model = $self->models->{$table}) {
918
                push @{$model->columns}, $column;
919
            }
920
        }
921
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
922
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
923
}
924

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
925
sub available_data_type {
926
    my $self = shift;
927
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
928
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
929
    foreach my $i (-1000 .. 1000) {
930
         my $type_info = $self->dbh->type_info($i);
931
         my $data_type = $type_info->{DATA_TYPE};
932
         my $type_name = $type_info->{TYPE_NAME};
933
         $data_types .= "$data_type ($type_name)\n"
934
           if defined $data_type;
935
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
936
    return "Data Type maybe equal to Type Name" unless $data_types;
937
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
938
    return $data_types;
939
}
940

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
941
sub available_type_name {
942
    my $self = shift;
943
    
944
    # Type Names
945
    my $type_names = {};
946
    $self->each_column(sub {
947
        my ($self, $table, $column, $column_info) = @_;
948
        $type_names->{$column_info->{TYPE_NAME}} = 1
949
          if $column_info->{TYPE_NAME};
950
    });
951
    my @output = sort keys %$type_names;
952
    unshift @output, "Type Name";
953
    return join "\n", @output;
954
}
955

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
956
sub type_rule {
957
    my $self = shift;
958
    
959
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
960
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
961
        
962
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
963
        foreach my $i (1 .. 2) {
964
            my $into = "into$i";
965
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
966
            $self->{type_rule} = $type_rule;
967
            $self->{"_$into"} = {};
968
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
969
                croak qq{type name of $into section must be lower case}
970
                  if $type_name =~ /[A-Z]/;
971
            }
972
            $self->each_column(sub {
973
                my ($dbi, $table, $column, $column_info) = @_;
974
                
975
                my $type_name = lc $column_info->{TYPE_NAME};
976
                if ($type_rule->{$into} &&
977
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
978
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
979
                    return unless exists $type_rule->{$into}->{$type_name};
980
                    if  (defined $filter && ref $filter ne 'CODE') 
981
                    {
982
                        my $fname = $filter;
983
                        croak qq{Filter "$fname" is not registered" } . _subname
984
                          unless exists $self->filters->{$fname};
985
                        
986
                        $filter = $self->filters->{$fname};
987
                    }
988

            
989
                    $self->{"_$into"}{$table}{$column} = $filter;
990
                }
991
            });
992
        }
993

            
994
        # From
995
        foreach my $i (1 .. 2) {
996
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
997
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
998
                croak qq{data type of from$i section must be lower case or number}
999
                  if $data_type =~ /[A-Z]/;
1000
                my $fname = $type_rule->{"from$i"}{$data_type};
1001
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1002
                    croak qq{Filter "$fname" is not registered" } . _subname
1003
                      unless exists $self->filters->{$fname};
1004
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1005
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1006
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1007
            }
1008
        }
1009
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1010
        return $self;
1011
    }
1012
    
1013
    return $self->{type_rule} || {};
1014
}
1015

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1016
our %UPDATE_ARGS = map { $_ => 1 } @COMMON_ARGS,
1017
  qw/param where allow_update_all where_param prefix/;
cleanup
yuki-kimoto authored on 2010-10-17
1018

            
1019
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1020
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1021

            
cleanup
yuki-kimoto authored on 2010-10-17
1022
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1023
    my $param;
1024
    $param = shift if @_ % 2;
1025
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1026
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1027
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1028
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1029
    my $p = delete $args{param} || {};
1030
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1031
    my $where = delete $args{where} || {};
1032
    my $where_param = delete $args{where_param} || {};
1033
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1034
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1035
    my $id = delete $args{id};
1036
    my $primary_key = delete $args{primary_key};
1037
    croak "update method primary_key option " .
1038
          "must be specified when id is specified " . _subname
1039
      if defined $id && !defined $primary_key;
1040
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1041
    my $prefix = delete $args{prefix};
version 0.0901
yuki-kimoto authored on 2009-12-17
1042
    
cleanup
Yuki Kimoto authored on 2011-04-02
1043
    # Check argument names
1044
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1045
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1046
          unless $UPDATE_ARGS{$name};
1047
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1048

            
cleanup
yuki-kimoto authored on 2010-10-17
1049
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1050
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1051

            
1052
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1053
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1054
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1055
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1056
        $where_clause = "where " . $where->[0];
1057
        $where_param = $where->[1];
1058
    }
1059
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1060
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1061
        $where_param = keys %$where_param
1062
                     ? $self->merge_param($where_param, $where->param)
1063
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1064
        
1065
        # String where
1066
        $where_clause = $where->to_string;
1067
    }
1068
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1069
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1070
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1071
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1072
    # Merge param
1073
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1074
    
cleanup
Yuki Kimoto authored on 2011-04-02
1075
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1076
    my @sql;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1077
    my $q = $self->_quote;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1078
    push @sql, "update";
1079
    push @sql, $prefix if defined $prefix;
1080
    push @sql, "$q$table$q $update_clause $where_clause";
1081
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1082
    
cleanup
Yuki Kimoto authored on 2011-01-27
1083
    # SQL
1084
    my $sql = join(' ', @sql);
1085
    
cleanup
yuki-kimoto authored on 2010-10-17
1086
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1087
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1088
}
1089

            
cleanup
yuki-kimoto authored on 2010-10-17
1090
sub update_all { shift->update(allow_update_all => 1, @_) };
1091

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1092
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1093
    my ($self, $param, $opt) = @_;
1094
    
cleanup
Yuki Kimoto authored on 2011-04-02
1095
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1096
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1097
    $tag = "set $tag" unless $opt->{no_set};
1098

            
cleanup
Yuki Kimoto authored on 2011-04-02
1099
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1100
}
1101

            
cleanup
Yuki Kimoto authored on 2011-01-25
1102
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1103
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1104
    
1105
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1106
    return DBIx::Custom::Where->new(
1107
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1108
        safety_character => $self->safety_character,
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1109
        quote => $self->_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1110
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1111
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1112
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1113

            
updated pod
Yuki Kimoto authored on 2011-06-21
1114
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1115
    
updated pod
Yuki Kimoto authored on 2011-06-21
1116
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1117
    
updated pod
Yuki Kimoto authored on 2011-06-21
1118
    # Cache
1119
    my $cache = $self->cache;
1120
    
1121
    # Query
1122
    my $query;
1123
    
1124
    # Get cached query
1125
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1126
        
updated pod
Yuki Kimoto authored on 2011-06-21
1127
        # Get query
1128
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1129
        
updated pod
Yuki Kimoto authored on 2011-06-21
1130
        # Create query
1131
        if ($q) {
1132
            $query = DBIx::Custom::Query->new($q);
1133
            $query->filters($self->filters);
cleanup
Yuki Kimoto authored on 2011-06-13
1134
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1135
    }
1136
    
1137
    # Create query
1138
    unless ($query) {
1139

            
1140
        # Create query
1141
        my $builder = $self->query_builder;
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
1142
        $builder->{_tag_parse} = $self->tag_parse;
updated pod
Yuki Kimoto authored on 2011-06-21
1143
        $query = $builder->build_query($source);
1144

            
1145
        # Remove reserved word quote
1146
        if (my $q = $self->_quote) {
1147
            $_ =~ s/$q//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1148
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1149

            
1150
        # Save query to cache
1151
        $self->cache_method->(
1152
            $self, $source,
1153
            {
1154
                sql     => $query->sql, 
1155
                columns => $query->columns,
1156
                tables  => $query->tables
1157
            }
1158
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1159
    }
1160
    
updated pod
Yuki Kimoto authored on 2011-06-21
1161
    # Prepare statement handle
1162
    my $sth;
1163
    eval { $sth = $self->dbh->prepare($query->{sql})};
1164
    
1165
    if ($@) {
1166
        $self->_croak($@, qq{. Following SQL is executed.\n}
1167
                        . qq{$query->{sql}\n} . _subname);
1168
    }
1169
    
1170
    # Set statement handle
1171
    $query->sth($sth);
1172
    
1173
    # Set filters
1174
    $query->filters($self->filters);
1175
    
1176
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1177
}
1178

            
cleanup
Yuki Kimoto authored on 2011-04-02
1179
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1180
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1181
    
cleanup
Yuki Kimoto authored on 2011-04-02
1182
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1183
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1184
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1185
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1186
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1187
        
1188
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1189
        my $value;
1190
        if(ref $params->{$column} eq 'ARRAY') {
1191
            my $i = $count->{$column} || 0;
1192
            $i += $not_exists->{$column} || 0;
1193
            my $found;
1194
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1195
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1196
                    $not_exists->{$column}++;
1197
                }
1198
                else  {
1199
                    $value = $params->{$column}->[$k];
1200
                    $found = 1;
1201
                    last
1202
                }
1203
            }
1204
            next unless $found;
1205
        }
1206
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1207
        
cleanup
Yuki Kimoto authored on 2011-01-12
1208
        # Filter
1209
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1210
        $value = $f->($value) if $f;
1211
        
1212
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1213
        foreach my $i (1 .. 2) {
1214
            my $type_filter = $type_filters->{$i};
1215
            my $tf = $type_filter->{$column};
1216
            $value = $tf->($value) if $tf;
1217
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1218
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1219
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1220
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1221
        
1222
        # Count up 
1223
        $count->{$column}++;
1224
    }
1225
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1226
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1227
}
1228

            
cleanup
Yuki Kimoto authored on 2011-06-08
1229
sub _create_param_from_id {
1230
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1231
    
cleanup
Yuki Kimoto authored on 2011-06-08
1232
    # Create parameter
1233
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1234
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1235
        $id = [$id] unless ref $id;
1236
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1237
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1238
          unless !ref $id || ref $id eq 'ARRAY';
1239
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1240
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1241
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1242
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1243
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1244
        }
1245
    }
1246
    
cleanup
Yuki Kimoto authored on 2011-06-08
1247
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1248
}
1249

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1250
sub _connect {
1251
    my $self = shift;
1252
    
1253
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1254
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1255
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1256
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1257
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1258
    croak qq{"dsn" must be specified } . _subname
1259
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1260
    my $user        = $self->user;
1261
    my $password    = $self->password;
1262
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1263
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1264
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1265
    
1266
    # Connect
1267
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1268
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1269
        $user,
1270
        $password,
1271
        {
1272
            %{$self->default_dbi_option},
1273
            %$dbi_option
1274
        }
1275
    )};
1276
    
1277
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1278
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1279
    
1280
    return $dbh;
1281
}
1282

            
cleanup
yuki-kimoto authored on 2010-10-17
1283
sub _croak {
1284
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1285
    
1286
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1287
    $append ||= "";
1288
    
1289
    # Verbose
1290
    if ($Carp::Verbose) { croak $error }
1291
    
1292
    # Not verbose
1293
    else {
1294
        
1295
        # Remove line and module infromation
1296
        my $at_pos = rindex($error, ' at ');
1297
        $error = substr($error, 0, $at_pos);
1298
        $error =~ s/\s+$//;
1299
        croak "$error$append";
1300
    }
1301
}
1302

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1303
sub _need_tables {
1304
    my ($self, $tree, $need_tables, $tables) = @_;
1305
    
cleanup
Yuki Kimoto authored on 2011-04-02
1306
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1307
    foreach my $table (@$tables) {
1308
        if ($tree->{$table}) {
1309
            $need_tables->{$table} = 1;
1310
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1311
        }
1312
    }
1313
}
1314

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1315
sub _push_join {
1316
    my ($self, $sql, $join, $join_tables) = @_;
1317
    
cleanup
Yuki Kimoto authored on 2011-04-02
1318
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1319
    return unless @$join;
1320
    
cleanup
Yuki Kimoto authored on 2011-04-02
1321
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1322
    my $tree = {};
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1323
    my $q = $self->_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1324
    for (my $i = 0; $i < @$join; $i++) {
1325
        
cleanup
Yuki Kimoto authored on 2011-04-02
1326
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1327
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1328
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1329
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1330
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1331
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1332
            my $table1 = $1;
1333
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1334
            croak qq{right side table of "$join_clause" must be unique }
1335
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1336
              if exists $tree->{$table2};
1337
            $tree->{$table2}
1338
              = {position => $i, parent => $table1, join => $join_clause};
1339
        }
1340
        else {
improved error message
Yuki Kimoto authored on 2011-06-13
1341
            croak qq{join clause must have two table name after "on" keyword. } .
1342
                  qq{"$join_clause" is passed }  . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1343
        }
1344
    }
1345
    
cleanup
Yuki Kimoto authored on 2011-04-02
1346
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1347
    my $need_tables = {};
1348
    $self->_need_tables($tree, $need_tables, $join_tables);
1349
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1350
    
1351
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1352
    foreach my $need_table (@need_tables) {
1353
        push @$sql, $tree->{$need_table}{join};
1354
    }
1355
}
cleanup
Yuki Kimoto authored on 2011-03-08
1356

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1357
sub _quote {
1358
    my $self = shift;
1359
    
1360
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1361
         : defined $self->quote ? $self->quote
1362
         : '';
1363
}
1364

            
cleanup
Yuki Kimoto authored on 2011-04-02
1365
sub _remove_duplicate_table {
1366
    my ($self, $tables, $main_table) = @_;
1367
    
1368
    # Remove duplicate table
1369
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1370
    delete $tables{$main_table} if $main_table;
1371
    
1372
    return [keys %tables, $main_table ? $main_table : ()];
1373
}
1374

            
cleanup
Yuki Kimoto authored on 2011-04-02
1375
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1376
    my ($self, $source) = @_;
1377
    
cleanup
Yuki Kimoto authored on 2011-04-02
1378
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1379
    my $tables = [];
1380
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1381
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1382
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1383
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1384
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1385
    while ($source =~ /$table_re/g) {
1386
        push @$tables, $1;
1387
    }
1388
    
1389
    return $tables;
1390
}
1391

            
cleanup
Yuki Kimoto authored on 2011-04-02
1392
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1393
    my ($self, $where) = @_;
1394
    
cleanup
Yuki Kimoto authored on 2011-04-02
1395
    my $obj;
1396
    
1397
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1398
    if (ref $where eq 'HASH') {
1399
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1400
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1401
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1402
            my $column_quote = "$q$column$q";
1403
            $column_quote =~ s/\./$q.$q/;
1404
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1405
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1406
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1407
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1408
    
1409
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1410
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1411
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1412
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1413
    
updated pod
Yuki Kimoto authored on 2011-06-21
1414
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1415
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1416
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1417
            clause => $where->[0],
1418
            param  => $where->[1]
1419
        );
1420
    }
1421
    
cleanup
Yuki Kimoto authored on 2011-04-02
1422
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1423
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1424
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1425
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1426
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1427
    
cleanup
Yuki Kimoto authored on 2011-04-02
1428
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1429
}
1430

            
updated pod
Yuki Kimoto authored on 2011-06-21
1431
sub _apply_filter {
1432
    my ($self, $table, @cinfos) = @_;
1433

            
1434
    # Initialize filters
1435
    $self->{filter} ||= {};
1436
    $self->{filter}{out} ||= {};
1437
    $self->{filter}{in} ||= {};
1438
    $self->{filter}{end} ||= {};
1439
    
1440
    # Usage
1441
    my $usage = "Usage: \$dbi->apply_filter(" .
1442
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1443
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1444
    
1445
    # Apply filter
1446
    for (my $i = 0; $i < @cinfos; $i += 2) {
1447
        
1448
        # Column
1449
        my $column = $cinfos[$i];
1450
        if (ref $column eq 'ARRAY') {
1451
            foreach my $c (@$column) {
1452
                push @cinfos, $c, $cinfos[$i + 1];
1453
            }
1454
            next;
1455
        }
1456
        
1457
        # Filter infomation
1458
        my $finfo = $cinfos[$i + 1] || {};
1459
        croak "$usage (table: $table) " . _subname
1460
          unless  ref $finfo eq 'HASH';
1461
        foreach my $ftype (keys %$finfo) {
1462
            croak "$usage (table: $table) " . _subname
1463
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1464
        }
1465
        
1466
        # Set filters
1467
        foreach my $way (qw/in out end/) {
1468
        
1469
            # Filter
1470
            my $filter = $finfo->{$way};
1471
            
1472
            # Filter state
1473
            my $state = !exists $finfo->{$way} ? 'not_exists'
1474
                      : !defined $filter        ? 'not_defined'
1475
                      : ref $filter eq 'CODE'   ? 'code'
1476
                      : 'name';
1477
            
1478
            # Filter is not exists
1479
            next if $state eq 'not_exists';
1480
            
1481
            # Check filter name
1482
            croak qq{Filter "$filter" is not registered } . _subname
1483
              if  $state eq 'name'
1484
               && ! exists $self->filters->{$filter};
1485
            
1486
            # Set filter
1487
            my $f = $state eq 'not_defined' ? undef
1488
                  : $state eq 'code'        ? $filter
1489
                  : $self->filters->{$filter};
1490
            $self->{filter}{$way}{$table}{$column} = $f;
1491
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1492
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1493
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1494
        }
1495
    }
1496
    
1497
    return $self;
1498
}
1499

            
1500
# DEPRECATED!
1501
sub create_query {
1502
    warn "create_query is DEPRECATED! use query option of each method";
1503
    shift->_create_query(@_);
1504
}
1505

            
cleanup
Yuki Kimoto authored on 2011-06-13
1506
# DEPRECATED!
1507
sub apply_filter {
1508
    my $self = shift;
1509
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1510
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1511
    return $self->_apply_filter(@_);
1512
}
1513

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1514
# DEPRECATED!
1515
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1516
sub select_at {
1517
    my ($self, %args) = @_;
1518

            
updated pod
Yuki Kimoto authored on 2011-06-08
1519
    warn "select_at is DEPRECATED! use update and id option instead";
1520

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1521
    # Arguments
1522
    my $primary_keys = delete $args{primary_key};
1523
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1524
    my $where = delete $args{where};
1525
    my $param = delete $args{param};
1526
    
1527
    # Check arguments
1528
    foreach my $name (keys %args) {
1529
        croak qq{"$name" is wrong option } . _subname
1530
          unless $SELECT_AT_ARGS{$name};
1531
    }
1532
    
1533
    # Table
1534
    croak qq{"table" option must be specified } . _subname
1535
      unless $args{table};
1536
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1537
    
1538
    # Create where parameter
1539
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1540
    
1541
    return $self->select(where => $where_param, %args);
1542
}
1543

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1544
# DEPRECATED!
1545
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1546
sub delete_at {
1547
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1548

            
1549
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1550
    
1551
    # Arguments
1552
    my $primary_keys = delete $args{primary_key};
1553
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1554
    my $where = delete $args{where};
1555
    
1556
    # Check arguments
1557
    foreach my $name (keys %args) {
1558
        croak qq{"$name" is wrong option } . _subname
1559
          unless $DELETE_AT_ARGS{$name};
1560
    }
1561
    
1562
    # Create where parameter
1563
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1564
    
1565
    return $self->delete(where => $where_param, %args);
1566
}
1567

            
cleanup
Yuki Kimoto authored on 2011-06-08
1568
# DEPRECATED!
1569
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1570
sub update_at {
1571
    my $self = shift;
1572

            
1573
    warn "update_at is DEPRECATED! use update and id option instead";
1574
    
1575
    # Arguments
1576
    my $param;
1577
    $param = shift if @_ % 2;
1578
    my %args = @_;
1579
    my $primary_keys = delete $args{primary_key};
1580
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1581
    my $where = delete $args{where};
1582
    my $p = delete $args{param} || {};
1583
    $param  ||= $p;
1584
    
1585
    # Check arguments
1586
    foreach my $name (keys %args) {
1587
        croak qq{"$name" is wrong option } . _subname
1588
          unless $UPDATE_AT_ARGS{$name};
1589
    }
1590
    
1591
    # Create where parameter
1592
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1593
    
1594
    return $self->update(where => $where_param, param => $param, %args);
1595
}
1596

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1597
# DEPRECATED!
1598
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1599
sub insert_at {
1600
    my $self = shift;
1601
    
1602
    warn "insert_at is DEPRECATED! use insert and id option instead";
1603
    
1604
    # Arguments
1605
    my $param;
1606
    $param = shift if @_ % 2;
1607
    my %args = @_;
1608
    my $primary_key = delete $args{primary_key};
1609
    $primary_key = [$primary_key] unless ref $primary_key;
1610
    my $where = delete $args{where};
1611
    my $p = delete $args{param} || {};
1612
    $param  ||= $p;
1613
    
1614
    # Check arguments
1615
    foreach my $name (keys %args) {
1616
        croak qq{"$name" is wrong option } . _subname
1617
          unless $INSERT_AT_ARGS{$name};
1618
    }
1619
    
1620
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1621
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1622
    $param = $self->merge_param($where_param, $param);
1623
    
1624
    return $self->insert(param => $param, %args);
1625
}
1626

            
added warnings
Yuki Kimoto authored on 2011-06-07
1627
# DEPRECATED!
1628
sub register_tag {
1629
    warn "register_tag is DEPRECATED!";
1630
    shift->query_builder->register_tag(@_)
1631
}
1632

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1633
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1634
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1635
has dbi_options => sub { {} };
1636
has filter_check  => 1;
1637
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1638

            
cleanup
Yuki Kimoto authored on 2011-01-25
1639
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1640
sub default_bind_filter {
1641
    my $self = shift;
1642
    
cleanup
Yuki Kimoto authored on 2011-06-13
1643
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1644
    
cleanup
Yuki Kimoto authored on 2011-01-12
1645
    if (@_) {
1646
        my $fname = $_[0];
1647
        
1648
        if (@_ && !$fname) {
1649
            $self->{default_out_filter} = undef;
1650
        }
1651
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1652
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1653
              unless exists $self->filters->{$fname};
1654
        
1655
            $self->{default_out_filter} = $self->filters->{$fname};
1656
        }
1657
        return $self;
1658
    }
1659
    
1660
    return $self->{default_out_filter};
1661
}
1662

            
cleanup
Yuki Kimoto authored on 2011-01-25
1663
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1664
sub default_fetch_filter {
1665
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1666

            
cleanup
Yuki Kimoto authored on 2011-06-13
1667
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1668
    
1669
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1670
        my $fname = $_[0];
1671

            
cleanup
Yuki Kimoto authored on 2011-01-12
1672
        if (@_ && !$fname) {
1673
            $self->{default_in_filter} = undef;
1674
        }
1675
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1676
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1677
              unless exists $self->filters->{$fname};
1678
        
1679
            $self->{default_in_filter} = $self->filters->{$fname};
1680
        }
1681
        
1682
        return $self;
1683
    }
1684
    
many changed
Yuki Kimoto authored on 2011-01-23
1685
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1686
}
1687

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1688
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1689
sub insert_param_tag {
1690
    warn "insert_param_tag is DEPRECATED! " .
1691
         "use insert_param instead!";
1692
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1693
}
1694

            
cleanup
Yuki Kimoto authored on 2011-01-25
1695
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1696
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1697
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1698
    return shift->query_builder->register_tag_processor(@_);
1699
}
1700

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1701
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1702
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1703
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1704
         "use update_param instead";
1705
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1706
}
cleanup
Yuki Kimoto authored on 2011-03-08
1707
# DEPRECATED!
1708
sub _push_relation {
1709
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1710
    
1711
    if (keys %{$relation || {}}) {
1712
        push @$sql, $need_where ? 'where' : 'and';
1713
        foreach my $rcolumn (keys %$relation) {
1714
            my $table1 = (split (/\./, $rcolumn))[0];
1715
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1716
            push @$tables, ($table1, $table2);
1717
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1718
        }
1719
    }
1720
    pop @$sql if $sql->[-1] eq 'and';    
1721
}
1722

            
1723
# DEPRECATED!
1724
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1725
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1726
    
1727
    if (keys %{$relation || {}}) {
1728
        foreach my $rcolumn (keys %$relation) {
1729
            my $table1 = (split (/\./, $rcolumn))[0];
1730
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1731
            my $table1_exists;
1732
            my $table2_exists;
1733
            foreach my $table (@$tables) {
1734
                $table1_exists = 1 if $table eq $table1;
1735
                $table2_exists = 1 if $table eq $table2;
1736
            }
1737
            unshift @$tables, $table1 unless $table1_exists;
1738
            unshift @$tables, $table2 unless $table2_exists;
1739
        }
1740
    }
1741
}
1742

            
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
1743
1;
1744

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1745
=head1 NAME
1746

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1747
DBIx::Custom - Execute insert, update, delete, and select statement easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1748

            
1749
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1750

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1751
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1752
    
1753
    # Connect
1754
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1755
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1756
        user => 'ken',
1757
        password => '!LFKD%$&',
1758
        dbi_option => {mysql_enable_utf8 => 1}
1759
    );
cleanup
yuki-kimoto authored on 2010-08-05
1760

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1761
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1762
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1763
    
1764
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1765
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1766
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1767
    
1768
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1769
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1770

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1771
    # Select
updated pod
Yuki Kimoto authored on 2011-06-21
1772
    my $result = $dbi->select(table  => 'book',
1773
      column => ['title', 'author'], where  => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1774

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1775
    # Select, more complex
1776
    my $result = $dbi->select(
1777
        table  => 'book',
1778
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1779
            {book => [qw/title author/]},
1780
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1781
        ],
1782
        where  => {'book.author' => 'Ken'},
1783
        join => ['left outer join company on book.company_id = company.id'],
1784
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1785
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1786
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1787
    # Fetch
1788
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1789
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1790
    }
1791
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1792
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1793
    while (my $row = $result->fetch_hash) {
1794
        
1795
    }
1796
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1797
    # Execute SQL with parameter.
1798
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1799
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1800
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1801
    );
1802
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1803
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1804

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1805
L<DBIx::Custom> is L<DBI> wrapper module.
1806

            
1807
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1808

            
updated pod
Yuki Kimoto authored on 2011-06-21
1809
L<DBIx::Custom> is the wrapper class of L<DBI> to execute SQL easily.
1810
This module have the following features.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1811

            
updated pod
Yuki Kimoto authored on 2011-06-21
1812
=over 4
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1813

            
updated pod
Yuki Kimoto authored on 2011-06-21
1814
=item * Execute INSERT, UPDATE, DELETE, SELECT statement easily
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1815

            
updated pod
Yuki Kimoto authored on 2011-06-21
1816
=item * You can specify bind values by hash reference
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1817

            
updated pod
Yuki Kimoto authored on 2011-06-21
1818
=item * Filtering by data type. and you can set filter to any column
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1819

            
updated pod
Yuki Kimoto authored on 2011-06-21
1820
=item * Creating where clause flexibly
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1821

            
updated pod
Yuki Kimoto authored on 2011-06-21
1822
=item * Support model
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1823

            
1824
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1825

            
1826
=head1 GUIDE
1827

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1828
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide
pod fix
Yuki Kimoto authored on 2011-01-21
1829

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1830
=head1 Wiki
pod fix
Yuki Kimoto authored on 2011-01-21
1831

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1832
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
updated document
yuki-kimoto authored on 2010-08-08
1833

            
update document
yuki-kimoto authored on 2010-01-30
1834
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
1835

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1836
=head2 C<connector>
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1837

            
1838
    my $connector = $dbi->connector;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1839
    $dbi = $dbi->connector(DBIx::Connector->new(...));
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1840

            
updated pod
Yuki Kimoto authored on 2011-06-21
1841
Connection manager object. if connector is set, you can get C<dbh>
1842
through connection manager. conection manager object must have C<dbh> mehtod.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1843

            
1844
This is L<DBIx::Connector> example. Please pass
updated pod
Yuki Kimoto authored on 2011-06-21
1845
C<default_dbi_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1846

            
1847
    my $connector = DBIx::Connector->new(
1848
        "dbi:mysql:database=$DATABASE",
1849
        $USER,
1850
        $PASSWORD,
1851
        DBIx::Custom->new->default_dbi_option
1852
    );
1853
    
updated pod
Yuki Kimoto authored on 2011-06-21
1854
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1855

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1856
=head2 C<dsn>
1857

            
1858
    my $dsn = $dbi->dsn;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1859
    $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
1860

            
updated pod
Yuki Kimoto authored on 2011-06-21
1861
Data source name, used when C<connect> method is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1862

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1863
=head2 C<dbi_option>
added dbi_options attribute
kimoto authored on 2010-12-20
1864

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1865
    my $dbi_option = $dbi->dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1866
    $dbi = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1867

            
updated pod
Yuki Kimoto authored on 2011-06-21
1868
L<DBI> option, used when C<connect> method is executed.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1869
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1870

            
1871
=head2 C<default_dbi_option>
1872

            
1873
    my $default_dbi_option = $dbi->default_dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1874
    $dbi = $dbi->default_dbi_option($default_dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1875

            
updated pod
Yuki Kimoto authored on 2011-06-21
1876
L<DBI> default option, used when C<connect> method is executed,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1877
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1878

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1879
    {
1880
        RaiseError => 1,
1881
        PrintError => 0,
1882
        AutoCommit => 1,
1883
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1884

            
cleanup
yuki-kimoto authored on 2010-10-17
1885
=head2 C<filters>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1886

            
cleanup
yuki-kimoto authored on 2010-10-17
1887
    my $filters = $dbi->filters;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1888
    $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1889

            
updated pod
Yuki Kimoto authored on 2011-06-21
1890
Filters, registered by C<register_filter> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1891

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1892
=head2 C<models>
add models() attribute
Yuki Kimoto authored on 2011-02-21
1893

            
1894
    my $models = $dbi->models;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1895
    $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
1896

            
updated pod
Yuki Kimoto authored on 2011-06-21
1897
Models, included by C<include_model> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1898

            
cleanup
yuki-kimoto authored on 2010-10-17
1899
=head2 C<password>
1900

            
1901
    my $password = $dbi->password;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1902
    $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
1903

            
updated pod
Yuki Kimoto authored on 2011-06-21
1904
Password, used when C<connect> method is executed.
update document
yuki-kimoto authored on 2010-01-30
1905

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1906
=head2 C<query_builder>
added commit method
yuki-kimoto authored on 2010-05-27
1907

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1908
    my $sql_class = $dbi->query_builder;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1909
    $dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new);
added commit method
yuki-kimoto authored on 2010-05-27
1910

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1911
Query builder, default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
1912

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1913
=head2 C<quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1914

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1915
     my quote = $dbi->quote;
1916
     $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1917

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1918
Reserved word quote.
1919
Default to double quote '"' except for mysql.
1920
In mysql, default to back quote '`'
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1921

            
cleanup
yuki-kimoto authored on 2010-10-17
1922
=head2 C<result_class>
cleanup
yuki-kimoto authored on 2010-08-05
1923

            
cleanup
yuki-kimoto authored on 2010-10-17
1924
    my $result_class = $dbi->result_class;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1925
    $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
1926

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1927
Result class, default to L<DBIx::Custom::Result>.
cleanup
yuki-kimoto authored on 2010-08-05
1928

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1929
=head2 C<safety_character>
update pod
Yuki Kimoto authored on 2011-01-27
1930

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1931
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1932
    $dbi = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
1933

            
update pod
Yuki Kimoto authored on 2011-03-13
1934
Regex of safety character for table and column name, default to '\w'.
cleanup
Yuki Kimoto authored on 2011-03-10
1935
Note that you don't have to specify like '[\w]'.
update pod
Yuki Kimoto authored on 2011-01-27
1936

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
1937
=head2 C<tag_parse>
1938

            
1939
    my $tag_parse = $dbi->tag_parse(0);
1940
    $dbi = $dbi->tag_parse;
1941

            
1942
Enable DEPRECATED tag parsing functionality, default to 1.
1943
If you want to disable tag parsing functionality, set to 0.
1944

            
cleanup
yuki-kimoto authored on 2010-10-17
1945
=head2 C<user>
cleanup
yuki-kimoto authored on 2010-08-05
1946

            
cleanup
yuki-kimoto authored on 2010-10-17
1947
    my $user = $dbi->user;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1948
    $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1949

            
updated pod
Yuki Kimoto authored on 2011-06-21
1950
User name, used when C<connect> method is executed.
update pod
Yuki Kimoto authored on 2011-01-27
1951

            
cleanup
yuki-kimoto authored on 2010-10-17
1952
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
1953

            
cleanup
yuki-kimoto authored on 2010-10-17
1954
L<DBIx::Custom> inherits all methods from L<Object::Simple>
cleanup
Yuki Kimoto authored on 2011-03-10
1955
and use all methods of L<DBI>
cleanup
yuki-kimoto authored on 2010-10-17
1956
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1957

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1958
=head2 C<available_data_type> EXPERIMENTAL
1959

            
1960
    print $dbi->available_data_type;
1961

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
1962
Get available data types. You can use these data types
updated pod
Yuki Kimoto authored on 2011-06-21
1963
in C<type rule>'s C<from1> and C<from2> section.
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
1964

            
1965
=head2 C<available_type_name> EXPERIMENTAL
1966

            
1967
    print $dbi->available_type_name;
1968

            
1969
Get available type names. You can use these type names in
updated pod
Yuki Kimoto authored on 2011-06-21
1970
C<type_rule>'s C<into1> and C<into2> section.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1971

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1972
=head2 C<assign_param> EXPERIMENTAL
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1973

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1974
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1975

            
updated pod
Yuki Kimoto authored on 2011-06-09
1976
Create assign parameter.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1977

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1978
    title = :title, author = :author
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1979

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1980
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1981

            
cleanup
Yuki Kimoto authored on 2011-06-13
1982
=head2 C<column> EXPERIMETNAL
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1983

            
cleanup
Yuki Kimoto authored on 2011-06-13
1984
    my $column = $dbi->column(book => ['author', 'title']);
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1985

            
1986
Create column clause. The follwoing column clause is created.
1987

            
1988
    book.author as "book.author",
1989
    book.title as "book.title"
1990

            
cleanup
Yuki Kimoto authored on 2011-06-13
1991
You can change separator by C<separator> method.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1992

            
cleanup
Yuki Kimoto authored on 2011-06-13
1993
    # Separator is double underbar
1994
    $dbi->separator('__');
1995
    
1996
    book.author as "book__author",
1997
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1998

            
cleanup
Yuki Kimoto authored on 2011-06-13
1999
    # Separator is hyphen
2000
    $dbi->separator('-');
2001
    
2002
    book.author as "book-author",
2003
    book.title as "book-title"
2004
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2005
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2006

            
update pod
Yuki Kimoto authored on 2011-03-13
2007
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2008
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2009
        user => 'ken',
2010
        password => '!LFKD%$&',
2011
        dbi_option => {mysql_enable_utf8 => 1}
2012
    );
2013

            
2014
Connect to the database and create a new L<DBIx::Custom> object.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
2015

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2016
L<DBIx::Custom> is a wrapper of L<DBI>.
cleanup
yuki-kimoto authored on 2010-08-09
2017
C<AutoCommit> and C<RaiseError> options are true, 
update pod
Yuki Kimoto authored on 2011-03-13
2018
and C<PrintError> option is false by default.
packaging one directory
yuki-kimoto authored on 2009-11-16
2019

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2020
=head2 create_model
2021

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2022
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2023
        table => 'book',
2024
        primary_key => 'id',
2025
        join => [
2026
            'inner join company on book.comparny_id = company.id'
2027
        ],
2028
    );
2029

            
2030
Create L<DBIx::Custom::Model> object and initialize model.
updated pod
Yuki Kimoto authored on 2011-06-21
2031
the module is also used from C<model> method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2032

            
2033
   $dbi->model('book')->select(...);
2034

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2035
=head2 C<dbh>
2036

            
2037
    my $dbh = $dbi->dbh;
2038

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2039
Get L<DBI> database handle. if C<connector> is set, you can get
updated pod
Yuki Kimoto authored on 2011-06-21
2040
database handle through C<connector> object.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2041

            
2042
=head2 C<each_column>
2043

            
2044
    $dbi->each_column(
2045
        sub {
2046
            my ($dbi, $table, $column, $column_info) = @_;
2047
            
2048
            my $type = $column_info->{TYPE_NAME};
2049
            
2050
            if ($type eq 'DATE') {
2051
                # ...
2052
            }
2053
        }
2054
    );
2055

            
2056
Iterate all column informations of all table from database.
2057
Argument is callback when one column is found.
2058
Callback receive four arguments, dbi object, table name,
2059
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2060

            
cleanup
yuki-kimoto authored on 2010-10-17
2061
=head2 C<execute>
packaging one directory
yuki-kimoto authored on 2009-11-16
2062

            
update pod
Yuki Kimoto authored on 2011-03-13
2063
    my $result = $dbi->execute(
updated pod
Yuki Kimoto authored on 2011-06-21
2064
      "select * from book where title = :title and author like :author",
2065
      {title => 'Perl', author => '%Ken%'}
2066
    );
2067

            
2068
    my $result = $dbi->execute(
2069
      "select * from book where title = :book.title and author like :book.author",
2070
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2071
    );
2072

            
updated pod
Yuki Kimoto authored on 2011-06-21
2073
Execute SQL. SQL can contain column parameter such as :author and :title.
2074
You can append table name to column name such as :book.title and :book.author.
2075
Second argunet is data, embedded into column parameter.
2076
Return value is L<DBIx::Custom::Result> object when select statement is executed,
2077
or the count of affected rows when insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2078

            
updated pod
Yuki Kimoto authored on 2011-06-09
2079
Parameter is replaced by placeholder C<?>.
update pod
Yuki Kimoto authored on 2011-03-13
2080

            
2081
    select * from where title = ? and author like ?;
2082

            
updated pod
Yuki Kimoto authored on 2011-06-09
2083
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2084

            
2085
=over 4
2086

            
2087
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2088
    
2089
    filter => {
2090
        title  => sub { uc $_[0] }
2091
        author => sub { uc $_[0] }
2092
    }
update pod
Yuki Kimoto authored on 2011-03-13
2093

            
updated pod
Yuki Kimoto authored on 2011-06-09
2094
    # Filter name
2095
    filter => {
2096
        title  => 'upper_case',
2097
        author => 'upper_case'
2098
    }
2099
        
2100
    # At once
2101
    filter => [
2102
        [qw/title author/]  => sub { uc $_[0] }
2103
    ]
2104

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2105
Filter. You can set subroutine or filter name
updated pod
Yuki Kimoto authored on 2011-06-21
2106
registered by by C<register_filter>.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2107
This filter is executed before data is saved into database.
2108
and before type rule filter is executed.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2109

            
updated document
Yuki Kimoto authored on 2011-06-09
2110
=item C<query>
2111

            
2112
    query => 1
2113

            
2114
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
updated pod
Yuki Kimoto authored on 2011-06-21
2115
You can check executed SQL and columns order.
2116

            
2117
    my $sql = $query->sql;
2118
    my $columns = $query->columns;
updated document
Yuki Kimoto authored on 2011-06-09
2119

            
updated pod
Yuki Kimoto authored on 2011-06-09
2120
=item C<table>
2121
    
2122
    table => 'author'
2123

            
updated pod
Yuki Kimoto authored on 2011-06-21
2124
If you want to omit table name in column name
2125
and enable C<into1> and C<into2> type filter,
2126
You must set C<table> option.
updated pod
Yuki Kimoto authored on 2011-06-09
2127

            
updated pod
Yuki Kimoto authored on 2011-06-21
2128
    $dbi->execute("select * from book where title = :title and author = :author",
2129
        {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2130

            
updated pod
Yuki Kimoto authored on 2011-06-21
2131
    # Same
2132
    $dbi->execute(
2133
      "select * from book where title = :book.title and author = :book.author",
2134
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2135

            
updated pod
Yuki Kimoto authored on 2011-06-21
2136
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2137

            
updated pod
Yuki Kimoto authored on 2011-06-21
2138
Specify database bind data type.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2139

            
updated pod
Yuki Kimoto authored on 2011-06-21
2140
    bind_type => [image => DBI::SQL_BLOB]
2141
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2142

            
updated pod
Yuki Kimoto authored on 2011-06-21
2143
This is used to bind parameter by C<bind_param> of statment handle.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2144

            
updated pod
Yuki Kimoto authored on 2011-06-21
2145
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2146

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2147
=item C<table_alias> EXPERIMENTAL
2148

            
2149
    table_alias => {user => 'hiker'}
2150

            
2151
Table alias. Key is real table name, value is alias table name.
2152
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2153
on alias table name.
2154

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2155
=item C<type_rule_off> EXPERIMENTAL
2156

            
2157
    type_rule_off => 1
2158

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2159
Turn C<into1> and C<into2> type rule off.
2160

            
2161
=item C<type_rule1_off> EXPERIMENTAL
2162

            
2163
    type_rule1_off => 1
2164

            
2165
Turn C<into1> type rule off.
2166

            
2167
=item C<type_rule2_off> EXPERIMENTAL
2168

            
2169
    type_rule2_off => 1
2170

            
2171
Turn C<into2> type rule off.
update document
yuki-kimoto authored on 2009-11-19
2172

            
update pod
Yuki Kimoto authored on 2011-03-13
2173
=back
version 0.0901
yuki-kimoto authored on 2009-12-17
2174

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2175
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
2176

            
update pod
Yuki Kimoto authored on 2011-03-13
2177
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2178

            
updated document
Yuki Kimoto authored on 2011-06-09
2179
Execute delete statement.
update pod
Yuki Kimoto authored on 2011-03-13
2180

            
updated document
Yuki Kimoto authored on 2011-06-09
2181
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2182

            
update pod
Yuki Kimoto authored on 2011-03-13
2183
=over 4
2184

            
update pod
Yuki Kimoto authored on 2011-03-13
2185
=item C<append>
2186

            
updated document
Yuki Kimoto authored on 2011-06-09
2187
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2188

            
2189
=item C<filter>
2190

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2191
Same as C<execute> method's C<filter> option.
update pod
Yuki Kimoto authored on 2011-03-13
2192

            
updated document
Yuki Kimoto authored on 2011-06-09
2193
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2194

            
updated document
Yuki Kimoto authored on 2011-06-09
2195
    id => 4
2196
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2197

            
updated document
Yuki Kimoto authored on 2011-06-09
2198
ID corresponding to C<primary_key>.
2199
You can delete rows by C<id> and C<primary_key>.
update pod
Yuki Kimoto authored on 2011-03-13
2200

            
updated document
Yuki Kimoto authored on 2011-06-09
2201
    $dbi->delete(
2202
        parimary_key => ['id1', 'id2'],
2203
        id => [4, 5],
2204
        table => 'book',
2205
    );
update pod
Yuki Kimoto authored on 2011-03-13
2206

            
updated document
Yuki Kimoto authored on 2011-06-09
2207
The above is same as the followin one.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2208

            
updated document
Yuki Kimoto authored on 2011-06-09
2209
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2210

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2211
=item C<prefix> EXPERIMENTAL
2212

            
2213
    prefix => 'some'
2214

            
2215
prefix before table name section.
2216

            
2217
    delete some from book
2218

            
updated document
Yuki Kimoto authored on 2011-06-09
2219
=item C<query>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2220

            
updated document
Yuki Kimoto authored on 2011-06-09
2221
Same as C<execute> method's C<query> option.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2222

            
updated document
Yuki Kimoto authored on 2011-06-09
2223
=item C<table>
update pod
Yuki Kimoto authored on 2011-03-13
2224

            
updated document
Yuki Kimoto authored on 2011-06-09
2225
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2226

            
updated pod
Yuki Kimoto authored on 2011-06-21
2227
Table name.
2228

            
updated document
Yuki Kimoto authored on 2011-06-09
2229
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2230

            
updated document
Yuki Kimoto authored on 2011-06-09
2231
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2232

            
updated pod
Yuki Kimoto authored on 2011-06-08
2233
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2234

            
updated pod
Yuki Kimoto authored on 2011-06-08
2235
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2236

            
updated pod
Yuki Kimoto authored on 2011-06-21
2237
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2238

            
updated pod
Yuki Kimoto authored on 2011-06-21
2239
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2240

            
2241
=item C<type_rule_off> EXPERIMENTAL
2242

            
2243
Same as C<execute> method's C<type_rule_off> option.
2244

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2245
=item C<type_rule1_off> EXPERIMENTAL
2246

            
2247
    type_rule1_off => 1
2248

            
2249
Same as C<execute> method's C<type_rule1_off> option.
2250

            
2251
=item C<type_rule2_off> EXPERIMENTAL
2252

            
2253
    type_rule2_off => 1
2254

            
2255
Same as C<execute> method's C<type_rule2_off> option.
2256

            
updated pod
Yuki Kimoto authored on 2011-06-08
2257
=back
update pod
Yuki Kimoto authored on 2011-03-13
2258

            
updated pod
Yuki Kimoto authored on 2011-06-08
2259
=head2 C<delete_all>
update pod
Yuki Kimoto authored on 2011-03-13
2260

            
updated pod
Yuki Kimoto authored on 2011-06-08
2261
    $dbi->delete_all(table => $table);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2262

            
updated document
Yuki Kimoto authored on 2011-06-09
2263
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
2264
Options is same as C<delete>.
update pod
Yuki Kimoto authored on 2011-03-13
2265

            
cleanup
yuki-kimoto authored on 2010-10-17
2266
=head2 C<insert>
2267

            
cleanup
Yuki Kimoto authored on 2011-06-09
2268
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2269

            
updated pod
Yuki Kimoto authored on 2011-06-21
2270
Execute insert statement. First argument is row data. Return value is
2271
affected row count.
update pod
Yuki Kimoto authored on 2011-03-13
2272

            
cleanup
Yuki Kimoto authored on 2011-06-09
2273
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2274

            
cleanup
Yuki Kimoto authored on 2011-06-09
2275
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2276

            
update pod
Yuki Kimoto authored on 2011-03-13
2277
=item C<append>
2278

            
cleanup
Yuki Kimoto authored on 2011-06-09
2279
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2280

            
2281
=item C<filter>
2282

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2283
Same as C<execute> method's C<filter> option.
2284

            
2285
=item C<id>
2286

            
updated document
Yuki Kimoto authored on 2011-06-09
2287
    id => 4
2288
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2289

            
updated document
Yuki Kimoto authored on 2011-06-09
2290
ID corresponding to C<primary_key>.
2291
You can insert a row by C<id> and C<primary_key>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2292

            
update pod
Yuki Kimoto authored on 2011-03-13
2293
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2294
        {title => 'Perl', author => 'Ken'}
2295
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2296
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2297
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2298
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2299

            
updated document
Yuki Kimoto authored on 2011-06-09
2300
The above is same as the followin one.
update pod
Yuki Kimoto authored on 2011-03-13
2301

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2302
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2303
        {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2304
        table => 'book'
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2305
    );
update pod
Yuki Kimoto authored on 2011-03-13
2306

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2307
=item C<prefix> EXPERIMENTAL
2308

            
2309
    prefix => 'or replace'
2310

            
2311
prefix before table name section
2312

            
2313
    insert or replace into book
2314

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2315
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2316

            
updated document
Yuki Kimoto authored on 2011-06-09
2317
    primary_key => 'id'
2318
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2319

            
updated document
Yuki Kimoto authored on 2011-06-09
2320
Primary key. This is used by C<id> option.
cleanup
Yuki Kimoto authored on 2011-06-09
2321

            
updated document
Yuki Kimoto authored on 2011-06-09
2322
=item C<query>
2323

            
2324
Same as C<execute> method's C<query> option.
2325

            
2326
=item C<table>
2327

            
2328
    table => 'book'
2329

            
2330
Table name.
2331

            
updated pod
Yuki Kimoto authored on 2011-06-21
2332
=item C<bind_type>
cleanup
yuki-kimoto authored on 2010-10-17
2333

            
updated pod
Yuki Kimoto authored on 2011-06-21
2334
Same as C<execute> method's C<bind_type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2335

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2336
=item C<type_rule_off> EXPERIMENTAL
2337

            
updated document
Yuki Kimoto authored on 2011-06-09
2338
Same as C<execute> method's C<type_rule_off> option.
update pod
Yuki Kimoto authored on 2011-03-13
2339

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2340
=item C<type_rule1_off> EXPERIMENTAL
2341

            
2342
    type_rule1_off => 1
2343

            
2344
Same as C<execute> method's C<type_rule1_off> option.
2345

            
2346
=item C<type_rule2_off> EXPERIMENTAL
2347

            
2348
    type_rule2_off => 1
2349

            
2350
Same as C<execute> method's C<type_rule2_off> option.
2351

            
update pod
Yuki Kimoto authored on 2011-03-13
2352
=back
2353

            
2354
=over 4
2355

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2356
=head2 C<insert_param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2357

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2358
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2359

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2360
Create insert parameters.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2361

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2362
    (title, author) values (title = :title, age = :age);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2363

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2364
=head2 C<include_model>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2365

            
update pod
Yuki Kimoto authored on 2011-03-13
2366
    $dbi->include_model('MyModel');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2367

            
update pod
Yuki Kimoto authored on 2011-03-13
2368
Include models from specified namespace,
2369
the following layout is needed to include models.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2370

            
update pod
Yuki Kimoto authored on 2011-03-13
2371
    lib / MyModel.pm
2372
        / MyModel / book.pm
2373
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2374

            
update pod
Yuki Kimoto authored on 2011-03-13
2375
Name space module, extending L<DBIx::Custom::Model>.
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2376

            
update pod
Yuki Kimoto authored on 2011-03-13
2377
B<MyModel.pm>
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2378

            
2379
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2380
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2381
    
2382
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2383

            
update pod
Yuki Kimoto authored on 2011-03-13
2384
Model modules, extending name space module.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2385

            
update pod
Yuki Kimoto authored on 2011-03-13
2386
B<MyModel/book.pm>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2387

            
update pod
Yuki Kimoto authored on 2011-03-13
2388
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2389
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2390
    
2391
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2392

            
update pod
Yuki Kimoto authored on 2011-03-13
2393
B<MyModel/company.pm>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2394

            
update pod
Yuki Kimoto authored on 2011-03-13
2395
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2396
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2397
    
2398
    1;
2399
    
updated pod
Yuki Kimoto authored on 2011-06-21
2400
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2401

            
updated pod
Yuki Kimoto authored on 2011-06-21
2402
You can get model object by C<model>.
update pod
Yuki Kimoto authored on 2011-03-13
2403

            
updated pod
Yuki Kimoto authored on 2011-06-21
2404
    my $book_model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
2405
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2406

            
update pod
Yuki Kimoto authored on 2011-03-13
2407
See L<DBIx::Custom::Model> to know model features.
2408

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
2409
=head2 C<map_param> EXPERIMENTAL
2410

            
2411
    my $map_param = $dbi->map_param(
2412
        {id => 1, authro => 'Ken', price => 1900},
2413
        'id' => 'book.id',
2414
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2415
        'price' => [
2416
            'book.price', {if => sub { length $_[0] }}
2417
        ]
2418
    );
2419

            
2420
Map paramters to other key and value. First argument is original
2421
parameter. this is hash reference. Rest argument is mapping.
2422
By default, Mapping is done if the value length is not zero.
2423

            
2424
=over 4
2425

            
2426
=item Key mapping
2427

            
2428
    'id' => 'book.id'
2429

            
2430
This is only key mapping. Value is same as original one.
2431

            
2432
    (id => 1) is mapped to ('book.id' => 1) if value length is not zero.
2433

            
2434
=item Key and value mapping
2435

            
2436
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2437

            
2438
This is key and value mapping. Frist element of array reference
2439
is mapped key name, second element is code reference to map the value.
2440

            
2441
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2442
      if value length is not zero.
2443

            
2444
=item Condition
2445

            
2446
    'price' => ['book.price', {if => 'exists'}]
2447
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2448
    'price' => ['book.price', {if => sub { defined shift }}]
2449

            
2450
If you need condition, you can sepecify it. this is code reference
2451
or 'exists'. By default, condition is the following one.
2452

            
2453
    sub { defined $_[0] && length $_[0] }
2454

            
2455
=back
2456

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2457
=head2 C<merge_param>
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2458

            
2459
    my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2});
2460

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2461
Merge parameters.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2462

            
2463
    {key1 => [1, 1], key2 => 2}
2464

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2465
=head2 C<method>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2466

            
2467
    $dbi->method(
2468
        update_or_insert => sub {
2469
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2470
            
2471
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2472
        },
2473
        find_or_create   => sub {
2474
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2475
            
2476
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2477
        }
2478
    );
2479

            
update pod
Yuki Kimoto authored on 2011-03-13
2480
Register method. These method is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2481

            
2482
    $dbi->update_or_insert;
2483
    $dbi->find_or_create;
2484

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2485
=head2 C<model>
update pod
Yuki Kimoto authored on 2011-03-13
2486

            
2487
    my $model = $dbi->model('book');
2488

            
updated pod
Yuki Kimoto authored on 2011-06-21
2489
Get a L<DBIx::Custom::Model> object,
update pod
Yuki Kimoto authored on 2011-03-13
2490

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2491
=head2 C<mycolumn>
cleanup
Yuki Kimoto authored on 2011-03-21
2492

            
2493
    my $column = $self->mycolumn(book => ['author', 'title']);
2494

            
2495
Create column clause for myself. The follwoing column clause is created.
2496

            
2497
    book.author as author,
2498
    book.title as title
2499

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2500
=head2 C<new>
2501

            
update pod
Yuki Kimoto authored on 2011-03-13
2502
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2503
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2504
        user => 'ken',
2505
        password => '!LFKD%$&',
2506
        dbi_option => {mysql_enable_utf8 => 1}
2507
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2508

            
2509
Create a new L<DBIx::Custom> object.
2510

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2511
=head2 C<not_exists>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2512

            
2513
    my $not_exists = $dbi->not_exists;
2514

            
update pod
Yuki Kimoto authored on 2011-03-13
2515
DBIx::Custom::NotExists object, indicating the column is not exists.
2516
This is used by C<clause> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2517

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2518
=head2 C<order> EXPERIMENTAL
2519

            
2520
    my $order = $dbi->order;
2521

            
2522
Create a new L<DBIx::Custom::Order> object.
2523

            
cleanup
yuki-kimoto authored on 2010-10-17
2524
=head2 C<register_filter>
2525

            
update pod
Yuki Kimoto authored on 2011-03-13
2526
    $dbi->register_filter(
2527
        # Time::Piece object to database DATE format
2528
        tp_to_date => sub {
2529
            my $tp = shift;
2530
            return $tp->strftime('%Y-%m-%d');
2531
        },
2532
        # database DATE format to Time::Piece object
2533
        date_to_tp => sub {
2534
           my $date = shift;
2535
           return Time::Piece->strptime($date, '%Y-%m-%d');
2536
        }
2537
    );
cleanup
yuki-kimoto authored on 2010-10-17
2538
    
update pod
Yuki Kimoto authored on 2011-03-13
2539
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2540

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2541
=head2 C<type_rule> EXPERIMENTAL
2542

            
2543
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2544
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2545
            date => sub { ... },
2546
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2547
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2548
        into2 => {
2549
            date => sub { ... },
2550
            datetime => sub { ... }
2551
        },
2552
        from1 => {
2553
            # DATE
2554
            9 => sub { ... },
2555
            # DATETIME or TIMESTAMP
2556
            11 => sub { ... },
2557
        }
2558
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2559
            # DATE
2560
            9 => sub { ... },
2561
            # DATETIME or TIMESTAMP
2562
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2563
        }
2564
    );
2565

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2566
Filtering rule when data is send into and get from database.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2567
This has a little complex problem.
cleanup
Yuki Kimoto authored on 2011-06-13
2568

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2569
In C<into1> and C<into2> you can specify
2570
type name as same as type name defined
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2571
by create table, such as C<DATETIME> or C<DATE>.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2572

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2573
Note that type name and data type don't contain upper case.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2574
If these contain upper case charactor, you convert it to lower case.
2575

            
updated pod
Yuki Kimoto authored on 2011-06-21
2576
C<into2> is executed after C<into1>.
2577

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2578
Type rule of C<into1> and C<into2> is enabled on the following
2579
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2580

            
cleanup
Yuki Kimoto authored on 2011-06-13
2581
=over 4
2582

            
2583
=item 1. column name
2584

            
2585
    issue_date
2586
    issue_datetime
2587

            
updated pod
Yuki Kimoto authored on 2011-06-21
2588
This need C<table> option in each method.
2589

            
cleanup
Yuki Kimoto authored on 2011-06-13
2590
=item 2. table name and column name, separator is dot
2591

            
2592
    book.issue_date
2593
    book.issue_datetime
2594

            
2595
=back
2596

            
update pod
Yuki Kimoto authored on 2011-06-15
2597
You get all type name used in database by C<available_type_name>.
2598

            
2599
    print $dbi->available_type_name;
2600

            
updated pod
Yuki Kimoto authored on 2011-06-21
2601
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2602
C<from2> is executed after C<from1>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2603
You get all data type by C<available_data_type>.
2604

            
2605
    print $dbi->available_data_type;
2606

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2607
You can also specify multiple types at once.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2608

            
2609
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2610
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2611
            [qw/DATE DATETIME/] => sub { ... },
2612
        ],
2613
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2614

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2615
=head2 C<select>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2616

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2617
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2618
        table  => 'book',
2619
        column => ['author', 'title'],
2620
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2621
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2622
    
updated document
Yuki Kimoto authored on 2011-06-09
2623
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2624

            
updated document
Yuki Kimoto authored on 2011-06-09
2625
The following opitons are available.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2626

            
2627
=over 4
2628

            
updated document
Yuki Kimoto authored on 2011-06-09
2629
=item C<append>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2630

            
updated document
Yuki Kimoto authored on 2011-06-09
2631
    append => 'order by title'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2632

            
updated document
Yuki Kimoto authored on 2011-06-09
2633
Append statement to last of SQL.
2634
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2635
=item C<column>
2636
    
updated document
Yuki Kimoto authored on 2011-06-09
2637
    column => 'author'
2638
    column => ['author', 'title']
2639

            
2640
Column clause.
updated pod
Yuki Kimoto authored on 2011-06-07
2641
    
updated document
Yuki Kimoto authored on 2011-06-09
2642
if C<column> is not specified, '*' is set.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2643

            
updated document
Yuki Kimoto authored on 2011-06-09
2644
    column => '*'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2645

            
updated pod
Yuki Kimoto authored on 2011-06-21
2646
You can specify hash of array reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2647

            
updated document
Yuki Kimoto authored on 2011-06-09
2648
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2649
        {book => [qw/author title/]},
2650
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2651
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2652

            
updated pod
Yuki Kimoto authored on 2011-06-21
2653
This is expanded to the following one by using C<colomn> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2654

            
2655
    book.author as "book.author",
2656
    book.title as "book.title",
2657
    person.name as "person.name",
2658
    person.age as "person.age"
2659

            
updated pod
Yuki Kimoto authored on 2011-06-21
2660
You can specify array of array reference.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2661

            
updated document
Yuki Kimoto authored on 2011-06-09
2662
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2663
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2664
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2665

            
updated document
Yuki Kimoto authored on 2011-06-09
2666
Alias is quoted and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2667

            
2668
    date(book.register_datetime) as "book.register_date"
updated pod
Yuki Kimoto authored on 2011-06-07
2669

            
updated document
Yuki Kimoto authored on 2011-06-09
2670
=item C<filter>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2671

            
updated document
Yuki Kimoto authored on 2011-06-09
2672
Same as C<execute> method's C<filter> option.
2673

            
2674
=item C<id>
2675

            
2676
    id => 4
2677
    id => [4, 5]
2678

            
2679
ID corresponding to C<primary_key>.
2680
You can select rows by C<id> and C<primary_key>.
2681

            
2682
    $dbi->select(
2683
        parimary_key => ['id1', 'id2'],
2684
        id => [4, 5],
2685
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2686
    );
2687

            
updated document
Yuki Kimoto authored on 2011-06-09
2688
The above is same as the followin one.
2689

            
updated pod
Yuki Kimoto authored on 2011-04-25
2690
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2691
        where => {id1 => 4, id2 => 5},
2692
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2693
    );
2694
    
updated document
Yuki Kimoto authored on 2011-06-09
2695
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2696

            
updated document
Yuki Kimoto authored on 2011-06-09
2697
    param => {'table2.key3' => 5}
update pod
Yuki Kimoto authored on 2011-03-12
2698

            
updated document
Yuki Kimoto authored on 2011-06-09
2699
Parameter shown before where clause.
2700
    
2701
For example, if you want to contain tag in join clause, 
2702
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
2703

            
updated document
Yuki Kimoto authored on 2011-06-09
2704
    join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
2705
              ' as table2 on table1.key1 = table2.key1']
2706

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2707
=itme C<prefix> EXPERIMENTAL
2708

            
2709
    prefix => 'SQL_CALC_FOUND_ROWS'
2710

            
2711
Prefix of column cluase
2712

            
2713
    select SQL_CALC_FOUND_ROWS title, author from book;
2714

            
updated document
Yuki Kimoto authored on 2011-06-09
2715
=item C<join>
2716

            
2717
    join => [
2718
        'left outer join company on book.company_id = company_id',
2719
        'left outer join location on company.location_id = location.id'
2720
    ]
2721
        
2722
Join clause. If column cluase or where clause contain table name like "company.name",
2723
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2724

            
2725
    $dbi->select(
2726
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2727
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2728
        where => {'company.name' => 'Orange'},
2729
        join => [
2730
            'left outer join company on book.company_id = company.id',
2731
            'left outer join location on company.location_id = location.id'
2732
        ]
2733
    );
2734

            
updated document
Yuki Kimoto authored on 2011-06-09
2735
In above select, column and where clause contain "company" table,
2736
the following SQL is created
update pod
Yuki Kimoto authored on 2011-03-12
2737

            
cleanup
Yuki Kimoto authored on 2011-06-13
2738
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2739
    from book
2740
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2741
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2742

            
updated document
Yuki Kimoto authored on 2011-06-09
2743
=item C<primary_key>
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2744

            
updated document
Yuki Kimoto authored on 2011-06-09
2745
    primary_key => 'id'
2746
    primary_key => ['id1', 'id2']
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2747

            
updated document
Yuki Kimoto authored on 2011-06-09
2748
Primary key. This is used by C<id> option.
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2749

            
updated document
Yuki Kimoto authored on 2011-06-09
2750
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-12
2751

            
updated document
Yuki Kimoto authored on 2011-06-09
2752
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-12
2753

            
updated pod
Yuki Kimoto authored on 2011-06-21
2754
=item C<bind_type>
updated pod
Yuki Kimoto authored on 2011-06-08
2755

            
updated document
Yuki Kimoto authored on 2011-06-09
2756
Same as C<execute> method's C<type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2757

            
updated document
Yuki Kimoto authored on 2011-06-09
2758
=item C<table>
updated pod
Yuki Kimoto authored on 2011-06-08
2759

            
updated document
Yuki Kimoto authored on 2011-06-09
2760
    table => 'book'
updated pod
Yuki Kimoto authored on 2011-06-08
2761

            
updated document
Yuki Kimoto authored on 2011-06-09
2762
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2763

            
updated document
Yuki Kimoto authored on 2011-06-09
2764
=item C<type_rule_off> EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-08
2765

            
updated document
Yuki Kimoto authored on 2011-06-09
2766
Same as C<execute> method's C<type_rule_off> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2767

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2768
=item C<type_rule1_off> EXPERIMENTAL
2769

            
2770
    type_rule1_off => 1
2771

            
2772
Same as C<execute> method's C<type_rule1_off> option.
2773

            
2774
=item C<type_rule2_off> EXPERIMENTAL
2775

            
2776
    type_rule2_off => 1
2777

            
2778
Same as C<execute> method's C<type_rule2_off> option.
2779

            
updated document
Yuki Kimoto authored on 2011-06-09
2780
=item C<where>
2781
    
2782
    # Hash refrence
2783
    where => {author => 'Ken', 'title' => 'Perl'}
2784
    
2785
    # DBIx::Custom::Where object
2786
    where => $dbi->where(
2787
        clause => ['and', 'author = :author', 'title like :title'],
2788
        param  => {author => 'Ken', title => '%Perl%'}
2789
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2790
    
2791
    # Array reference 1 (array reference, hash referenc). same as above
2792
    where => [
2793
        ['and', 'author = :author', 'title like :title'],
2794
        {author => 'Ken', title => '%Perl%'}
2795
    ];    
2796
    
2797
    # Array reference 2 (String, hash reference)
2798
    where => [
2799
        'title like :title',
2800
        {title => '%Perl%'}
2801
    ]
2802
    
2803
    # String
2804
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2805

            
updated document
Yuki Kimoto authored on 2011-06-09
2806
Where clause.
2807
    
improved pod
Yuki Kimoto authored on 2011-04-19
2808
=item C<wrap> EXPERIMENTAL
2809

            
2810
Wrap statement. This is array reference.
2811

            
2812
    $dbi->select(wrap => ['select * from (', ') as t where ROWNUM < 10']);
2813

            
2814
This option is for Oracle and SQL Server paging process.
2815

            
update pod
Yuki Kimoto authored on 2011-03-12
2816
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2817

            
cleanup
yuki-kimoto authored on 2010-10-17
2818
=head2 C<update>
removed reconnect method
yuki-kimoto authored on 2010-05-28
2819

            
updated document
Yuki Kimoto authored on 2011-06-09
2820
    $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2821

            
updated pod
Yuki Kimoto authored on 2011-06-21
2822
Execute update statement. First argument is update data.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2823

            
updated document
Yuki Kimoto authored on 2011-06-09
2824
The following opitons are available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2825

            
update pod
Yuki Kimoto authored on 2011-03-13
2826
=over 4
2827

            
updated document
Yuki Kimoto authored on 2011-06-09
2828
=item C<append>
update pod
Yuki Kimoto authored on 2011-03-13
2829

            
updated document
Yuki Kimoto authored on 2011-06-09
2830
Same as C<select> method's C<append> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2831

            
updated document
Yuki Kimoto authored on 2011-06-09
2832
=item C<filter>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2833

            
updated document
Yuki Kimoto authored on 2011-06-09
2834
Same as C<execute> method's C<filter> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2835

            
updated document
Yuki Kimoto authored on 2011-06-09
2836
=item C<id>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2837

            
updated document
Yuki Kimoto authored on 2011-06-09
2838
    id => 4
2839
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2840

            
updated document
Yuki Kimoto authored on 2011-06-09
2841
ID corresponding to C<primary_key>.
2842
You can update rows by C<id> and C<primary_key>.
update pod
Yuki Kimoto authored on 2011-03-13
2843

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2844
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2845
        {title => 'Perl', author => 'Ken'}
2846
        parimary_key => ['id1', 'id2'],
2847
        id => [4, 5],
2848
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2849
    );
update pod
Yuki Kimoto authored on 2011-03-13
2850

            
updated document
Yuki Kimoto authored on 2011-06-09
2851
The above is same as the followin one.
update pod
Yuki Kimoto authored on 2011-03-13
2852

            
updated document
Yuki Kimoto authored on 2011-06-09
2853
    $dbi->update(
2854
        {title => 'Perl', author => 'Ken'}
2855
        where => {id1 => 4, id2 => 5},
2856
        table => 'book'
2857
    );
update pod
Yuki Kimoto authored on 2011-03-13
2858

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2859
=item C<prefix> EXPERIMENTAL
2860

            
2861
    prefix => 'or replace'
2862

            
2863
prefix before table name section
2864

            
2865
    update or replace book
2866

            
updated document
Yuki Kimoto authored on 2011-06-09
2867
=item C<primary_key>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2868

            
updated document
Yuki Kimoto authored on 2011-06-09
2869
    primary_key => 'id'
2870
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2871

            
updated document
Yuki Kimoto authored on 2011-06-09
2872
Primary key. This is used by C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2873

            
updated document
Yuki Kimoto authored on 2011-06-09
2874
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
2875

            
updated document
Yuki Kimoto authored on 2011-06-09
2876
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-13
2877

            
updated document
Yuki Kimoto authored on 2011-06-09
2878
=item C<table>
update pod
Yuki Kimoto authored on 2011-03-13
2879

            
updated document
Yuki Kimoto authored on 2011-06-09
2880
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2881

            
updated document
Yuki Kimoto authored on 2011-06-09
2882
Table name.
update pod
Yuki Kimoto authored on 2011-03-13
2883

            
updated document
Yuki Kimoto authored on 2011-06-09
2884
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2885

            
updated document
Yuki Kimoto authored on 2011-06-09
2886
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2887

            
updated pod
Yuki Kimoto authored on 2011-06-21
2888
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2889

            
2890
Same as C<execute> method's C<type> option.
2891

            
2892
=item C<type_rule_off> EXPERIMENTAL
2893

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2894
Same as C<execute> method's C<type_rule_off> option.
2895

            
2896
=item C<type_rule1_off> EXPERIMENTAL
2897

            
2898
    type_rule1_off => 1
2899

            
2900
Same as C<execute> method's C<type_rule1_off> option.
2901

            
2902
=item C<type_rule2_off> EXPERIMENTAL
2903

            
2904
    type_rule2_off => 1
2905

            
2906
Same as C<execute> method's C<type_rule2_off> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2907

            
updated pod
Yuki Kimoto authored on 2011-06-08
2908
=back
update pod
Yuki Kimoto authored on 2011-03-13
2909

            
updated pod
Yuki Kimoto authored on 2011-06-08
2910
=head2 C<update_all>
update pod
Yuki Kimoto authored on 2011-03-13
2911

            
updated pod
Yuki Kimoto authored on 2011-06-21
2912
    $dbi->update_all({title => 'Perl'}, table => 'book', );
update pod
Yuki Kimoto authored on 2011-03-13
2913

            
updated document
Yuki Kimoto authored on 2011-06-09
2914
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
2915
Options is same as C<update> method.
update pod
Yuki Kimoto authored on 2011-03-13
2916

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2917
=head2 C<update_param>
update pod
Yuki Kimoto authored on 2011-03-13
2918

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2919
    my $update_param = $dbi->update_param({title => 'a', age => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2920

            
2921
Create update parameter tag.
2922

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2923
    set title = :title, author = :author
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2924

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2925
=head2 C<where>
fix tests
Yuki Kimoto authored on 2011-01-18
2926

            
cleanup
Yuki Kimoto authored on 2011-03-09
2927
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2928
        clause => ['and', 'title = :title', 'author = :author'],
cleanup
Yuki Kimoto authored on 2011-03-09
2929
        param => {title => 'Perl', author => 'Ken'}
2930
    );
fix tests
Yuki Kimoto authored on 2011-01-18
2931

            
2932
Create a new L<DBIx::Custom::Where> object.
2933

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2934
=head2 C<setup_model>
cleanup
Yuki Kimoto authored on 2011-01-12
2935

            
update pod
Yuki Kimoto authored on 2011-03-13
2936
    $dbi->setup_model;
cleanup
Yuki Kimoto authored on 2011-01-12
2937

            
update pod
Yuki Kimoto authored on 2011-03-13
2938
Setup all model objects.
update pod
Yuki Kimoto authored on 2011-03-13
2939
C<columns> of model object is automatically set, parsing database information.
cleanup
Yuki Kimoto authored on 2011-01-12
2940

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
2941
=head1 ENVIRONMENT VARIABLE
2942

            
2943
=head2 C<DBIX_CUSTOM_DEBUG>
2944

            
2945
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
improved debug message
Yuki Kimoto authored on 2011-05-23
2946
executed SQL and bind values are printed to STDERR.
2947

            
2948
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2949

            
2950
DEBUG output encoding. Default to UTF-8.
added environment variable D...
Yuki Kimoto authored on 2011-04-02
2951

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2952
=head1 DEPRECATED FUNCTIONALITIES
2953

            
2954
L<DBIx::Custom>
2955

            
2956
    # Attribute methods
2957
    data_source # Removed at 2017/1/1
2958
    dbi_options # Removed at 2017/1/1
2959
    filter_check # Removed at 2017/1/1
2960
    reserved_word_quote # Removed at 2017/1/1
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2961
    cache_method # Removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2962
    
2963
    # Methods
2964
    create_query # Removed at 2017/1/1
2965
    apply_filter # Removed at 2017/1/1
2966
    select_at # Removed at 2017/1/1
2967
    delete_at # Removed at 2017/1/1
2968
    update_at # Removed at 2017/1/1
2969
    insert_at # Removed at 2017/1/1
2970
    register_tag # Removed at 2017/1/1
2971
    default_bind_filter # Removed at 2017/1/1
2972
    default_fetch_filter # Removed at 2017/1/1
2973
    insert_param_tag # Removed at 2017/1/1
2974
    register_tag_processor # Removed at 2017/1/1
2975
    update_param_tag # Removed at 2017/1/1
2976
    
2977
    # Options
2978
    select method relation option # Removed at 2017/1/1
2979
    select method param option # Removed at 2017/1/1
2980
    
2981
    # Others
2982
    execute("select * from {= title}"); # execute tag parsing functionality
2983
                                        # Removed at 2017/1/1
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2984
    Query caching # Removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2985

            
2986
L<DBIx::Custom::Model>
2987

            
2988
    # Attribute method
2989
    filter # Removed at 2017/1/1
2990
    name # Removed at 2017/1/1
2991
    type # Removed at 2017/1/1
2992

            
2993
L<DBIx::Custom::Query>
2994
    
2995
    # Attribute method
2996
    default_filter # Removed at 2017/1/1
2997

            
2998
L<DBIx::Custom::QueryBuilder>
2999
    
3000
    # Attribute method
3001
    tags # Removed at 2017/1/1
3002
    tag_processors # Removed at 2017/1/1
3003
    
3004
    # Method
3005
    register_tag # Removed at 2017/1/1
3006
    register_tag_processor # Removed at 2017/1/1
3007
    
3008
    # Others
3009
    build_query("select * from {= title}"); # tag parsing functionality
3010
                                            # Removed at 2017/1/1
3011

            
3012
L<DBIx::Custom::Result>
3013
    
3014
    # Attribute method
3015
    filter_check # Removed at 2017/1/1
3016
    
3017
    # Methods
3018
    end_filter # Removed at 2017/1/1
3019
    remove_end_filter # Removed at 2017/1/1
3020
    remove_filter # Removed at 2017/1/1
3021
    default_filter # Removed at 2017/1/1
3022

            
3023
L<DBIx::Custom::Tag>
3024

            
3025
    This module is DEPRECATED! # Removed at 2017/1/1
3026

            
3027
=head1 BACKWORD COMPATIBLE POLICY
3028

            
3029
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3030
except for attribute method.
3031
You can check all DEPRECATED functionalities by document.
3032
DEPRECATED functionality is removed after five years,
3033
but if at least one person use the functionality and tell me that thing
3034
I extend one year each time you tell me it.
3035

            
3036
EXPERIMENTAL functionality will be changed without warnings.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3037

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3038
This policy is changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3039

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
3040
=head1 BUGS
3041

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
3042
Please tell me bugs if found.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
3043

            
3044
C<< <kimoto.yuki at gmail.com> >>
3045

            
3046
L<http://github.com/yuki-kimoto/DBIx-Custom>
3047

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3048
=head1 AUTHOR
3049

            
3050
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
version 0.0901
yuki-kimoto authored on 2009-12-17
3051

            
packaging one directory
yuki-kimoto authored on 2009-11-16
3052
=head1 COPYRIGHT & LICENSE
3053

            
cleanup
Yuki Kimoto authored on 2011-01-25
3054
Copyright 2009-2011 Yuki Kimoto, all rights reserved.
packaging one directory
yuki-kimoto authored on 2009-11-16
3055

            
3056
This program is free software; you can redistribute it and/or modify it
3057
under the same terms as Perl itself.
3058

            
3059
=cut