DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2943 lines | 75.686kb
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

            
fixed version
Yuki Kimoto authored on 2011-06-24
4
our $VERSION = '0.1697';
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;
cleanup
Yuki Kimoto authored on 2011-04-25
15
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
16
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
17

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
233
sub DESTROY { }
234

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

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

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

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

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

            
450
        return $result;
451
    }
cleanup
Yuki Kimoto authored on 2011-04-02
452
    
453
    # Not select statement
454
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
455
}
456

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

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

            
480
    # Check arguments
481
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
482
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
483
          unless $INSERT_ARGS{$name};
484
    }
485

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
486
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
487
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
488
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
489
        $param = $self->merge_param($id_param, $param);
490
    }
491

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
528
sub include_model {
529
    my ($self, $name_space, $model_infos) = @_;
530
    
cleanup
Yuki Kimoto authored on 2011-04-02
531
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
532
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
533
    
534
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
535
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
536

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

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

            
619
        # Map parameter
620
        my $value;
621
        if (ref $condition eq 'CODE') {
622
            $map_param->{$map_key} = $value_cb->($param->{$key})
623
              if $condition->($param->{$key});
624
        }
625
        elsif ($condition eq 'exists') {
626
            $map_param->{$map_key} = $value_cb->($param->{$key})
627
              if exists $param->{$key};
628
        }
629
        else { croak qq/Condition must be code reference or "exists" / . _subname }
630
    }
631
    
632
    return $map_param;
633
}
634

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
659
sub method {
660
    my $self = shift;
661
    
cleanup
Yuki Kimoto authored on 2011-04-02
662
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
663
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
664
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
665
    
666
    return $self;
667
}
668

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
669
sub model {
670
    my ($self, $name, $model) = @_;
671
    
cleanup
Yuki Kimoto authored on 2011-04-02
672
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
673
    if ($model) {
674
        $self->models->{$name} = $model;
675
        return $self;
676
    }
677
    
678
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
679
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
680
      unless $self->models->{$name};
681
    
cleanup
Yuki Kimoto authored on 2011-04-02
682
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
683
    return $self->models->{$name};
684
}
685

            
cleanup
Yuki Kimoto authored on 2011-03-21
686
sub mycolumn {
687
    my ($self, $table, $columns) = @_;
688
    
cleanup
Yuki Kimoto authored on 2011-04-02
689
    # Create column clause
690
    my @column;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
691
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
692
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
693
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
694
    
695
    return join (', ', @column);
696
}
697

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
728
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
729
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
730
    
731
    # Register filter
732
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
733
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
734
    
cleanup
Yuki Kimoto authored on 2011-04-02
735
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
736
}
packaging one directory
yuki-kimoto authored on 2009-11-16
737

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

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

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

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

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
880
sub separator {
881
    my $self = shift;
882
    
883
    if (@_) {
884
        my $separator = $_[0] || '';
885
        croak qq{Separator must be "." or "__" or "-" } . _subname
886
          unless $separator eq '.' || $separator eq '__'
887
              || $separator eq '-';
888
        
889
        $self->{separator} = $separator;
890
    
891
        return $self;
892
    }
893
    return $self->{separator} ||= '.';
894
}
895

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
896
sub setup_model {
897
    my $self = shift;
898
    
cleanup
Yuki Kimoto authored on 2011-04-02
899
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
900
    $self->each_column(
901
        sub {
902
            my ($self, $table, $column, $column_info) = @_;
903
            if (my $model = $self->models->{$table}) {
904
                push @{$model->columns}, $column;
905
            }
906
        }
907
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
908
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
909
}
910

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
911
sub available_data_type {
912
    my $self = shift;
913
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
914
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
915
    foreach my $i (-1000 .. 1000) {
916
         my $type_info = $self->dbh->type_info($i);
917
         my $data_type = $type_info->{DATA_TYPE};
918
         my $type_name = $type_info->{TYPE_NAME};
919
         $data_types .= "$data_type ($type_name)\n"
920
           if defined $data_type;
921
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
922
    return "Data Type maybe equal to Type Name" unless $data_types;
923
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
924
    return $data_types;
925
}
926

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
927
sub available_type_name {
928
    my $self = shift;
929
    
930
    # Type Names
931
    my $type_names = {};
932
    $self->each_column(sub {
933
        my ($self, $table, $column, $column_info) = @_;
934
        $type_names->{$column_info->{TYPE_NAME}} = 1
935
          if $column_info->{TYPE_NAME};
936
    });
937
    my @output = sort keys %$type_names;
938
    unshift @output, "Type Name";
939
    return join "\n", @output;
940
}
941

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

            
975
                    $self->{"_$into"}{$table}{$column} = $filter;
976
                }
977
            });
