DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2853 lines | 73.111kb
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 small insert, update, ...
Yuki Kimoto authored on 2011-06-21
4
our $VERSION = '0.1696';
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 updat_par...
Yuki Kimoto authored on 2011-03-30
593
sub merge_param {
594
    my ($self, @params) = @_;
595
    
cleanup
Yuki Kimoto authored on 2011-04-02
596
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
597
    my $merge = {};
598
    foreach my $param (@params) {
599
        foreach my $column (keys %$param) {
600
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
601
            
602
            if (exists $merge->{$column}) {
603
                $merge->{$column} = [$merge->{$column}]
604
                  unless ref $merge->{$column} eq 'ARRAY';
605
                push @{$merge->{$column}},
606
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
607
            }
608
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
609
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
610
            }
611
        }
612
    }
613
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
614
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
615
}
616

            
cleanup
Yuki Kimoto authored on 2011-03-21
617
sub method {
618
    my $self = shift;
619
    
cleanup
Yuki Kimoto authored on 2011-04-02
620
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
621
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
622
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
623
    
624
    return $self;
625
}
626

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
627
sub model {
628
    my ($self, $name, $model) = @_;
629
    
cleanup
Yuki Kimoto authored on 2011-04-02
630
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
631
    if ($model) {
632
        $self->models->{$name} = $model;
633
        return $self;
634
    }
635
    
636
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
637
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
638
      unless $self->models->{$name};
639
    
cleanup
Yuki Kimoto authored on 2011-04-02
640
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
641
    return $self->models->{$name};
642
}
643

            
cleanup
Yuki Kimoto authored on 2011-03-21
644
sub mycolumn {
645
    my ($self, $table, $columns) = @_;
646
    
cleanup
Yuki Kimoto authored on 2011-04-02
647
    # Create column clause
648
    my @column;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
649
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
650
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
651
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
652
    
653
    return join (', ', @column);
654
}
655

            
added dbi_options attribute
kimoto authored on 2010-12-20
656
sub new {
657
    my $self = shift->SUPER::new(@_);
658
    
cleanup
Yuki Kimoto authored on 2011-04-02
659
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
660
    my @attrs = keys %$self;
661
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
662
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
663
          unless $self->can($attr);
664
    }
cleanup
Yuki Kimoto authored on 2011-04-02
665
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
666
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
667
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
668
        '?'     => \&DBIx::Custom::Tag::placeholder,
669
        '='     => \&DBIx::Custom::Tag::equal,
670
        '<>'    => \&DBIx::Custom::Tag::not_equal,
671
        '>'     => \&DBIx::Custom::Tag::greater_than,
672
        '<'     => \&DBIx::Custom::Tag::lower_than,
673
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
674
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
675
        'like'  => \&DBIx::Custom::Tag::like,
676
        'in'    => \&DBIx::Custom::Tag::in,
677
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
678
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
679
    };
added dbi_options attribute
kimoto authored on 2010-12-20
680
    
681
    return $self;
682
}
683

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

            
cleanup
yuki-kimoto authored on 2010-10-17
686
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
687
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
688
    
689
    # Register filter
690
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
691
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
692
    
cleanup
Yuki Kimoto authored on 2011-04-02
693
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
694
}
packaging one directory
yuki-kimoto authored on 2009-11-16
695

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

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
702
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
703
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
704
    my $tables = ref $table eq 'ARRAY' ? $table
705
               : defined $table ? [$table]
706
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
707
    my $columns   = delete $args{column};
708
    my $where     = delete $args{where} || {};
709
    my $append    = delete $args{append};
710
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
711
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
712
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
713
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
714
    warn "select() relation option is DEPRECATED! use join option instead"
715
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
716
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
717
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
718
      if keys %$param;
719
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
720
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
721
    my $id = delete $args{id};
722
    my $primary_key = delete $args{primary_key};
723
    croak "update method primary_key option " .
724
          "must be specified when id is specified " . _subname
725
      if defined $id && !defined $primary_key;
726
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
727
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
728
    
cleanup
Yuki Kimoto authored on 2011-04-02
729
    # Check arguments
730
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
731
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
732
          unless $SELECT_ARGS{$name};
733
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
734
    
cleanup
Yuki Kimoto authored on 2011-03-09
735
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
736
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
737
    
cleanup
Yuki Kimoto authored on 2011-04-02
738
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
739
    my @sql;
740
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
741
    
- select() column option can...
Yuki Kimoto authored on 2011-06-08
742
    # Reserved word quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
743
    my $q = $self->_quote;
- select() column option can...
Yuki Kimoto authored on 2011-06-08
744
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
745
    # Prefix
746
    push @sql, $prefix if defined $prefix;
747
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
748
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
749
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
750
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
751
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
752
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
753
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
754
            }
755
            elsif (ref $column eq 'ARRAY') {
756
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
757
                  unless @$column == 3 && $column->[1] eq 'as';
758
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
759
            }
cleanup
Yuki Kimoto authored on 2011-04-02
760
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
761
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
762
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
763
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
764
    }
765
    else { push @sql, '*' }
766
    
767
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
768
    push @sql, 'from';
769
    if ($relation) {
770
        my $found = {};
771
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
772
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
773
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
774
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
775
    }
cleanup
Yuki Kimoto authored on 2011-03-30
776
    else {
777
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
778
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
779
    }
780
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
781
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
782
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
783

            
cleanup
Yuki Kimoto authored on 2011-04-02
784
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
785
    unshift @$tables,
786
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
787
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
788
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
789
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
790
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
791
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
792
        $where_clause = "where " . $where->[0];
793
        $where_param = $where->[1];
794
    }
795
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
796
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
797
        $where_param = keys %$where_param
798
                     ? $self->merge_param($where_param, $where->param)
799
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
800
        
801
        # String where
802
        $where_clause = $where->to_string;
803
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
804
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
805
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
806
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
807
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
808
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
809
    # Push join
810
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
811
    
cleanup
Yuki Kimoto authored on 2011-03-09
812
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
813
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
814
    
