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

            
test cleanup complete
Yuki Kimoto authored on 2011-08-10
4
our $VERSION = '0.1712';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
61
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
62
    my $self = shift;
63
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
64
    my $data_types = '';
65
    foreach my $i (-1000 .. 1000) {
66
         my $type_info = $self->dbh->type_info($i);
67
         my $data_type = $type_info->{DATA_TYPE};
68
         my $type_name = $type_info->{TYPE_NAME};
69
         $data_types .= "$data_type ($type_name)\n"
70
           if defined $data_type;
71
    }
72
    return "Data Type maybe equal to Type Name" unless $data_types;
73
    $data_types = "Data Type (Type name)\n" . $data_types;
74
    return $data_types;
75
}
76

            
77
sub available_typename {
78
    my $self = shift;
79
    
80
    # Type Names
81
    my $type_names = {};
82
    $self->each_column(sub {
83
        my ($self, $table, $column, $column_info) = @_;
84
        $type_names->{$column_info->{TYPE_NAME}} = 1
85
          if $column_info->{TYPE_NAME};
86
    });
87
    my @output = sort keys %$type_names;
88
    unshift @output, "Type Name";
89
    return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
90
}
91

            
added helper method
yuki-kimoto authored on 2010-10-17
92
our $AUTOLOAD;
93
sub AUTOLOAD {
94
    my $self = shift;
95

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
99
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
100
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
101
    if (my $method = $self->{_methods}->{$mname}) {
102
        return $self->$method(@_)
103
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
104
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
105
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
106
    }
107
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
108
        croak qq{Can't locate object method "$mname" via "$package" }
109
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
110
    }
added helper method
yuki-kimoto authored on 2010-10-17
111
}
112

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
113
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
114
    my ($self, $param) = @_;
115
    
116
    # Create set tag
117
    my @params;
118
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
119
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
120
        croak qq{"$column" is not safety column name } . _subname
121
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
122
        my $column_quote = $self->_q($column);
123
        $column_quote =~ s/\./$self->_q(".")/e;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
124
        push @params, ref $param->{$column} eq 'SCALAR'
125
          ? "$column_quote = " . ${$param->{$column}}
126
          : "$column_quote = :$column";
127

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
128
    }
129
    my $tag = join(', ', @params);
130
    
131
    return $tag;
132
}
133

            
cleanup
Yuki Kimoto authored on 2011-03-21
134
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
135
    my $self = shift;
136
    my $option = pop if ref $_[-1] eq 'HASH';
137
    my $real_table = shift;
138
    my $columns = shift;
139
    my $table = $option->{alias} || $real_table;
140
    
141
    # Columns
142
    unless ($columns) {
143
        $columns ||= $self->model($real_table)->columns;
144
    }
added helper method
yuki-kimoto authored on 2010-10-17
145
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
146
    # Separator
147
    my $separator = $self->separator;
148
    
cleanup
Yuki Kimoto authored on 2011-04-02
149
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
150
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
151
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
152
    push @column, $self->_q($table) . "." . $self->_q($_) .
153
      " as " . $self->_q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
154
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
155
    
156
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
157
}
158

            
packaging one directory
yuki-kimoto authored on 2009-11-16
159
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
160
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
161
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
162
    # Connect
163
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
164
    
packaging one directory
yuki-kimoto authored on 2009-11-16
165
    return $self;
166
}
167

            
update pod
Yuki Kimoto authored on 2011-03-13
168
sub dbh {
169
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
170
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
171
    # Set
172
    if (@_) {
173
        $self->{dbh} = $_[0];
174
        
175
        return $self;
176
    }
177
    
178
    # Get
179
    else {
180
        # From Connction manager
181
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
182
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
183
              unless ref $connector && $connector->can('dbh');
184
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
185
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
186
        }
187
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
188
        # Connect
189
        $self->{dbh} ||= $self->_connect;
190
        
191
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
192
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
193
            my $driver = $self->{dbh}->{Driver}->{Name};
194
            my $quote = $driver eq 'mysql' ? '`' : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
195
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
196
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
197
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
198
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
199
    }
200
}
201

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

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
205
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
206
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
207
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
208
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
209
    my $where            = delete $args{where} || {};
210
    my $append           = delete $args{append};
211
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
212
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
213
    my $id = delete $args{id};
214
    my $primary_key = delete $args{primary_key};
215
    croak "update method primary_key option " .
216
          "must be specified when id is specified " . _subname
217
      if defined $id && !defined $primary_key;
218
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
219
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
220
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
221
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
222
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
223
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
224
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
225
        $where_clause = "where " . $where->[0];
226
        $where_param = $where->[1];
227
    }
228
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
229
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
230
        $where_param = keys %$where_param
231
                     ? $self->merge_param($where_param, $where->param)
232
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
233
        
234
        # String where
235
        $where_clause = $where->to_string;
236
    }
237
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
238
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
239
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
240

            
cleanup
Yuki Kimoto authored on 2011-04-02
241
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
242
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
243
    push @sql, "delete";
244
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
245
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
246
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
247
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
248
    
249
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
250
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
251
}
252

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
255
sub DESTROY {
256

            
257
}
added helper method
yuki-kimoto authored on 2010-10-17
258

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
259
sub create_model {
260
    my $self = shift;
261
    
cleanup
Yuki Kimoto authored on 2011-04-02
262
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
263
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
264
    $args->{dbi} = $self;
265
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
266
    my $model_name  = delete $args->{name};
267
    my $model_table = delete $args->{table};
268
    $model_name ||= $model_table;
269
    
cleanup
Yuki Kimoto authored on 2011-04-02
270
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
271
    my $model = $model_class->new($args);
fixed memory leak and connec...
Yuki Kimoto authored on 2011-08-12
272
    weaken $self unless isweak $self;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
273
    $model->name($model_name) unless $model->name;
274
    $model->table($model_table) unless $model->table;
275
    
micro optimization
Yuki Kimoto authored on 2011-07-30
276
    # Apply filter(DEPRECATED logic)
277
    if ($model->{filter}) {
278
        my $filter = ref $model->filter eq 'HASH'
279
                   ? [%{$model->filter}]
280
                   : $model->filter;
281
        $filter ||= [];
282
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
283
          if @$filter;
284
        $self->_apply_filter($model->table, @$filter);
285
    }
286
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
287
    # Set model
288
    $self->model($model->name, $model);
289
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
290
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
291
}
292

            
293
sub each_column {
294
    my ($self, $cb) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
295

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
296
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
297
    
298
    # Iterate all tables
299
    my $sth_tables = $self->dbh->table_info;
300
    while (my $table_info = $sth_tables->fetchrow_hashref) {
301
        
302
        # Table
303
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
304
        next if defined $re && $table =~ /$re/;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
305
        
306
        # Iterate all columns
307
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
308
        while (my $column_info = $sth_columns->fetchrow_hashref) {
309
            my $column = $column_info->{COLUMN_NAME};
310
            $self->$cb($table, $column, $column_info);
311
        }
312
    }
313
}
314

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
315
sub each_table {
316
    my ($self, $cb) = @_;
317
    
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
318
    my $re = $self->exclude_table;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
319
    
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
320
    # Iterate all tables
321
    my $sth_tables = $self->dbh->table_info;
322
    while (my $table_info = $sth_tables->fetchrow_hashref) {
323
        
324
        # Table
325
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
326
        next if defined $re && $table =~ /$re/;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
327
        $self->$cb($table, $table_info);
328
    }
329
}
330

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
331
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
332
  allow_update_all bind_type column filter id join param prefix primary_key
333
  query relation table table_alias type type_rule_off type_rule1_off
334
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
335

            
336
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
337
    my $self = shift;
338
    my $query = shift;
339
    my $param;
340
    $param = shift if @_ % 2;
341
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
342
    
cleanup
Yuki Kimoto authored on 2011-04-02
343
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
344
    my $p = delete $args{param} || {};
345
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
346
    my $tables = delete $args{table} || [];
347
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
348
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
349
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
350
    my $bind_type = delete $args{bind_type} || delete $args{type};
351
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
352
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
353
    my $type_rule_off_parts = {
354
        1 => delete $args{type_rule1_off},
355
        2 => delete $args{type_rule2_off}
356
    };
cleanup
Yuki Kimoto authored on 2011-06-09
357
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
358
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
359
    
cleanup
Yuki Kimoto authored on 2011-03-09
360
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
361
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
362
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
363
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
364
    }
365
    
cleanup
Yuki Kimoto authored on 2011-04-02
366
    # Create query
updated pod
Yuki Kimoto authored on 2011-06-21
367
    $query = $self->_create_query($query) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
368
    
369
    # Save query
370
    $self->last_sql($query->sql);
371

            
cleanup
Yuki Kimoto authored on 2011-06-09
372
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
373
    
374
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
375
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
376
    
cleanup
Yuki Kimoto authored on 2011-04-02
377
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
378
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
379
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
380
    
micro optimization
Yuki Kimoto authored on 2011-07-30
381
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
382
    $tables = $self->_remove_duplicate_table($tables, $main_table)