978
        }
979

            
980
        # From
981
        foreach my $i (1 .. 2) {
982
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
983
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
984
                croak qq{data type of from$i section must be lower case or number}
985
                  if $data_type =~ /[A-Z]/;
986
                my $fname = $type_rule->{"from$i"}{$data_type};
987
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
988
                    croak qq{Filter "$fname" is not registered" } . _subname
989
                      unless exists $self->filters->{$fname};
990
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
991
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
992
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
993
            }
994
        }
995
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
996
        return $self;
997
    }
998
    
999
    return $self->{type_rule} || {};
1000
}
1001

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1008
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1009
    my $param;
1010
    $param = shift if @_ % 2;
1011
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1012
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1013
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1014
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1015
    my $p = delete $args{param} || {};
1016
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1017
    my $where = delete $args{where} || {};
1018
    my $where_param = delete $args{where_param} || {};
1019
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1020
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1021
    my $id = delete $args{id};
1022
    my $primary_key = delete $args{primary_key};
1023
    croak "update method primary_key option " .
1024
          "must be specified when id is specified " . _subname
1025
      if defined $id && !defined $primary_key;
1026
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1027
    my $prefix = delete $args{prefix};
version 0.0901
yuki-kimoto authored on 2009-12-17
1028
    
cleanup
Yuki Kimoto authored on 2011-04-02
1029
    # Check argument names
1030
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1031
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1032
          unless $UPDATE_ARGS{$name};
1033
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1034

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1078
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1079
    my ($self, $param, $opt) = @_;
1080
    
cleanup
Yuki Kimoto authored on 2011-04-02
1081
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1082
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1083
    $tag = "set $tag" unless $opt->{no_set};
1084

            
cleanup
Yuki Kimoto authored on 2011-04-02
1085
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1086
}
1087

            
cleanup
Yuki Kimoto authored on 2011-01-25
1088
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1089
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1090
    
1091
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1092
    return DBIx::Custom::Where->new(
1093
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1094
        safety_character => $self->safety_character,
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1095
        quote => $self->_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1096
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1097
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1098
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1099

            
updated pod
Yuki Kimoto authored on 2011-06-21
1100
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1101
    
updated pod
Yuki Kimoto authored on 2011-06-21
1102
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1103
    
updated pod
Yuki Kimoto authored on 2011-06-21
1104
    # Cache
1105
    my $cache = $self->cache;
1106
    
1107
    # Query
1108
    my $query;
1109
    
1110
    # Get cached query
1111
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1112
        
updated pod
Yuki Kimoto authored on 2011-06-21
1113
        # Get query
1114
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1115
        
updated pod
Yuki Kimoto authored on 2011-06-21
1116
        # Create query
1117
        if ($q) {
1118
            $query = DBIx::Custom::Query->new($q);
1119
            $query->filters($self->filters);
cleanup
Yuki Kimoto authored on 2011-06-13
1120
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1121
    }
1122
    
1123
    # Create query
1124
    unless ($query) {
1125

            
1126
        # Create query
1127
        my $builder = $self->query_builder;
1128
        $query = $builder->build_query($source);
1129

            
1130
        # Remove reserved word quote
1131
        if (my $q = $self->_quote) {
1132
            $_ =~ s/$q//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1133
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1134

            
1135
        # Save query to cache
1136
        $self->cache_method->(
1137
            $self, $source,
1138
            {
1139
                sql     => $query->sql, 
1140
                columns => $query->columns,
1141
                tables  => $query->tables
1142
            }
1143
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1144
    }
1145
    
updated pod
Yuki Kimoto authored on 2011-06-21
1146
    # Prepare statement handle
1147
    my $sth;
1148
    eval { $sth = $self->dbh->prepare($query->{sql})};
1149
    
1150
    if ($@) {
1151
        $self->_croak($@, qq{. Following SQL is executed.\n}
1152
                        . qq{$query->{sql}\n} . _subname);
1153
    }
1154
    
1155
    # Set statement handle
1156
    $query->sth($sth);
1157
    
1158
    # Set filters
1159
    $query->filters($self->filters);
1160
    
1161
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1162
}
1163

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1214
sub _create_param_from_id {
1215
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1216
    
cleanup
Yuki Kimoto authored on 2011-06-08
1217
    # Create parameter
1218
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1219
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1220
        $id = [$id] unless ref $id;
1221
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1222
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1223
          unless !ref $id || ref $id eq 'ARRAY';
1224
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1225
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1226
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1227
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1228
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1229
        }
1230
    }
1231
    
cleanup
Yuki Kimoto authored on 2011-06-08
1232
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1233
}
1234

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1235
sub _connect {
1236
    my $self = shift;
1237
    
1238
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1239
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1240
    warn "data_source is DEPRECATED! use dsn instead\n"
1241
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1242
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1243
    croak qq{"dsn" must be specified } . _subname
1244
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1245
    my $user        = $self->user;
1246
    my $password    = $self->password;
1247
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1248
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1249
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1250
    
1251
    # Connect
1252
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1253
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1254
        $user,
1255
        $password,
1256
        {
1257
            %{$self->default_dbi_option},
1258
            %$dbi_option
1259
        }
1260
    )};