cleanup
Yuki Kimoto authored on 2011-03-08
815
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
816
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
817
    
cleanup
Yuki Kimoto authored on 2011-04-02
818
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
819
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
820
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
821
    # Wrap
822
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
823
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
824
          unless ref $wrap eq 'ARRAY';
825
        unshift @sql, $wrap->[0];
826
        push @sql, $wrap->[1];
827
    }
828
    
cleanup
Yuki Kimoto authored on 2011-01-27
829
    # SQL
830
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
831
    
832
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
833
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
834
    
835
    return $result;
836
}
837

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
838
sub separator {
839
    my $self = shift;
840
    
841
    if (@_) {
842
        my $separator = $_[0] || '';
843
        croak qq{Separator must be "." or "__" or "-" } . _subname
844
          unless $separator eq '.' || $separator eq '__'
845
              || $separator eq '-';
846
        
847
        $self->{separator} = $separator;
848
    
849
        return $self;
850
    }
851
    return $self->{separator} ||= '.';
852
}
853

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
854
sub setup_model {
855
    my $self = shift;
856
    
cleanup
Yuki Kimoto authored on 2011-04-02
857
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
858
    $self->each_column(
859
        sub {
860
            my ($self, $table, $column, $column_info) = @_;
861
            if (my $model = $self->models->{$table}) {
862
                push @{$model->columns}, $column;
863
            }
864
        }
865
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
866
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
867
}
868

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
869
sub available_data_type {
870
    my $self = shift;
871
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
872
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
873
    foreach my $i (-1000 .. 1000) {
874
         my $type_info = $self->dbh->type_info($i);
875
         my $data_type = $type_info->{DATA_TYPE};
876
         my $type_name = $type_info->{TYPE_NAME};
877
         $data_types .= "$data_type ($type_name)\n"
878
           if defined $data_type;
879
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
880
    return "Data Type maybe equal to Type Name" unless $data_types;
881
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
882
    return $data_types;
883
}
884

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
885
sub available_type_name {
886
    my $self = shift;
887
    
888
    # Type Names
889
    my $type_names = {};
890
    $self->each_column(sub {
891
        my ($self, $table, $column, $column_info) = @_;
892
        $type_names->{$column_info->{TYPE_NAME}} = 1
893
          if $column_info->{TYPE_NAME};
894
    });
895
    my @output = sort keys %$type_names;
896
    unshift @output, "Type Name";
897
    return join "\n", @output;
898
}
899

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
900
sub type_rule {
901
    my $self = shift;
902
    
903
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
904
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
905
        
906
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
907
        foreach my $i (1 .. 2) {
908
            my $into = "into$i";
909
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
910
            $self->{type_rule} = $type_rule;
911
            $self->{"_$into"} = {};
912
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
913
                croak qq{type name of $into section must be lower case}
914
                  if $type_name =~ /[A-Z]/;
915
            }
916
            $self->each_column(sub {
917
                my ($dbi, $table, $column, $column_info) = @_;
918
                
919
                my $type_name = lc $column_info->{TYPE_NAME};
920
                if ($type_rule->{$into} &&
921
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
922
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
923
                    return unless exists $type_rule->{$into}->{$type_name};
924
                    if  (defined $filter && ref $filter ne 'CODE') 
925
                    {
926
                        my $fname = $filter;
927
                        croak qq{Filter "$fname" is not registered" } . _subname
928
                          unless exists $self->filters->{$fname};
929
                        
930
                        $filter = $self->filters->{$fname};
931
                    }
932

            
933
                    $self->{"_$into"}{$table}{$column} = $filter;
934
                }
935
            });
936
        }
937

            
938
        # From
939
        foreach my $i (1 .. 2) {
940
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
941
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
942
                croak qq{data type of from$i section must be lower case or number}
943
                  if $data_type =~ /[A-Z]/;
944
                my $fname = $type_rule->{"from$i"}{$data_type};
945
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
946
                    croak qq{Filter "$fname" is not registered" } . _subname
947
                      unless exists $self->filters->{$fname};
948
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
949
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
950
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
951
            }
952
        }
953
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
954
        return $self;
955
    }
956
    
957
    return $self->{type_rule} || {};
958
}
959

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
966
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
967
    my $param;
968
    $param = shift if @_ % 2;
969
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
970
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
971
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
972
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
973
    my $p = delete $args{param} || {};
974
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
975
    my $where = delete $args{where} || {};
976
    my $where_param = delete $args{where_param} || {};
977
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
978
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
979
    my $id = delete $args{id};
980
    my $primary_key = delete $args{primary_key};
981
    croak "update method primary_key option " .
982
          "must be specified when id is specified " . _subname
983
      if defined $id && !defined $primary_key;
984
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
985
    my $prefix = delete $args{prefix};
version 0.0901
yuki-kimoto authored on 2009-12-17
986
    
cleanup
Yuki Kimoto authored on 2011-04-02
987
    # Check argument names
988
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
989
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
990
          unless $UPDATE_ARGS{$name};
991
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
992

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

            
996
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
997
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
998
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
999
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1000
        $where_clause = "where " . $where->[0];
1001
        $where_param = $where->[1];
1002
    }
1003
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1004
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1005
        $where_param = keys %$where_param
1006
                     ? $self->merge_param($where_param, $where->param)
1007
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1008
        
1009
        # String where
1010
        $where_clause = $where->to_string;
1011
    }
1012
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1013
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1014
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1015
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1016
    # Merge param
1017
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1018
    
cleanup
Yuki Kimoto authored on 2011-04-02
1019
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1020
    my @sql;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1021
    my $q = $self->_quote;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1022
    push @sql, "update";
1023
    push @sql, $prefix if defined $prefix;
1024
    push @sql, "$q$table$q $update_clause $where_clause";
1025
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1026
    
cleanup
Yuki Kimoto authored on 2011-01-27
1027
    # SQL
1028
    my $sql = join(' ', @sql);
1029
    
cleanup
yuki-kimoto authored on 2010-10-17
1030
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1031
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1032
}
1033

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1036
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1037
    my ($self, $param, $opt) = @_;