383
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
384
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
385
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
386
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
387
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
388
        foreach my $i (1, 2) {
389
            unless ($type_rule_off_parts->{$i}) {
390
                $type_filters->{$i} = {};
391
                foreach my $alias (keys %$table_alias) {
392
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
393
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
394
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
395
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
396
                    }
397
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
398
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
399
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
400
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
401
        }
402
    }
cleanup
Yuki Kimoto authored on 2011-04-02
403
    
micro optimization
Yuki Kimoto authored on 2011-07-30
404
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
405
    if ($self->{filter}{on}) {
406
        my $applied_filter = {};
407
        foreach my $table (@$tables) {
408
            $applied_filter = {
409
                %$applied_filter,
410
                %{$self->{filter}{out}->{$table} || {}}
411
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
412
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
413
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
414
    }
415
    
cleanup
Yuki Kimoto authored on 2011-04-02
416
    # Replace filter name to code
417
    foreach my $column (keys %$filter) {
418
        my $name = $filter->{$column};
419
        if (!defined $name) {
420
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
421
        }
cleanup
Yuki Kimoto authored on 2011-04-02
422
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
423
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
424
            unless exists $self->filters->{$name};
425
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
426
        }
427
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
428
    
cleanup
Yuki Kimoto authored on 2011-04-02
429
    # Create bind values
430
    my $bind = $self->_create_bind_values(
431
        $param,
432
        $query->columns,
433
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
434
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
435
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
436
    );
cleanup
yuki-kimoto authored on 2010-10-17
437
    
438
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
439
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
440
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
441
    eval {
442
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
443
            my $bind_type = $bind->[$i]->{bind_type};
444
            $sth->bind_param(
445
                $i + 1,
446
                $bind->[$i]->{value},
447
                $bind_type ? $bind_type : ()
448
            );
cleanup
Yuki Kimoto authored on 2011-03-21
449
        }
450
        $affected = $sth->execute;
451
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
452
    
micro optimization
Yuki Kimoto authored on 2011-07-30
453
    $self->_croak($@, qq{. Following SQL is executed.\n}
454
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
455
    
improved debug message
Yuki Kimoto authored on 2011-05-23
456
    # DEBUG message
457
    if (DEBUG) {
458
        print STDERR "SQL:\n" . $query->sql . "\n";
459
        my @output;
460
        foreach my $b (@$bind) {
461
            my $value = $b->{value};
462
            $value = 'undef' unless defined $value;
463
            $value = encode(DEBUG_ENCODING(), $value)
464
              if utf8::is_utf8($value);
465
            push @output, $value;
466
        }
467
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
468
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
469
    
cleanup
Yuki Kimoto authored on 2011-04-02
470
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
471
    if ($sth->{NUM_OF_FIELDS}) {
472
        
micro optimization
Yuki Kimoto authored on 2011-07-30
473
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
474
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
475
        if ($self->{filter}{on}) {
476
            $filter->{in}  = {};
477
            $filter->{end} = {};
478
            push @$tables, $main_table if $main_table;
479
            foreach my $table (@$tables) {
480
                foreach my $way (qw/in end/) {
481
                    $filter->{$way} = {
482
                        %{$filter->{$way}},
483
                        %{$self->{filter}{$way}{$table} || {}}
484
                    };
485
                }
cleanup
Yuki Kimoto authored on 2011-04-02
486
            }
cleanup
Yuki Kimoto authored on 2011-01-12
487
        }
488
        
489
        # Result
490
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
491
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
492
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
493
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
494
            filter => $filter->{in} || {},
495
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
496
            type_rule => {
497
                from1 => $self->type_rule->{from1},
498
                from2 => $self->type_rule->{from2}
499
            },
cleanup
yuki-kimoto authored on 2010-10-17
500
        );
501

            
502
        return $result;
503
    }
cleanup
Yuki Kimoto authored on 2011-04-02
504
    
505
    # Not select statement
506
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
507
}
508

            
509
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
510
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
511
    
cleanup
yuki-kimoto authored on 2010-10-17
512
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
513
    my $param;
514
    $param = shift if @_ % 2;
515
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
516
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
517
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
518
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
519
    my $p = delete $args{param} || {};
520
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
521
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
522
    my $id = delete $args{id};
523
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
524
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
525
          "must be specified when id is specified " . _subname
526
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
527
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
528
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
529

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
530
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
531
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
532
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
533
        $param = $self->merge_param($id_param, $param);
534
    }
535

            
cleanup
Yuki Kimoto authored on 2011-04-02
536
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
537
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
538
    push @sql, "insert";
539
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
540
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
541
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
542
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
543
    
544
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
545
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
546
}
547

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
548
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
549
    my ($self, $param) = @_;
550
    
cleanup
Yuki Kimoto authored on 2011-04-02
551
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
552
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
553
    my @columns;
554
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
555
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
556
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
557
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
558
        my $column_quote = $self->_q($column);
559
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
560
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
561
        push @placeholders, ref $param->{$column} eq 'SCALAR'
562
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
563
    }
564
    
cleanup
Yuki Kimoto authored on 2011-04-02
565
    return '(' . join(', ', @columns) . ') ' . 'values ' .
566
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
567
}
568

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
569
sub include_model {
570
    my ($self, $name_space, $model_infos) = @_;
571
    
cleanup
Yuki Kimoto authored on 2011-04-02
572
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
573
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
574
    
575
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
576
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
577

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
578
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
579
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
580
          if $name_space =~ /[^\w:]/;
581
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
582
        croak qq{Name space module "$name_space.pm" is needed. $@ }
583
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
584
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
585
        
586
        # Search model modules
587
        my $path = $INC{"$name_space.pm"};
588
        $path =~ s/\.pm$//;
589
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
590
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
591
        $model_infos = [];
592
        while (my $module = readdir $dh) {
593
            push @$model_infos, $module
594
              if $module =~ s/\.pm$//;
595
        }
596
        close $dh;
597
    }
598
    
cleanup
Yuki Kimoto authored on 2011-04-02
599
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
600
    foreach my $model_info (@$model_infos) {
601
        
cleanup
Yuki Kimoto authored on 2011-04-02
602
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
603
        my $model_class;
604
        my $model_name;
605
        my $model_table;
606
        if (ref $model_info eq 'HASH') {
607
            $model_class = $model_info->{class};
608
            $model_name  = $model_info->{name};
609
            $model_table = $model_info->{table};
610
            
611
            $model_name  ||= $model_class;
612
            $model_table ||= $model_name;
613
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
614
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
615
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
616
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
617
          if $mclass =~ /[^\w:]/;
618
        unless ($mclass->can('isa')) {
619
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
620
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
621
        }
622
        
cleanup
Yuki Kimoto authored on 2011-04-02
623
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
624
        my $args = {};
625
        $args->{model_class} = $mclass if $mclass;
626
        $args->{name}        = $model_name if $model_name;
627
        $args->{table}       = $model_table if $model_table;
628
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
629
    }
630
    
631
    return $self;
632
}
633

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
634
sub map_param {
635
    my $self = shift;
636
    my $param = shift;
637
    my %map = @_;
638
    
639
    # Mapping
640
    my $map_param = {};
641
    foreach my $key (keys %map) {
642
        my $value_cb;
643
        my $condition;
644
        my $map_key;
645
        
646
        # Get mapping information
647
        if (ref $map{$key} eq 'ARRAY') {
648
            foreach my $some (@{$map{$key}}) {
649
                $map_key = $some unless ref $some;
650
                $condition = $some->{if} if ref $some eq 'HASH';
651
                $value_cb = $some if ref $some eq 'CODE';
652
            }
653
        }
654
        else {
655
            $map_key = $map{$key};
656
        }
657
        $value_cb ||= sub { $_[0] };
658
        $condition ||= sub { defined $_[0] && length $_[0] };
659

            
660
        # Map parameter
661
        my $value;
662
        if (ref $condition eq 'CODE') {
663
            $map_param->{$map_key} = $value_cb->($param->{$key})
664
              if $condition->($param->{$key});
665
        }
666
        elsif ($condition eq 'exists') {
667
            $map_param->{$map_key} = $value_cb->($param->{$key})
668
              if exists $param->{$key};
669
        }
670
        else { croak qq/Condition must be code reference or "exists" / . _subname }
671
    }
672
    
673
    return $map_param;
674
}
675

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
676
sub merge_param {
677
    my ($self, @params) = @_;
678
    
cleanup
Yuki Kimoto authored on 2011-04-02
679
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
680
    my $merge = {};
681
    foreach my $param (@params) {
682
        foreach my $column (keys %$param) {
683
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
684
            
685
            if (exists $merge->{$column}) {
686
                $merge->{$column} = [$merge->{$column}]
687
                  unless ref $merge->{$column} eq 'ARRAY';
688
                push @{$merge->{$column}},
689
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
690
            }
691
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
692
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
693
            }
694
        }
695
    }