1261
    
1262
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1263
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1264
    
1265
    return $dbh;
1266
}
1267

            
cleanup
yuki-kimoto authored on 2010-10-17
1268
sub _croak {
1269
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1270
    
1271
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1272
    $append ||= "";
1273
    
1274
    # Verbose
1275
    if ($Carp::Verbose) { croak $error }
1276
    
1277
    # Not verbose
1278
    else {
1279
        
1280
        # Remove line and module infromation
1281
        my $at_pos = rindex($error, ' at ');
1282
        $error = substr($error, 0, $at_pos);
1283
        $error =~ s/\s+$//;
1284
        croak "$error$append";
1285
    }
1286
}
1287

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1288
sub _need_tables {
1289
    my ($self, $tree, $need_tables, $tables) = @_;
1290
    
cleanup
Yuki Kimoto authored on 2011-04-02
1291
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1292
    foreach my $table (@$tables) {
1293
        if ($tree->{$table}) {
1294
            $need_tables->{$table} = 1;
1295
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1296
        }
1297
    }
1298
}
1299

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1342
sub _quote {
1343
    my $self = shift;
1344
    
1345
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1346
         : defined $self->quote ? $self->quote
1347
         : '';
1348
}
1349

            
cleanup
Yuki Kimoto authored on 2011-04-02
1350
sub _remove_duplicate_table {
1351
    my ($self, $tables, $main_table) = @_;
1352
    
1353
    # Remove duplicate table
1354
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1355
    delete $tables{$main_table} if $main_table;
1356
    
1357
    return [keys %tables, $main_table ? $main_table : ()];
1358
}
1359

            
cleanup
Yuki Kimoto authored on 2011-04-02
1360
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1361
    my ($self, $source) = @_;
1362
    
cleanup
Yuki Kimoto authored on 2011-04-02
1363
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1364
    my $tables = [];
1365
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1366
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1367
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1368
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1369
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1370
    while ($source =~ /$table_re/g) {
1371
        push @$tables, $1;
1372
    }
1373
    
1374
    return $tables;