1038
    
cleanup
Yuki Kimoto authored on 2011-04-02
1039
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1040
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1041
    $tag = "set $tag" unless $opt->{no_set};
1042

            
cleanup
Yuki Kimoto authored on 2011-04-02
1043
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1044
}
1045

            
cleanup
Yuki Kimoto authored on 2011-01-25
1046
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1047
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1048
    
1049
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1050
    return DBIx::Custom::Where->new(
1051
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1052
        safety_character => $self->safety_character,
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1053
        quote => $self->_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1054
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1055
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1056
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1057

            
updated pod
Yuki Kimoto authored on 2011-06-21
1058
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1059
    
updated pod
Yuki Kimoto authored on 2011-06-21
1060
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1061
    
updated pod
Yuki Kimoto authored on 2011-06-21
1062
    # Cache
1063
    my $cache = $self->cache;
1064
    
1065
    # Query
1066
    my $query;
1067
    
1068
    # Get cached query
1069
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1070
        
updated pod
Yuki Kimoto authored on 2011-06-21
1071
        # Get query
1072
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1073
        
updated pod
Yuki Kimoto authored on 2011-06-21
1074
        # Create query
1075
        if ($q) {
1076
            $query = DBIx::Custom::Query->new($q);
1077
            $query->filters($self->filters);
cleanup
Yuki Kimoto authored on 2011-06-13
1078
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1079
    }
1080
    
1081
    # Create query
1082
    unless ($query) {
1083

            
1084
        # Create query
1085
        my $builder = $self->query_builder;
1086
        $query = $builder->build_query($source);
1087

            
1088
        # Remove reserved word quote
1089
        if (my $q = $self->_quote) {
1090
            $_ =~ s/$q//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1091
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1092

            
1093
        # Save query to cache
1094
        $self->cache_method->(
1095
            $self, $source,
1096
            {
1097
                sql     => $query->sql, 
1098
                columns => $query->columns,
1099
                tables  => $query->tables
1100
            }
1101
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1102
    }
1103
    
updated pod
Yuki Kimoto authored on 2011-06-21
1104
    # Prepare statement handle
1105
    my $sth;
1106
    eval { $sth = $self->dbh->prepare($query->{sql})};
1107
    
1108
    if ($@) {
1109
        $self->_croak($@, qq{. Following SQL is executed.\n}
1110
                        . qq{$query->{sql}\n} . _subname);
1111
    }
1112
    
1113
    # Set statement handle
1114
    $query->sth($sth);
1115
    
1116
    # Set filters
1117
    $query->filters($self->filters);
1118
    
1119
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1120
}
1121

            
cleanup
Yuki Kimoto authored on 2011-04-02
1122
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1123
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1124
    
cleanup
Yuki Kimoto authored on 2011-04-02
1125
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1126
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1127
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1128
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1129
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1130
        
1131
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1132
        my $value;
1133
        if(ref $params->{$column} eq 'ARRAY') {
1134
            my $i = $count->{$column} || 0;
1135
            $i += $not_exists->{$column} || 0;
1136
            my $found;
1137
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1138
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1139
                    $not_exists->{$column}++;
1140
                }
1141
                else  {
1142
                    $value = $params->{$column}->[$k];
1143
                    $found = 1;
1144
                    last
1145
                }
1146
            }
1147
            next unless $found;
1148
        }
1149
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1150
        
cleanup
Yuki Kimoto authored on 2011-01-12
1151
        # Filter
1152
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1153
        $value = $f->($value) if $f;
1154
        
1155
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1156
        foreach my $i (1 .. 2) {
1157
            my $type_filter = $type_filters->{$i};
1158
            my $tf = $type_filter->{$column};
1159
            $value = $tf->($value) if $tf;
1160
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1161
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1162
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1163
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1164
        
1165
        # Count up 
1166
        $count->{$column}++;
1167
    }
1168
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1169
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1170
}
1171

            
cleanup
Yuki Kimoto authored on 2011-06-08
1172
sub _create_param_from_id {
1173
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1174
    
cleanup
Yuki Kimoto authored on 2011-06-08
1175
    # Create parameter
1176
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1177
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1178
        $id = [$id] unless ref $id;
1179
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1180
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1181
          unless !ref $id || ref $id eq 'ARRAY';
1182
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1183
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1184
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1185
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1186
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1187
        }
1188
    }
1189
    
cleanup
Yuki Kimoto authored on 2011-06-08
1190
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1191
}
1192

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1193
sub _connect {
1194
    my $self = shift;
1195
    
1196
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1197
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1198
    warn "data_source is DEPRECATED! use dsn instead\n"
1199
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1200
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1201
    croak qq{"dsn" must be specified } . _subname
1202
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1203
    my $user        = $self->user;
1204
    my $password    = $self->password;
1205
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1206
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1207
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1208
    
1209
    # Connect
1210
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1211
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1212
        $user,
1213
        $password,
1214
        {
1215
            %{$self->default_dbi_option},
1216
            %$dbi_option
1217
        }
1218
    )};
1219
    
1220
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1221
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1222
    
1223
    return $dbh;