696
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
697
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
698
}
699

            
cleanup
Yuki Kimoto authored on 2011-03-21
700
sub method {
701
    my $self = shift;
702
    
cleanup
Yuki Kimoto authored on 2011-04-02
703
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
704
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
705
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
706
    
707
    return $self;
708
}
709

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
710
sub model {
711
    my ($self, $name, $model) = @_;
712
    
cleanup
Yuki Kimoto authored on 2011-04-02
713
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
714
    if ($model) {
715
        $self->models->{$name} = $model;
716
        return $self;
717
    }
718
    
719
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
720
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
721
      unless $self->models->{$name};
722
    
cleanup
Yuki Kimoto authored on 2011-04-02
723
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
724
    return $self->models->{$name};
725
}
726

            
cleanup
Yuki Kimoto authored on 2011-03-21
727
sub mycolumn {
728
    my ($self, $table, $columns) = @_;
729
    
cleanup
Yuki Kimoto authored on 2011-04-02
730
    # Create column clause
731
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
732
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
733
    push @column, $self->_q($table) . "." . $self->_q($_) .
734
      " as " . $self->_q($_)
735
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
736
    
737
    return join (', ', @column);
738
}
739

            
added dbi_options attribute
kimoto authored on 2010-12-20
740
sub new {
741
    my $self = shift->SUPER::new(@_);
742
    
cleanup
Yuki Kimoto authored on 2011-04-02
743
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
744
    my @attrs = keys %$self;
745
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
746
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
747
          unless $self->can($attr);
748
    }
cleanup
Yuki Kimoto authored on 2011-04-02
749
    
added dbi_options attribute
kimoto authored on 2010-12-20
750
    return $self;
751
}
752

            
fixed if is not converted to...
Yuki Kimoto authored on 2011-08-09
753
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
754
sub not_exists { $not_exists }
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
755

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
756
sub order {
757
    my $self = shift;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
758
    return DBIx::Custom::Order->new(dbi => $self, @_);
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
759
}
760

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
761
sub query_builder {
762
    my $self = shift;
763
    my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
764
    
765
    # DEPRECATED
766
    $builder->register_tag(
767
        '?'     => \&DBIx::Custom::Tag::placeholder,
768
        '='     => \&DBIx::Custom::Tag::equal,
769
        '<>'    => \&DBIx::Custom::Tag::not_equal,
770
        '>'     => \&DBIx::Custom::Tag::greater_than,
771
        '<'     => \&DBIx::Custom::Tag::lower_than,
772
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
773
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
774
        'like'  => \&DBIx::Custom::Tag::like,
775
        'in'    => \&DBIx::Custom::Tag::in,
776
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
777
        'update_param' => \&DBIx::Custom::Tag::update_param
778
    );
779
    $builder->register_tag($self->{_tags} || {});
780
    return $builder;
781
}
782

            
cleanup
yuki-kimoto authored on 2010-10-17
783
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
784
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
785
    
786
    # Register filter
787
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
788
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
789
    
cleanup
Yuki Kimoto authored on 2011-04-02
790
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
791
}
packaging one directory
yuki-kimoto authored on 2009-11-16
792

            
793
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
794
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
795

            
refactoring select
yuki-kimoto authored on 2010-04-28
796
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
797
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
798
    my $tables = ref $table eq 'ARRAY' ? $table
799
               : defined $table ? [$table]
800
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
801
    my $columns   = delete $args{column};
802
    my $where     = delete $args{where} || {};
803
    my $append    = delete $args{append};
804
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
805
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
806
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
807
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
808
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
809
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
810
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
811
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
812
      if keys %$param;
813
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
814
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
815
    my $id = delete $args{id};
816
    my $primary_key = delete $args{primary_key};
817
    croak "update method primary_key option " .
818
          "must be specified when id is specified " . _subname
819
      if defined $id && !defined $primary_key;
820
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
821
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
822
    
cleanup
Yuki Kimoto authored on 2011-03-09
823
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
824
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
825
    
cleanup
Yuki Kimoto authored on 2011-04-02
826
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
827
    my @sql;
828
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
829
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
830
    # Prefix
831
    push @sql, $prefix if defined $prefix;
832
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
833
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
834
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
835
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
836
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
837
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
838
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
839
            }
840
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
841
                if (@$column == 3 && $column->[1] eq 'as') {
842
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
843
                    splice @$column, 1, 1;
844
                }
845
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
846
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
847
            }
cleanup
Yuki Kimoto authored on 2011-04-02
848
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
849
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
850
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
851
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
852
    }
853
    else { push @sql, '*' }
854
    
855
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
856
    push @sql, 'from';
857
    if ($relation) {
858
        my $found = {};
859
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
860
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
861
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
862
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
863
    }
cleanup
Yuki Kimoto authored on 2011-03-30
864
    else {
865
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
866
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
867
    }
868
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
869
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
870
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
871

            
cleanup
Yuki Kimoto authored on 2011-04-02
872
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
873
    unshift @$tables,
874
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
875
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
876
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
877
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
878
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
879
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
880
        $where_clause = "where " . $where->[0];
881
        $where_param = $where->[1];
882
    }
883
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
884
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
885
        $where_param = keys %$where_param
886
                     ? $self->merge_param($where_param, $where->param)
887
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
888
        
889
        # String where
890
        $where_clause = $where->to_string;
891
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
892
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
893
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
894
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
895
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
896
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
897
    # Push join
898
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
899
    
cleanup
Yuki Kimoto authored on 2011-03-09
900
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
901
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
902
    
cleanup
Yuki Kimoto authored on 2011-03-08
903
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
904
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
905
    
cleanup
Yuki Kimoto authored on 2011-04-02
906
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
907
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
908
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
909
    # Wrap
910
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
911
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
912
          unless ref $wrap eq 'ARRAY';
913
        unshift @sql, $wrap->[0];
914
        push @sql, $wrap->[1];
915
    }
916
    
cleanup
Yuki Kimoto authored on 2011-01-27
917
    # SQL
918
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
919
    
920
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
921
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
922
    
923
    return $result;
924
}
925

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
926
sub setup_model {
927
    my $self = shift;
928
    
cleanup
Yuki Kimoto authored on 2011-04-02
929
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
930
    $self->each_column(
931
        sub {
932
            my ($self, $table, $column, $column_info) = @_;
933
            if (my $model = $self->models->{$table}) {
934
                push @{$model->columns}, $column;
935
            }
936
        }
937
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
938
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
939
}
940

            
update pod
Yuki Kimoto authored on 2011-08-10
941
sub show_datatype {
942
    my ($self, $table) = @_;
943
    croak "Table name must be specified" unless defined $table;
944
    print "$table\n";
945
    
946
    my $result = $self->select(table => $table, where => "'0' <> '0'");
947
    my $sth = $result->sth;
948

            
949
    my $columns = $sth->{NAME};
950
    my $data_types = $sth->{TYPE};
951
    
952
    for (my $i = 0; $i < @$columns; $i++) {
953
        my $column = $columns->[$i];
954
        my $data_type = $data_types->[$i];
955
        print "$column: $data_type\n";
956
    }
957
}
958

            
959
sub show_typename {
960
    my ($self, $t) = @_;
961
    croak "Table name must be specified" unless defined $t;
962
    print "$t\n";
963
    
964
    $self->each_column(sub {
965
        my ($self, $table, $column, $infos) = @_;
966
        return unless $table eq $t;
967
        my $typename = $infos->{TYPE_NAME};
968
        print "$column: $typename\n";
969
    });
970
    
971
    return $self;
972
}
973

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
974
sub type_rule {
975
    my $self = shift;
976
    
977
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
978
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
979
        
980
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
981
        foreach my $i (1 .. 2) {
982
            my $into = "into$i";
983
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
984
            $self->{type_rule} = $type_rule;
985
            $self->{"_$into"} = {};
986
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
987
                croak qq{type name of $into section must be lower case}
988
                  if $type_name =~ /[A-Z]/;
989
            }
990
            $self->each_column(sub {
991
                my ($dbi, $table, $column, $column_info) = @_;
992
                
993
                my $type_name = lc $column_info->{TYPE_NAME};
994
                if ($type_rule->{$into} &&
995
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
996
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
997
                    return unless exists $type_rule->{$into}->{$type_name};
998
                    if  (defined $filter && ref $filter ne 'CODE') 
999
                    {
1000
                        my $fname = $filter;
1001
                        croak qq{Filter "$fname" is not registered" } . _subname
1002
                          unless exists $self->filters->{$fname};
1003
                        
1004
                        $filter = $self->filters->{$fname};
1005
                    }
1006

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1007
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1008
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1009
                }
1010
            });
1011
        }
1012

            
1013
        # From
1014
        foreach my $i (1 .. 2) {
1015
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1016
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1017
                croak qq{data type of from$i section must be lower case or number}
1018
                  if $data_type =~ /[A-Z]/;
1019
                my $fname = $type_rule->{"from$i"}{$data_type};
1020
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1021
                    croak qq{Filter "$fname" is not registered" } . _subname
1022
                      unless exists $self->filters->{$fname};
1023
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1024
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1025
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1026
            }
1027
        }
1028
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1029
        return $self;
1030
    }
1031
    
1032
    return $self->{type_rule} || {};
1033
}
1034

            
cleanup
yuki-kimoto authored on 2010-10-17
1035
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1036
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1037

            
cleanup
yuki-kimoto authored on 2010-10-17
1038
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1039
    my $param;