1375
}
1376

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1416
# DEPRECATED!
1417
sub _apply_filter {
1418
    my ($self, $table, @cinfos) = @_;
1419

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

            
1486
# DEPRECATED!
1487
sub create_query {
1488
    warn "create_query is DEPRECATED! use query option of each method";
1489
    shift->_create_query(@_);
1490
}
1491

            
cleanup
Yuki Kimoto authored on 2011-06-13
1492
# DEPRECATED!
1493
sub apply_filter {
1494
    my $self = shift;
1495
    
1496
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1497
         "use type_rule method and DBIx::Custom::Result filter method, " .
1498
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1499
    
1500
    return $self->_apply_filter(@_);
1501
}
1502

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1503
# DEPRECATED!
1504
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1505
sub select_at {
1506
    my ($self, %args) = @_;
1507

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1510
    # Arguments
1511
    my $primary_keys = delete $args{primary_key};
1512
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1513
    my $where = delete $args{where};
1514
    my $param = delete $args{param};
1515
    
1516
    # Check arguments
1517
    foreach my $name (keys %args) {
1518
        croak qq{"$name" is wrong option } . _subname
1519
          unless $SELECT_AT_ARGS{$name};
1520
    }
1521
    
1522
    # Table
1523
    croak qq{"table" option must be specified } . _subname
1524
      unless $args{table};
1525
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1526
    
1527
    # Create where parameter
1528
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1529
    
1530
    return $self->select(where => $where_param, %args);
1531
}
1532

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1533
# DEPRECATED!
1534
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1535
sub delete_at {
1536
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1537

            
1538
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1539
    
1540
    # Arguments
1541
    my $primary_keys = delete $args{primary_key};
1542
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1543
    my $where = delete $args{where};
1544
    
1545
    # Check arguments
1546
    foreach my $name (keys %args) {
1547
        croak qq{"$name" is wrong option } . _subname
1548
          unless $DELETE_AT_ARGS{$name};
1549
    }
1550
    
1551
    # Create where parameter
1552
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1553
    
1554
    return $self->delete(where => $where_param, %args);
1555
}
1556

            
cleanup
Yuki Kimoto authored on 2011-06-08
1557
# DEPRECATED!
1558
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1559
sub update_at {
1560
    my $self = shift;
1561

            
1562
    warn "update_at is DEPRECATED! use update and id option instead";
1563
    
1564
    # Arguments
1565
    my $param;
1566
    $param = shift if @_ % 2;
1567
    my %args = @_;
1568
    my $primary_keys = delete $args{primary_key};
1569
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1570
    my $where = delete $args{where};
1571
    my $p = delete $args{param} || {};
1572
    $param  ||= $p;
1573
    
1574
    # Check arguments
1575
    foreach my $name (keys %args) {
1576
        croak qq{"$name" is wrong option } . _subname
1577
          unless $UPDATE_AT_ARGS{$name};
1578
    }
1579
    
1580
    # Create where parameter
1581
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1582
    
1583
    return $self->update(where => $where_param, param => $param, %args);
1584
}
1585

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1616
# DEPRECATED!
1617
sub register_tag {
1618
    warn "register_tag is DEPRECATED!";
1619
    shift->query_builder->register_tag(@_)
1620
}
1621

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1622
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1623
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1624
has dbi_options => sub { {} };
1625
has filter_check  => 1;
1626
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1627

            
cleanup
Yuki Kimoto authored on 2011-01-25
1628
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1629
sub default_bind_filter {
1630
    my $self = shift;
1631
    
cleanup
Yuki Kimoto authored on 2011-06-13
1632
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1633
    
cleanup
Yuki Kimoto authored on 2011-01-12
1634
    if (@_) {
1635
        my $fname = $_[0];
1636
        
1637
        if (@_ && !$fname) {
1638
            $self->{default_out_filter} = undef;
1639
        }
1640
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1641
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1642
              unless exists $self->filters->{$fname};
1643
        
1644
            $self->{default_out_filter} = $self->filters->{$fname};
1645
        }
1646
        return $self;
1647
    }
1648
    
1649
    return $self->{default_out_filter};
1650
}
1651

            
cleanup
Yuki Kimoto authored on 2011-01-25
1652
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1653
sub default_fetch_filter {
1654
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1655

            
cleanup
Yuki Kimoto authored on 2011-06-13
1656
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1657
    
1658
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1659
        my $fname = $_[0];
1660

            
cleanup
Yuki Kimoto authored on 2011-01-12
1661
        if (@_ && !$fname) {
1662
            $self->{default_in_filter} = undef;
1663
        }
1664
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1665
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1666
              unless exists $self->filters->{$fname};
1667
        
1668
            $self->{default_in_filter} = $self->filters->{$fname};
1669
        }
1670
        
1671
        return $self;
1672
    }
1673
    
many changed
Yuki Kimoto authored on 2011-01-23
1674
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1675
}
1676

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1677
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1678
sub insert_param_tag {
1679
    warn "insert_param_tag is DEPRECATED! " .
1680
         "use insert_param instead!";
1681
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1682
}
1683

            
cleanup
Yuki Kimoto authored on 2011-01-25
1684
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1685
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1686
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1687
    return shift->query_builder->register_tag_processor(@_);
1688
}
1689

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1690
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1691
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1692
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1693
         "use update_param instead";
1694
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1695
}
cleanup
Yuki Kimoto authored on 2011-03-08
1696
# DEPRECATED!
1697
sub _push_relation {
1698
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1699
    
1700
    if (keys %{$relation || {}}) {
1701
        push @$sql, $need_where ? 'where' : 'and';
1702
        foreach my $rcolumn (keys %$relation) {
1703
            my $table1 = (split (/\./, $rcolumn))[0];
1704
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1705
            push @$tables, ($table1, $table2);
1706
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1707
        }
1708
    }
1709
    pop @$sql if $sql->[-1] eq 'and';    
1710
}
1711

            
1712
# DEPRECATED!
1713
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1714
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1715
    
1716
    if (keys %{$relation || {}}) {
1717
        foreach my $rcolumn (keys %$relation) {
1718
            my $table1 = (split (/\./, $rcolumn))[0];
1719
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1720
            my $table1_exists;
1721
            my $table2_exists;
1722
            foreach my $table (@$tables) {
1723
                $table1_exists = 1 if $table eq $table1;
1724
                $table2_exists = 1 if $table eq $table2;
1725
            }
1726
            unshift @$tables, $table1 unless $table1_exists;
1727
            unshift @$tables, $table2 unless $table2_exists;
1728
        }
1729
    }