1224
}
1225

            
cleanup
yuki-kimoto authored on 2010-10-17
1226
sub _croak {
1227
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1228
    
1229
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1230
    $append ||= "";
1231
    
1232
    # Verbose
1233
    if ($Carp::Verbose) { croak $error }
1234
    
1235
    # Not verbose
1236
    else {
1237
        
1238
        # Remove line and module infromation
1239
        my $at_pos = rindex($error, ' at ');
1240
        $error = substr($error, 0, $at_pos);
1241
        $error =~ s/\s+$//;
1242
        croak "$error$append";
1243
    }
1244
}
1245

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1246
sub _need_tables {
1247
    my ($self, $tree, $need_tables, $tables) = @_;
1248
    
cleanup
Yuki Kimoto authored on 2011-04-02
1249
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1250
    foreach my $table (@$tables) {
1251
        if ($tree->{$table}) {
1252
            $need_tables->{$table} = 1;
1253
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1254
        }
1255
    }
1256
}
1257

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1258
sub _push_join {
1259
    my ($self, $sql, $join, $join_tables) = @_;
1260
    
cleanup
Yuki Kimoto authored on 2011-04-02
1261
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1262
    return unless @$join;
1263
    
cleanup
Yuki Kimoto authored on 2011-04-02
1264
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1265
    my $tree = {};
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1266
    my $q = $self->_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1267
    for (my $i = 0; $i < @$join; $i++) {
1268
        
cleanup
Yuki Kimoto authored on 2011-04-02
1269
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1270
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1271
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1272
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1273
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1274
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1275
            my $table1 = $1;
1276
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1277
            croak qq{right side table of "$join_clause" must be unique }
1278
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1279
              if exists $tree->{$table2};
1280
            $tree->{$table2}
1281
              = {position => $i, parent => $table1, join => $join_clause};
1282
        }
1283
        else {
improved error message
Yuki Kimoto authored on 2011-06-13
1284
            croak qq{join clause must have two table name after "on" keyword. } .
1285
                  qq{"$join_clause" is passed }  . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1286
        }
1287
    }
1288
    
cleanup
Yuki Kimoto authored on 2011-04-02
1289
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1290
    my $need_tables = {};
1291
    $self->_need_tables($tree, $need_tables, $join_tables);
1292
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1293
    
1294
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1295
    foreach my $need_table (@need_tables) {
1296
        push @$sql, $tree->{$need_table}{join};
1297
    }
1298
}
cleanup
Yuki Kimoto authored on 2011-03-08
1299

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1300
sub _quote {
1301
    my $self = shift;
1302
    
1303
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1304
         : defined $self->quote ? $self->quote
1305
         : '';
1306
}
1307

            
cleanup
Yuki Kimoto authored on 2011-04-02
1308
sub _remove_duplicate_table {
1309
    my ($self, $tables, $main_table) = @_;
1310
    
1311
    # Remove duplicate table
1312
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1313
    delete $tables{$main_table} if $main_table;
1314
    
1315
    return [keys %tables, $main_table ? $main_table : ()];
1316
}
1317

            
cleanup
Yuki Kimoto authored on 2011-04-02
1318
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1319
    my ($self, $source) = @_;
1320
    
cleanup
Yuki Kimoto authored on 2011-04-02
1321
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1322
    my $tables = [];
1323
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1324
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1325
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1326
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1327
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1328
    while ($source =~ /$table_re/g) {
1329
        push @$tables, $1;
1330
    }
1331
    
1332
    return $tables;
1333
}
1334

            
cleanup
Yuki Kimoto authored on 2011-04-02
1335
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1336
    my ($self, $where) = @_;
1337
    
cleanup
Yuki Kimoto authored on 2011-04-02
1338
    my $obj;
1339
    
1340
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1341
    if (ref $where eq 'HASH') {
1342
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1343
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1344
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1345
            my $column_quote = "$q$column$q";
1346
            $column_quote =~ s/\./$q.$q/;
1347
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1348
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1349
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1350
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1351
    
1352
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1353
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1354
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1355
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1356
    
updated pod
Yuki Kimoto authored on 2011-06-21
1357
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1358
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1359
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1360
            clause => $where->[0],
1361
            param  => $where->[1]
1362
        );
1363
    }
1364
    
cleanup
Yuki Kimoto authored on 2011-04-02
1365
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1366
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1367
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1368
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1369
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1370
    