1040
    $param = shift if @_ % 2;
1041
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1042
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1043
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1044
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1045
    my $p = delete $args{param} || {};
1046
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1047
    my $where = delete $args{where} || {};
1048
    my $where_param = delete $args{where_param} || {};
1049
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1050
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1051
    my $id = delete $args{id};
1052
    my $primary_key = delete $args{primary_key};
1053
    croak "update method primary_key option " .
1054
          "must be specified when id is specified " . _subname
1055
      if defined $id && !defined $primary_key;
1056
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1057
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1058

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1101
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1102
    my ($self, $param, $opt) = @_;
1103
    
cleanup
Yuki Kimoto authored on 2011-04-02
1104
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1105
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1106
    $tag = "set $tag" unless $opt->{no_set};
1107

            
cleanup
Yuki Kimoto authored on 2011-04-02
1108
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1109
}
1110

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
1111
sub where { DBIx::Custom::Where->new(dbi => shift, @_) }
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1112

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

            
1139
        # Create query
1140
        my $builder = $self->query_builder;
1141
        $query = $builder->build_query($source);
1142

            
1143
        # Remove reserved word quote
1144
        if (my $q = $self->_quote) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1145
            $q = quotemeta($q);
1146
            $_ =~ s/[$q]//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1147
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1148

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

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

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

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

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

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

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1317
sub _push_join {
1318
    my ($self, $sql, $join, $join_tables) = @_;
1319
    
cleanup
Yuki Kimoto authored on 2011-04-02
1320
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1321
    return unless @$join;
1322
    
cleanup
Yuki Kimoto authored on 2011-04-02
1323
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1324
    my $tree = {};
1325
    for (my $i = 0; $i < @$join; $i++) {
1326
        
cleanup
Yuki Kimoto authored on 2011-07-28
1327
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1328
        my $join_clause;;
1329
        my $option;
1330
        if (ref $join->[$i] eq 'HASH') {
1331
            $join_clause = $join->[$i]->{clause};
1332
            $option = {table => $join->[$i]->{table}};
1333
        }
1334
        else {
1335
            $join_clause = $join->[$i];
1336
            $option = {};
1337
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1338

            
1339
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1340
        my $table1;
1341
        my $table2;
1342
        if (my $table = $option->{table}) {
1343
            $table1 = $table->[0];
1344
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1345
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1346
        else {
1347
            my $q = $self->_quote;
1348
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1349
            $j_clause =~ s/'.+?'//g;
1350
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1351
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1352
            my $c = $self->safety_character;
1353
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1354
            if ($j_clause =~ $join_re) {
1355
                $table1 = $1;
1356
                $table2 = $2;
1357
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1358
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1359
        croak qq{join clause must have two table name after "on" keyword. } .
1360
              qq{"$join_clause" is passed }  . _subname
1361
          unless defined $table1 && defined $table2;
1362
        croak qq{right side table of "$join_clause" must be unique }
1363
            . _subname
1364
          if exists $tree->{$table2};
1365
        croak qq{Same table "$table1" is specified} . _subname
1366
          if $table1 eq $table2;
1367
        $tree->{$table2}
1368
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1369
    }
1370
    
cleanup
Yuki Kimoto authored on 2011-04-02
1371
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1372
    my $need_tables = {};
1373
    $self->_need_tables($tree, $need_tables, $join_tables);
1374
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1375
    
1376
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1377
    foreach my $need_table (@need_tables) {
1378
        push @$sql, $tree->{$need_table}{join};
1379
    }
1380
}
cleanup
Yuki Kimoto authored on 2011-03-08
1381

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1382
sub _quote {
1383
    my $self = shift;
1384
    
1385
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1386
         : defined $self->quote ? $self->quote
1387
         : '';
1388
}
1389

            
cleanup
Yuki Kimoto authored on 2011-07-29
1390
sub _q {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1391
    my ($self, $value) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1392
    
1393
    my $quote = $self->_quote;
1394
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1395
    my $p;
1396
    if (defined $quote && length $quote > 1) {
1397
        $p = substr($quote, 1, 1);
1398
    }
1399
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1400
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1401
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1402
}
1403

            
cleanup
Yuki Kimoto authored on 2011-04-02
1404
sub _remove_duplicate_table {
1405
    my ($self, $tables, $main_table) = @_;
1406
    
1407
    # Remove duplicate table
1408
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1409
    delete $tables{$main_table} if $main_table;
1410
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1411
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1412
    if (my $q = $self->_quote) {
1413
        $q = quotemeta($q);
1414
        $_ =~ s/[$q]//g for @$new_tables;
1415
    }
1416

            
1417
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1418
}
1419

            
cleanup
Yuki Kimoto authored on 2011-04-02
1420
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1421
    my ($self, $source) = @_;
1422
    
cleanup
Yuki Kimoto authored on 2011-04-02
1423
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1424
    my $tables = [];
1425
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1426
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1427
    my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1428
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)");
1429
    my $table_re = $q ? qr/(?:^|[^$safety_character])$quoted_safety_character_re?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1430
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1431
    while ($source =~ /$table_re/g) {
1432
        push @$tables, $1;
1433
    }
1434
    
1435
    return $tables;
1436
}
1437

            
cleanup
Yuki Kimoto authored on 2011-04-02
1438
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1439
    my ($self, $where) = @_;
1440
    
cleanup
Yuki Kimoto authored on 2011-04-02
1441
    my $obj;
1442
    
1443
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1444
    if (ref $where eq 'HASH') {
1445
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1446
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1447
        foreach my $column (keys %$where) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1448
            my $column_quote = $self->_q($column);
1449
            $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1450
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1451
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1452
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1453
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1454
    
1455
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1456
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1457
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1458
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1459
    
updated pod
Yuki Kimoto authored on 2011-06-21
1460
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1461
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1462
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1463
            clause => $where->[0],
1464
            param  => $where->[1]
1465
        );
1466
    }
1467
    
cleanup
Yuki Kimoto authored on 2011-04-02
1468
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1469
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1470
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1471
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1472
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1473
    
cleanup
Yuki Kimoto authored on 2011-04-02
1474
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1475
}
1476

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

            
1480
    # Initialize filters
1481
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1482
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1483
    $self->{filter}{out} ||= {};
1484
    $self->{filter}{in} ||= {};
1485
    $self->{filter}{end} ||= {};
1486
    
1487
    # Usage
1488
    my $usage = "Usage: \$dbi->apply_filter(" .
1489
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1490
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1491
    
1492
    # Apply filter
1493
    for (my $i = 0; $i < @cinfos; $i += 2) {
1494
        
1495
        # Column
1496
        my $column = $cinfos[$i];
1497
        if (ref $column eq 'ARRAY') {
1498
            foreach my $c (@$column) {
1499
                push @cinfos, $c, $cinfos[$i + 1];
1500
            }
1501
            next;
1502
        }
1503
        
1504
        # Filter infomation
1505
        my $finfo = $cinfos[$i + 1] || {};
1506
        croak "$usage (table: $table) " . _subname
1507
          unless  ref $finfo eq 'HASH';
1508
        foreach my $ftype (keys %$finfo) {
1509
            croak "$usage (table: $table) " . _subname
1510
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1511
        }
1512
        
1513
        # Set filters
1514
        foreach my $way (qw/in out end/) {
1515
        
1516
            # Filter
1517
            my $filter = $finfo->{$way};
1518
            
1519
            # Filter state
1520
            my $state = !exists $finfo->{$way} ? 'not_exists'
1521
                      : !defined $filter        ? 'not_defined'
1522
                      : ref $filter eq 'CODE'   ? 'code'
1523
                      : 'name';
1524
            
1525
            # Filter is not exists
1526
            next if $state eq 'not_exists';
1527
            
1528
            # Check filter name
1529
            croak qq{Filter "$filter" is not registered } . _subname
1530
              if  $state eq 'name'
1531
               && ! exists $self->filters->{$filter};
1532
            
1533
            # Set filter
1534
            my $f = $state eq 'not_defined' ? undef
1535
                  : $state eq 'code'        ? $filter
1536
                  : $self->filters->{$filter};
1537
            $self->{filter}{$way}{$table}{$column} = $f;
1538
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1539
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1540
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1541
        }
1542
    }
1543
    
1544
    return $self;