1730
}
1731

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1734
=head1 NAME
1735

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1736
DBIx::Custom - Useful database access, respecting SQL!
removed reconnect method
yuki-kimoto authored on 2010-05-28
1737

            
1738
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1739

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1740
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1741
    
1742
    # Connect
1743
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1744
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1745
        user => 'ken',
1746
        password => '!LFKD%$&',
1747
        dbi_option => {mysql_enable_utf8 => 1}
1748
    );
cleanup
yuki-kimoto authored on 2010-08-05
1749

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1750
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1751
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1752
    
1753
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1754
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1755
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1756
    
1757
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1758
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1759

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

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

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

            
1796
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1797

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

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

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

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

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

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

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

            
1813
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1814

            
1815
=head1 GUIDE
1816

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

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

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

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

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

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

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

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

            
1836
    my $connector = DBIx::Connector->new(
1837
        "dbi:mysql:database=$DATABASE",
1838
        $USER,
1839
        $PASSWORD,
1840
        DBIx::Custom->new->default_dbi_option
1841
    );
1842
    
updated pod
Yuki Kimoto authored on 2011-06-21
1843
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1844

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

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

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

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

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

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

            
1860
=head2 C<default_dbi_option>
1861

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1868
    {
1869
        RaiseError => 1,
1870
        PrintError => 0,
1871
        AutoCommit => 1,
1872
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1873

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1888
=head2 C<password>
1889

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1941
    print $dbi->available_data_type;
1942

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

            
1946
=head2 C<available_type_name> EXPERIMENTAL
1947

            
1948
    print $dbi->available_type_name;
1949

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

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

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

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

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

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

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

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

            
1967
Create column clause. The follwoing column clause is created.
1968

            
1969
    book.author as "book.author",
1970
    book.title as "book.title"
1971

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1974
    # Separator is double underbar
1975
    $dbi->separator('__');
1976
    
1977
    book.author as "book__author",
1978
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1979

            
cleanup
Yuki Kimoto authored on 2011-06-13
1980
    # Separator is hyphen
1981
    $dbi->separator('-');
1982
    
1983
    book.author as "book-author",
1984
    book.title as "book-title"
1985
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1986
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1987

            
update pod
Yuki Kimoto authored on 2011-03-13
1988
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1989
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1990
        user => 'ken',
1991
        password => '!LFKD%$&',
1992
        dbi_option => {mysql_enable_utf8 => 1}
1993
    );
1994

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2003
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2004
        table => 'book',
2005
        primary_key => 'id',
2006
        join => [
2007
            'inner join company on book.comparny_id = company.id'
2008
        ],
2009
    );
2010

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

            
2014
   $dbi->model('book')->select(...);
2015

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

            
2018
    my $dbh = $dbi->dbh;
2019

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

            
2023
=head2 C<each_column>
2024

            
2025
    $dbi->each_column(
2026
        sub {
2027
            my ($dbi, $table, $column, $column_info) = @_;
2028
            
2029
            my $type = $column_info->{TYPE_NAME};
2030
            
2031
            if ($type eq 'DATE') {
2032
                # ...
2033
            }
2034
        }
2035
    );
2036

            
2037
Iterate all column informations of all table from database.
2038
Argument is callback when one column is found.
2039
Callback receive four arguments, dbi object, table name,
2040
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2041

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

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

            
2049
    my $result = $dbi->execute(
2050
      "select * from book where title = :book.title and author like :book.author",
2051
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2052
    );
2053

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

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

            
2062
    select * from where title = ? and author like ?;
2063

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

            
2066
=over 4
2067

            
2068
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2069
    
2070
    filter => {
2071
        title  => sub { uc $_[0] }
2072
        author => sub { uc $_[0] }
2073
    }
update pod
Yuki Kimoto authored on 2011-03-13
2074

            
updated pod
Yuki Kimoto authored on 2011-06-09
2075
    # Filter name
2076
    filter => {
2077
        title  => 'upper_case',
2078
        author => 'upper_case'
2079
    }
2080
        
2081
    # At once
2082
    filter => [
2083
        [qw/title author/]  => sub { uc $_[0] }
2084
    ]
2085

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

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

            
2093
    query => 1
2094

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

            
2098
    my $sql = $query->sql;
2099
    my $columns = $query->columns;