cleanup
Yuki Kimoto authored on 2011-04-02
1371
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1372
}
1373

            
updated pod
Yuki Kimoto authored on 2011-06-21
1374
# DEPRECATED!
1375
sub _apply_filter {
1376
    my ($self, $table, @cinfos) = @_;
1377

            
1378
    # Initialize filters
1379
    $self->{filter} ||= {};
1380
    $self->{filter}{out} ||= {};
1381
    $self->{filter}{in} ||= {};
1382
    $self->{filter}{end} ||= {};
1383
    
1384
    # Usage
1385
    my $usage = "Usage: \$dbi->apply_filter(" .
1386
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1387
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1388
    
1389
    # Apply filter
1390
    for (my $i = 0; $i < @cinfos; $i += 2) {
1391
        
1392
        # Column
1393
        my $column = $cinfos[$i];
1394
        if (ref $column eq 'ARRAY') {
1395
            foreach my $c (@$column) {
1396
                push @cinfos, $c, $cinfos[$i + 1];
1397
            }
1398
            next;
1399
        }
1400
        
1401
        # Filter infomation
1402
        my $finfo = $cinfos[$i + 1] || {};
1403
        croak "$usage (table: $table) " . _subname
1404
          unless  ref $finfo eq 'HASH';
1405
        foreach my $ftype (keys %$finfo) {
1406
            croak "$usage (table: $table) " . _subname
1407
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1408
        }
1409
        
1410
        # Set filters
1411
        foreach my $way (qw/in out end/) {
1412
        
1413
            # Filter
1414
            my $filter = $finfo->{$way};
1415
            
1416
            # Filter state
1417
            my $state = !exists $finfo->{$way} ? 'not_exists'
1418
                      : !defined $filter        ? 'not_defined'
1419
                      : ref $filter eq 'CODE'   ? 'code'
1420
                      : 'name';
1421
            
1422
            # Filter is not exists
1423
            next if $state eq 'not_exists';
1424
            
1425
            # Check filter name
1426
            croak qq{Filter "$filter" is not registered } . _subname
1427
              if  $state eq 'name'
1428
               && ! exists $self->filters->{$filter};
1429
            
1430
            # Set filter
1431
            my $f = $state eq 'not_defined' ? undef
1432
                  : $state eq 'code'        ? $filter
1433
                  : $self->filters->{$filter};
1434
            $self->{filter}{$way}{$table}{$column} = $f;
1435
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1436
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1437
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1438
        }
1439
    }
1440
    
1441
    return $self;
1442
}
1443

            
1444
# DEPRECATED!
1445
sub create_query {
1446
    warn "create_query is DEPRECATED! use query option of each method";
1447
    shift->_create_query(@_);
1448
}
1449

            
cleanup
Yuki Kimoto authored on 2011-06-13
1450
# DEPRECATED!
1451
sub apply_filter {
1452
    my $self = shift;
1453
    
1454
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1455
         "use type_rule method and DBIx::Custom::Result filter method, " .
1456
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1457
    
1458
    return $self->_apply_filter(@_);
1459
}
1460

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1461
# DEPRECATED!
1462
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1463
sub select_at {
1464
    my ($self, %args) = @_;
1465

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1468
    # Arguments
1469
    my $primary_keys = delete $args{primary_key};
1470
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1471
    my $where = delete $args{where};
1472
    my $param = delete $args{param};
1473
    
1474
    # Check arguments
1475
    foreach my $name (keys %args) {
1476
        croak qq{"$name" is wrong option } . _subname
1477
          unless $SELECT_AT_ARGS{$name};
1478
    }
1479
    
1480
    # Table
1481
    croak qq{"table" option must be specified } . _subname
1482
      unless $args{table};
1483
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1484
    
1485
    # Create where parameter
1486
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1487
    
1488
    return $self->select(where => $where_param, %args);
1489
}
1490

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1491
# DEPRECATED!
1492
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1493
sub delete_at {
1494
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1495

            
1496
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1497
    
1498
    # Arguments
1499
    my $primary_keys = delete $args{primary_key};
1500
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1501
    my $where = delete $args{where};
1502
    
1503
    # Check arguments
1504
    foreach my $name (keys %args) {
1505
        croak qq{"$name" is wrong option } . _subname
1506
          unless $DELETE_AT_ARGS{$name};
1507
    }
1508
    
1509
    # Create where parameter
1510
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1511
    
1512
    return $self->delete(where => $where_param, %args);
1513
}
1514

            
cleanup
Yuki Kimoto authored on 2011-06-08
1515
# DEPRECATED!
1516
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1517
sub update_at {
1518
    my $self = shift;
1519

            
1520
    warn "update_at is DEPRECATED! use update and id option instead";
1521
    
1522
    # Arguments
1523
    my $param;
1524
    $param = shift if @_ % 2;
1525
    my %args = @_;
1526
    my $primary_keys = delete $args{primary_key};
1527
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1528
    my $where = delete $args{where};
1529
    my $p = delete $args{param} || {};
1530
    $param  ||= $p;
1531
    
1532
    # Check arguments
1533
    foreach my $name (keys %args) {
1534
        croak qq{"$name" is wrong option } . _subname
1535
          unless $UPDATE_AT_ARGS{$name};
1536
    }
1537
    
1538
    # Create where parameter
1539
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1540
    
1541
    return $self->update(where => $where_param, param => $param, %args);
1542
}
1543

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1544
# DEPRECATED!
1545
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1546
sub insert_at {
1547
    my $self = shift;
1548
    
1549
    warn "insert_at is DEPRECATED! use insert and id option instead";
1550
    
1551
    # Arguments
1552
    my $param;
1553
    $param = shift if @_ % 2;
1554
    my %args = @_;
1555
    my $primary_key = delete $args{primary_key};
1556
    $primary_key = [$primary_key] unless ref $primary_key;
1557
    my $where = delete $args{where};
1558
    my $p = delete $args{param} || {};
1559
    $param  ||= $p;
1560
    
1561
    # Check arguments
1562
    foreach my $name (keys %args) {
1563
        croak qq{"$name" is wrong option } . _subname
1564
          unless $INSERT_AT_ARGS{$name};
1565
    }
1566
    
1567
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1568
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1569
    $param = $self->merge_param($where_param, $param);
1570
    
1571
    return $self->insert(param => $param, %args);
1572
}
1573

            
added warnings
Yuki Kimoto authored on 2011-06-07
1574
# DEPRECATED!
1575
sub register_tag {
1576
    warn "register_tag is DEPRECATED!";
1577
    shift->query_builder->register_tag(@_)
1578
}
1579

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1580
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1581
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1582
has dbi_options => sub { {} };
1583
has filter_check  => 1;
1584
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1585

            
cleanup
Yuki Kimoto authored on 2011-01-25
1586
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1587
sub default_bind_filter {
1588
    my $self = shift;
1589
    
cleanup
Yuki Kimoto authored on 2011-06-13
1590
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1591
    
cleanup
Yuki Kimoto authored on 2011-01-12
1592
    if (@_) {
1593
        my $fname = $_[0];
1594
        
1595
        if (@_ && !$fname) {
1596
            $self->{default_out_filter} = undef;
1597
        }
1598
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1599
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1600
              unless exists $self->filters->{$fname};
1601
        
1602
            $self->{default_out_filter} = $self->filters->{$fname};
1603
        }
1604
        return $self;
1605
    }
1606
    
1607
    return $self->{default_out_filter};
1608
}
1609

            
cleanup
Yuki Kimoto authored on 2011-01-25
1610
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1611
sub default_fetch_filter {
1612
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1613

            
cleanup
Yuki Kimoto authored on 2011-06-13
1614
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1615
    
1616
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1617
        my $fname = $_[0];
1618

            
cleanup
Yuki Kimoto authored on 2011-01-12
1619
        if (@_ && !$fname) {
1620
            $self->{default_in_filter} = undef;
1621
        }
1622
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1623
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1624
              unless exists $self->filters->{$fname};
1625
        
1626
            $self->{default_in_filter} = $self->filters->{$fname};
1627
        }
1628
        
1629
        return $self;
1630
    }
1631
    
many changed
Yuki Kimoto authored on 2011-01-23
1632
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1633
}
1634

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1635
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1636
sub insert_param_tag {
1637
    warn "insert_param_tag is DEPRECATED! " .
1638
         "use insert_param instead!";
1639
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1640
}
1641

            
cleanup
Yuki Kimoto authored on 2011-01-25
1642
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1643
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1644
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1645
    return shift->query_builder->register_tag_processor(@_);