1545
}
1546

            
1547
# DEPRECATED!
1548
sub create_query {
1549
    warn "create_query is DEPRECATED! use query option of each method";
1550
    shift->_create_query(@_);
1551
}
1552

            
cleanup
Yuki Kimoto authored on 2011-06-13
1553
# DEPRECATED!
1554
sub apply_filter {
1555
    my $self = shift;
1556
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1557
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1558
    return $self->_apply_filter(@_);
1559
}
1560

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1561
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1562
our %SELECT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1563
sub select_at {
1564
    my ($self, %args) = @_;
1565

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1568
    # Arguments
1569
    my $primary_keys = delete $args{primary_key};
1570
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1571
    my $where = delete $args{where};
1572
    my $param = delete $args{param};
1573
    
1574
    # Check arguments
1575
    foreach my $name (keys %args) {
1576
        croak qq{"$name" is wrong option } . _subname
1577
          unless $SELECT_AT_ARGS{$name};
1578
    }
1579
    
1580
    # Table
1581
    croak qq{"table" option must be specified } . _subname
1582
      unless $args{table};
1583
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1584
    
1585
    # Create where parameter
1586
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1587
    
1588
    return $self->select(where => $where_param, %args);
1589
}
1590

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1591
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1592
our %DELETE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1593
sub delete_at {
1594
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1595

            
1596
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1597
    
1598
    # Arguments
1599
    my $primary_keys = delete $args{primary_key};
1600
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1601
    my $where = delete $args{where};
1602
    
1603
    # Check arguments
1604
    foreach my $name (keys %args) {
1605
        croak qq{"$name" is wrong option } . _subname
1606
          unless $DELETE_AT_ARGS{$name};
1607
    }
1608
    
1609
    # Create where parameter
1610
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1611
    
1612
    return $self->delete(where => $where_param, %args);
1613
}
1614

            
cleanup
Yuki Kimoto authored on 2011-06-08
1615
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1616
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1617
sub update_at {
1618
    my $self = shift;
1619

            
1620
    warn "update_at is DEPRECATED! use update and id option instead";
1621
    
1622
    # Arguments
1623
    my $param;
1624
    $param = shift if @_ % 2;
1625
    my %args = @_;
1626
    my $primary_keys = delete $args{primary_key};
1627
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1628
    my $where = delete $args{where};
1629
    my $p = delete $args{param} || {};
1630
    $param  ||= $p;
1631
    
1632
    # Check arguments
1633
    foreach my $name (keys %args) {
1634
        croak qq{"$name" is wrong option } . _subname
1635
          unless $UPDATE_AT_ARGS{$name};
1636
    }
1637
    
1638
    # Create where parameter
1639
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1640
    
1641
    return $self->update(where => $where_param, param => $param, %args);
1642
}
1643

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1644
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1645
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1646
sub insert_at {
1647
    my $self = shift;
1648
    
1649
    warn "insert_at is DEPRECATED! use insert and id option instead";
1650
    
1651
    # Arguments
1652
    my $param;
1653
    $param = shift if @_ % 2;
1654
    my %args = @_;
1655
    my $primary_key = delete $args{primary_key};
1656
    $primary_key = [$primary_key] unless ref $primary_key;
1657
    my $where = delete $args{where};
1658
    my $p = delete $args{param} || {};
1659
    $param  ||= $p;
1660
    
1661
    # Check arguments
1662
    foreach my $name (keys %args) {
1663
        croak qq{"$name" is wrong option } . _subname
1664
          unless $INSERT_AT_ARGS{$name};
1665
    }
1666
    
1667
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1668
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1669
    $param = $self->merge_param($where_param, $param);
1670
    
1671
    return $self->insert(param => $param, %args);
1672
}
1673

            
added warnings
Yuki Kimoto authored on 2011-06-07
1674
# DEPRECATED!
1675
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1676
    my $self = shift;
1677
    
added warnings
Yuki Kimoto authored on 2011-06-07
1678
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1679
    
1680
    # Merge tag
1681
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1682
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1683
    
1684
    return $self;
1685
}
1686

            
1687
# DEPRECATED!
1688
sub register_tag_processor {
1689
    my $self = shift;
1690
    warn "register_tag_processor is DEPRECATED!";
1691
    # Merge tag
1692
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1693
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1694
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1695
}
1696

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1697
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1698
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1699
has dbi_options => sub { {} };
1700
has filter_check  => 1;
1701
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1702

            
cleanup
Yuki Kimoto authored on 2011-01-25
1703
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1704
sub default_bind_filter {
1705
    my $self = shift;
1706
    
cleanup
Yuki Kimoto authored on 2011-06-13
1707
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1708
    
cleanup
Yuki Kimoto authored on 2011-01-12
1709
    if (@_) {
1710
        my $fname = $_[0];
1711
        
1712
        if (@_ && !$fname) {
1713
            $self->{default_out_filter} = undef;
1714
        }
1715
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1716
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1717
              unless exists $self->filters->{$fname};
1718
        
1719
            $self->{default_out_filter} = $self->filters->{$fname};
1720
        }
1721
        return $self;
1722
    }
1723
    
1724
    return $self->{default_out_filter};
1725
}
1726

            
cleanup
Yuki Kimoto authored on 2011-01-25
1727
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1728
sub default_fetch_filter {
1729
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1730

            
cleanup
Yuki Kimoto authored on 2011-06-13
1731
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1732
    
1733
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1734
        my $fname = $_[0];
1735

            
cleanup
Yuki Kimoto authored on 2011-01-12
1736
        if (@_ && !$fname) {
1737
            $self->{default_in_filter} = undef;
1738
        }
1739
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1740
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1741
              unless exists $self->filters->{$fname};
1742
        
1743
            $self->{default_in_filter} = $self->filters->{$fname};
1744
        }
1745
        
1746
        return $self;
1747
    }
1748
    
many changed
Yuki Kimoto authored on 2011-01-23
1749
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1750
}
1751

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1752
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1753
sub insert_param_tag {
1754
    warn "insert_param_tag is DEPRECATED! " .
1755
         "use insert_param instead!";
1756
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1757
}
1758

            
1759
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1760
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1761
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1762
         "use update_param instead";
1763
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1764
}
cleanup
Yuki Kimoto authored on 2011-03-08
1765
# DEPRECATED!
1766
sub _push_relation {
1767
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1768
    
1769
    if (keys %{$relation || {}}) {
1770
        push @$sql, $need_where ? 'where' : 'and';
1771
        foreach my $rcolumn (keys %$relation) {
1772
            my $table1 = (split (/\./, $rcolumn))[0];
1773
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1774
            push @$tables, ($table1, $table2);
1775
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1776
        }
1777
    }
1778
    pop @$sql if $sql->[-1] eq 'and';    
1779
}
1780

            
1781
# DEPRECATED!
1782
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1783
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1784
    
1785
    if (keys %{$relation || {}}) {
1786
        foreach my $rcolumn (keys %$relation) {
1787
            my $table1 = (split (/\./, $rcolumn))[0];
1788
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1789
            my $table1_exists;
1790
            my $table2_exists;
1791
            foreach my $table (@$tables) {
1792
                $table1_exists = 1 if $table eq $table1;
1793
                $table2_exists = 1 if $table eq $table2;
1794
            }
1795
            unshift @$tables, $table1 unless $table1_exists;
1796
            unshift @$tables, $table2 unless $table2_exists;
1797
        }
1798
    }
1799
}
1800

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1803
=head1 NAME
1804

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

            
1807
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1808

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1809
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1810
    
1811
    # Connect
1812
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1813
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1814
        user => 'ken',
1815
        password => '!LFKD%$&',
1816
        dbi_option => {mysql_enable_utf8 => 1}
1817
    );
cleanup
yuki-kimoto authored on 2010-08-05
1818

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1819
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1820
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1821
    
1822
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1823
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1824
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1825
    
1826
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1827
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1828

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1833
    # Select, more complex
1834
    my $result = $dbi->select(
1835
        table  => 'book',
1836
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1837
            {book => [qw/title author/]},
1838
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1839
        ],
1840
        where  => {'book.author' => 'Ken'},
1841
        join => ['left outer join company on book.company_id = company.id'],
1842
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1843
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1844
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1845
    # Fetch
1846
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1847
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1848
    }
1849
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1850
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1851
    while (my $row = $result->fetch_hash) {
1852
        
1853
    }
1854
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1855
    # Execute SQL with parameter.
1856
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1857
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1858
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1859
    );