updated document
Yuki Kimoto authored on 2011-06-09
2100

            
updated pod
Yuki Kimoto authored on 2011-06-09
2101
=item C<table>
2102
    
2103
    table => 'author'
2104

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2112
    # Same
2113
    $dbi->execute(
2114
      "select * from book where title = :book.title and author = :book.author",
2115
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2116

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

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

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

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

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

            
2128
=item C<type_rule_off> EXPERIMENTAL
2129

            
2130
    type_rule_off => 1
2131

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

            
2134
=item C<type_rule1_off> EXPERIMENTAL
2135

            
2136
    type_rule1_off => 1
2137

            
2138
Turn C<into1> type rule off.
2139

            
2140
=item C<type_rule2_off> EXPERIMENTAL
2141

            
2142
    type_rule2_off => 1
2143

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2156
=over 4
2157

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

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

            
2162
=item C<filter>
2163

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2168
    id => 4
2169
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2170

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2174
    $dbi->delete(
2175
        parimary_key => ['id1', 'id2'],
2176
        id => [4, 5],
2177
        table => 'book',
2178
    );
update pod
Yuki Kimoto authored on 2011-03-13
2179

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

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

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

            
2186
    prefix => 'some'
2187

            
2188
prefix before table name section.
2189

            
2190
    delete some from book
2191

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2200
Table name.
2201

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

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

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

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

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

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

            
2214
=item C<type_rule_off> EXPERIMENTAL
2215

            
2216
Same as C<execute> method's C<type_rule_off> option.
2217

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

            
2220
    type_rule1_off => 1
2221

            
2222
Same as C<execute> method's C<type_rule1_off> option.
2223

            
2224
=item C<type_rule2_off> EXPERIMENTAL
2225

            
2226
    type_rule2_off => 1
2227

            
2228
Same as C<execute> method's C<type_rule2_off> option.
2229

            
updated pod
Yuki Kimoto authored on 2011-06-08
2230
=back
update pod
Yuki Kimoto authored on 2011-03-13
2231

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2239
=head2 C<insert>
2240

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

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

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

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

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

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

            
2254
=item C<filter>
2255

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

            
2258
=item C<id>
2259

            
updated document
Yuki Kimoto authored on 2011-06-09
2260
    id => 4
2261
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2262

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2266
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2267
        {title => 'Perl', author => 'Ken'}
2268
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2269
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2270
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2271
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2272

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

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

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

            
2282
    prefix => 'or replace'
2283

            
2284
prefix before table name section
2285

            
2286
    insert or replace into book
2287

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

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

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

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

            
2297
Same as C<execute> method's C<query> option.
2298

            
2299
=item C<table>
2300

            
2301
    table => 'book'
2302

            
2303
Table name.
2304

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

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

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

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

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

            
2315
    type_rule1_off => 1
2316

            
2317
Same as C<execute> method's C<type_rule1_off> option.
2318

            
2319
=item C<type_rule2_off> EXPERIMENTAL
2320

            
2321
    type_rule2_off => 1
2322

            
2323
Same as C<execute> method's C<type_rule2_off> option.
2324

            
update pod
Yuki Kimoto authored on 2011-03-13
2325
=back
2326

            
2327
=over 4
2328

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2344
    lib / MyModel.pm
2345
        / MyModel / book.pm
2346
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2347

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

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

            
2352
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2353
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2354
    
2355
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2356

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2361
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2362
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2363
    
2364
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2365

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2368
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2369
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2370
    
2371
    1;
2372
    
updated pod
Yuki Kimoto authored on 2011-06-21
2373
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2374

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

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

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

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

            
2384
    my $map_param = $dbi->map_param(
2385
        {id => 1, authro => 'Ken', price => 1900},
2386
        'id' => 'book.id',
2387
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2388
        'price' => [
2389
            'book.price', {if => sub { length $_[0] }}
2390
        ]
2391
    );
2392

            
2393
Map paramters to other key and value. First argument is original
2394
parameter. this is hash reference. Rest argument is mapping.
2395
By default, Mapping is done if the value length is not zero.
2396

            
2397
=over 4
2398

            
2399
=item Key mapping
2400

            
2401
    'id' => 'book.id'
2402

            
2403
This is only key mapping. Value is same as original one.
2404

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

            
2407
=item Key and value mapping
2408

            
2409
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2410

            
2411
This is key and value mapping. Frist element of array reference
2412
is mapped key name, second element is code reference to map the value.
2413

            
2414
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2415
      if value length is not zero.
2416

            
2417
=item Condition
2418

            
2419
    'price' => ['book.price', {if => 'exists'}]
2420
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2421
    'price' => ['book.price', {if => sub { defined shift }}]
2422

            
2423
If you need condition, you can sepecify it. this is code reference
2424
or 'exists'. By default, condition is the following one.
2425

            
2426
    sub { defined $_[0] && length $_[0] }
2427

            
2428
=back
2429

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

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

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

            
2436
    {key1 => [1, 1], key2 => 2}
2437

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

            
2440
    $dbi->method(
2441
        update_or_insert => sub {
2442
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2443
            
2444
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2445
        },
2446
        find_or_create   => sub {
2447
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2448
            
2449
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2450
        }
2451
    );
2452

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

            
2455
    $dbi->update_or_insert;
2456
    $dbi->find_or_create;
2457

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

            
2460
    my $model = $dbi->model('book');
2461

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

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

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

            
2468
Create column clause for myself. The follwoing column clause is created.
2469

            
2470
    book.author as author,
2471
    book.title as title
2472

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2475
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2476
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2477
        user => 'ken',
2478
        password => '!LFKD%$&',
2479
        dbi_option => {mysql_enable_utf8 => 1}
2480
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2481

            
2482
Create a new L<DBIx::Custom> object.
2483

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

            
2486
    my $not_exists = $dbi->not_exists;
2487

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2491
=head2 C<register_filter>
2492

            
update pod
Yuki Kimoto authored on 2011-03-13
2493
    $dbi->register_filter(
2494
        # Time::Piece object to database DATE format
2495
        tp_to_date => sub {
2496
            my $tp = shift;
2497
            return $tp->strftime('%Y-%m-%d');
2498
        },
2499
        # database DATE format to Time::Piece object
2500
        date_to_tp => sub {
2501
           my $date = shift;
2502
           return Time::Piece->strptime($date, '%Y-%m-%d');
2503
        }
2504
    );
cleanup
yuki-kimoto authored on 2010-10-17
2505
    
update pod
Yuki Kimoto authored on 2011-03-13
2506
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2507

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

            
2510
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2511
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2512
            date => sub { ... },
2513
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2514
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2515
        into2 => {
2516
            date => sub { ... },
2517
            datetime => sub { ... }
2518
        },
2519
        from1 => {
2520
            # DATE
2521
            9 => sub { ... },
2522
            # DATETIME or TIMESTAMP
2523
            11 => sub { ... },
2524
        }
2525
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2526
            # DATE
2527
            9 => sub { ... },
2528
            # DATETIME or TIMESTAMP
2529
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2530
        }