1646
}
1647

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1648
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1649
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1650
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1651
         "use update_param instead";
1652
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1653
}
cleanup
Yuki Kimoto authored on 2011-03-08
1654
# DEPRECATED!
1655
sub _push_relation {
1656
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1657
    
1658
    if (keys %{$relation || {}}) {
1659
        push @$sql, $need_where ? 'where' : 'and';
1660
        foreach my $rcolumn (keys %$relation) {
1661
            my $table1 = (split (/\./, $rcolumn))[0];
1662
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1663
            push @$tables, ($table1, $table2);
1664
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1665
        }
1666
    }
1667
    pop @$sql if $sql->[-1] eq 'and';    
1668
}
1669

            
1670
# DEPRECATED!
1671
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1672
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1673
    
1674
    if (keys %{$relation || {}}) {
1675
        foreach my $rcolumn (keys %$relation) {
1676
            my $table1 = (split (/\./, $rcolumn))[0];
1677
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1678
            my $table1_exists;
1679
            my $table2_exists;
1680
            foreach my $table (@$tables) {
1681
                $table1_exists = 1 if $table eq $table1;
1682
                $table2_exists = 1 if $table eq $table2;
1683
            }
1684
            unshift @$tables, $table1 unless $table1_exists;
1685
            unshift @$tables, $table2 unless $table2_exists;
1686
        }
1687
    }
1688
}
1689

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1692
=head1 NAME
1693

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

            
1696
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1697

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1698
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1699
    
1700
    # Connect
1701
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1702
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1703
        user => 'ken',
1704
        password => '!LFKD%$&',
1705
        dbi_option => {mysql_enable_utf8 => 1}
1706
    );
cleanup
yuki-kimoto authored on 2010-08-05
1707

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1708
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1709
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1710
    
1711
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1712
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1713
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1714
    
1715
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1716
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1717

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1722
    # Select, more complex
1723
    my $result = $dbi->select(
1724
        table  => 'book',
1725
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1726
            {book => [qw/title author/]},
1727
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1728
        ],
1729
        where  => {'book.author' => 'Ken'},
1730
        join => ['left outer join company on book.company_id = company.id'],
1731
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1732
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1733
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1734
    # Fetch
1735
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1736
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1737
    }
1738
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1739
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1740
    while (my $row = $result->fetch_hash) {
1741
        
1742
    }
1743
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1744
    # Execute SQL with parameter.
1745
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1746
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1747
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1748
    );
1749
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1750
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1751

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

            
1754
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1755

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

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

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

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

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

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

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

            
1771
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1772

            
1773
=head1 GUIDE
1774

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

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

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

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

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

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

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

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

            
1794
    my $connector = DBIx::Connector->new(
1795
        "dbi:mysql:database=$DATABASE",
1796
        $USER,
1797
        $PASSWORD,
1798
        DBIx::Custom->new->default_dbi_option
1799
    );
1800
    
updated pod
Yuki Kimoto authored on 2011-06-21
1801
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1802

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

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

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

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

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

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

            
1818
=head2 C<default_dbi_option>
1819

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1826
    {
1827
        RaiseError => 1,
1828
        PrintError => 0,
1829
        AutoCommit => 1,
1830
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1831

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1846
=head2 C<password>
1847

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1899
    print $dbi->available_data_type;
1900

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

            
1904
=head2 C<available_type_name> EXPERIMENTAL
1905

            
1906
    print $dbi->available_type_name;
1907

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

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

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

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

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

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

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

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

            
1925
Create column clause. The follwoing column clause is created.
1926

            
1927
    book.author as "book.author",
1928
    book.title as "book.title"
1929

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1932
    # Separator is double underbar
1933
    $dbi->separator('__');
1934
    
1935
    book.author as "book__author",
1936
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1937

            
cleanup
Yuki Kimoto authored on 2011-06-13
1938
    # Separator is hyphen
1939
    $dbi->separator('-');
1940
    
1941
    book.author as "book-author",
1942
    book.title as "book-title"
1943
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1944
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1945

            
update pod
Yuki Kimoto authored on 2011-03-13
1946
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1947
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1948
        user => 'ken',
1949
        password => '!LFKD%$&',
1950
        dbi_option => {mysql_enable_utf8 => 1}
1951
    );
1952

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1961
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1962
        table => 'book',
1963
        primary_key => 'id',
1964
        join => [
1965
            'inner join company on book.comparny_id = company.id'
1966
        ],
1967
    );
1968

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

            
1972
   $dbi->model('book')->select(...);
1973

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

            
1976
    my $dbh = $dbi->dbh;
1977

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

            
1981
=head2 C<each_column>
1982

            
1983
    $dbi->each_column(
1984
        sub {
1985
            my ($dbi, $table, $column, $column_info) = @_;
1986
            
1987
            my $type = $column_info->{TYPE_NAME};
1988
            
1989
            if ($type eq 'DATE') {
1990
                # ...
1991
            }
1992
        }
1993
    );
1994

            
1995
Iterate all column informations of all table from database.
1996
Argument is callback when one column is found.
1997
Callback receive four arguments, dbi object, table name,
1998
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1999

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

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

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

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

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

            
2020
    select * from where title = ? and author like ?;
2021

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

            
2024
=over 4
2025

            
2026
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2027
    
2028
    filter => {
2029
        title  => sub { uc $_[0] }
2030
        author => sub { uc $_[0] }
2031
    }
update pod
Yuki Kimoto authored on 2011-03-13
2032

            
updated pod
Yuki Kimoto authored on 2011-06-09
2033
    # Filter name
2034
    filter => {
2035
        title  => 'upper_case',
2036
        author => 'upper_case'
2037
    }
2038
        
2039
    # At once
2040
    filter => [
2041
        [qw/title author/]  => sub { uc $_[0] }
2042
    ]
2043

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

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

            
2051
    query => 1
2052

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

            
2056
    my $sql = $query->sql;
2057
    my $columns = $query->columns;