1860
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1861
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1862

            
cleanup
Yuki Kimoto authored on 2011-07-29
1863
L<DBIx::Custom> is L<DBI> wrapper module to execute SQL easily.
updated pod
Yuki Kimoto authored on 2011-06-21
1864
This module have the following features.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1865

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
1868
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1869

            
cleanup
Yuki Kimoto authored on 2011-07-29
1870
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1871

            
cleanup
Yuki Kimoto authored on 2011-07-29
1872
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1873

            
cleanup
Yuki Kimoto authored on 2011-07-29
1874
Create C<where> clause flexibly
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1875

            
cleanup
Yuki Kimoto authored on 2011-07-29
1876
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1877

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1878
Named place holder support
1879

            
1880
=item *
1881

            
cleanup
Yuki Kimoto authored on 2011-07-29
1882
Model support
1883

            
1884
=item *
1885

            
1886
Connection manager support
1887

            
1888
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1889

            
cleanup
Yuki Kimoto authored on 2011-07-30
1890
Choice your favorite relational database management system,
cleanup
Yuki Kimoto authored on 2011-07-29
1891
C<MySQL>, C<SQLite>, C<PostgreSQL>, C<Oracle>,
1892
C<Microsoft SQL Server>, C<Microsoft Access>, C<DB2> or anything, 
1893

            
1894
=item *
1895

            
1896
Filtering by data type or column name(EXPERIMENTAL)
1897

            
1898
=item *
1899

            
1900
Create C<order by> clause flexibly(EXPERIMENTAL)
1901

            
1902
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1903

            
cleanup
Yuki Kimoto authored on 2011-07-29
1904
=head1 DOCUMENTATIONS
pod fix
Yuki Kimoto authored on 2011-01-21
1905

            
cleanup
Yuki Kimoto authored on 2011-07-29
1906
L<DBIx::Custom::Guide> - How to use L<DBIx::Custom>
pod fix
Yuki Kimoto authored on 2011-01-21
1907

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1908
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
cleanup
Yuki Kimoto authored on 2011-07-29
1909
- Theare are various examples.
1910

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1911
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1912
L<DBIx::Custom::Result>,
1913
L<DBIx::Custom::Query>,
1914
L<DBIx::Custom::Where>,
1915
L<DBIx::Custom::Model>,
1916
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1917

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

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

            
1922
    my $connector = $dbi->connector;
micro optimization
Yuki Kimoto authored on 2011-07-30
1923
    $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1924

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1925
Connection manager object. if C<connector> is set, you can get C<dbh>
1926
through connection manager. Conection manager object must have C<dbh> mehtod.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1927

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

            
1931
    my $connector = DBIx::Connector->new(
1932
        "dbi:mysql:database=$DATABASE",
1933
        $USER,
1934
        $PASSWORD,
1935
        DBIx::Custom->new->default_dbi_option
1936
    );
1937
    
updated pod
Yuki Kimoto authored on 2011-06-21
1938
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1939

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

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

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

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

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

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

            
1955
=head2 C<default_dbi_option>
1956

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1963
    {
1964
        RaiseError => 1,
1965
        PrintError => 0,
1966
        AutoCommit => 1,
1967
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1968

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
1976
=head2 C<last_sql>
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1977

            
1978
    my $last_sql = $dbi->last_sql;
1979
    $dbi = $dbi->last_sql($last_sql);
1980

            
1981
Get last successed SQL executed by C<execute> method.
1982

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1990
=head2 C<password>
1991

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
1999
    my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2000

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2001
Creat query builder. This is L<DBIx::Custom::QueryBuilder>.
cleanup
yuki-kimoto authored on 2010-08-05
2002

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2012
You can set quote pair.
2013

            
2014
    $dbi->quote('[]');
2015

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2031
=head2 C<separator>
2032

            
2033
    my $separator = $self->separator;
2034
    $dbi = $self->separator($separator);
2035

            
2036
Separator whichi join table and column.
2037
This is used by C<column> and C<mycolumn> method.
2038

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2039
=head2 C<exclude_table EXPERIMENTAL>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2040

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2041
    my $exclude_table = $self->exclude_table;
2042
    $dbi = $self->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2043

            
2044
Regex matching system table.
2045
this regex match is used by C<each_table> method and C<each_column> method
2046
System table is ignored.
2047
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2048
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2049
The performance is up.
2050

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

            
2053
    my $tag_parse = $dbi->tag_parse(0);
2054
    $dbi = $dbi->tag_parse;
2055

            
2056
Enable DEPRECATED tag parsing functionality, default to 1.
2057
If you want to disable tag parsing functionality, set to 0.
2058

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

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

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2072
=head2 C<available_datatype> EXPERIMENTAL
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2073

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2074
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2075

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2079
=head2 C<available_typename> EXPERIMENTAL
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2080

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2081
    print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2082

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

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

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

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

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

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

            
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2096
=head2 C<column>
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2097

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

            
2100
Create column clause. The follwoing column clause is created.
2101

            
2102
    book.author as "book.author",
2103
    book.title as "book.title"
2104

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2105
You can change separator by C<separator> attribute.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2106

            
cleanup
Yuki Kimoto authored on 2011-06-13
2107
    # Separator is double underbar
2108
    $dbi->separator('__');
2109
    
2110
    book.author as "book__author",
2111
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2112

            
cleanup
Yuki Kimoto authored on 2011-06-13
2113
    # Separator is hyphen
2114
    $dbi->separator('-');
2115
    
2116
    book.author as "book-author",
2117
    book.title as "book-title"
2118
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2119
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2120

            
update pod
Yuki Kimoto authored on 2011-03-13
2121
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2122
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2123
        user => 'ken',
2124
        password => '!LFKD%$&',
2125
        dbi_option => {mysql_enable_utf8 => 1}
2126
    );
2127

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2136
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2137
        table => 'book',
2138
        primary_key => 'id',
2139
        join => [
2140
            'inner join company on book.comparny_id = company.id'
2141
        ],
2142
    );
2143

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

            
2147
   $dbi->model('book')->select(...);
2148

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

            
2151
    my $dbh = $dbi->dbh;
2152

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

            
2156
=head2 C<each_column>
2157

            
2158
    $dbi->each_column(
2159
        sub {
2160
            my ($dbi, $table, $column, $column_info) = @_;
2161
            
2162
            my $type = $column_info->{TYPE_NAME};
2163
            
2164
            if ($type eq 'DATE') {
2165
                # ...
2166
            }
2167
        }
2168
    );
2169

            
2170
Iterate all column informations of all table from database.
2171
Argument is callback when one column is found.
2172
Callback receive four arguments, dbi object, table name,
2173
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2174

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2175
=head2 C<each_table>
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2176

            
2177
    $dbi->each_table(
2178
        sub {
2179
            my ($dbi, $table, $table_info) = @_;
2180
            
2181
            my $table_name = $table_info->{TABLE_NAME};
2182
        }
2183
    );
2184

            
2185
Iterate all table informationsfrom database.
2186
Argument is callback when one table is found.
2187
Callback receive three arguments, dbi object, table name,
2188
table information.
2189

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2208
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2209
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2210
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2211
    select * from book where title = :title and author like :author
2212
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2213
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2214
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2215

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2216
You can specify operator with named placeholder
2217
 by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2218

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2219
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2220
    select * from book where :title{=} and :author{like}
2221
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2222
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2223
    select * from where title = ? and author like ?;
2224

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
2225
Note that colons in time format such as 12:13:15 is exeption,
2226
it is not parsed as named placeholder.
2227
If you want to use colon generally, you must escape it by C<\\>
2228

            
2229
    select * from where title = "aa\\:bb";
2230

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

            
2233
=over 4
2234

            
2235
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2236
    
2237
    filter => {
2238
        title  => sub { uc $_[0] }
2239
        author => sub { uc $_[0] }
2240
    }
update pod
Yuki Kimoto authored on 2011-03-13
2241

            
updated pod
Yuki Kimoto authored on 2011-06-09
2242
    # Filter name
2243
    filter => {
2244
        title  => 'upper_case',
2245
        author => 'upper_case'
2246
    }
2247
        
2248
    # At once
2249
    filter => [
2250
        [qw/title author/]  => sub { uc $_[0] }
2251
    ]
2252

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

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

            
2260
    query => 1
2261

            
2262
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
cleanup
Yuki Kimoto authored on 2011-07-30
2263
You can check SQL or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2264

            
2265
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2266
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2267
    my $columns = $query->columns;
2268
    
2269
If you want to execute SQL fast, you can do the following way.
2270

            
2271
    my $query;
2272
    foreach my $row (@$rows) {
2273
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2274
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2275
    }
2276

            
2277
Statement handle is reused and SQL parsing is finished,
2278
so you can get more performance than normal way.
cleanup
Yuki Kimoto authored on 2011-07-30
2279

            
2280
If you want to execute SQL as possible as fast and don't need filtering.
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2281
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2282
    
2283
    my $query;
2284
    my $sth;
2285
    foreach my $row (@$rows) {
2286
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2287
      $sth ||= $query->sth;
2288
      $sth->execute(map { $row->{$_} } sort keys %$row);
2289
    }
2290

            
2291
Note that $row must be simple hash reference, such as
2292
{title => 'Perl', author => 'Ken'}.
2293
and don't forget to sort $row values by $row key asc order.
updated document
Yuki Kimoto authored on 2011-06-09
2294

            
updated pod
Yuki Kimoto authored on 2011-06-09
2295
=item C<table>
2296
    
2297
    table => 'author'
2298

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2306
    # Same