2531
    );
2532

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2548
=over 4
2549

            
2550
=item 1. column name
2551

            
2552
    issue_date
2553
    issue_datetime
2554

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

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

            
2559
    book.issue_date
2560
    book.issue_datetime
2561

            
2562
=back
2563

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

            
2566
    print $dbi->available_type_name;
2567

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

            
2572
    print $dbi->available_data_type;
2573

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

            
2576
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2577
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2578
            [qw/DATE DATETIME/] => sub { ... },
2579
        ],
2580
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2581

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2584
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2585
        table  => 'book',
2586
        column => ['author', 'title'],
2587
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2588
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2589
    
updated document
Yuki Kimoto authored on 2011-06-09
2590
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2591

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

            
2594
=over 4
2595

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2600
Append statement to last of SQL.
2601
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2602
=item C<column>
2603
    
updated document
Yuki Kimoto authored on 2011-06-09
2604
    column => 'author'
2605
    column => ['author', 'title']
2606

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2615
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2616
        {book => [qw/author title/]},
2617
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2618
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2619

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

            
2622
    book.author as "book.author",
2623
    book.title as "book.title",
2624
    person.name as "person.name",
2625
    person.age as "person.age"
2626

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2629
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2630
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2631
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2632

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

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

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

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

            
2641
=item C<id>
2642

            
2643
    id => 4
2644
    id => [4, 5]
2645

            
2646
ID corresponding to C<primary_key>.
2647
You can select rows by C<id> and C<primary_key>.
2648

            
2649
    $dbi->select(
2650
        parimary_key => ['id1', 'id2'],
2651
        id => [4, 5],
2652
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2653
    );
2654

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2657
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2658
        where => {id1 => 4, id2 => 5},
2659
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2660
    );
2661
    
updated document
Yuki Kimoto authored on 2011-06-09
2662
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2663

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

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

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

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

            
2676
    prefix => 'SQL_CALC_FOUND_ROWS'
2677

            
2678
Prefix of column cluase
2679

            
2680
    select SQL_CALC_FOUND_ROWS title, author from book;