updated document
Yuki Kimoto authored on 2011-06-09
2058

            
updated pod
Yuki Kimoto authored on 2011-06-09
2059
=item C<table>
2060
    
2061
    table => 'author'
2062

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2070
    # Same
2071
    $dbi->execute(
2072
      "select * from book where title = :book.title and author = :book.author",
2073
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2074

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

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

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

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

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

            
2086
=item C<type_rule_off> EXPERIMENTAL
2087

            
2088
    type_rule_off => 1
2089

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

            
2092
=item C<type_rule1_off> EXPERIMENTAL
2093

            
2094
    type_rule1_off => 1
2095

            
2096
Turn C<into1> type rule off.
2097

            
2098
=item C<type_rule2_off> EXPERIMENTAL
2099

            
2100
    type_rule2_off => 1
2101

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2114
=over 4
2115

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

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

            
2120
=item C<filter>
2121

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2126
    id => 4
2127
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2128

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2132
    $dbi->delete(
2133
        parimary_key => ['id1', 'id2'],
2134
        id => [4, 5],
2135
        table => 'book',
2136
    );
update pod
Yuki Kimoto authored on 2011-03-13
2137

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

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

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

            
2144
    prefix => 'some'
2145

            
2146
prefix before table name section.
2147

            
2148
    delete some from book
2149

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2158
Table name.
2159

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

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

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

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

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

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

            
2172
=item C<type_rule_off> EXPERIMENTAL
2173

            
2174
Same as C<execute> method's C<type_rule_off> option.
2175

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

            
2178
    type_rule1_off => 1
2179

            
2180
Same as C<execute> method's C<type_rule1_off> option.
2181

            
2182
=item C<type_rule2_off> EXPERIMENTAL
2183

            
2184
    type_rule2_off => 1
2185

            
2186
Same as C<execute> method's C<type_rule2_off> option.
2187

            
updated pod
Yuki Kimoto authored on 2011-06-08
2188
=back
update pod
Yuki Kimoto authored on 2011-03-13
2189

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2197
=head2 C<insert>
2198

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

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

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

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

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

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

            
2212
=item C<filter>
2213

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

            
2216
=item C<id>
2217

            
updated document
Yuki Kimoto authored on 2011-06-09
2218
    id => 4
2219
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2220

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2224
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2225
        {title => 'Perl', author => 'Ken'}
2226
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2227
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2228
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2229
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2230

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

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

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

            
2240
    prefix => 'or replace'
2241

            
2242
prefix before table name section
2243

            
2244
    insert or replace into book
2245

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

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

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

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

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

            
2257
=item C<table>
2258

            
2259
    table => 'book'
2260

            
2261
Table name.
2262

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

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

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

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

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

            
2273
    type_rule1_off => 1
2274

            
2275
Same as C<execute> method's C<type_rule1_off> option.
2276

            
2277
=item C<type_rule2_off> EXPERIMENTAL
2278

            
2279
    type_rule2_off => 1
2280

            
2281
Same as C<execute> method's C<type_rule2_off> option.
2282

            
update pod
Yuki Kimoto authored on 2011-03-13
2283
=back
2284

            
2285
=over 4
2286

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2302
    lib / MyModel.pm
2303
        / MyModel / book.pm
2304
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2305

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

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

            
2310
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2311
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2312
    
2313
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2314

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2319
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2320
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2321
    
2322
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2323

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2326
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2327
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2328
    
2329
    1;
2330
    
updated pod
Yuki Kimoto authored on 2011-06-21
2331
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2332

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

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

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

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

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

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

            
2346
    {key1 => [1, 1], key2 => 2}
2347

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

            
2350
    $dbi->method(
2351
        update_or_insert => sub {
2352
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2353
            
2354
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2355
        },
2356
        find_or_create   => sub {
2357
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2358
            
2359
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2360
        }
2361
    );
2362

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

            
2365
    $dbi->update_or_insert;
2366
    $dbi->find_or_create;
2367

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

            
2370
    my $model = $dbi->model('book');
2371

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

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

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

            
2378
Create column clause for myself. The follwoing column clause is created.
2379

            
2380
    book.author as author,
2381
    book.title as title
2382

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2385
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2386
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2387
        user => 'ken',
2388
        password => '!LFKD%$&',
2389
        dbi_option => {mysql_enable_utf8 => 1}
2390
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2391

            
2392
Create a new L<DBIx::Custom> object.
2393

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

            
2396
    my $not_exists = $dbi->not_exists;
2397

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2401
=head2 C<register_filter>
2402

            
update pod
Yuki Kimoto authored on 2011-03-13
2403
    $dbi->register_filter(
2404
        # Time::Piece object to database DATE format
2405
        tp_to_date => sub {
2406
            my $tp = shift;
2407
            return $tp->strftime('%Y-%m-%d');
2408
        },
2409
        # database DATE format to Time::Piece object
2410
        date_to_tp => sub {
2411
           my $date = shift;
2412
           return Time::Piece->strptime($date, '%Y-%m-%d');
2413
        }
2414
    );
cleanup
yuki-kimoto authored on 2010-10-17
2415
    
update pod
Yuki Kimoto authored on 2011-03-13
2416
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2417

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

            
2420
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2421
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2422
            date => sub { ... },
2423
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2424
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2425
        into2 => {
2426
            date => sub { ... },
2427
            datetime => sub { ... }
2428
        },
2429
        from1 => {
2430
            # DATE
2431
            9 => sub { ... },
2432
            # DATETIME or TIMESTAMP
2433
            11 => sub { ... },
2434
        }
2435
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2436
            # DATE
2437
            9 => sub { ... },
2438
            # DATETIME or TIMESTAMP
2439
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2440
        }
2441
    );
2442

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2458
=over 4
2459

            
2460
=item 1. column name
2461

            
2462
    issue_date
2463
    issue_datetime
2464

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

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

            
2469
    book.issue_date
2470
    book.issue_datetime
2471

            
2472
=back
2473

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

            
2476
    print $dbi->available_type_name;