2307
    $dbi->execute(
2308
      "select * from book where title = :book.title and author = :book.author",
2309
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2310

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

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

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

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

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

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

            
2324
    table_alias => {user => 'hiker'}
2325

            
2326
Table alias. Key is real table name, value is alias table name.
2327
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2328
on alias table name.
2329

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

            
2332
    type_rule_off => 1
2333

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

            
2336
=item C<type_rule1_off> EXPERIMENTAL
2337

            
2338
    type_rule1_off => 1
2339

            
2340
Turn C<into1> type rule off.
2341

            
2342
=item C<type_rule2_off> EXPERIMENTAL
2343

            
2344
    type_rule2_off => 1
2345

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2358
=over 4
2359

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

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

            
2364
=item C<filter>
2365

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2370
    id => 4
2371
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2372

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2376
    $dbi->delete(
2377
        parimary_key => ['id1', 'id2'],
2378
        id => [4, 5],
2379
        table => 'book',
2380
    );
update pod
Yuki Kimoto authored on 2011-03-13
2381

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2386
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2387

            
2388
    prefix => 'some'
2389

            
2390
prefix before table name section.
2391

            
2392
    delete some from book
2393

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2402
Table name.
2403

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

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

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

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

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

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

            
2416
=item C<type_rule_off> EXPERIMENTAL
2417

            
2418
Same as C<execute> method's C<type_rule_off> option.
2419

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

            
2422
    type_rule1_off => 1
2423

            
2424
Same as C<execute> method's C<type_rule1_off> option.
2425

            
2426
=item C<type_rule2_off> EXPERIMENTAL
2427

            
2428
    type_rule2_off => 1
2429

            
2430
Same as C<execute> method's C<type_rule2_off> option.
2431

            
updated pod
Yuki Kimoto authored on 2011-06-08
2432
=back
update pod
Yuki Kimoto authored on 2011-03-13
2433

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2441
=head2 C<insert>
2442

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

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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
2448
If you want to set constant value to row data, use scalar reference
2449
as parameter value.
2450

            
2451
    {date => \"NOW()"}
2452

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

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

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

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

            
2461
=item C<filter>
2462

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

            
2465
=item C<id>
2466

            
updated document
Yuki Kimoto authored on 2011-06-09
2467
    id => 4
2468
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2469

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2473
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2474
        {title => 'Perl', author => 'Ken'}
2475
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2476
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2477
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2478
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2479

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2487
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2488

            
2489
    prefix => 'or replace'
2490

            
2491
prefix before table name section
2492

            
2493
    insert or replace into book
2494

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

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

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

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

            
2504
Same as C<execute> method's C<query> option.
2505

            
2506
=item C<table>
2507

            
2508
    table => 'book'
2509

            
2510
Table name.
2511

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

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

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

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

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

            
2522
    type_rule1_off => 1
2523

            
2524
Same as C<execute> method's C<type_rule1_off> option.
2525

            
2526
=item C<type_rule2_off> EXPERIMENTAL
2527

            
2528
    type_rule2_off => 1
2529

            
2530
Same as C<execute> method's C<type_rule2_off> option.
2531

            
update pod
Yuki Kimoto authored on 2011-03-13
2532
=back
2533

            
2534
=over 4
2535

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2551
    lib / MyModel.pm
2552
        / MyModel / book.pm
2553
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2554

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

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

            
2559
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2560
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2561
    
2562
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2563

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2568
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2569
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2570
    
2571
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2572

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2575
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2576
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2577
    
2578
    1;
2579
    
updated pod
Yuki Kimoto authored on 2011-06-21
2580
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2581

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

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

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

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

            
2591
    my $map_param = $dbi->map_param(
2592
        {id => 1, authro => 'Ken', price => 1900},
2593
        'id' => 'book.id',
2594
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2595
        'price' => [
2596
            'book.price', {if => sub { length $_[0] }}
2597
        ]
2598
    );
2599

            
2600
Map paramters to other key and value. First argument is original
2601
parameter. this is hash reference. Rest argument is mapping.
2602
By default, Mapping is done if the value length is not zero.
2603

            
2604
=over 4
2605

            
2606
=item Key mapping
2607

            
2608
    'id' => 'book.id'
2609

            
2610
This is only key mapping. Value is same as original one.
2611

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

            
2614
=item Key and value mapping
2615

            
2616
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2617

            
2618
This is key and value mapping. Frist element of array reference
2619
is mapped key name, second element is code reference to map the value.
2620

            
2621
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2622
      if value length is not zero.
2623

            
2624
=item Condition
2625

            
2626
    'price' => ['book.price', {if => 'exists'}]
2627
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2628
    'price' => ['book.price', {if => sub { defined shift }}]
2629

            
2630
If you need condition, you can sepecify it. this is code reference
2631
or 'exists'. By default, condition is the following one.
2632

            
2633
    sub { defined $_[0] && length $_[0] }
2634

            
2635
=back
2636

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

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

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

            
2643
    {key1 => [1, 1], key2 => 2}
2644

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

            
2647
    $dbi->method(
2648
        update_or_insert => sub {
2649
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2650
            
2651
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2652
        },
2653
        find_or_create   => sub {
2654
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2655
            
2656
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2657
        }
2658
    );
2659

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

            
2662
    $dbi->update_or_insert;
2663
    $dbi->find_or_create;
2664

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

            
2667
    my $model = $dbi->model('book');
2668

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

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

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

            
2675
Create column clause for myself. The follwoing column clause is created.
2676

            
2677
    book.author as author,
2678
    book.title as title
2679

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2682
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2683
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2684
        user => 'ken',
2685
        password => '!LFKD%$&',
2686
        dbi_option => {mysql_enable_utf8 => 1}
2687
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2688

            
2689
Create a new L<DBIx::Custom> object.
2690

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

            
2693
    my $not_exists = $dbi->not_exists;
2694

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

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

            
2700
    my $order = $dbi->order;
2701

            
2702
Create a new L<DBIx::Custom::Order> object.
2703

            
cleanup
yuki-kimoto authored on 2010-10-17
2704
=head2 C<register_filter>
2705

            
update pod
Yuki Kimoto authored on 2011-03-13
2706
    $dbi->register_filter(
2707
        # Time::Piece object to database DATE format
2708
        tp_to_date => sub {
2709
            my $tp = shift;
2710
            return $tp->strftime('%Y-%m-%d');
2711
        },
2712
        # database DATE format to Time::Piece object
2713
        date_to_tp => sub {
2714
           my $date = shift;
2715
           return Time::Piece->strptime($date, '%Y-%m-%d');
2716
        }
2717
    );
cleanup
yuki-kimoto authored on 2010-10-17
2718
    
update pod
Yuki Kimoto authored on 2011-03-13
2719
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2720

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

            
2723
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2724
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2725
            date => sub { ... },
2726
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2727
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2728
        into2 => {
2729
            date => sub { ... },
2730
            datetime => sub { ... }
2731
        },
2732
        from1 => {
2733
            # DATE
2734
            9 => sub { ... },
2735
            # DATETIME or TIMESTAMP
2736
            11 => sub { ... },
2737
        }
2738
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2739
            # DATE
2740
            9 => sub { ... },
2741
            # DATETIME or TIMESTAMP
2742
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2743
        }
2744
    );
2745

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2761
=over 4
2762

            
2763
=item 1. column name
2764

            
2765
    issue_date
2766
    issue_datetime
2767

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

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

            
2772
    book.issue_date
2773
    book.issue_datetime
2774

            
2775
=back
2776

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2777
You get all type name used in database by C<available_typename>.
update pod
Yuki Kimoto authored on 2011-06-15
2778

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2779
    print $dbi->available_typename;
update pod
Yuki Kimoto authored on 2011-06-15
2780

            
updated pod
Yuki Kimoto authored on 2011-06-21
2781
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2782
C<from2> is executed after C<from1>.
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2783
You get all data type by C<available_datatype>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2784

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2785
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2786

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

            
2789
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2790
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2791
            [qw/DATE DATETIME/] => sub { ... },
2792
        ],
2793
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2794

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2797
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2798
        table  => 'book',
2799
        column => ['author', 'title'],
2800
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2801
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2802
    
updated document
Yuki Kimoto authored on 2011-06-09
2803
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2804

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

            
2807
=over 4
2808

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2813
Append statement to last of SQL.
2814
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2815
=item C<column>
2816
    
updated document
Yuki Kimoto authored on 2011-06-09
2817
    column => 'author'
2818
    column => ['author', 'title']
2819

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2826
You can specify hash of array reference.
updated pod
Yuki Kimoto authored on 2011-06-07
2827

            
updated document
Yuki Kimoto authored on 2011-06-09
2828
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2829
        {book => [qw/author title/]},
2830
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2831
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2832

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

            
2835
    book.author as "book.author",
2836
    book.title as "book.title",
2837
    person.name as "person.name",
2838
    person.age as "person.age"