2681

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

            
2684
    join => [
2685
        'left outer join company on book.company_id = company_id',
2686
        'left outer join location on company.location_id = location.id'
2687
    ]
2688
        
2689
Join clause. If column cluase or where clause contain table name like "company.name",
2690
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2691

            
2692
    $dbi->select(
2693
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2694
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2695
        where => {'company.name' => 'Orange'},
2696
        join => [
2697
            'left outer join company on book.company_id = company.id',
2698
            'left outer join location on company.location_id = location.id'
2699
        ]
2700
    );
2701

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2705
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2706
    from book
2707
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2708
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2709

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2729
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2730

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

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

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

            
2737
    type_rule1_off => 1
2738

            
2739
Same as C<execute> method's C<type_rule1_off> option.
2740

            
2741
=item C<type_rule2_off> EXPERIMENTAL
2742

            
2743
    type_rule2_off => 1
2744

            
2745
Same as C<execute> method's C<type_rule2_off> option.
2746

            
updated document
Yuki Kimoto authored on 2011-06-09
2747
=item C<where>
2748
    
2749
    # Hash refrence
2750
    where => {author => 'Ken', 'title' => 'Perl'}
2751
    
2752
    # DBIx::Custom::Where object
2753
    where => $dbi->where(
2754
        clause => ['and', 'author = :author', 'title like :title'],
2755
        param  => {author => 'Ken', title => '%Perl%'}
2756
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2757
    
2758
    # Array reference 1 (array reference, hash referenc). same as above
2759
    where => [
2760
        ['and', 'author = :author', 'title like :title'],
2761
        {author => 'Ken', title => '%Perl%'}
2762
    ];    
2763
    
2764
    # Array reference 2 (String, hash reference)
2765
    where => [
2766
        'title like :title',
2767
        {title => '%Perl%'}
2768
    ]
2769
    
2770
    # String
2771
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2772

            
updated document
Yuki Kimoto authored on 2011-06-09
2773
Where clause.
2774
    
improved pod
Yuki Kimoto authored on 2011-04-19
2775
=item C<wrap> EXPERIMENTAL
2776

            
2777
Wrap statement. This is array reference.
2778

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

            
2781
This option is for Oracle and SQL Server paging process.
2782

            
update pod
Yuki Kimoto authored on 2011-03-12
2783
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2784

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2793
=over 4
2794

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2805
    id => 4
2806
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2807

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2811
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2812
        {title => 'Perl', author => 'Ken'}
2813
        parimary_key => ['id1', 'id2'],
2814
        id => [4, 5],
2815
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2816
    );
update pod
Yuki Kimoto authored on 2011-03-13
2817

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2820
    $dbi->update(
2821
        {title => 'Perl', author => 'Ken'}
2822
        where => {id1 => 4, id2 => 5},
2823
        table => 'book'
2824
    );
update pod
Yuki Kimoto authored on 2011-03-13
2825

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

            
2828
    prefix => 'or replace'
2829

            
2830
prefix before table name section
2831

            
2832
    update or replace book
2833

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

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

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

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

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

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

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

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

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

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

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

            
2857
Same as C<execute> method's C<type> option.
2858

            
2859
=item C<type_rule_off> EXPERIMENTAL
2860

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

            
2863
=item C<type_rule1_off> EXPERIMENTAL
2864

            
2865
    type_rule1_off => 1
2866

            
2867
Same as C<execute> method's C<type_rule1_off> option.
2868

            
2869
=item C<type_rule2_off> EXPERIMENTAL
2870

            
2871
    type_rule2_off => 1
2872

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2875
=back
update pod
Yuki Kimoto authored on 2011-03-13
2876

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

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

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

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

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

            
2888
Create update parameter tag.
2889

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

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

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

            
2899
Create a new L<DBIx::Custom::Where> object.
2900

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

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

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

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

            
2910
=head2 C<DBIX_CUSTOM_DEBUG>
2911

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

            
2915
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2916

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

            
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2919
=head1 STABILITY
2920

            
cleanup
Yuki Kimoto authored on 2011-01-25
2921
L<DBIx::Custom> is stable. APIs keep backword compatible
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2922
except EXPERIMENTAL one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2923

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

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

            
2928
C<< <kimoto.yuki at gmail.com> >>
2929

            
2930
L<http://github.com/yuki-kimoto/DBIx-Custom>
2931

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2932
=head1 AUTHOR
2933

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

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

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

            
2940
This program is free software; you can redistribute it and/or modify it
2941
under the same terms as Perl itself.
2942

            
2943
=cut