2477

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

            
2482
    print $dbi->available_data_type;
2483

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

            
2486
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2487
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2488
            [qw/DATE DATETIME/] => sub { ... },
2489
        ],
2490
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2491

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2494
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2495
        table  => 'book',
2496
        column => ['author', 'title'],
2497
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2498
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2499
    
updated document
Yuki Kimoto authored on 2011-06-09
2500
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2501

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

            
2504
=over 4
2505

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2510
Append statement to last of SQL.
2511
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2512
=item C<column>
2513
    
updated document
Yuki Kimoto authored on 2011-06-09
2514
    column => 'author'
2515
    column => ['author', 'title']
2516

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2525
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2526
        {book => [qw/author title/]},
2527
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2528
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2529

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

            
2532
    book.author as "book.author",
2533
    book.title as "book.title",
2534
    person.name as "person.name",
2535
    person.age as "person.age"
2536

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2539
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2540
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2541
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2542

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

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

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

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

            
2551
=item C<id>
2552

            
2553
    id => 4
2554
    id => [4, 5]
2555

            
2556
ID corresponding to C<primary_key>.
2557
You can select rows by C<id> and C<primary_key>.
2558

            
2559
    $dbi->select(
2560
        parimary_key => ['id1', 'id2'],
2561
        id => [4, 5],
2562
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2563
    );
2564

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2567
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2568
        where => {id1 => 4, id2 => 5},
2569
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2570
    );
2571
    
updated document
Yuki Kimoto authored on 2011-06-09
2572
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2573

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

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

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

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

            
2586
    prefix => 'SQL_CALC_FOUND_ROWS'
2587

            
2588
Prefix of column cluase
2589

            
2590
    select SQL_CALC_FOUND_ROWS title, author from book;
2591

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

            
2594
    join => [
2595
        'left outer join company on book.company_id = company_id',
2596
        'left outer join location on company.location_id = location.id'
2597
    ]
2598
        
2599
Join clause. If column cluase or where clause contain table name like "company.name",
2600
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2601

            
2602
    $dbi->select(
2603
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2604
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2605
        where => {'company.name' => 'Orange'},
2606
        join => [
2607
            'left outer join company on book.company_id = company.id',
2608
            'left outer join location on company.location_id = location.id'
2609
        ]
2610
    );
2611

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2615
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2616
    from book
2617
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2618
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2619

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2639
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2640

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

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

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

            
2647
    type_rule1_off => 1
2648

            
2649
Same as C<execute> method's C<type_rule1_off> option.
2650

            
2651
=item C<type_rule2_off> EXPERIMENTAL
2652

            
2653
    type_rule2_off => 1
2654

            
2655
Same as C<execute> method's C<type_rule2_off> option.
2656

            
updated document
Yuki Kimoto authored on 2011-06-09
2657
=item C<where>
2658
    
2659
    # Hash refrence
2660
    where => {author => 'Ken', 'title' => 'Perl'}
2661
    
2662
    # DBIx::Custom::Where object
2663
    where => $dbi->where(
2664
        clause => ['and', 'author = :author', 'title like :title'],
2665
        param  => {author => 'Ken', title => '%Perl%'}
2666
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2667
    
2668
    # Array reference 1 (array reference, hash referenc). same as above
2669
    where => [
2670
        ['and', 'author = :author', 'title like :title'],
2671
        {author => 'Ken', title => '%Perl%'}
2672
    ];    
2673
    
2674
    # Array reference 2 (String, hash reference)
2675
    where => [
2676
        'title like :title',
2677
        {title => '%Perl%'}
2678
    ]
2679
    
2680
    # String
2681
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2682

            
updated document
Yuki Kimoto authored on 2011-06-09
2683
Where clause.
2684
    
improved pod
Yuki Kimoto authored on 2011-04-19
2685
=item C<wrap> EXPERIMENTAL
2686

            
2687
Wrap statement. This is array reference.
2688

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

            
2691
This option is for Oracle and SQL Server paging process.
2692

            
update pod
Yuki Kimoto authored on 2011-03-12
2693
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2694

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2703
=over 4
2704

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2715
    id => 4
2716
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2717

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2721
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2722
        {title => 'Perl', author => 'Ken'}
2723
        parimary_key => ['id1', 'id2'],
2724
        id => [4, 5],
2725
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2726
    );
update pod
Yuki Kimoto authored on 2011-03-13
2727

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2730
    $dbi->update(
2731
        {title => 'Perl', author => 'Ken'}
2732
        where => {id1 => 4, id2 => 5},
2733
        table => 'book'
2734
    );
update pod
Yuki Kimoto authored on 2011-03-13
2735

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

            
2738
    prefix => 'or replace'
2739

            
2740
prefix before table name section
2741

            
2742
    update or replace book
2743

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

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

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

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

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

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

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

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

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

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

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

            
2767
Same as C<execute> method's C<type> option.
2768

            
2769
=item C<type_rule_off> EXPERIMENTAL
2770

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

            
2773
=item C<type_rule1_off> EXPERIMENTAL
2774

            
2775
    type_rule1_off => 1
2776

            
2777
Same as C<execute> method's C<type_rule1_off> option.
2778

            
2779
=item C<type_rule2_off> EXPERIMENTAL
2780

            
2781
    type_rule2_off => 1
2782

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2785
=back
update pod
Yuki Kimoto authored on 2011-03-13
2786

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

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

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

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

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

            
2798
Create update parameter tag.
2799

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

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

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

            
2809
Create a new L<DBIx::Custom::Where> object.
2810

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

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

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

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

            
2820
=head2 C<DBIX_CUSTOM_DEBUG>
2821

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

            
2825
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2826

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

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

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

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

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

            
2838
C<< <kimoto.yuki at gmail.com> >>
2839

            
2840
L<http://github.com/yuki-kimoto/DBIx-Custom>
2841

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2842
=head1 AUTHOR
2843

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

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

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

            
2850
This program is free software; you can redistribute it and/or modify it
2851
under the same terms as Perl itself.
2852

            
2853
=cut