2839

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2840
You can specify array of array reference, first argument is
2841
column name, second argument is alias.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2842

            
updated document
Yuki Kimoto authored on 2011-06-09
2843
    column => [
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2844
        ['date(book.register_datetime)' => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2845
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2846

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2847
Alias is quoted properly and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2848

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

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

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

            
2855
=item C<id>
2856

            
2857
    id => 4
2858
    id => [4, 5]
2859

            
2860
ID corresponding to C<primary_key>.
2861
You can select rows by C<id> and C<primary_key>.
2862

            
2863
    $dbi->select(
2864
        parimary_key => ['id1', 'id2'],
2865
        id => [4, 5],
2866
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2867
    );
2868

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2871
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2872
        where => {id1 => 4, id2 => 5},
2873
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2874
    );
2875
    
updated document
Yuki Kimoto authored on 2011-06-09
2876
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2877

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2888
=itme C<prefix>
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2889

            
2890
    prefix => 'SQL_CALC_FOUND_ROWS'
2891

            
2892
Prefix of column cluase
2893

            
2894
    select SQL_CALC_FOUND_ROWS title, author from book;
2895

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

            
2898
    join => [
2899
        'left outer join company on book.company_id = company_id',
2900
        'left outer join location on company.location_id = location.id'
2901
    ]
2902
        
2903
Join clause. If column cluase or where clause contain table name like "company.name",
2904
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2905

            
2906
    $dbi->select(
2907
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2908
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2909
        where => {'company.name' => 'Orange'},
2910
        join => [
2911
            'left outer join company on book.company_id = company.id',
2912
            'left outer join location on company.location_id = location.id'
2913
        ]
2914
    );
2915

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2919
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2920
    from book
2921
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2922
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2923

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
2924
You can specify two table by yourself. This is useful when join parser can't parse
cleanup
Yuki Kimoto authored on 2011-07-28
2925
the join clause correctly. This is EXPERIMENTAL.
added join new syntax
Yuki Kimoto authored on 2011-07-28
2926

            
2927
    $dbi->select(
2928
        table => 'book',
2929
        column => ['company.location_id as location_id'],
2930
        where => {'company.name' => 'Orange'},
2931
        join => [
2932
            {
2933
                clause => 'left outer join location on company.location_id = location.id',
2934
                table => ['company', 'location']
2935
            }
2936
        ]
2937
    );
2938

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-28
2952
Same as C<execute> method's C<bind_type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2953

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2958
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2959

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

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

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

            
2966
    type_rule1_off => 1
2967

            
2968
Same as C<execute> method's C<type_rule1_off> option.
2969

            
2970
=item C<type_rule2_off> EXPERIMENTAL
2971

            
2972
    type_rule2_off => 1
2973

            
2974
Same as C<execute> method's C<type_rule2_off> option.
2975

            
updated document
Yuki Kimoto authored on 2011-06-09
2976
=item C<where>
2977
    
2978
    # Hash refrence
2979
    where => {author => 'Ken', 'title' => 'Perl'}
2980
    
2981
    # DBIx::Custom::Where object
2982
    where => $dbi->where(
2983
        clause => ['and', 'author = :author', 'title like :title'],
2984
        param  => {author => 'Ken', title => '%Perl%'}
2985
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2986
    
2987
    # Array reference 1 (array reference, hash referenc). same as above
2988
    where => [
2989
        ['and', 'author = :author', 'title like :title'],
2990
        {author => 'Ken', title => '%Perl%'}
2991
    ];    
2992
    
2993
    # Array reference 2 (String, hash reference)
2994
    where => [
2995
        'title like :title',
2996
        {title => '%Perl%'}
2997
    ]
2998
    
2999
    # String
3000
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3001

            
updated document
Yuki Kimoto authored on 2011-06-09
3002
Where clause.
3003
    
improved pod
Yuki Kimoto authored on 2011-04-19
3004
=item C<wrap> EXPERIMENTAL
3005

            
3006
Wrap statement. This is array reference.
3007

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

            
3010
This option is for Oracle and SQL Server paging process.
3011

            
update pod
Yuki Kimoto authored on 2011-03-12
3012
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3013

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

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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
3018
Execute update statement. First argument is update row data.
3019

            
3020
If you want to set constant value to row data, use scalar reference
3021
as parameter value.
3022

            
3023
    {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3024

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3027
=over 4
3028

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3039
    id => 4
3040
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3041

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3045
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3046
        {title => 'Perl', author => 'Ken'}
3047
        parimary_key => ['id1', 'id2'],
3048
        id => [4, 5],
3049
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3050
    );
update pod
Yuki Kimoto authored on 2011-03-13
3051

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3054
    $dbi->update(
3055
        {title => 'Perl', author => 'Ken'}
3056
        where => {id1 => 4, id2 => 5},
3057
        table => 'book'
3058
    );
update pod
Yuki Kimoto authored on 2011-03-13
3059

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
3060
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3061

            
3062
    prefix => 'or replace'
3063

            
3064
prefix before table name section
3065

            
3066
    update or replace book
3067

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-28
3091
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3092

            
3093
=item C<type_rule_off> EXPERIMENTAL
3094

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

            
3097
=item C<type_rule1_off> EXPERIMENTAL
3098

            
3099
    type_rule1_off => 1
3100

            
3101
Same as C<execute> method's C<type_rule1_off> option.
3102

            
3103
=item C<type_rule2_off> EXPERIMENTAL
3104

            
3105
    type_rule2_off => 1
3106

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3109
=back
update pod
Yuki Kimoto authored on 2011-03-13
3110

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

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

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

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

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

            
3122
Create update parameter tag.
3123

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

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

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

            
3133
Create a new L<DBIx::Custom::Where> object.
3134

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

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

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

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

            
3144
=head2 C<DBIX_CUSTOM_DEBUG>
3145

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

            
update pod
Yuki Kimoto authored on 2011-08-10
3149
=head2 C<show_datatype EXPERIMENTAL>
3150

            
3151
    $dbi->show_datatype($table);
3152

            
3153
Show data type of the columns of specified table.
3154

            
3155
    book
3156
    title: 5
3157
    issue_date: 91
3158

            
3159
This data type is used in C<type_rule>'s C<from1> and C<from2>.
3160

            
3161
=head2 C<show_typename EXPERIMENTAL>
3162

            
3163
    $dbi->show_typename($table);
3164

            
3165
Show type name of the columns of specified table.
3166

            
3167
    book
3168
    title: varchar
3169
    issue_date: date
3170

            
3171
This type name is used in C<type_rule>'s C<into1> and C<into2>.
3172

            
improved debug message
Yuki Kimoto authored on 2011-05-23
3173
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3174

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

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

            
3179
L<DBIx::Custom>
3180

            
3181
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3182
    data_source # will be removed at 2017/1/1
3183
    dbi_options # will be removed at 2017/1/1
3184
    filter_check # will be removed at 2017/1/1
3185
    reserved_word_quote # will be removed at 2017/1/1
3186
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3187
    
3188
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3189
    create_query # will be removed at 2017/1/1
3190
    apply_filter # will be removed at 2017/1/1
3191
    select_at # will be removed at 2017/1/1
3192
    delete_at # will be removed at 2017/1/1
3193
    update_at # will be removed at 2017/1/1
3194
    insert_at # will be removed at 2017/1/1
3195
    register_tag # will be removed at 2017/1/1
3196
    default_bind_filter # will be removed at 2017/1/1
3197
    default_fetch_filter # will be removed at 2017/1/1
3198
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3199
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3200
    register_tag_processor # will be removed at 2017/1/1
3201
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3202
    
3203
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3204
    select method relation option # will be removed at 2017/1/1
3205
    select method param option # will be removed at 2017/1/1
3206
    select method column option [COLUMN, as => ALIAS] format
3207
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3208
    
3209
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3210
    execute("select * from {= title}"); # execute method's
3211
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3212
                                        # will be removed at 2017/1/1
3213
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3214

            
3215
L<DBIx::Custom::Model>
3216

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3217
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3218
    filter # will be removed at 2017/1/1
3219
    name # will be removed at 2017/1/1
3220
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3221

            
3222
L<DBIx::Custom::Query>
3223
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3224
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3225
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3226
    table # will be removed at 2017/1/1
3227
    filters # will be removed at 2017/1/1
3228
    
3229
    # Methods
3230
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3231

            
3232
L<DBIx::Custom::QueryBuilder>
3233
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3234
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3235
    tags # will be removed at 2017/1/1
3236
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3237
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3238
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3239
    register_tag # will be removed at 2017/1/1
3240
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3241
    
3242
    # Others
3243
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3244
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3245

            
3246
L<DBIx::Custom::Result>
3247
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3248
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3249
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3250
    
3251
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3252
    end_filter # will be removed at 2017/1/1
3253
    remove_end_filter # will be removed at 2017/1/1
3254
    remove_filter # will be removed at 2017/1/1
3255
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3256

            
3257
L<DBIx::Custom::Tag>
3258

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3259
    This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3260

            
3261
=head1 BACKWORD COMPATIBLE POLICY
3262

            
3263
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3264
except for attribute method.
3265
You can check all DEPRECATED functionalities by document.
3266
DEPRECATED functionality is removed after five years,
3267
but if at least one person use the functionality and tell me that thing
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3268
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3269

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3272
This policy was changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3273

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

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

            
3278
C<< <kimoto.yuki at gmail.com> >>
3279

            
3280
L<http://github.com/yuki-kimoto/DBIx-Custom>
3281

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3282
=head1 AUTHOR
3283

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

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

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

            
3290
This program is free software; you can redistribute it and/or modify it
3291
under the same terms as Perl itself.
3292

            
3293
=cut