DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3876 lines | 95.072kb
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1
use 5.008007;
cleanup
yuki-kimoto authored on 2009-12-22
2
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
4

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
5
our $VERSION = '0.23';
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/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21

            
packaging one directory
yuki-kimoto authored on 2009-11-16
22

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
23
has [qw/connector dsn password quote user exclude_table user_table_info
cleanup
Yuki Kimoto authored on 2012-01-20
24
     user_column_info safety_character/],
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
25
  async_conf => sub { {} },
cleanup
Yuki Kimoto authored on 2012-01-20
26
  cache => 0,
27
  cache_method => sub {
28
    sub {
29
      my $self = shift;
30
      $self->{_cached} ||= {};
31
      if (@_ > 1) { $self->{_cached}{$_[0]} = $_[1] }
32
      else { return $self->{_cached}{$_[0]} }
33
    }
34
  },
35
  option => sub { {} },
36
  default_option => sub {
37
    {
38
      RaiseError => 1,
39
      PrintError => 0,
40
      AutoCommit => 1
41
    }
42
  },
43
  filters => sub {
44
    {
45
      encode_utf8 => sub { encode_utf8($_[0]) },
46
      decode_utf8 => sub { decode_utf8($_[0]) }
47
    }
48
  },
49
  last_sql => '',
50
  models => sub { {} },
51
  now => sub {
52
    sub {
53
      my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
54
      $mon++;
55
      $year += 1900;
56
      my $now = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
57
        $year, $mon, $mday, $hour, $min, $sec);
58
      return $now;
59
    }
60
  },
61
  query_builder => sub {
62
    my $self = shift;
63
    my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
64
    weaken $builder->{dbi};
65
    return $builder;
66
  },
67
  result_class  => 'DBIx::Custom::Result',
68
  separator => '.',
69
  stash => sub { {} };
cleanup
yuki-kimoto authored on 2010-10-17
70

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
71
sub available_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
72
  my $self = shift;
73
  
74
  my $data_types = '';
75
  for my $i (-1000 .. 1000) {
76
     my $type_info = $self->dbh->type_info($i);
77
     my $data_type = $type_info->{DATA_TYPE};
78
     my $type_name = $type_info->{TYPE_NAME};
79
     $data_types .= "$data_type ($type_name)\n"
80
       if defined $data_type;
81
  }
82
  return "Data Type maybe equal to Type Name" unless $data_types;
83
  $data_types = "Data Type (Type name)\n" . $data_types;
84
  return $data_types;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
85
}
86

            
87
sub available_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
88
  my $self = shift;
89
  
90
  # Type Names
91
  my $type_names = {};
92
  $self->each_column(sub {
93
    my ($self, $table, $column, $column_info) = @_;
94
    $type_names->{$column_info->{TYPE_NAME}} = 1
95
      if $column_info->{TYPE_NAME};
96
  });
97
  my @output = sort keys %$type_names;
98
  unshift @output, "Type Name";
99
  return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
100
}
101

            
added helper method
yuki-kimoto authored on 2010-10-17
102
our $AUTOLOAD;
103
sub AUTOLOAD {
cleanup
Yuki Kimoto authored on 2012-01-20
104
  my $self = shift;
added helper method
yuki-kimoto authored on 2010-10-17
105

            
cleanup
Yuki Kimoto authored on 2012-01-20
106
  # Method name
107
  my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
108

            
cleanup
Yuki Kimoto authored on 2012-01-20
109
  # Call method
110
  $self->{_methods} ||= {};
111
  if (my $method = $self->{_methods}->{$mname}) {
112
    return $self->$method(@_)
113
  }
114
  elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
115
    $self->dbh->$dbh_method(@_);
116
  }
117
  else {
118
    croak qq{Can't locate object method "$mname" via "$package" }
119
      . _subname;
120
  }
added helper method
yuki-kimoto authored on 2010-10-17
121
}
122

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
123
sub assign_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
124
  my ($self, $param, $opts) = @_;
125
  
126
  my $wrap = $opts->{wrap} || {};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
127
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
128
  
129
  # Assign clause (performance is important)
130
  join(
131
    ', ',
132
    map {
133
      ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
134
      : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
135
      : "$q$_$p = :$_";
136
    } sort keys %$param
137
  );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
138
}
139

            
cleanup
Yuki Kimoto authored on 2011-03-21
140
sub column {
cleanup
Yuki Kimoto authored on 2012-01-20
141
  my $self = shift;
142
  my $option = pop if ref $_[-1] eq 'HASH';
143
  my $real_table = shift;
144
  my $columns = shift;
145
  my $table = $option->{alias} || $real_table;
146
  
147
  # Columns
148
  unless (defined $columns) {
149
    $columns ||= $self->model($real_table)->columns;
150
  }
151
  
152
  # Separator
153
  my $separator = $self->separator;
154
  
fixed test
Yuki Kimoto authored on 2012-03-01
155
  # . is replaced
improved test
Yuki Kimoto authored on 2012-03-01
156
  my $t = $table;
157
  $t =~ s/\./$separator/g;
fixed test
Yuki Kimoto authored on 2012-03-01
158
  
cleanup
Yuki Kimoto authored on 2012-01-20
159
  # Column clause
160
  my @column;
161
  $columns ||= [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
162
  push @column, $self->_tq($table) . "." . $self->q($_) .
improved test
Yuki Kimoto authored on 2012-03-01
163
    " as " . $self->q("${t}${separator}$_")
cleanup
Yuki Kimoto authored on 2012-01-20
164
    for @$columns;
165
  
166
  return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
167
}
168

            
packaging one directory
yuki-kimoto authored on 2009-11-16
169
sub connect {
cleanup
Yuki Kimoto authored on 2012-01-20
170
  my $self = ref $_[0] ? shift : shift->new(@_);
171
  
172
  my $connector = $self->connector;
173
  
174
  if (!ref $connector && $connector) {
175
    require DBIx::Connector;
176
    
177
    my $dsn = $self->dsn;
178
    my $user = $self->user;
179
    my $password = $self->password;
180
    my $option = $self->_option;
181
    my $connector = DBIx::Connector->new($dsn, $user, $password,
182
      {%{$self->default_option} , %$option});
183
    $self->connector($connector);
184
  }
185
  
186
  # Connect
187
  $self->dbh;
188
  
189
  return $self;
packaging one directory
yuki-kimoto authored on 2009-11-16
190
}
191

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
192
sub count { shift->select(column => 'count(*)', @_)->fetch_one->[0] }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
193

            
update pod
Yuki Kimoto authored on 2011-03-13
194
sub dbh {
cleanup
Yuki Kimoto authored on 2012-01-20
195
  my $self = shift;
196
  
197
  # Set
198
  if (@_) {
199
    $self->{dbh} = $_[0];
cleanup
Yuki Kimoto authored on 2011-04-02
200
    
cleanup
Yuki Kimoto authored on 2012-01-20
201
    return $self;
202
  }
203
  
204
  # Get
205
  else {
206
    # From Connction manager
207
    if (my $connector = $self->connector) {
208
      croak "connector must have dbh() method " . _subname
209
        unless ref $connector && $connector->can('dbh');
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
210
        
cleanup
Yuki Kimoto authored on 2012-01-20
211
      $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
212
    }
213
    
cleanup
Yuki Kimoto authored on 2012-01-20
214
    # Connect
215
    $self->{dbh} ||= $self->_connect;
216
    
217
    # Quote
218
    if (!defined $self->reserved_word_quote && !defined $self->quote) {
219
      my $driver = $self->_driver;
220
      my $quote =  $driver eq 'odbc' ? '[]'
221
        : $driver eq 'ado' ? '[]'
222
        : $driver eq 'mysql' ? '`'
223
        : '"';
224
      $self->quote($quote);
update pod
Yuki Kimoto authored on 2011-03-13
225
    }
cleanup
Yuki Kimoto authored on 2012-01-20
226
    
227
    return $self->{dbh};
228
  }
update pod
Yuki Kimoto authored on 2011-03-13
229
}
230

            
cleanup
Yuki Kimoto authored on 2011-10-21
231
sub delete {
cleanup
Yuki Kimoto authored on 2012-01-20
232
  my ($self, %opt) = @_;
233
  warn "delete method where_param option is DEPRECATED!"
234
    if $opt{where_param};
235
  
236
  # Don't allow delete all rows
237
  croak qq{delete method where or id option must be specified } . _subname
238
    if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
239
  
240
  # Where
241
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
242
    delete $opt{id}, $opt{primary_key}, $opt{table});
243

            
244
  # Delete statement
245
  my $sql = "delete ";
246
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
247
  $sql .= "from " . $self->_tq($opt{table}) . " $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
248
  
249
  # Execute query
250
  $opt{statement} = 'delete';
251
  $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
252
}
253

            
cleanup
Yuki Kimoto authored on 2011-11-01
254
sub delete_all { shift->delete(@_, allow_delete_all => 1) }
packaging one directory
yuki-kimoto authored on 2009-11-16
255

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
256
sub DESTROY {}
added helper method
yuki-kimoto authored on 2010-10-17
257

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

            
292
sub each_column {
cleanup
Yuki Kimoto authored on 2012-01-20
293
  my ($self, $cb, %options) = @_;
improved test
Yuki Kimoto authored on 2012-03-01
294
  
cleanup
Yuki Kimoto authored on 2012-01-20
295
  my $user_column_info = $self->user_column_info;
296
  
297
  if ($user_column_info) {
298
    $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
299
  }
300
  else {
301
    my $re = $self->exclude_table || $options{exclude_table};
302
    # Tables
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
303
    my $tables = {};
304
    $self->each_table(sub {
305
      my ($dbi, $table, $table_info) = @_;
306
      my $schema = $table_info->{TABLE_SCHEM};
307
      
308
      $tables->{$schema}{$table}++;
309
    });
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
310

            
cleanup
Yuki Kimoto authored on 2012-01-20
311
    # Iterate all tables
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
312
    for my $schema (sort keys %$tables) {
313
      for my $table (sort keys %{$tables->{$schema}}) {
314
        
315
        # Iterate all columns
316
        my $sth_columns;
317
        eval {$sth_columns = $self->dbh->column_info(undef, $schema, $table, '%')};
318
        next if $@;
319
        while (my $column_info = $sth_columns->fetchrow_hashref) {
cleanup
Yuki Kimoto authored on 2012-03-02
320
          $DB::single = 1;
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
321
          my $column = $column_info->{COLUMN_NAME};
322
          $self->$cb($table, $column, $column_info);
323
        }
cleanup
Yuki Kimoto authored on 2012-01-20
324
      }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
325
    }
cleanup
Yuki Kimoto authored on 2012-01-20
326
  }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
327
}
328

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
329
sub each_table {
cleanup
Yuki Kimoto authored on 2012-01-20
330
  my ($self, $cb, %option) = @_;
331
  
332
  my $user_table_infos = $self->user_table_info;
333
  
334
  # Iterate tables
335
  if ($user_table_infos) {
336
      $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
337
  }
338
  else {
339
    my $re = $self->exclude_table || $option{exclude};
340
    my $sth_tables = $self->dbh->table_info;
341
    while (my $table_info = $sth_tables->fetchrow_hashref) {
342
      # Table
343
      my $table = $table_info->{TABLE_NAME};
344
      next if defined $re && $table =~ /$re/;
345
      $self->$cb($table, $table_info);
346
    }
347
  }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
348
}
349

            
cleanup
Yuki Kimoto authored on 2011-04-02
350
sub execute {
cleanup
Yuki Kimoto authored on 2012-01-20
351
  my $self = shift;
352
  my $sql = shift;
353

            
354
  # Options
355
  my $params;
356
  $params = shift if @_ % 2;
357
  my %opt = @_;
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
358
  
359
  # Async query
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
360
  $opt{prepare_attr} = $self->async_conf->{prepare_attr} if $opt{async};
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
361
  if ($opt{async} && !$self->{_new_connection}) {
362
    my $dsn = $self->dsn;
363
    croak qq/Data source must be specified when "async" option is used/
364
      unless defined $dsn;
365
    
366
    my $user = $self->user;
367
    my $password = $self->password;
368
    my $option = $self->_option;
369
    
370
    my $new_dbi = bless {%$self}, ref $self;
371
    $new_dbi->connector(undef);
372
    $new_dbi->{dbh} = DBI->connect($dsn, $user, $password,
373
      {%{$new_dbi->default_option}, %$option});
374
    
375
    $new_dbi->{_new_connection} = 1;
376
    return $new_dbi->execute($sql, defined $params ? ($params) : (), %opt);
377
  }
378
  
379
  # Options
cleanup
Yuki Kimoto authored on 2012-01-20
380
  warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
381
  $params ||= $opt{param} || {};
382
  my $tables = $opt{table} || [];
383
  $tables = [$tables] unless ref $tables eq 'ARRAY';
384
  my $filter = ref $opt{filter} eq 'ARRAY' ?
385
    _array_to_hash($opt{filter}) : $opt{filter};
386
  
387
  # Merge second parameter
388
  my @cleanup;
389
  my $saved_param;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
390
  $opt{statement} ||= '';
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
391
  $opt{statement} = 'select' if $opt{select};
cleanup
Yuki Kimoto authored on 2012-01-20
392
  if (($opt{statement} || '') ne 'insert' && ref $params eq 'ARRAY') {
393
    my $params2 = $params->[1];
394
    $params = $params->[0];
395
    for my $column (keys %$params2) {
396
      if (!exists $params->{$column}) {
397
        $params->{$column} = $params2->{$column};
398
        push @cleanup, $column;
399
      }
400
      else {
401
        delete $params->{$_} for @cleanup;
402
        @cleanup = ();
403
        $saved_param  = $params;
404
        $params = $self->merge_param($params, $params2);
405
        delete $saved_param->{$_} for (@{$opt{cleanup} || []});
406
        last;
407
      }
408
    }
409
  }
410
  $params = [$params] unless ref $params eq 'ARRAY';
411
  
412
  # Append
413
  $sql .= $opt{append} if defined $opt{append} && !ref $sql;
414
  
415
  # Query
416
  my $query;
417
  if (ref $sql) {
418
    $query = $sql;
419
    warn "execute method receiving query object as first parameter is DEPRECATED!" .
420
      "because this is very buggy.";
421
  }
422
  else {
423
    $query = $opt{reuse}->{$sql} if $opt{reuse};
424
    unless ($query) {
425
      my $c = $self->{safety_character};
426
      # Check unsafety keys
427
      unless ((join('', keys %{$params->[0]}) || '') =~ /^[$c\.]+$/) {
428
        for my $column (keys %{$params->[0]}) {
429
          croak qq{"$column" is not safety column name } . _subname
430
            unless $column =~ /^[$c\.]+$/;
micro optimization
Yuki Kimoto authored on 2011-11-16
431
        }
cleanup
Yuki Kimoto authored on 2012-01-20
432
      }
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
433
      $query = $self->_create_query($sql,
434
        $opt{after_build_sql} || $opt{sqlfilter}, $opt{prepare_attr});
cleanup
Yuki Kimoto authored on 2012-01-20
435
    }
436
    $query->{statement} = $opt{statement} || '';
437
    $opt{reuse}->{$sql} = $query if $opt{reuse};
438
  }
439
      
440
  # Save query
441
  $self->{last_sql} = $query->{sql};
442

            
443
  # Return query
444
  if ($opt{query}) {
445
    for my $column (@cleanup, @{$opt{cleanup} || []}) {
446
      delete $_->{$column} for @$params;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
447
    }
cleanup
Yuki Kimoto authored on 2012-01-20
448
    return $query;
449
  };
450
  
451
  # Merge query filter(DEPRECATED!)
452
  $filter ||= $query->{filter} || {};
453
  
454
  # Tables
455
  unshift @$tables, @{$query->{tables} || []};
456
  my $main_table = @{$tables}[-1];
457

            
458
  # Merge id to parameter
459
  if (defined $opt{id}) {
460
    my $statement = $query->{statement};
461
    warn "execute method id option is DEPRECATED!" unless $statement;
462
    croak "execute id option must be specified with primary_key option"
463
      unless $opt{primary_key};
464
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
465
    $opt{id} = [$opt{id}] unless ref $opt{id};
466
    for (my $i = 0; $i < @{$opt{id}}; $i++) {
467
      my $key = $opt{primary_key}->[$i];
468
      $key = "$main_table.$key" if $statement eq 'update' ||
469
        $statement eq 'delete' || $statement eq 'select';
470
      next if exists $params->[0]->{$key};
471
      $params->[0]->{$key} = $opt{id}->[$i];
472
      push @cleanup, $key;1
473
    }
474
  }
475
  
476
  # Cleanup tables(DEPRECATED!)
477
  $tables = $self->_remove_duplicate_table($tables, $main_table)
478
    if @$tables > 1;
479
  
480
  # Type rule
481
  my $type_filters = {};
482
  my $type_rule_off = !$self->{_type_rule_is_called} || $opt{type_rule_off};
483
  unless ($type_rule_off) {
484
    my $type_rule_off_parts = {
485
      1 => $opt{type_rule1_off},
486
      2 => $opt{type_rule2_off}
cleanup
Yuki Kimoto authored on 2011-11-16
487
    };
cleanup
Yuki Kimoto authored on 2012-01-20
488
    for my $i (1, 2) {
489
      unless ($type_rule_off_parts->{$i}) {
490
        $type_filters->{$i} = {};
491
        my $table_alias = $opt{table_alias} || {};
492
        for my $alias (keys %$table_alias) {
493
          my $table = $table_alias->{$alias};
494
          
495
          for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
496
            $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
497
          }
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
498
        }
cleanup
Yuki Kimoto authored on 2012-01-20
499
        $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
500
          if $main_table;
501
      }
502
    }
503
  }
504
  
505
  # Applied filter(DEPRECATED!)
506
  if ($self->{filter}{on}) {
507
    my $applied_filter = {};
508
    for my $table (@$tables) {
509
      $applied_filter = {
510
        %$applied_filter,
511
        %{$self->{filter}{out}->{$table} || {}}
512
      }
513
    }
514
    $filter = {%$applied_filter, %$filter};
515
  }
516
  
517
  # Replace filter name to code
518
  for my $column (keys %$filter) {
519
    my $name = $filter->{$column};
520
    if (!defined $name) {
521
      $filter->{$column} = undef;
522
    }
523
    elsif (ref $name ne 'CODE') {
524
      croak qq{Filter "$name" is not registered" } . _subname
525
        unless exists $self->filters->{$name};
526
      $filter->{$column} = $self->filters->{$name};
527
    }
528
  }
529

            
530
  # Execute
531
  my $sth = $query->{sth};
532
  my $affected;
533
  if ((!$query->{duplicate} || $opt{bulk_insert}) && $type_rule_off
534
    && !keys %$filter && !$self->{default_out_filter}
535
    && !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
536
  {
537
    eval {
538
      if ($opt{bulk_insert}) {
539
        my %count;
540
        my $param = $params->[0];
541
        $affected = $sth->execute(map { $param->{$_}->[++$count{$_} - 1] }
542
          @{$query->{columns}});
543
      }
544
      else {
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
545
        for my $param (@$params) {
cleanup
Yuki Kimoto authored on 2012-01-20
546
          $affected = $sth->execute(map { $param->{$_} }
547
            @{$query->{columns}});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
548
        }
cleanup
Yuki Kimoto authored on 2012-01-20
549
      }
550
    };
551
  }
552
  else {
553
    for my $param (@$params) {
554
      # Create bind values
555
      my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
556
        $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
557

            
558
      # Execute
559
      eval {
560
        if ($opt{bind_type} || $opt{type}) {
561
          $sth->bind_param($_ + 1, $bind->[$_],
562
              $bind_types->[$_] ? $bind_types->[$_] : ())
563
            for (0 .. @$bind - 1);
564
          $affected = $sth->execute;
cleanup
Yuki Kimoto authored on 2011-01-12
565
        }
cleanup
Yuki Kimoto authored on 2012-01-20
566
        else { $affected = $sth->execute(@$bind) }
567

            
568
        # DEBUG message
569
        if ($ENV{DBIX_CUSTOM_DEBUG}) {
570
          warn "SQL:\n" . $query->{sql} . "\n";
571
          my @output;
572
          for my $value (@$bind) {
573
            $value = 'undef' unless defined $value;
574
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
575
              if utf8::is_utf8($value);
576
            push @output, $value;
577
          }
578
          warn "Bind values: " . join(', ', @output) . "\n\n";
579
        }
580
      };
581
    }
582
  }
583
  
584
  $self->_croak($@, qq{. Following SQL is executed.\n}
585
    . qq{$query->{sql}\n} . _subname) if $@;
586

            
587
  # Remove id from parameter
588
  for my $column (@cleanup, @{$opt{cleanup} || []}) {
589
    delete $_->{$column} for @$params;
590
  }
591
  
592
  # Not select statement
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
593
  return $affected if !$sth->{NUM_OF_FIELDS} && $opt{statement} ne 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
594

            
595
  # Filter(DEPRECATED!)
596
  my $infilter = {};
597
  if ($self->{filter}{on}) {
598
    $infilter->{in}  = {};
599
    $infilter->{end} = {};
600
    push @$tables, $main_table if $main_table;
601
    for my $table (@$tables) {
602
      for my $way (qw/in end/) {
603
        $infilter->{$way} = {%{$infilter->{$way}},
604
          %{$self->{filter}{$way}{$table} || {}}};
605
      }
606
    }
607
  }
608
  
609
  # Result
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
610
  my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2012-01-20
611
    sth => $sth,
612
    dbi => $self,
613
    default_filter => $self->{default_in_filter},
614
    filter => $infilter->{in} || {},
615
    end_filter => $infilter->{end} || {},
616
    type_rule => {
617
      from1 => $self->type_rule->{from1},
618
      from2 => $self->type_rule->{from2}
619
    },
620
  );
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
621
  
622
  if (my $cb = $opt{async}) {
623
    require AnyEvent;
624
    my $watcher;
625
    weaken $self;
626
    $watcher = AnyEvent->io(
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
627
      fh => $self->async_conf->{fh}->($self),
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
628
      poll => 'r',
629
      cb   => sub {
630
        $cb->($self, $result);
select method can be called ...
Yuki Kimoto authored on 2012-02-07
631
        undef $watcher;
632
        undef $result;
633
        undef $cb;
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
634
      },
635
    );
636
  }
637
  else { $result }
cleanup
yuki-kimoto authored on 2010-10-17
638
}
639

            
added test
Yuki Kimoto authored on 2011-08-16
640
sub get_table_info {
cleanup
Yuki Kimoto authored on 2012-01-20
641
  my ($self, %opt) = @_;
642
  
643
  my $exclude = delete $opt{exclude};
644
  croak qq/"$_" is wrong option/ for keys %opt;
645
  
646
  my $table_info = [];
647
  $self->each_table(
648
    sub { push @$table_info, {table => $_[1], info => $_[2] } },
649
    exclude => $exclude
650
  );
651
  
652
  return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
653
}
654

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
655
sub get_column_info {
cleanup
Yuki Kimoto authored on 2012-01-20
656
  my ($self, %opt) = @_;
657
  
658
  my $exclude_table = delete $opt{exclude_table};
659
  croak qq/"$_" is wrong option/ for keys %opt;
660
  
661
  my $column_info = [];
662
  $self->each_column(
663
    sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
664
    exclude_table => $exclude_table
665
  );
666
  
667
  return [
668
    sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
669
      @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
670
}
671

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
672
sub helper {
cleanup
Yuki Kimoto authored on 2012-01-20
673
  my $self = shift;
674
  
675
  # Register method
676
  my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
677
  $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
678
  
679
  return $self;
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
680
}
681

            
cleanup
yuki-kimoto authored on 2010-10-17
682
sub insert {
cleanup
Yuki Kimoto authored on 2012-01-20
683
  my $self = shift;
684
  
685
  # Options
686
  my $params = @_ % 2 ? shift : undef;
687
  my %opt = @_;
688
  warn "insert method param option is DEPRECATED!" if $opt{param};
689
  $params ||= delete $opt{param} || {};
690
  
691
  my $multi;
692
  if (ref $params eq 'ARRAY') { $multi = 1 }
693
  else { $params = [$params] }
694
  
695
  # Timestamp(DEPRECATED!)
696
  if (!$multi && $opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
697
    warn "insert timestamp option is DEPRECATED! use ctime option";
cleanup
Yuki Kimoto authored on 2012-01-20
698
    my $columns = $insert_timestamp->[0];
699
    $columns = [$columns] unless ref $columns eq 'ARRAY';
700
    my $value = $insert_timestamp->[1];
701
    $value = $value->() if ref $value eq 'CODE';
702
    $params->[0]->{$_} = $value for @$columns;
703
  }
704

            
705
  # Created time and updated time
706
  my @timestamp_cleanup;
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
707
  warn "insert method created_at option is DEPRECATED! "
708
      . "use ctime option instead. " . _subname
709
    if $opt{created_at};
710
  warn "insert method updated_at option is DEPRECATED! "
711
      . "use mtime option instead. " . _subname
712
    if $opt{updated_at};
713
  $opt{ctime} ||= $opt{created_at};
714
  $opt{mtime} ||= $opt{updated_at};
715
  if (defined $opt{ctime} || defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
716
    my $now = $self->now;
717
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
718
    if (defined $opt{ctime}) {
719
      $_->{$opt{ctime}} = $now for @$params;
720
      push @timestamp_cleanup, $opt{ctime};
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
721
    }
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
722
    if (defined $opt{mtime}) {
723
      $_->{$opt{mtime}} = $now for @$params;
724
      push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
725
    }
726
  }
727
  
728
  # Merge id to parameter
729
  my @cleanup;
730
  my $id_param = {};
731
  if (defined $opt{id} && !$multi) {
732
    croak "insert id option must be specified with primary_key option"
733
      unless $opt{primary_key};
734
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
735
    $opt{id} = [$opt{id}] unless ref $opt{id};
736
    for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
737
      my $key = $opt{primary_key}->[$i];
738
      next if exists $params->[0]->{$key};
739
      $params->[0]->{$key} = $opt{id}->[$i];
740
      push @cleanup, $key;
741
    }
742
  }
743
  
744
  # Insert statement
745
  my $sql = "insert ";
746
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
747
  $sql .= "into " . $self->_tq($opt{table}) . " ";
cleanup
Yuki Kimoto authored on 2012-01-20
748
  if ($opt{bulk_insert}) {
749
    $sql .= $self->_multi_values_clause($params, {wrap => $opt{wrap}}) . " ";
750
    my $new_param = {};
751
    $new_param->{$_} = [] for keys %{$params->[0]};
752
    for my $param (@$params) {
753
      push @{$new_param->{$_}}, $param->{$_} for keys %$param;
754
    }
755
    $params = [$new_param];
756
  }
757
  else {
758
    $sql .= $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " ";
759
  }
760

            
761
  # Remove id from parameter
762
  delete $params->[0]->{$_} for @cleanup;
763
  
764
  # Execute query
765
  $opt{statement} = 'insert';
766
  $opt{cleanup} = \@timestamp_cleanup;
767
  $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
768
}
769

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
770
sub insert_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
771
  my $self = shift;
772
  
773
  warn "insert_timestamp method is DEPRECATED! use now attribute";
774
  
775
  if (@_) {
776
    $self->{insert_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
777
    
cleanup
Yuki Kimoto authored on 2012-01-20
778
    return $self;
779
  }
780
  return $self->{insert_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
781
}
782

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
783
sub include_model {
cleanup
Yuki Kimoto authored on 2012-01-20
784
  my ($self, $name_space, $model_infos) = @_;
785
  
786
  # Name space
787
  $name_space ||= '';
788
  
789
  # Get Model infomations
790
  unless ($model_infos) {
791

            
792
    # Load name space module
793
    croak qq{"$name_space" is invalid class name } . _subname
794
      if $name_space =~ /[^\w:]/;
795
    eval "use $name_space";
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
796
    croak qq{Name space module "$name_space.pm" is needed. $@ } . _subname
cleanup
Yuki Kimoto authored on 2012-01-20
797
      if $@;
798
    
799
    # Search model modules
800
    my $path = $INC{"$name_space.pm"};
801
    $path =~ s/\.pm$//;
802
    opendir my $dh, $path
803
      or croak qq{Can't open directory "$path": $! } . _subname
support model full-qualified...
Yuki Kimoto authored on 2012-03-01
804
    my @modules;
805
    while (my $file = readdir $dh) {
806
      my $file_abs = "$path/$file";
807
      if (-d $file_abs) {
808
        next if $file eq '.' || $file eq '..';
809
        opendir my $fq_dh, $file_abs
810
          or croak qq{Can't open directory "$file_abs": $! } . _subname;
811
        while (my $fq_file = readdir $fq_dh) {
812
          my $fq_file_abs = "$file_abs/$fq_file";
813
          push @modules, "${file}::$fq_file" if -f $fq_file_abs;
814
        }
815
        close $fq_dh;
816
      }
817
      elsif(-f $file_abs) { push @modules, $file }
cleanup
Yuki Kimoto authored on 2012-01-20
818
    }
819
    close $dh;
support model full-qualified...
Yuki Kimoto authored on 2012-03-01
820
    
821
    $model_infos = [];
822
    for my $module (@modules) {
823
      if ($module =~ s/\.pm$//) { push @$model_infos, $module }
824
    }
cleanup
Yuki Kimoto authored on 2012-01-20
825
  }
826
  
827
  # Include models
828
  for my $model_info (@$model_infos) {
829
    
830
    # Load model
831
    my $model_class;
832
    my $model_name;
833
    my $model_table;
834
    if (ref $model_info eq 'HASH') {
835
      $model_class = $model_info->{class};
836
      $model_name  = $model_info->{name};
837
      $model_table = $model_info->{table};
838
      
839
      $model_name  ||= $model_class;
840
      $model_table ||= $model_name;
841
    }
support model full-qualified...
Yuki Kimoto authored on 2012-03-01
842
    else {
843
      $model_class = $model_name = $model_table = $model_info;
844
    }
improved test
Yuki Kimoto authored on 2012-03-01
845

            
846
    $model_class =~ s/\./::/g;
847
    $model_name =~ s/::/./;
848
    $model_table =~ s/::/./;
849

            
cleanup
Yuki Kimoto authored on 2012-01-20
850
    my $mclass = "${name_space}::$model_class";
851
    croak qq{"$mclass" is invalid class name } . _subname
852
      if $mclass =~ /[^\w:]/;
853
    unless ($mclass->can('isa')) {
854
      eval "use $mclass";
855
      croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
856
    }
857
    
cleanup
Yuki Kimoto authored on 2012-01-20
858
    # Create model
859
    my $opt = {};
860
    $opt->{model_class} = $mclass if $mclass;
861
    $opt->{name}        = $model_name if $model_name;
862
    $opt->{table}       = $model_table if $model_table;
863
    $self->create_model($opt);
864
  }
865
  
866
  return $self;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
867
}
868

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
869
sub like_value { sub { "%$_[0]%" } }
870

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
871
sub mapper {
cleanup
Yuki Kimoto authored on 2012-01-20
872
  my $self = shift;
873
  return DBIx::Custom::Mapper->new(@_);
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
874
}
875

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
876
sub merge_param {
cleanup
Yuki Kimoto authored on 2012-01-20
877
  my ($self, @params) = @_;
878
  
879
  # Merge parameters
880
  my $merge = {};
881
  for my $param (@params) {
882
    for my $column (keys %$param) {
883
      my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
884
      
885
      if (exists $merge->{$column}) {
886
        $merge->{$column} = [$merge->{$column}]
887
          unless ref $merge->{$column} eq 'ARRAY';
888
        push @{$merge->{$column}},
889
          ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
890
      }
891
      else { $merge->{$column} = $param->{$column} }
892
    }
893
  }
894
  
895
  return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
896
}
897

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
898
sub model {
cleanup
Yuki Kimoto authored on 2012-01-20
899
  my ($self, $name, $model) = @_;
900
  
901
  # Set model
902
  if ($model) {
903
    $self->models->{$name} = $model;
904
    return $self;
905
  }
906
  
907
  # Check model existance
908
  croak qq{Model "$name" is not included } . _subname
909
    unless $self->models->{$name};
910
  
911
  # Get model
912
  return $self->models->{$name};
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
913
}
914

            
cleanup
Yuki Kimoto authored on 2011-03-21
915
sub mycolumn {
cleanup
Yuki Kimoto authored on 2012-01-20
916
  my ($self, $table, $columns) = @_;
917
  
918
  # Create column clause
919
  my @column;
920
  $columns ||= [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
921
  push @column, $self->_tq($table) . "." . $self->q($_) . " as " . $self->q($_)
cleanup
Yuki Kimoto authored on 2012-01-20
922
    for @$columns;
923
  
924
  return join (', ', @column);
cleanup
Yuki Kimoto authored on 2011-03-21
925
}
926

            
added dbi_options attribute
kimoto authored on 2010-12-20
927
sub new {
cleanup
Yuki Kimoto authored on 2012-01-20
928
  my $self = shift->SUPER::new(@_);
929
  
930
  # Check attributes
931
  my @attrs = keys %$self;
932
  for my $attr (@attrs) {
933
    croak qq{Invalid attribute: "$attr" } . _subname
934
      unless $self->can($attr);
935
  }
936
  
937
  $self->{safety_character} = 'a-zA-Z0-9_'
938
    unless exists $self->{safety_character};
939

            
940
  # DEPRECATED
941
  $self->{_tags} = {
942
    '?'     => \&DBIx::Custom::Tag::placeholder,
943
    '='     => \&DBIx::Custom::Tag::equal,
944
    '<>'    => \&DBIx::Custom::Tag::not_equal,
945
    '>'     => \&DBIx::Custom::Tag::greater_than,
946
    '<'     => \&DBIx::Custom::Tag::lower_than,
947
    '>='    => \&DBIx::Custom::Tag::greater_than_equal,
948
    '<='    => \&DBIx::Custom::Tag::lower_than_equal,
949
    'like'  => \&DBIx::Custom::Tag::like,
950
    'in'    => \&DBIx::Custom::Tag::in,
951
    'insert_param' => \&DBIx::Custom::Tag::insert_param,
952
    'update_param' => \&DBIx::Custom::Tag::update_param
953
  };
954
  $self->{tag_parse} = 1 unless exists $self->{tag_parse};
955
  $self->{cache} = 0 unless exists $self->{cache};
956
  
957
  return $self;
cleanup
Yuki Kimoto authored on 2011-08-13
958
}
959

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
960
sub not_exists { DBIx::Custom::NotExists->singleton }
cleanup
Yuki Kimoto authored on 2011-08-13
961

            
962
sub order {
cleanup
Yuki Kimoto authored on 2012-01-20
963
  my $self = shift;
964
  return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
965
}
966

            
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
967
sub q { shift->_tq($_[0], $_[1], whole => 1) }
968

            
969
sub _tq {
970
  my ($self, $value, $quotemeta, %opt) = @_;
cleanup
Yuki Kimoto authored on 2012-01-20
971
  
972
  my $quote = $self->{reserved_word_quote}
973
    || $self->{quote} || $self->quote || '';
974
  
975
  my $q = substr($quote, 0, 1) || '';
976
  my $p;
977
  if (defined $quote && length $quote > 1) {
978
    $p = substr($quote, 1, 1);
979
  }
980
  else { $p = $q }
981
  
982
  if ($quotemeta) {
983
    $q = quotemeta($q);
984
    $p = quotemeta($p);
985
  }
986
  
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
987
  if ($opt{whole}) { return "$q$value$p" }
988
  else {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
989
    my @values = split /\./, $value;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
990
    push @values, '' unless @values;
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
991
    for my $v (@values) { $v = "$q$v$p" }
992
    return join '.', @values;
993
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
994
}
995

            
996
sub _qp {
997
  my ($self, %opt) = @_;
998

            
999
  my $quote = $self->{reserved_word_quote}
1000
    || $self->{quote} || $self->quote || '';
1001
  
1002
  my $q = substr($quote, 0, 1) || '';
1003
  my $p;
1004
  if (defined $quote && length $quote > 1) {
1005
    $p = substr($quote, 1, 1);
1006
  }
1007
  else { $p = $q }
1008
  
1009
  if ($opt{quotemeta}) {
1010
    $q = quotemeta($q);
1011
    $p = quotemeta($p);
1012
  }
1013
  
1014
  return ($q, $p);
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1015
}
1016

            
cleanup
yuki-kimoto authored on 2010-10-17
1017
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1018
  my $self = shift;
1019
  
1020
  # Register filter
1021
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1022
  $self->filters({%{$self->filters}, %$filters});
1023
  
1024
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
1025
}
packaging one directory
yuki-kimoto authored on 2009-11-16
1026

            
1027
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
1028
  my $self = shift;
1029
  my $column = shift if @_ % 2;
1030
  my %opt = @_;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1031
  $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
1032
  $opt{column} = $column if defined $column;
1033

            
1034
  # Options
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1035
  my $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1036
  my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
1037
    : defined $opt{table} ? [$opt{table}]
1038
    : [];
1039
  $opt{table} = $tables;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1040
  $table_is_empty = 1 unless @$tables;
cleanup
Yuki Kimoto authored on 2012-01-20
1041
  my $where_param = $opt{where_param} || delete $opt{param} || {};
1042
  warn "select method where_param option is DEPRECATED!"
1043
    if $opt{where_param};
1044
  
1045
  # Add relation tables(DEPRECATED!);
1046
  if ($opt{relation}) {
1047
    warn "select() relation option is DEPRECATED!";
1048
    $self->_add_relation_table($tables, $opt{relation});
1049
  }
1050
  
1051
  # Select statement
1052
  my $sql = 'select ';
1053
  
1054
  # Prefix
1055
  $sql .= "$opt{prefix} " if defined $opt{prefix};
1056
  
1057
  # Column
1058
  if (defined $opt{column}) {
1059
    my $columns
1060
      = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
1061
    for my $column (@$columns) {
1062
      if (ref $column eq 'HASH') {
1063
        $column = $self->column(%$column) if ref $column eq 'HASH';
1064
      }
1065
      elsif (ref $column eq 'ARRAY') {
1066
        warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
1067
          "use q method to quote the value";
1068
        if (@$column == 3 && $column->[1] eq 'as') {
1069
          warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
1070
          splice @$column, 1, 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1071
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1072
        
1073
        $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
1074
      }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1075
      unshift @$tables, @{$self->_search_tables($column)}
1076
        unless $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1077
      $sql .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
1078
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1079
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2012-01-20
1080
  }
1081
  else { $sql .= '* ' }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1082

            
1083
  # Execute query without table
1084
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1085

            
cleanup
Yuki Kimoto authored on 2012-01-20
1086
  # Table
1087
  $sql .= 'from ';
1088
  if ($opt{relation}) {
1089
    my $found = {};
1090
    for my $table (@$tables) {
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1091
      $sql .= $self->_tq($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2012-01-20
1092
      $found->{$table} = 1;
1093
    }
1094
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1095
  else { $sql .= $self->_tq($tables->[-1] || '') . ' ' }
cleanup
Yuki Kimoto authored on 2012-01-20
1096
  $sql =~ s/, $/ /;
1097

            
1098
  # Add tables in parameter
1099
  unshift @$tables,
1100
    @{$self->_search_tables(join(' ', keys %$where_param) || '')};
1101
  
1102
  # Where
1103
  my $w = $self->_where_clause_and_param($opt{where}, $where_param,
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1104
    delete $opt{id}, $opt{primary_key}, @$tables ? $tables->[-1] : undef);
cleanup
Yuki Kimoto authored on 2012-01-20
1105
  
1106
  # Add table names in where clause
1107
  unshift @$tables, @{$self->_search_tables($w->{clause})};
1108
  
1109
  # Join statement
1110
  $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
1111
  
1112
  # Add where clause
1113
  $sql .= "$w->{clause} ";
1114
  
1115
  # Relation(DEPRECATED!);
1116
  $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
1117
    if $opt{relation};
1118
  
1119
  # Execute query
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1120
  return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
1121
}
1122

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1123
sub setup_model {
improved test
Yuki Kimoto authored on 2012-03-01
1124
  my ($self, %opt) = @_;
cleanup
Yuki Kimoto authored on 2012-01-20
1125
  
1126
  # Setup model
1127
  $self->each_column(
1128
    sub {
1129
      my ($self, $table, $column, $column_info) = @_;
cleanup
Yuki Kimoto authored on 2012-03-02
1130
      my $schema = $column_info->{TABLE_SCHEM};
1131
      return if exists $opt{database} && $opt{database} ne $schema;
improved test
Yuki Kimoto authored on 2012-03-01
1132
      
cleanup
Yuki Kimoto authored on 2012-03-02
1133
      $table = "$schema.$table" if exists $opt{prefix};
cleanup
Yuki Kimoto authored on 2012-01-20
1134
      if (my $model = $self->models->{$table}) {
1135
        push @{$model->columns}, $column;
1136
      }
1137
    }
1138
  );
1139
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1140
}
1141

            
update pod
Yuki Kimoto authored on 2011-08-10
1142
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1143
  my ($self, $table) = @_;
1144
  croak "Table name must be specified" unless defined $table;
1145
  print "$table\n";
1146
  
1147
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1148
  my $sth = $result->sth;
1149

            
1150
  my $columns = $sth->{NAME};
1151
  my $data_types = $sth->{TYPE};
1152
  
1153
  for (my $i = 0; $i < @$columns; $i++) {
1154
    my $column = $columns->[$i];
1155
    my $data_type = lc $data_types->[$i];
1156
    print "$column: $data_type\n";
1157
  }
update pod
Yuki Kimoto authored on 2011-08-10
1158
}
1159

            
1160
sub show_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
1161
  my ($self, $t) = @_;
1162
  croak "Table name must be specified" unless defined $t;
1163
  print "$t\n";
1164
  
1165
  $self->each_column(sub {
1166
    my ($self, $table, $column, $infos) = @_;
1167
    return unless $table eq $t;
1168
    my $typename = lc $infos->{TYPE_NAME};
1169
    print "$column: $typename\n";
1170
  });
1171
  
1172
  return $self;
update pod
Yuki Kimoto authored on 2011-08-10
1173
}
1174

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1175
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1176
  my $self = shift;
1177
  
1178
  my %tables;
1179
  $self->each_table(sub { $tables{$_[1]}++ });
1180
  print join("\n", sort keys %tables) . "\n";
1181
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1182
}
1183

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1184
sub type_rule {
cleanup
Yuki Kimoto authored on 2012-01-20
1185
  my $self = shift;
1186

            
1187
  $self->{_type_rule_is_called} = 1;
1188
  
1189
  if (@_) {
1190
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1191
    
1192
    # Into
1193
    for my $i (1 .. 2) {
1194
      my $into = "into$i";
1195
      my $exists_into = exists $type_rule->{$into};
1196
      $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1197
      $self->{type_rule} = $type_rule;
1198
      $self->{"_$into"} = {};
1199
      for my $type_name (keys %{$type_rule->{$into} || {}}) {
1200
        croak qq{type name of $into section must be lower case}
1201
          if $type_name =~ /[A-Z]/;
1202
      }
1203
      
1204
      $self->each_column(sub {
1205
        my ($dbi, $table, $column, $column_info) = @_;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1206
        
cleanup
Yuki Kimoto authored on 2012-01-20
1207
        my $type_name = lc $column_info->{TYPE_NAME};
1208
        if ($type_rule->{$into} &&
1209
            (my $filter = $type_rule->{$into}->{$type_name}))
1210
        {
1211
          return unless exists $type_rule->{$into}->{$type_name};
1212
          if (defined $filter && ref $filter ne 'CODE') 
1213
          {
1214
            my $fname = $filter;
1215
            croak qq{Filter "$fname" is not registered" } . _subname
1216
              unless exists $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-08-16
1217
            
cleanup
Yuki Kimoto authored on 2012-01-20
1218
            $filter = $self->filters->{$fname};
1219
          }
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
1220
          
cleanup
Yuki Kimoto authored on 2012-03-02
1221
          my $schema = $column_info->{TABLE_SCHEM};
cleanup
Yuki Kimoto authored on 2012-01-20
1222
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1223
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
cleanup
Yuki Kimoto authored on 2012-03-02
1224
          $self->{"_$into"}{key}{"$schema.$table"}{$column} = $filter;
1225
          $self->{"_$into"}{dot}{"$schema.$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1226
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1227
      });
1228
    }
1229

            
1230
    # From
1231
    for my $i (1 .. 2) {
1232
      $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1233
      for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1234
        croak qq{data type of from$i section must be lower case or number}
1235
          if $data_type =~ /[A-Z]/;
1236
        my $fname = $type_rule->{"from$i"}{$data_type};
1237
        if (defined $fname && ref $fname ne 'CODE') {
1238
          croak qq{Filter "$fname" is not registered" } . _subname
1239
            unless exists $self->filters->{$fname};
1240
          
1241
          $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
1242
        }
1243
      }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1244
    }
1245
    
cleanup
Yuki Kimoto authored on 2012-01-20
1246
    return $self;
1247
  }
1248
  
1249
  return $self->{type_rule} || {};
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1250
}
1251

            
cleanup
yuki-kimoto authored on 2010-10-17
1252
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1253
  my $self = shift;
1254

            
1255
  # Options
1256
  my $param = @_ % 2 ? shift : undef;
1257
  my %opt = @_;
1258
  warn "update param option is DEPRECATED!" if $opt{param};
1259
  warn "update method where_param option is DEPRECATED!"
1260
    if $opt{where_param};
1261
  $param ||= $opt{param} || {};
1262
  
1263
  # Don't allow update all rows
1264
  croak qq{update method where option must be specified } . _subname
1265
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1266
  
1267
  # Timestamp(DEPRECATED!)
1268
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1269
    warn "update timestamp option is DEPRECATED! use mtime";
cleanup
Yuki Kimoto authored on 2012-01-20
1270
    my $columns = $update_timestamp->[0];
1271
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1272
    my $value = $update_timestamp->[1];
1273
    $value = $value->() if ref $value eq 'CODE';
1274
    $param->{$_} = $value for @$columns;
1275
  }
1276

            
1277
  # Created time and updated time
1278
  my @timestamp_cleanup;
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1279
  warn "update method update_at option is DEPRECATED! "
1280
      . "use mtime option instead " . _subname
1281
    if $opt{updated_at};
1282
  $opt{mtime} ||= $opt{updated_at};
1283
  if (defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
1284
    my $now = $self->now;
1285
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1286
    $param->{$opt{mtime}} = $self->now->();
1287
    push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
1288
  }
1289

            
1290
  # Assign clause
1291
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1292
  
1293
  # Where
1294
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1295
    delete $opt{id}, $opt{primary_key}, $opt{table});
1296
  
1297
  # Update statement
1298
  my $sql = "update ";
1299
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1300
  $sql .= $self->_tq($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
1301
  
1302
  # Execute query
1303
  $opt{statement} = 'update';
1304
  $opt{cleanup} = \@timestamp_cleanup;
1305
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1306
}
1307

            
cleanup
Yuki Kimoto authored on 2011-11-01
1308
sub update_all { shift->update(@_, allow_update_all => 1) };
cleanup
yuki-kimoto authored on 2010-10-17
1309

            
cleanup
Yuki Kimoto authored on 2011-10-21
1310
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1311
  my ($self, $param, %opt) = @_;
1312
  croak "update_or_insert method need primary_key and id option "
1313
    unless defined $opt{id} && defined $opt{primary_key};
1314
  my $statement_opt = $opt{option} || {};
1315

            
1316
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1317
  if (@$rows == 0) {
1318
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1319
  }
1320
  elsif (@$rows == 1) {
1321
    return 0 unless keys %$param;
1322
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1323
  }
1324
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1325
}
1326

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1327
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1328
  my $self = shift;
1329
  
1330
  warn "update_timestamp method is DEPRECATED! use now method";
1331
  
1332
  if (@_) {
1333
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1334
    
cleanup
Yuki Kimoto authored on 2012-01-20
1335
    return $self;
1336
  }
1337
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1338
}
1339

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1340
sub values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1341
  my ($self, $param, $opts) = @_;
1342
  
1343
  my $wrap = $opts->{wrap} || {};
1344
  
1345
  # Create insert parameter tag
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1346
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
1347
  
1348
  # values clause(performance is important)
1349
  '(' .
1350
  join(
1351
    ', ',
1352
    map { "$q$_$p" } sort keys %$param
1353
  ) .
1354
  ') values (' .
1355
  join(
1356
    ', ',
1357
    map {
1358
      ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1359
      $wrap->{$_} ? $wrap->{$_}->(":$_") :
1360
      ":$_";
1361
    } sort keys %$param
1362
  ) .
1363
  ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1364
}
1365

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1366
sub _multi_values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1367
  my ($self, $params, $opts) = @_;
1368
  
1369
  my $wrap = $opts->{wrap} || {};
1370
  
1371
  # Create insert parameter tag
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1372
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
1373
  
1374
  # Multi values clause
1375
  my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1376
  
1377
  for (1 .. @$params) {
1378
    $clause .= '(' . join(', ', 
1379
      map {
1380
        ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1381
        $wrap->{$_} ? $wrap->{$_}->(":$_") :
1382
        ":$_";
1383
      } sort keys %{$params->[0]}
1384
    ) . '), '
1385
  }
1386
  $clause =~ s/, $//;
1387
  return $clause;
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1388
}
1389

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1392
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1393
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1394
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1395
  
1396
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1397
  
1398
  # Cache
1399
  my $cache = $self->{cache};
1400
  
1401
  # Query
1402
  my $query;
1403
  
1404
  # Get cached query
1405
  if ($cache) {
1406
    
1407
    # Get query
1408
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1409
    
1410
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1411
    if ($q) {
1412
      $query = DBIx::Custom::Query->new($q);
1413
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1414
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1415
  }
1416
  
1417
  # Create query
1418
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1419

            
cleanup
Yuki Kimoto authored on 2012-01-20
1420
    # Create query
1421
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1422
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1423

            
1424
    my $sql = " " . $source || '';
1425
    if ($tag_parse && ($sql =~ /\s\{/)) {
1426
      $query = $self->query_builder->build_query($sql);
updated pod
Yuki Kimoto authored on 2011-06-21
1427
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1428
    else {
1429
      my @columns;
1430
      my $c = $self->{safety_character};
1431
      my $re = $c eq 'a-zA-Z0-9_'
1432
        ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1433
        : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
1434
      my %duplicate;
1435
      my $duplicate;
1436
      # Parameter regex
1437
      $sql =~ s/([0-9]):/$1\\:/g;
1438
      my $new_sql = '';
1439
      while ($sql =~ /$re/) {
1440
        push @columns, $2;
1441
        $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1442
        ($new_sql, $sql) = defined $3 ?
1443
          ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
1444
      }
1445
      $new_sql .= $sql;
1446
      $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
1447

            
1448
      # Create query
1449
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1450
    }
1451
    
1452
    # Save query to cache
1453
    $self->cache_method->(
1454
      $self, $source,
1455
      {
1456
        sql     => $query->{sql}, 
1457
        columns => $query->{columns},
1458
        tables  => $query->{tables} || []
1459
      }
1460
    ) if $cache;
1461
  }
1462

            
1463
  # Filter SQL
1464
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1465
  
1466
  # Save sql
1467
  $self->{last_sql} = $query->{sql};
1468
  
1469
  # Prepare statement handle
1470
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1471
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1472
  
1473
  if ($@) {
1474
    $self->_croak($@, qq{. Following SQL is executed.\n}
1475
                    . qq{$query->{sql}\n} . _subname);
1476
  }
1477
  
1478
  # Set statement handle
1479
  $query->{sth} = $sth;
1480
  
1481
  # Set filters
1482
  $query->{filters} = $self->{filters} || $self->filters;
1483
  
1484
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1485
}
1486

            
cleanup
Yuki Kimoto authored on 2012-01-20
1487
sub _create_bind_values {
1488
  my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
1489
  
1490
  $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1491
  
1492
  # Create bind values
1493
  my @bind;
1494
  my @types;
1495
  my %count;
1496
  my %not_exists;
1497
  for my $column (@$columns) {
1498
    
1499
    # Bind value
1500
    if(ref $params->{$column} eq 'ARRAY') {
1501
      my $i = $count{$column} || 0;
1502
      $i += $not_exists{$column} || 0;
1503
      my $found;
1504
      for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1505
        if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1506
            $not_exists{$column}++;
micro optimization
Yuki Kimoto authored on 2011-10-23
1507
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1508
        else  {
1509
          push @bind, $params->{$column}->[$k];
1510
          $found = 1;
1511
          last
micro optimization
Yuki Kimoto authored on 2011-10-23
1512
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1513
      }
1514
      next unless $found;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1515
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1516
    else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1517
    
cleanup
Yuki Kimoto authored on 2012-01-20
1518
    # Filter
1519
    if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
1520
      $bind[-1] = $f->($bind[-1]);
1521
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
1522
    
cleanup
Yuki Kimoto authored on 2012-01-20
1523
    # Type rule
1524
    if ($self->{_type_rule_is_called}) {
1525
      my $tf1 = $self->{"_into1"}->{dot}->{$column}
1526
        || $type_filters->{1}->{$column};
1527
      $bind[-1] = $tf1->($bind[-1]) if $tf1;
1528
      my $tf2 = $self->{"_into2"}->{dot}->{$column}
1529
        || $type_filters->{2}->{$column};
1530
      $bind[-1] = $tf2->($bind[-1]) if $tf2;
improved error messages
Yuki Kimoto authored on 2011-04-18
1531
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1532
   
1533
    # Bind types
1534
    push @types, $bind_type->{$column};
improved error messages
Yuki Kimoto authored on 2011-04-18
1535
    
cleanup
Yuki Kimoto authored on 2012-01-20
1536
    # Count up 
1537
    $count{$column}++;
1538
  }
1539
  
1540
  return (\@bind, \@types);
1541
}
1542

            
1543
sub _id_to_param {
1544
  my ($self, $id, $primary_keys, $table) = @_;
1545
  
1546
  # Check primary key
1547
  croak "primary_key option " .
1548
        "must be specified when id option is used" . _subname
1549
    unless defined $primary_keys;
1550
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1551
  
1552
  # Create parameter
1553
  my $param = {};
1554
  if (defined $id) {
1555
    $id = [$id] unless ref $id;
1556
    for(my $i = 0; $i < @$id; $i++) {
1557
      my $key = $primary_keys->[$i];
1558
      $key = "$table." . $key if $table;
1559
      $param->{$key} = $id->[$i];
1560
    }
1561
  }
1562
  
1563
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1564
}
1565

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1566
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1567
  my $self = shift;
1568
  
1569
  # Attributes
1570
  my $dsn = $self->data_source;
1571
  warn "data_source is DEPRECATED!\n"
1572
    if $dsn;
1573
  $dsn ||= $self->dsn;
1574
  croak qq{"dsn" must be specified } . _subname
1575
    unless $dsn;
1576
  my $user        = $self->user;
1577
  my $password    = $self->password;
1578
  my $option = $self->_option;
1579
  $option = {%{$self->default_option}, %$option};
1580
  
1581
  # Connect
1582
  my $dbh;
1583
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1584
  
1585
  # Connect error
1586
  croak "$@ " . _subname if $@;
1587
  
1588
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1589
}
1590

            
cleanup
yuki-kimoto authored on 2010-10-17
1591
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1592
  my ($self, $error, $append) = @_;
1593
  
1594
  # Append
1595
  $append ||= "";
1596
  
1597
  # Verbose
1598
  if ($Carp::Verbose) { croak $error }
1599
  
1600
  # Not verbose
1601
  else {
1602
    # Remove line and module infromation
1603
    my $at_pos = rindex($error, ' at ');
1604
    $error = substr($error, 0, $at_pos);
1605
    $error =~ s/\s+$//;
1606
    croak "$error$append";
1607
  }
cleanup
yuki-kimoto authored on 2010-10-17
1608
}
1609

            
prepare oracle test
Yuki Kimoto authored on 2011-08-15
1610
sub _driver { lc shift->{dbh}->{Driver}->{Name} }
1611

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1612
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1613
  my ($self, $tree, $need_tables, $tables) = @_;
1614
  
1615
  # Get needed tables
1616
  for my $table (@$tables) {
1617
    if ($tree->{$table}) {
1618
      $need_tables->{$table} = 1;
1619
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1620
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1621
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1622
}
1623

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1624
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1625
  my $self = shift;
1626
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1627
  warn "dbi_options is DEPRECATED! use option instead\n"
1628
    if keys %{$self->dbi_options};
1629
  warn "dbi_option is DEPRECATED! use option instead\n"
1630
    if keys %{$self->dbi_option};
1631
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1632
}
1633

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1634
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1635
  my ($self, $sql, $join, $join_tables) = @_;
1636
  
1637
  $join = [$join] unless ref $join eq 'ARRAY';
1638
  
1639
  # No join
1640
  return unless @$join;
1641
  
1642
  # Push join clause
1643
  my $tree = {};
1644
  for (my $i = 0; $i < @$join; $i++) {
1645
    
1646
    # Arrange
1647
    my $join_clause;;
1648
    my $option;
1649
    if (ref $join->[$i] eq 'HASH') {
1650
      $join_clause = $join->[$i]->{clause};
1651
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1652
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1653
    else {
1654
      $join_clause = $join->[$i];
1655
      $option = {};
1656
    };
1657

            
1658
    # Find tables in join clause
1659
    my $table1;
1660
    my $table2;
1661
    if (my $table = $option->{table}) {
1662
      $table1 = $table->[0];
1663
      $table2 = $table->[1];
1664
    }
1665
    else {
1666
      my $q = $self->_quote;
1667
      my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1668
      $j_clause =~ s/'.+?'//g;
1669
      my $q_re = quotemeta($q);
1670
      $j_clause =~ s/[$q_re]//g;
1671
      
1672
      my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
1673
      my $c = $self->{safety_character};
improved test
Yuki Kimoto authored on 2012-03-01
1674
      my $join_re = qr/((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+[^$c].*?((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/sm;
cleanup
Yuki Kimoto authored on 2012-01-20
1675
      for my $clause (@j_clauses) {
1676
        if ($clause =~ $join_re) {
1677
          $table1 = $1;
1678
          $table2 = $2;
1679
          last;
1680
        }                
1681
      }
1682
    }
1683
    croak qq{join clause must have two table name after "on" keyword. } .
1684
        qq{"$join_clause" is passed }  . _subname
1685
      unless defined $table1 && defined $table2;
1686
    croak qq{right side table of "$join_clause" must be unique } . _subname
1687
      if exists $tree->{$table2};
1688
    croak qq{Same table "$table1" is specified} . _subname
1689
      if $table1 eq $table2;
1690
    $tree->{$table2}
1691
      = {position => $i, parent => $table1, join => $join_clause};
1692
  }
1693
  
1694
  # Search need tables
1695
  my $need_tables = {};
1696
  $self->_need_tables($tree, $need_tables, $join_tables);
1697
  my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1698
    keys %$need_tables;
1699
  
1700
  # Add join clause
1701
  $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1702
}
cleanup
Yuki Kimoto authored on 2011-03-08
1703

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1704
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1705
  my $self = shift;
1706
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1707
}
1708

            
cleanup
Yuki Kimoto authored on 2011-04-02
1709
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1710
  my ($self, $tables, $main_table) = @_;
1711
  
1712
  # Remove duplicate table
1713
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1714
  delete $tables{$main_table} if $main_table;
1715
  
1716
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1717
  if (my $q = $self->_quote) {
1718
    $q = quotemeta($q);
1719
    $_ =~ s/[$q]//g for @$new_tables;
1720
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1721

            
cleanup
Yuki Kimoto authored on 2012-01-20
1722
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1723
}
1724

            
cleanup
Yuki Kimoto authored on 2011-04-02
1725
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1726
  my ($self, $source) = @_;
1727
  
1728
  # Search tables
1729
  my $tables = [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1730
  my ($q, $p) = $self->_qp(quotemeta => 1);
1731
  $source =~ s/$q//g;
1732
  $source =~ s/$p//g;
1733
  my $c = $self->safety_character;
1734
  
1735
  while ($source =~ /((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/g) {
1736
    push @$tables, $1;
1737
  }
cleanup
Yuki Kimoto authored on 2012-01-20
1738
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1739
}
1740

            
cleanup
Yuki Kimoto authored on 2011-10-21
1741
sub _where_clause_and_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1742
  my ($self, $where, $where_param, $id, $primary_key, $table) = @_;
1743

            
1744
  $where ||= {};
1745
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1746
  $where_param ||= {};
1747
  my $w = {};
1748

            
cleanup
Yuki Kimoto authored on 2012-02-28
1749
  if (ref $where eq 'HASH') {
1750
    my $clause = [];
1751
    my $column_join = '';
1752
    for my $column (keys %$where) {
1753
      $column_join .= $column;
1754
      my $table;
1755
      my $c;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1756
      if ($column =~ /(?:(.*)\.)?(.*)/) {
cleanup
Yuki Kimoto authored on 2012-02-28
1757
        $table = $1;
1758
        $c = $2;
cleanup
Yuki Kimoto authored on 2012-01-20
1759
      }
cleanup
Yuki Kimoto authored on 2012-02-28
1760
      
1761
      my $table_quote;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1762
      $table_quote = $self->_tq($table) if defined $table;
cleanup
Yuki Kimoto authored on 2012-02-28
1763
      my $column_quote = $self->q($c);
1764
      $column_quote = $table_quote . '.' . $column_quote
1765
        if defined $table_quote;
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1766
      if (ref $where->{$column} eq 'ARRAY') {
1767
        my $c = join(', ', (":$column") x @{$where->{$column}});
fixed where multi value bug
Yuki Kimoto authored on 2012-02-28
1768
        if (@{$where->{$column}}) {
1769
          push @$clause, "$column_quote in ( $c )";
1770
        }
1771
        else { push @$clause, '1 <> 1' }
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1772
      }
1773
      else { push @$clause, "$column_quote = :$column" }
cleanup
Yuki Kimoto authored on 2012-02-28
1774
    }
1775
    
1776
    $w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ;
1777
    $w->{param} = $where;
1778
    $w->{param} = keys %$where_param
1779
      ? $self->merge_param($where_param, $where)
1780
      : $where;
1781
  }  
1782
  elsif (ref $where) {
1783
    my $obj;
1784

            
1785
    if (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2012-01-20
1786
    elsif (ref $where eq 'ARRAY') {
1787
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1788
    }
1789
    
1790
    # Check where argument
1791
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1792
        . qq{or array reference, which contains where clause and parameter}
1793
        . _subname
1794
      unless ref $obj eq 'DBIx::Custom::Where';
1795

            
cleanup
Yuki Kimoto authored on 2012-02-28
1796
    $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2012-01-20
1797
    $w->{param} = keys %$where_param
1798
      ? $self->merge_param($where_param, $obj->param)
1799
      : $obj->param;
1800
  }
1801
  elsif ($where) {
1802
    $w->{clause} = "where $where";
1803
    $w->{param} = $where_param;
1804
  }
1805
  
1806
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1807
}
1808

            
updated pod
Yuki Kimoto authored on 2011-06-21
1809
sub _apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1810
  my ($self, $table, @cinfos) = @_;
1811

            
1812
  # Initialize filters
1813
  $self->{filter} ||= {};
1814
  $self->{filter}{on} = 1;
1815
  $self->{filter}{out} ||= {};
1816
  $self->{filter}{in} ||= {};
1817
  $self->{filter}{end} ||= {};
1818
  
1819
  # Usage
1820
  my $usage = "Usage: \$dbi->apply_filter(" .
1821
    "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1822
    "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1823
  
1824
  # Apply filter
1825
  for (my $i = 0; $i < @cinfos; $i += 2) {
updated pod
Yuki Kimoto authored on 2011-06-21
1826
    
cleanup
Yuki Kimoto authored on 2012-01-20
1827
    # Column
1828
    my $column = $cinfos[$i];
1829
    if (ref $column eq 'ARRAY') {
1830
      for my $c (@$column) { push @cinfos, $c, $cinfos[$i + 1] }
1831
      next;
1832
    }
updated pod
Yuki Kimoto authored on 2011-06-21
1833
    
cleanup
Yuki Kimoto authored on 2012-01-20
1834
    # Filter infomation
1835
    my $finfo = $cinfos[$i + 1] || {};
1836
    croak "$usage (table: $table) " . _subname
1837
      unless  ref $finfo eq 'HASH';
1838
    for my $ftype (keys %$finfo) {
1839
      croak "$usage (table: $table) " . _subname
1840
        unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
updated pod
Yuki Kimoto authored on 2011-06-21
1841
    }
1842
    
cleanup
Yuki Kimoto authored on 2012-01-20
1843
    # Set filters
1844
    for my $way (qw/in out end/) {
1845
  
1846
      # Filter
1847
      my $filter = $finfo->{$way};
1848
      
1849
      # Filter state
1850
      my $state = !exists $finfo->{$way} ? 'not_exists'
1851
        : !defined $filter        ? 'not_defined'
1852
        : ref $filter eq 'CODE'   ? 'code'
1853
        : 'name';
1854
      
1855
      # Filter is not exists
1856
      next if $state eq 'not_exists';
1857
      
1858
      # Check filter name
1859
      croak qq{Filter "$filter" is not registered } . _subname
1860
        if  $state eq 'name' && ! exists $self->filters->{$filter};
1861
      
1862
      # Set filter
1863
      my $f = $state eq 'not_defined' ? undef
1864
        : $state eq 'code' ? $filter
1865
        : $self->filters->{$filter};
1866
      $self->{filter}{$way}{$table}{$column} = $f;
1867
      $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1868
      $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1869
      $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1870
    }
1871
  }
1872
  
1873
  return $self;
updated pod
Yuki Kimoto authored on 2011-06-21
1874
}
1875

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1876
# DEPRECATED!
1877
has 'data_source';
1878
has dbi_options => sub { {} };
1879
has filter_check  => 1;
1880
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1881
has dbi_option => sub { {} };
1882
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1883
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1884
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1885
};
1886

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1887
# DEPRECATED
1888
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1889
 my $self = shift;
1890
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1891
   "environment variable";
1892
  if (@_) {
1893
    $self->{tag_parse} = $_[0];
1894
    return $self;
1895
  }
1896
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1897
}
1898

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1899
# DEPRECATED!
1900
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1901
  warn "method is DEPRECATED! use helper instead";
1902
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1903
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1904

            
1905
# DEPRECATED!
1906
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1907
  my $self = shift;
1908
  warn "assing_param is DEPRECATED! use assign_clause instead";
1909
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1910
}
1911

            
1912
# DEPRECATED
1913
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1914
  my ($self, $param, $opts) = @_;
1915
  
1916
  warn "update_param is DEPRECATED! use assign_clause instead.";
1917
  
1918
  # Create update parameter tag
1919
  my $tag = $self->assign_clause($param, $opts);
1920
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1921

            
cleanup
Yuki Kimoto authored on 2012-01-20
1922
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1923
}
1924

            
updated pod
Yuki Kimoto authored on 2011-06-21
1925
# DEPRECATED!
1926
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1927
  warn "create_query is DEPRECATED! use query option of each method";
1928
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1929
}
1930

            
cleanup
Yuki Kimoto authored on 2011-06-13
1931
# DEPRECATED!
1932
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1933
  my $self = shift;
1934
  
1935
  warn "apply_filter is DEPRECATED!";
1936
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1937
}
1938

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1939
# DEPRECATED!
1940
sub select_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1941
  my ($self, %opt) = @_;
1942

            
1943
  warn "select_at is DEPRECATED! use select method id option instead";
1944

            
1945
  # Options
1946
  my $primary_keys = delete $opt{primary_key};
1947
  my $where = delete $opt{where};
1948
  my $param = delete $opt{param};
1949
  
1950
  # Table
1951
  croak qq{"table" option must be specified } . _subname
1952
    unless $opt{table};
1953
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1954
  
1955
  # Create where parameter
1956
  my $where_param = $self->_id_to_param($where, $primary_keys);
1957
  
1958
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1959
}
1960

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1961
# DEPRECATED!
1962
sub delete_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1963
  my ($self, %opt) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1964

            
cleanup
Yuki Kimoto authored on 2012-01-20
1965
  warn "delete_at is DEPRECATED! use delete method id option instead";
1966
  
1967
  # Options
1968
  my $primary_keys = delete $opt{primary_key};
1969
  my $where = delete $opt{where};
1970
  
1971
  # Create where parameter
1972
  my $where_param = $self->_id_to_param($where, $primary_keys);
1973
  
1974
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1975
}
1976

            
cleanup
Yuki Kimoto authored on 2011-06-08
1977
# DEPRECATED!
1978
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1979
  my $self = shift;
1980

            
1981
  warn "update_at is DEPRECATED! use update method id option instead";
1982
  
1983
  # Options
1984
  my $param;
1985
  $param = shift if @_ % 2;
1986
  my %opt = @_;
1987
  my $primary_keys = delete $opt{primary_key};
1988
  my $where = delete $opt{where};
1989
  my $p = delete $opt{param} || {};
1990
  $param  ||= $p;
1991
  
1992
  # Create where parameter
1993
  my $where_param = $self->_id_to_param($where, $primary_keys);
1994
  
1995
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1996
}
1997

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1998
# DEPRECATED!
1999
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
2000
  my $self = shift;
2001
  
2002
  warn "insert_at is DEPRECATED! use insert method id option instead";
2003
  
2004
  # Options
2005
  my $param;
2006
  $param = shift if @_ % 2;
2007
  my %opt = @_;
2008
  my $primary_key = delete $opt{primary_key};
2009
  $primary_key = [$primary_key] unless ref $primary_key;
2010
  my $where = delete $opt{where};
2011
  my $p = delete $opt{param} || {};
2012
  $param  ||= $p;
2013
  
2014
  # Create where parameter
2015
  my $where_param = $self->_id_to_param($where, $primary_key);
2016
  $param = $self->merge_param($where_param, $param);
2017
  
2018
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2019
}
2020

            
added warnings
Yuki Kimoto authored on 2011-06-07
2021
# DEPRECATED!
2022
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2023
  my $self = shift;
2024
  
2025
  warn "register_tag is DEPRECATED!";
2026
  
2027
  # Merge tag
2028
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2029
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
2030
  
2031
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
2032
}
2033

            
2034
# DEPRECATED!
2035
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
2036
  my $self = shift;
2037
  warn "register_tag_processor is DEPRECATED!";
2038
  # Merge tag
2039
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2040
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
2041
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
2042
}
2043

            
cleanup
Yuki Kimoto authored on 2011-01-25
2044
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2045
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2046
  my $self = shift;
2047
  
2048
  warn "default_bind_filter is DEPRECATED!";
2049
  
2050
  if (@_) {
2051
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
2052
    
cleanup
Yuki Kimoto authored on 2012-01-20
2053
    if (@_ && !$fname) {
2054
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
2055
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2056
    else {
2057
      croak qq{Filter "$fname" is not registered}
2058
        unless exists $self->filters->{$fname};
2059
  
2060
      $self->{default_out_filter} = $self->filters->{$fname};
2061
    }
2062
    return $self;
2063
  }
2064
  
2065
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2066
}
2067

            
cleanup
Yuki Kimoto authored on 2011-01-25
2068
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2069
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2070
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2071

            
cleanup
Yuki Kimoto authored on 2012-01-20
2072
  warn "default_fetch_filter is DEPRECATED!";
2073
  
2074
  if (@_) {
2075
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
2076

            
cleanup
Yuki Kimoto authored on 2012-01-20
2077
    if (@_ && !$fname) {
2078
      $self->{default_in_filter} = undef;
2079
    }
2080
    else {
2081
      croak qq{Filter "$fname" is not registered}
2082
        unless exists $self->filters->{$fname};
2083
  
2084
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2085
    }
2086
    
cleanup
Yuki Kimoto authored on 2012-01-20
2087
    return $self;
2088
  }
2089
  
2090
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2091
}
2092

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2093
# DEPRECATED!
2094
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2095
  my $self = shift;
2096
  warn "insert_param is DEPRECATED! use values_clause instead";
2097
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2098
}
2099

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2100
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2101
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2102
  warn "insert_param_tag is DEPRECATED! " .
2103
    "use insert_param instead!";
2104
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2105
}
2106

            
2107
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2108
sub update_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2109
  warn "update_param_tag is DEPRECATED! " .
2110
    "use update_param instead";
2111
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2112
}
cleanup
Yuki Kimoto authored on 2011-03-08
2113
# DEPRECATED!
2114
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
2115
  my ($self, $sql, $tables, $relation, $need_where) = @_;
2116
  
2117
  if (keys %{$relation || {}}) {
2118
    $$sql .= $need_where ? 'where ' : 'and ';
2119
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2120
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2121
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2122
      push @$tables, ($table1, $table2);
2123
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2124
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2125
  }
2126
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2127
}
2128

            
2129
# DEPRECATED!
2130
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2131
  my ($self, $tables, $relation) = @_;
2132
  
2133
  if (keys %{$relation || {}}) {
2134
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2135
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2136
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2137
      my $table1_exists;
2138
      my $table2_exists;
2139
      for my $table (@$tables) {
2140
        $table1_exists = 1 if $table eq $table1;
2141
        $table2_exists = 1 if $table eq $table2;
2142
      }
2143
      unshift @$tables, $table1 unless $table1_exists;
2144
      unshift @$tables, $table2 unless $table2_exists;
2145
    }
2146
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2147
}
2148

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2151
=head1 NAME
2152

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2153
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
2154

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2155
=head1 SYNOPSIS
cleanup
yuki-kimoto authored on 2010-08-05
2156

            
cleanup
Yuki Kimoto authored on 2012-01-20
2157
  use DBIx::Custom;
2158
  
2159
  # Connect
2160
  my $dbi = DBIx::Custom->connect(
2161
    dsn => "dbi:mysql:database=dbname",
2162
    user => 'ken',
2163
    password => '!LFKD%$&',
2164
    option => {mysql_enable_utf8 => 1}
2165
  );
2166

            
2167
  # Insert 
2168
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2169
  
2170
  # Update 
2171
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2172
    where  => {id => 5});
2173
  
2174
  # Delete
2175
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2176

            
2177
  # Select
2178
  my $result = $dbi->select(table  => 'book',
2179
    column => ['title', 'author'], where  => {author => 'Ken'});
2180

            
2181
  # Select, more complex
2182
  my $result = $dbi->select(
2183
    table  => 'book',
2184
    column => [
2185
      {book => [qw/title author/]},
2186
      {company => ['name']}
2187
    ],
2188
    where  => {'book.author' => 'Ken'},
2189
    join => ['left outer join company on book.company_id = company.id'],
2190
    append => 'order by id limit 5'
2191
  );
2192
  
2193
  # Fetch
2194
  while (my $row = $result->fetch) {
2195
      
2196
  }
2197
  
2198
  # Fetch as hash
2199
  while (my $row = $result->fetch_hash) {
2200
      
2201
  }
2202
  
2203
  # Execute SQL with parameter.
2204
  $dbi->execute(
2205
    "select id from book where author = :author and title like :title",
2206
    {author => 'ken', title => '%Perl%'}
2207
  );
2208
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2209
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2210

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2226
Named place holder support
2227

            
2228
=item *
2229

            
cleanup
Yuki Kimoto authored on 2011-07-29
2230
Model support
2231

            
2232
=item *
2233

            
2234
Connection manager support
2235

            
2236
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2237

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

            
2242
=item *
2243

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2244
Filtering by data type or column name
cleanup
Yuki Kimoto authored on 2011-07-29
2245

            
2246
=item *
2247

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2248
Create C<order by> clause flexibly
cleanup
Yuki Kimoto authored on 2011-07-29
2249

            
2250
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2251

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2252
=head1 DOCUMENTATION
pod fix
Yuki Kimoto authored on 2011-01-21
2253

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2259
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2260
L<DBIx::Custom::Result>,
2261
L<DBIx::Custom::Query>,
2262
L<DBIx::Custom::Where>,
2263
L<DBIx::Custom::Model>,
2264
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2265

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

            
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
2268
=head2 C<async_conf> EXPERIMENTAL
2269

            
2270
  my $async_conf = $dbi->async_conf;
2271
  $dbi = $dbi->async_conf($conf);
2272

            
2273
Setting when C<async> option is used.
2274

            
2275
  # MySQL
2276
  $dbi->async_conf({
2277
    prepare_attr => {async => 1},
2278
    fh => sub { shift->dbh->mysql_fd }
2279
  })
2280

            
2281
C<prepare_attr> is DBI's C<prepare> method second argument,
2282
C<fh> is callback that return file handle to watch.
2283

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2286
  my $connector = $dbi->connector;
2287
  $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2288

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

            
2292
This is L<DBIx::Connector> example. Please pass
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2293
C<default_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2294

            
cleanup
Yuki Kimoto authored on 2012-01-20
2295
  my $connector = DBIx::Connector->new(
2296
    "dbi:mysql:database=$database",
2297
    $user,
2298
    $password,
2299
    DBIx::Custom->new->default_option
2300
  );
2301
  
2302
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2303

            
cleanup
Yuki Kimoto authored on 2011-08-16
2304
If C<connector> is set to 1 when connect method is called,
2305
L<DBIx::Connector> is automatically set to C<connector>
2306

            
cleanup
Yuki Kimoto authored on 2012-01-20
2307
  my $dbi = DBIx::Custom->connect(
2308
    dsn => $dsn, user => $user, password => $password, connector => 1);
2309
  
2310
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2311

            
2312
Note that L<DBIx::Connector> must be installed.
2313

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2316
  my $dsn = $dbi->dsn;
2317
  $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
2318

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2321
=head2 C<default_option>
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2322

            
cleanup
Yuki Kimoto authored on 2012-01-20
2323
  my $default_option = $dbi->default_option;
2324
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2325

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2329
  {
2330
    RaiseError => 1,
2331
    PrintError => 0,
2332
    AutoCommit => 1,
2333
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2334

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2335
=head2 C<exclude_table>
2336

            
cleanup
Yuki Kimoto authored on 2012-01-20
2337
  my $exclude_table = $dbi->exclude_table;
2338
  $dbi = $dbi->exclude_table(qr/pg_/);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2339

            
2340
Excluded table regex.
2341
C<each_column>, C<each_table>, C<type_rule>,
2342
and C<setup_model> methods ignore matching tables.
2343

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2346
  my $filters = $dbi->filters;
2347
  $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
2348

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2353
  my $last_sql = $dbi->last_sql;
2354
  $dbi = $dbi->last_sql($last_sql);
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
2355

            
2356
Get last successed SQL executed by C<execute> method.
2357

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2358
=head2 C<now>
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2359

            
cleanup
Yuki Kimoto authored on 2012-01-20
2360
  my $now = $dbi->now;
2361
  $dbi = $dbi->now($now);
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2362

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2363
Code reference which return current time, default to the following code reference.
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2364

            
cleanup
Yuki Kimoto authored on 2012-01-20
2365
  sub {
2366
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2367
    $mon++;
2368
    $year += 1900;
2369
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2370
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2371

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2372
This return the time like C<2011-10-14 05:05:27>.
2373

            
2374
This is used by C<insert> method's C<created_at> option and C<updated_at> option,
2375
and C<update> method's C<updated_at> option.
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2376

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2379
  my $models = $dbi->models;
2380
  $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
2381

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2384
=head2 C<option>
2385

            
cleanup
Yuki Kimoto authored on 2012-01-20
2386
  my $option = $dbi->option;
2387
  $dbi = $dbi->option($option);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2388

            
2389
L<DBI> option, used when C<connect> method is executed.
2390
Each value in option override the value of C<default_option>.
2391

            
cleanup
yuki-kimoto authored on 2010-10-17
2392
=head2 C<password>
2393

            
cleanup
Yuki Kimoto authored on 2012-01-20
2394
  my $password = $dbi->password;
2395
  $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
2396

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2401
  my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2402

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2407
  my quote = $dbi->quote;
2408
  $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2409

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2414
You can set quote pair.
2415

            
cleanup
Yuki Kimoto authored on 2012-01-20
2416
  $dbi->quote('[]');
cleanup
Yuki Kimoto authored on 2011-07-30
2417

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2420
  my $result_class = $dbi->result_class;
2421
  $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
2422

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2427
  my $safety_character = $dbi->safety_character;
2428
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2429

            
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
2430
Regex of safety character for table and column name, default to 'a-zA-Z_'.
2431
Note that you don't have to specify like '[a-zA-Z_]'.
update pod
Yuki Kimoto authored on 2011-01-27
2432

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2435
  my $separator = $dbi->separator;
2436
  $dbi = $dbi->separator('-');
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2437

            
2438
Separator which join table name and column name.
2439
This have effect to C<column> and C<mycolumn> method,
2440
and C<select> method's column option.
cleanup test
Yuki Kimoto authored on 2011-08-10
2441

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2442
Default to C<.>.
cleanup test
Yuki Kimoto authored on 2011-08-10
2443

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2446
  my $tag_parse = $dbi->tag_parse(0);
2447
  $dbi = $dbi->tag_parse;
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2448

            
2449
Enable DEPRECATED tag parsing functionality, default to 1.
2450
If you want to disable tag parsing functionality, set to 0.
2451

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2454
  my $user = $dbi->user;
2455
  $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
2456

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2459
=head2 C<user_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2460

            
cleanup
Yuki Kimoto authored on 2012-01-20
2461
  my $user_column_info = $dbi->user_column_info;
2462
  $dbi = $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2463

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2464
You can set the date like the following one.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2465

            
cleanup
Yuki Kimoto authored on 2012-01-20
2466
  [
2467
    {table => 'book', column => 'title', info => {...}},
2468
    {table => 'author', column => 'name', info => {...}}
2469
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2470

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2471
Usually, you set return value of C<get_column_info>.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2472

            
cleanup
Yuki Kimoto authored on 2012-01-20
2473
  my $user_column_info
2474
    = $dbi->get_column_info(exclude_table => qr/^system/);
2475
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2476

            
2477
If C<user_column_info> is set, C<each_column> use C<user_column_info>
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2478
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2479

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2480
=head2 C<user_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2481

            
cleanup
Yuki Kimoto authored on 2012-01-20
2482
  my $user_table_info = $dbi->user_table_info;
2483
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2484

            
2485
You can set the following data.
2486

            
cleanup
Yuki Kimoto authored on 2012-01-20
2487
  [
2488
    {table => 'book', info => {...}},
2489
    {table => 'author', info => {...}}
2490
  ]
added test
Yuki Kimoto authored on 2011-08-16
2491

            
2492
Usually, you can set return value of C<get_table_info>.
2493

            
cleanup
Yuki Kimoto authored on 2012-01-20
2494
  my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2495
  $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2496

            
2497
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2498
to find table info.
2499

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2506
=head2 C<available_datatype>
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2507

            
cleanup
Yuki Kimoto authored on 2012-01-20
2508
  print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2509

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2513
=head2 C<available_typename>
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2514

            
cleanup
Yuki Kimoto authored on 2012-01-20
2515
  print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2516

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2520
=head2 C<assign_clause>
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2521

            
cleanup
Yuki Kimoto authored on 2012-01-20
2522
  my $assign_clause = $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2523

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2524
Create assign clause
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2525

            
cleanup
Yuki Kimoto authored on 2012-01-20
2526
  title = :title, author = :author
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2527

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2528
This is used to create update clause.
2529

            
cleanup
Yuki Kimoto authored on 2012-01-20
2530
  "update book set " . $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2531

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2532
=head2 C<async> EXPERIMENTAL
2533

            
2534
  async => sub {
2535
    my ($dbi, $result) = @_;
2536
    ...
2537
  };
2538

            
2539
Database async access. L<AnyEvent> is required.
2540

            
2541
This is C<mysql> async access example.
2542

            
2543
  use AnyEvent;
2544

            
2545
  my $cond = AnyEvent->condvar;
2546

            
2547
  my $timer = AnyEvent->timer(
2548
    interval => 1,
2549
    cb => sub { 1 }
2550
  );
2551

            
2552
  my $count = 0;
2553

            
2554
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2555
    prepare_attr => {async => 1}, statement => 'select',
2556
    async => sub {
2557
      my ($dbi, $result) = @_;
2558
      my $row = $result->fetch_one;
2559
      is($row->[1], 3, 'before');
2560
      $cond->send if ++$count == 2;
2561
    }
2562
  );
2563

            
2564
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2565
    async => sub {
2566
      my ($dbi, $result) = @_;
2567
      my $row = $result->fetch_one;
2568
      is($row->[0], 1, 'after1');
2569
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2570
        async => sub {
2571
          my ($dbi, $result) = @_;
2572
          my $row = $result->fetch_one;
2573
          is($row->[0], 1, 'after2');
2574
          $cond->send if ++$count == 2;
2575
        }
2576
      )
2577
    }
2578
  );
2579

            
2580
  $cond->recv;
2581

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2584
  my $column = $dbi->column(book => ['author', 'title']);
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2585

            
2586
Create column clause. The follwoing column clause is created.
2587

            
cleanup
Yuki Kimoto authored on 2012-01-20
2588
  book.author as "book.author",
2589
  book.title as "book.title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2590

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2593
  # Separator is hyphen
2594
  $dbi->separator('-');
2595
  
2596
  book.author as "book-author",
2597
  book.title as "book-title"
2598
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2599
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2600

            
cleanup
Yuki Kimoto authored on 2012-01-20
2601
  my $dbi = DBIx::Custom->connect(
2602
    dsn => "dbi:mysql:database=dbname",
2603
    user => 'ken',
2604
    password => '!LFKD%$&',
2605
    option => {mysql_enable_utf8 => 1}
2606
  );
update pod
Yuki Kimoto authored on 2011-03-13
2607

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2614
=head2 C<count>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2615

            
cleanup
Yuki Kimoto authored on 2012-01-20
2616
  my $count = $dbi->count(table => 'book');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2617

            
2618
Get rows count.
2619

            
2620
Options is same as C<select> method's ones.
2621

            
2622
=head2 C<create_model>
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2623

            
cleanup
Yuki Kimoto authored on 2012-01-20
2624
  my $model = $dbi->create_model(
2625
    table => 'book',
2626
    primary_key => 'id',
2627
    join => [
2628
      'inner join company on book.comparny_id = company.id'
2629
    ],
2630
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2631

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2635
 $dbi->model('book')->select(...);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2636

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2639
  my $dbh = $dbi->dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2640

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

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2644
=head2 C<delete>
2645

            
cleanup
Yuki Kimoto authored on 2012-01-20
2646
  $dbi->delete(table => 'book', where => {title => 'Perl'});
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2647

            
2648
Execute delete statement.
2649

            
2650
The following opitons are available.
2651

            
cleanup
Yuki Kimoto authored on 2011-10-20
2652
B<OPTIONS>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2653

            
cleanup
Yuki Kimoto authored on 2011-10-20
2654
C<delete> method use all of C<execute> method's options,
2655
and use the following new ones.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2656

            
cleanup
Yuki Kimoto authored on 2011-10-20
2657
=over 4
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2658

            
2659
=item C<id>
2660

            
cleanup
Yuki Kimoto authored on 2012-01-20
2661
  id => 4
2662
  id => [4, 5]
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2663

            
2664
ID corresponding to C<primary_key>.
2665
You can delete rows by C<id> and C<primary_key>.
2666

            
cleanup
Yuki Kimoto authored on 2012-01-20
2667
  $dbi->delete(
2668
    primary_key => ['id1', 'id2'],
2669
    id => [4, 5],
2670
    table => 'book',
2671
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2672

            
2673
The above is same as the followin one.
2674

            
cleanup
Yuki Kimoto authored on 2012-01-20
2675
  $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2676

            
2677
=item C<prefix>
2678

            
cleanup
Yuki Kimoto authored on 2012-01-20
2679
  prefix => 'some'
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2680

            
2681
prefix before table name section.
2682

            
cleanup
Yuki Kimoto authored on 2012-01-20
2683
  delete some from book
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2684

            
2685
=item C<table>
2686

            
cleanup
Yuki Kimoto authored on 2012-01-20
2687
  table => 'book'
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2688

            
2689
Table name.
2690

            
2691
=item C<where>
2692

            
2693
Same as C<select> method's C<where> option.
2694

            
2695
=back
2696

            
2697
=head2 C<delete_all>
2698

            
cleanup
Yuki Kimoto authored on 2012-01-20
2699
  $dbi->delete_all(table => $table);
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2700

            
2701
Execute delete statement for all rows.
2702
Options is same as C<delete>.
2703

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2704
=head2 C<each_column>
2705

            
cleanup
Yuki Kimoto authored on 2012-01-20
2706
  $dbi->each_column(
2707
    sub {
2708
      my ($dbi, $table, $column, $column_info) = @_;
2709
      
2710
      my $type = $column_info->{TYPE_NAME};
2711
      
2712
      if ($type eq 'DATE') {
2713
          # ...
2714
      }
2715
    }
2716
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2717

            
improved pod
Yuki Kimoto authored on 2011-10-14
2718
Iterate all column informations in database.
2719
Argument is callback which is executed when one column is found.
2720
Callback receive four arguments. C<DBIx::Custom object>, C<table name>,
2721
C<column name>, and C<column information>.
2722

            
2723
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2724
infromation, you can improve the performance of C<each_column> in
2725
the following way.
2726

            
cleanup
Yuki Kimoto authored on 2012-01-20
2727
  my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
2728
  $dbi->user_column_info($column_info);
2729
  $dbi->each_column(sub { ... });
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2730

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2733
  $dbi->each_table(
2734
    sub {
2735
      my ($dbi, $table, $table_info) = @_;
2736
      
2737
      my $table_name = $table_info->{TABLE_NAME};
2738
    }
2739
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2740

            
improved pod
Yuki Kimoto authored on 2011-10-14
2741
Iterate all table informationsfrom in database.
2742
Argument is callback which is executed when one table is found.
2743
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2744
C<table information>.
2745

            
2746
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2747
infromation, you can improve the performance of C<each_table> in
2748
the following way.
2749

            
cleanup
Yuki Kimoto authored on 2012-01-20
2750
  my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
2751
  $dbi->user_table_info($table_info);
2752
  $dbi->each_table(sub { ... });
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2753

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2756
  my $result = $dbi->execute(
2757
    "select * from book where title = :title and author like :author",
2758
    {title => 'Perl', author => '%Ken%'}
2759
  );
updated pod
Yuki Kimoto authored on 2011-06-21
2760

            
cleanup
Yuki Kimoto authored on 2012-01-20
2761
  my $result = $dbi->execute(
2762
    "select * from book where title = :book.title and author like :book.author",
2763
    {'book.title' => 'Perl', 'book.author' => '%Ken%'}
2764
  );
update pod
Yuki Kimoto authored on 2011-03-13
2765

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2772
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2773
  
2774
  # Original
2775
  select * from book where title = :title and author like :author
2776
  
2777
  # Replaced
2778
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2779

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2780
You can specify operator with named placeholder
fixed pod
Yuki Kimoto authored on 2011-10-20
2781
by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2782

            
cleanup
Yuki Kimoto authored on 2012-01-20
2783
  # Original
2784
  select * from book where :title{=} and :author{like}
2785
  
2786
  # Replaced
2787
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2788

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2793
  select * from where title = "aa\\:bb";
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
2794

            
cleanup
Yuki Kimoto authored on 2011-10-20
2795
B<OPTIONS>
2796

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

            
2799
=over 4
2800

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2801
=item C<after_build_sql> 
2802

            
2803
You can filter sql after the sql is build.
2804

            
cleanup
Yuki Kimoto authored on 2012-01-20
2805
  after_build_sql => $code_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2806

            
2807
The following one is one example.
2808

            
cleanup
Yuki Kimoto authored on 2012-01-20
2809
  $dbi->select(
2810
    table => 'book',
2811
    column => 'distinct(name)',
2812
    after_build_sql => sub {
2813
      "select count(*) from ($_[0]) as t1"
2814
    }
2815
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2816

            
2817
The following SQL is executed.
2818

            
cleanup
Yuki Kimoto authored on 2012-01-20
2819
  select count(*) from (select distinct(name) from book) as t1;
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2820

            
cleanup
Yuki Kimoto authored on 2011-10-20
2821
=item C<append>
2822

            
cleanup
Yuki Kimoto authored on 2012-01-20
2823
  append => 'order by name'
cleanup
Yuki Kimoto authored on 2011-10-20
2824

            
2825
Append some statement after SQL.
2826

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2827
=item C<prepare_attr> EXPERIMENTAL
2828

            
2829
  prepare_attr => {async => 1}
2830

            
2831
Statemend handle attributes,
2832
this is L<DBI>'s C<prepare> method second argument.
2833

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2834
=item C<bind_type>
2835

            
2836
Specify database bind data type.
2837

            
cleanup
Yuki Kimoto authored on 2012-01-20
2838
  bind_type => [image => DBI::SQL_BLOB]
2839
  bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2840

            
2841
This is used to bind parameter by C<bind_param> of statment handle.
2842

            
cleanup
Yuki Kimoto authored on 2012-01-20
2843
  $sth->bind_param($pos, $value, DBI::SQL_BLOB);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2844

            
update pod
Yuki Kimoto authored on 2011-03-13
2845
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2846
  
2847
  filter => {
2848
    title  => sub { uc $_[0] }
2849
    author => sub { uc $_[0] }
2850
  }
2851

            
2852
  # Filter name
2853
  filter => {
2854
    title  => 'upper_case',
2855
    author => 'upper_case'
2856
  }
2857
      
2858
  # At once
2859
  filter => [
2860
    [qw/title author/]  => sub { uc $_[0] }
2861
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2862

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2870
  query => 1
updated document
Yuki Kimoto authored on 2011-06-09
2871

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2872
C<execute> method return hash reference which contain SQL and column
2873
infromation
updated pod
Yuki Kimoto authored on 2011-06-21
2874

            
cleanup
Yuki Kimoto authored on 2012-01-20
2875
  my $sql = $query->{sql};
2876
  my $columns = $query->{columns};
2877
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2878
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2879
  
2880
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2881

            
2882
Reuse query object if the hash reference variable is set.
cleanup
Yuki Kimoto authored on 2012-01-20
2883
  
2884
  my $queries = {};
2885
  $dbi->execute($sql, $param, reuse => $queries);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2886

            
2887
This will improved performance when you want to execute same query repeatedly
2888
because generally creating query object is slow.
2889

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2890
=item C<primary_key>
2891

            
cleanup
Yuki Kimoto authored on 2012-01-20
2892
  primary_key => 'id'
2893
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2894

            
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
2895
Priamry key. This is used for C<id> option.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2896

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2897
=item C<select> EXPERIMETAL
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2898

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2899
  select => 1
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2900

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2901
If you set C<select> to 1, this statement become select statement
2902
and return value is always L<DBIx::Custom::Result> object.
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2903

            
updated pod
Yuki Kimoto authored on 2011-06-09
2904
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2905
  
2906
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2907

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2912
  $dbi->execute("select * from book where title = :title and author = :author",
2913
    {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2914

            
cleanup
Yuki Kimoto authored on 2012-01-20
2915
  # Same
2916
  $dbi->execute(
2917
    "select * from book where title = :book.title and author = :book.author",
2918
    {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2919

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2920
=item C<table_alias>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2921

            
cleanup
Yuki Kimoto authored on 2012-01-20
2922
  table_alias => {user => 'worker'}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2923

            
2924
Table alias. Key is real table name, value is alias table name.
2925
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2926
on alias table name.
2927

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2928
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2929

            
cleanup
Yuki Kimoto authored on 2012-01-20
2930
  type_rule_off => 1
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2931

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2934
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2935

            
cleanup
Yuki Kimoto authored on 2012-01-20
2936
  type_rule1_off => 1
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2937

            
2938
Turn C<into1> type rule off.
2939

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2940
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2941

            
cleanup
Yuki Kimoto authored on 2012-01-20
2942
  type_rule2_off => 1
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2943

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2948
=head2 C<get_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2949

            
cleanup
Yuki Kimoto authored on 2012-01-20
2950
  my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2951

            
2952
get column infomation except for one which match C<exclude_table> pattern.
2953

            
cleanup
Yuki Kimoto authored on 2012-01-20
2954
  [
2955
    {table => 'book', column => 'title', info => {...}},
2956
    {table => 'author', column => 'name' info => {...}}
2957
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2958

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2959
=head2 C<get_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2960

            
cleanup
Yuki Kimoto authored on 2012-01-20
2961
  my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2962

            
added test
Yuki Kimoto authored on 2011-08-16
2963
get table infomation except for one which match C<exclude> pattern.
2964

            
cleanup
Yuki Kimoto authored on 2012-01-20
2965
  [
2966
    {table => 'book', info => {...}},
2967
    {table => 'author', info => {...}}
2968
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2969

            
added test
Yuki Kimoto authored on 2011-08-16
2970
You can set this value to C<user_table_info>.
update pod
Yuki Kimoto authored on 2011-03-13
2971

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2972
=head2 C<helper>
2973

            
cleanup
Yuki Kimoto authored on 2012-01-20
2974
  $dbi->helper(
2975
    find_or_create   => sub {
2976
      my $self = shift;
2977
      
2978
      # Process
2979
    },
2980
    ...
2981
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2982

            
2983
Register helper. These helper is called directly from L<DBIx::Custom> object.
2984

            
cleanup
Yuki Kimoto authored on 2012-01-20
2985
  $dbi->find_or_create;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2986

            
cleanup
yuki-kimoto authored on 2010-10-17
2987
=head2 C<insert>
2988

            
cleanup
Yuki Kimoto authored on 2012-01-20
2989
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2990

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2997
  {date => \"NOW()"}
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
2998

            
updated pod
Yuki Kimoto authored on 2011-11-25
2999
You can pass multiple parameters, this is very fast.
3000

            
cleanup
Yuki Kimoto authored on 2012-01-20
3001
  $dbi->insert(
3002
    [
3003
      {title => 'Perl', author => 'Ken'},
3004
      {title => 'Ruby', author => 'Tom'}
3005
    ],
3006
    table  => 'book'
3007
  );
updated pod
Yuki Kimoto authored on 2011-11-25
3008

            
3009
In multiple insert, you can't use C<id> option.
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
3010
and only first parameter is used to create sql.
updated pod
Yuki Kimoto authored on 2011-11-25
3011

            
cleanup
Yuki Kimoto authored on 2011-10-20
3012
B<options>
3013

            
cleanup
Yuki Kimoto authored on 2011-10-20
3014
C<insert> method use all of C<execute> method's options,
cleanup
Yuki Kimoto authored on 2011-10-20
3015
and use the following new ones.
update pod
Yuki Kimoto authored on 2011-03-13
3016

            
cleanup
Yuki Kimoto authored on 2011-06-09
3017
=over 4
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
3018

            
3019
=item C<bulk_insert>
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
3020

            
cleanup
Yuki Kimoto authored on 2012-01-20
3021
  bulk_insert => 1
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
3022

            
3023
bulk insert is executed if database support bulk insert and 
3024
multiple parameters is passed to C<insert>.
3025
The SQL like the following one is executed.
3026

            
cleanup
Yuki Kimoto authored on 2012-01-20
3027
  insert into book (id, title) values (?, ?), (?, ?);
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
3028

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3029
=item C<ctime>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3030

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3031
  ctime => 'created_time'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3032

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3033
Created time column name. time when row is created is set to the column.
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3034
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by
3035
C<now> attribute.
3036

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3037
=item C<id>
3038

            
cleanup
Yuki Kimoto authored on 2012-01-20
3039
  id => 4
3040
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
3041

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3045
  $dbi->insert(
3046
    {title => 'Perl', author => 'Ken'}
3047
    primary_key => ['id1', 'id2'],
3048
    id => [4, 5],
3049
    table => 'book'
3050
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3054
  $dbi->insert(
3055
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
3056
    table => 'book'
3057
  );
update pod
Yuki Kimoto authored on 2011-03-13
3058

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3061
  prefix => 'or replace'
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3062

            
3063
prefix before table name section
3064

            
cleanup
Yuki Kimoto authored on 2012-01-20
3065
  insert or replace into book
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3066

            
updated document
Yuki Kimoto authored on 2011-06-09
3067
=item C<table>
3068

            
cleanup
Yuki Kimoto authored on 2012-01-20
3069
  table => 'book'
updated document
Yuki Kimoto authored on 2011-06-09
3070

            
3071
Table name.
3072

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3073
=item C<mtime>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3074

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3075
This option is same as C<update> method C<mtime> option.
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3076

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3077
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
3078

            
cleanup
Yuki Kimoto authored on 2012-01-20
3079
  wrap => {price => sub { "max($_[0])" }}
updated pod
Yuki Kimoto authored on 2011-09-02
3080

            
3081
placeholder wrapped string.
3082

            
3083
If the following statement
3084

            
cleanup
Yuki Kimoto authored on 2012-01-20
3085
  $dbi->insert({price => 100}, table => 'book',
3086
    {price => sub { "$_[0] + 5" }});
updated pod
Yuki Kimoto authored on 2011-09-02
3087

            
3088
is executed, the following SQL is executed.
3089

            
cleanup
Yuki Kimoto authored on 2012-01-20
3090
  insert into book price values ( ? + 5 );
updated pod
Yuki Kimoto authored on 2011-09-02
3091

            
update pod
Yuki Kimoto authored on 2011-03-13
3092
=back
3093

            
3094
=over 4
3095

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3098
  $dbi->include_model('MyModel');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3099

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3103
  lib / MyModel.pm
3104
      / MyModel / book.pm
3105
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3106

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3111
  package MyModel;
3112
  use DBIx::Custom::Model -base;
3113
  
3114
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3115

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3120
  package MyModel::book;
3121
  use MyModel -base;
3122
  
3123
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3124

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3127
  package MyModel::company;
3128
  use MyModel -base;
3129
  
3130
  1;
3131
  
updated pod
Yuki Kimoto authored on 2011-06-21
3132
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3133

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3136
  my $book_model = $dbi->model('book');
3137
  my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3138

            
support model full-qualified...
Yuki Kimoto authored on 2012-03-01
3139
You can include full-qualified table name like C<main.book>
3140

            
3141
  lib / MyModel.pm
3142
      / MyModel / main / book.pm
3143
                       / company.pm
3144

            
3145
  my $main_book = $self->model('main.book');
3146

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3149
=head2 C<like_value>
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3150

            
cleanup
Yuki Kimoto authored on 2012-01-20
3151
  my $like_value = $dbi->like_value
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3152

            
cleanup
Yuki Kimoto authored on 2011-10-20
3153
Code reference which return a value for the like value.
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3154

            
cleanup
Yuki Kimoto authored on 2012-01-20
3155
  sub { "%$_[0]%" }
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
3156

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3157
=head2 C<mapper>
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3158

            
cleanup
Yuki Kimoto authored on 2012-01-20
3159
  my $mapper = $dbi->mapper(param => $param);
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
3160

            
3161
Create a new L<DBIx::Custom::Mapper> object.
3162

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3165
  my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
3166

            
cleanup
Yuki Kimoto authored on 2011-10-20
3167
Merge parameters. The following new parameter is created.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
3168

            
cleanup
Yuki Kimoto authored on 2012-01-20
3169
  {key1 => [1, 1], key2 => 2}
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
3170

            
cleanup
Yuki Kimoto authored on 2011-10-20
3171
If same keys contains, the value is converted to array reference.
3172

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3175
  my $model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
3176

            
cleanup
Yuki Kimoto authored on 2011-10-20
3177
Get a L<DBIx::Custom::Model> object
3178
create by C<create_model> or C<include_model>
update pod
Yuki Kimoto authored on 2011-03-13
3179

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3182
  my $column = $dbi->mycolumn(book => ['author', 'title']);
cleanup
Yuki Kimoto authored on 2011-03-21
3183

            
3184
Create column clause for myself. The follwoing column clause is created.
3185

            
cleanup
Yuki Kimoto authored on 2012-01-20
3186
  book.author as author,
3187
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3188

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3191
  my $dbi = DBIx::Custom->new(
3192
    dsn => "dbi:mysql:database=dbname",
3193
    user => 'ken',
3194
    password => '!LFKD%$&',
3195
    option => {mysql_enable_utf8 => 1}
3196
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3197

            
3198
Create a new L<DBIx::Custom> object.
3199

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3202
  my $not_exists = $dbi->not_exists;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3203

            
update pod
Yuki Kimoto authored on 2011-03-13
3204
DBIx::Custom::NotExists object, indicating the column is not exists.
cleanup
Yuki Kimoto authored on 2011-10-20
3205
This is used in C<param> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
3206

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3207
=head2 C<order>
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3208

            
cleanup
Yuki Kimoto authored on 2012-01-20
3209
  my $order = $dbi->order;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3210

            
3211
Create a new L<DBIx::Custom::Order> object.
3212

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3213
=head2 C<q>
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
3214

            
cleanup
Yuki Kimoto authored on 2012-01-20
3215
  my $quooted = $dbi->q("title");
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
3216

            
3217
Quote string by value of C<quote>.
3218

            
cleanup
yuki-kimoto authored on 2010-10-17
3219
=head2 C<register_filter>
3220

            
cleanup
Yuki Kimoto authored on 2012-01-20
3221
  $dbi->register_filter(
3222
    # Time::Piece object to database DATE format
3223
    tp_to_date => sub {
3224
      my $tp = shift;
3225
      return $tp->strftime('%Y-%m-%d');
3226
    },
3227
    # database DATE format to Time::Piece object
3228
    date_to_tp => sub {
3229
      my $date = shift;
3230
      return Time::Piece->strptime($date, '%Y-%m-%d');
3231
    }
3232
  );
3233
  
update pod
Yuki Kimoto authored on 2011-03-13
3234
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3235

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3238
  my $result = $dbi->select(
3239
    column => ['author', 'title'],
3240
    table  => 'book',
3241
    where  => {author => 'Ken'},
3242
  );
3243
  
updated document
Yuki Kimoto authored on 2011-06-09
3244
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3245

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
3246
You can pass odd number arguments. first argument is C<column>.
3247

            
cleanup
Yuki Kimoto authored on 2012-01-20
3248
  my $result = $dbi->select(['author', 'title'], table => 'book');
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
3249

            
cleanup
Yuki Kimoto authored on 2011-10-20
3250
B<OPTIONS>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3251

            
cleanup
Yuki Kimoto authored on 2011-10-20
3252
C<select> method use all of C<execute> method's options,
3253
and use the following new ones.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3254

            
cleanup
Yuki Kimoto authored on 2011-10-20
3255
=over 4
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3256

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3257
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3258
  
3259
  column => 'author'
3260
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3261

            
3262
Column clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3263
  
updated document
Yuki Kimoto authored on 2011-06-09
3264
if C<column> is not specified, '*' is set.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3265

            
cleanup
Yuki Kimoto authored on 2012-01-20
3266
  column => '*'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3267

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3270
  column => [
3271
    {book => [qw/author title/]},
3272
    {person => [qw/name age/]}
3273
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3274

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3277
  book.author as "book.author",
3278
  book.title as "book.title",
3279
  person.name as "person.name",
3280
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3281

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3285
  column => [
3286
    ['date(book.register_datetime)' => 'book.register_date']
3287
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3288

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3291
  date(book.register_datetime) as "book.register_date"
updated pod
Yuki Kimoto authored on 2011-06-07
3292

            
updated document
Yuki Kimoto authored on 2011-06-09
3293
=item C<id>
3294

            
cleanup
Yuki Kimoto authored on 2012-01-20
3295
  id => 4
3296
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3297

            
3298
ID corresponding to C<primary_key>.
3299
You can select rows by C<id> and C<primary_key>.
3300

            
cleanup
Yuki Kimoto authored on 2012-01-20
3301
  $dbi->select(
3302
    primary_key => ['id1', 'id2'],
3303
    id => [4, 5],
3304
    table => 'book'
3305
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3306

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3309
  $dbi->select(
3310
    where => {id1 => 4, id2 => 5},
3311
    table => 'book'
3312
  );
3313
  
cleanup
Yuki Kimoto authored on 2011-10-20
3314
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3315

            
cleanup
Yuki Kimoto authored on 2012-01-20
3316
  param => {'table2.key3' => 5}
update pod
Yuki Kimoto authored on 2011-03-12
3317

            
updated document
Yuki Kimoto authored on 2011-06-09
3318
Parameter shown before where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3319
  
cleanup
Yuki Kimoto authored on 2012-02-28
3320
For example, if you want to contain named placeholder in join clause, 
updated document
Yuki Kimoto authored on 2011-06-09
3321
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
3322

            
cleanup
Yuki Kimoto authored on 2012-01-20
3323
  join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
3324
            ' as table2 on table1.key1 = table2.key1']
updated document
Yuki Kimoto authored on 2011-06-09
3325

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  prefix => 'SQL_CALC_FOUND_ROWS'
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3329

            
3330
Prefix of column cluase
3331

            
cleanup
Yuki Kimoto authored on 2012-01-20
3332
  select SQL_CALC_FOUND_ROWS title, author from book;
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3333

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3336
  join => [
3337
    'left outer join company on book.company_id = company_id',
3338
    'left outer join location on company.location_id = location.id'
3339
  ]
3340
      
updated document
Yuki Kimoto authored on 2011-06-09
3341
Join clause. If column cluase or where clause contain table name like "company.name",
3342
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3343

            
cleanup
Yuki Kimoto authored on 2012-01-20
3344
  $dbi->select(
3345
    table => 'book',
3346
    column => ['company.location_id as location_id'],
3347
    where => {'company.name' => 'Orange'},
3348
    join => [
3349
      'left outer join company on book.company_id = company.id',
3350
      'left outer join location on company.location_id = location.id'
3351
    ]
3352
  );
update pod
Yuki Kimoto authored on 2011-03-12
3353

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3357
  select company.location_id as location_id
3358
  from book
3359
    left outer join company on book.company_id = company.id
3360
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3361

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3362
You can specify two table by yourself. This is useful when join parser can't parse
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3363
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3364

            
cleanup
Yuki Kimoto authored on 2012-01-20
3365
  $dbi->select(
3366
    table => 'book',
3367
    column => ['company.location_id as location_id'],
3368
    where => {'company.name' => 'Orange'},
3369
    join => [
3370
      {
3371
        clause => 'left outer join location on company.location_id = location.id',
3372
        table => ['company', 'location']
3373
      }
3374
    ]
3375
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3376

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3379
  table => 'book'
updated pod
Yuki Kimoto authored on 2011-06-08
3380

            
updated document
Yuki Kimoto authored on 2011-06-09
3381
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3382

            
updated document
Yuki Kimoto authored on 2011-06-09
3383
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3384
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3385
  # (1) Hash reference
3386
  where => {author => 'Ken', 'title' => ['Perl', 'Ruby']}
3387
  # -> where author = 'Ken' and title in ('Perl', 'Ruby')
cleanup
Yuki Kimoto authored on 2012-01-20
3388
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3389
  # (2) DBIx::Custom::Where object
cleanup
Yuki Kimoto authored on 2012-01-20
3390
  where => $dbi->where(
3391
    clause => ['and', ':author{=}', ':title{like}'],
3392
    param  => {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3393
  )
3394
  # -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3395
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3396
  # (3) Array reference[Array refenrece, Hash reference]
cleanup
Yuki Kimoto authored on 2012-01-20
3397
  where => [
3398
    ['and', ':author{=}', ':title{like}'],
3399
    {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3400
  ]
3401
  # -> where author = 'Ken' and title like '%Perl%'
3402
  
3403
  # (4) Array reference[String, Hash reference]
3404
  where => [
3405
    ':author{=} and :title{like}',
3406
    {author => 'Ken', title => '%Perl%'}
3407
  ]
3408
  #  -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3409
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3410
  # (5) String
cleanup
Yuki Kimoto authored on 2012-01-20
3411
  where => 'title is null'
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3412
  #  -> where title is null
update pod
Yuki Kimoto authored on 2011-03-12
3413

            
improved where document
Yuki Kimoto authored on 2012-03-01
3414
Where clause.
3415
See also L<DBIx::Custom::Where> to know how to create where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3416
  
update pod
Yuki Kimoto authored on 2011-03-12
3417
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3418

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3419
=head2 C<setup_model>
3420

            
cleanup
Yuki Kimoto authored on 2012-01-20
3421
  $dbi->setup_model;
improved test
Yuki Kimoto authored on 2012-03-01
3422
  $dbi->setup_model(database => 'main');
3423
  $dbi->setup_model(database => 'main', prefix => 1);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3424

            
3425
Setup all model objects.
3426
C<columns> of model object is automatically set, parsing database information.
3427

            
improved test
Yuki Kimoto authored on 2012-03-01
3428
If C<database> option is specified, only the database is searched.
3429

            
3430
If C<prefix> option is specified, Target model is qualified by dabtabase name
3431
like C<main.book>.
3432

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3433
=head2 C<type_rule>
3434

            
cleanup
Yuki Kimoto authored on 2012-01-20
3435
  $dbi->type_rule(
3436
    into1 => {
3437
      date => sub { ... },
3438
      datetime => sub { ... }
3439
    },
3440
    into2 => {
3441
      date => sub { ... },
3442
      datetime => sub { ... }
3443
    },
3444
    from1 => {
3445
      # DATE
3446
      9 => sub { ... },
3447
      # DATETIME or TIMESTAMP
3448
      11 => sub { ... },
3449
    }
3450
    from2 => {
3451
      # DATE
3452
      9 => sub { ... },
3453
      # DATETIME or TIMESTAMP
3454
      11 => sub { ... },
3455
    }
3456
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3457

            
3458
Filtering rule when data is send into and get from database.
3459
This has a little complex problem.
3460

            
3461
In C<into1> and C<into2> you can specify
3462
type name as same as type name defined
3463
by create table, such as C<DATETIME> or C<DATE>.
3464

            
3465
Note that type name and data type don't contain upper case.
3466
If these contain upper case charactor, you convert it to lower case.
3467

            
3468
C<into2> is executed after C<into1>.
3469

            
3470
Type rule of C<into1> and C<into2> is enabled on the following
3471
column name.
3472

            
3473
=over 4
3474

            
3475
=item 1. column name
3476

            
cleanup
Yuki Kimoto authored on 2012-01-20
3477
  issue_date
3478
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3479

            
3480
This need C<table> option in each method.
3481

            
3482
=item 2. table name and column name, separator is dot
3483

            
cleanup
Yuki Kimoto authored on 2012-01-20
3484
  book.issue_date
3485
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3486

            
3487
=back
3488

            
3489
You get all type name used in database by C<available_typename>.
3490

            
cleanup
Yuki Kimoto authored on 2012-01-20
3491
  print $dbi->available_typename;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3492

            
3493
In C<from1> and C<from2> you specify data type, not type name.
3494
C<from2> is executed after C<from1>.
3495
You get all data type by C<available_datatype>.
3496

            
cleanup
Yuki Kimoto authored on 2012-01-20
3497
  print $dbi->available_datatype;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3498

            
3499
You can also specify multiple types at once.
3500

            
cleanup
Yuki Kimoto authored on 2012-01-20
3501
  $dbi->type_rule(
3502
    into1 => [
3503
      [qw/DATE DATETIME/] => sub { ... },
3504
    ],
3505
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3506

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3509
  $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
removed reconnect method
yuki-kimoto authored on 2010-05-28
3510

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

            
3513
If you want to set constant value to row data, use scalar reference
3514
as parameter value.
3515

            
cleanup
Yuki Kimoto authored on 2012-01-20
3516
  {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3517

            
cleanup
Yuki Kimoto authored on 2011-10-20
3518
B<OPTIONS>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3519

            
cleanup
Yuki Kimoto authored on 2011-10-20
3520
C<update> method use all of C<execute> method's options,
3521
and use the following new ones.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3522

            
cleanup
Yuki Kimoto authored on 2011-10-20
3523
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3524

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3527
  id => 4
3528
  id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3529

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3533
  $dbi->update(
3534
    {title => 'Perl', author => 'Ken'}
3535
    primary_key => ['id1', 'id2'],
3536
    id => [4, 5],
3537
    table => 'book'
3538
  );
update pod
Yuki Kimoto authored on 2011-03-13
3539

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3542
  $dbi->update(
3543
    {title => 'Perl', author => 'Ken'}
3544
    where => {id1 => 4, id2 => 5},
3545
    table => 'book'
3546
  );
update pod
Yuki Kimoto authored on 2011-03-13
3547

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3550
  prefix => 'or replace'
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3551

            
3552
prefix before table name section
3553

            
cleanup
Yuki Kimoto authored on 2012-01-20
3554
  update or replace book
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3555

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3558
  table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
3559

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3562
=item C<where>
3563

            
3564
Same as C<select> method's C<where> option.
3565

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3566
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
3567

            
cleanup
Yuki Kimoto authored on 2012-01-20
3568
  wrap => {price => sub { "max($_[0])" }}
updated pod
Yuki Kimoto authored on 2011-09-02
3569

            
3570
placeholder wrapped string.
3571

            
3572
If the following statement
3573

            
cleanup
Yuki Kimoto authored on 2012-01-20
3574
  $dbi->update({price => 100}, table => 'book',
3575
    {price => sub { "$_[0] + 5" }});
updated pod
Yuki Kimoto authored on 2011-09-02
3576

            
3577
is executed, the following SQL is executed.
3578

            
cleanup
Yuki Kimoto authored on 2012-01-20
3579
  update book set price =  ? + 5;
updated pod
Yuki Kimoto authored on 2011-09-02
3580

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3581
=item C<mtime>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3582

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3583
  mtime => 'modified_time'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3584

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3585
Modified time column name. time row is updated is set to the column.
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3586
default time format is C<YYYY-mm-dd HH:MM:SS>, which can be changed by
3587
C<now> attribute.
3588

            
updated pod
Yuki Kimoto authored on 2011-06-08
3589
=back
update pod
Yuki Kimoto authored on 2011-03-13
3590

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3593
  $dbi->update_all({title => 'Perl'}, table => 'book', );
update pod
Yuki Kimoto authored on 2011-03-13
3594

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3598
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3599
  
3600
  # ID
3601
  $dbi->update_or_insert(
3602
    {title => 'Perl'},
3603
    table => 'book',
3604
    id => 1,
3605
    primary_key => 'id',
3606
    option => {
3607
      select => {
3608
         append => 'for update'
3609
      }
3610
    }
3611
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3612

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3613
Update or insert.
3614

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3615
C<update_or_insert> method execute C<select> method first to find row.
3616
If the row is exists, C<update> is executed.
3617
If not, C<insert> is executed.
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3618

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3619
C<OPTIONS>
3620

            
3621
C<update_or_insert> method use all common option
3622
in C<select>, C<update>, C<delete>, and has the following new ones.
3623

            
3624
=over 4
3625

            
3626
=item C<option>
3627

            
cleanup
Yuki Kimoto authored on 2012-01-20
3628
  option => {
3629
    select => {
3630
      append => '...'
3631
    },
3632
    insert => {
3633
      prefix => '...'
3634
    },
3635
    update => {
3636
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3637
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3638
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3639

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3640
If you want to pass option to each method,
3641
you can use C<option> option.
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3642

            
3643
=over 4
3644

            
3645
=item C<select_option>
3646

            
cleanup
Yuki Kimoto authored on 2012-01-20
3647
  select_option => {append => 'for update'}
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3648

            
3649
select method option,
3650
select method is used to check the row is already exists.
3651

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3652
=head2 C<show_datatype>
update pod
Yuki Kimoto authored on 2011-08-10
3653

            
cleanup
Yuki Kimoto authored on 2012-01-20
3654
  $dbi->show_datatype($table);
update pod
Yuki Kimoto authored on 2011-08-10
3655

            
3656
Show data type of the columns of specified table.
3657

            
cleanup
Yuki Kimoto authored on 2012-01-20
3658
  book
3659
  title: 5
3660
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3661

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

            
- removed EXPERIMENTAL the f...
Yuki Kimoto authored on 2011-09-12
3664
=head2 C<show_tables>
test cleanup
Yuki Kimoto authored on 2011-08-15
3665

            
cleanup
Yuki Kimoto authored on 2012-01-20
3666
  $dbi->show_tables;
test cleanup
Yuki Kimoto authored on 2011-08-15
3667

            
3668
Show tables.
3669

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3670
=head2 C<show_typename>
update pod
Yuki Kimoto authored on 2011-08-10
3671

            
cleanup
Yuki Kimoto authored on 2012-01-20
3672
  $dbi->show_typename($table);
update pod
Yuki Kimoto authored on 2011-08-10
3673

            
3674
Show type name of the columns of specified table.
3675

            
cleanup
Yuki Kimoto authored on 2012-01-20
3676
  book
3677
  title: varchar
3678
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3679

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3682
=head2 C<values_clause>
3683

            
cleanup
Yuki Kimoto authored on 2012-01-20
3684
  my $values_clause = $dbi->values_clause({title => 'a', age => 2});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3685

            
3686
Create values clause.
3687

            
cleanup
Yuki Kimoto authored on 2012-01-20
3688
  (title, author) values (title = :title, age = :age);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3689

            
3690
You can use this in insert statement.
3691

            
cleanup
Yuki Kimoto authored on 2012-01-20
3692
  my $insert_sql = "insert into book $values_clause";
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3693

            
3694
=head2 C<where>
3695

            
cleanup
Yuki Kimoto authored on 2012-01-20
3696
  my $where = $dbi->where(
3697
    clause => ['and', 'title = :title', 'author = :author'],
3698
    param => {title => 'Perl', author => 'Ken'}
3699
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3700

            
3701
Create a new L<DBIx::Custom::Where> object.
improved where document
Yuki Kimoto authored on 2012-03-01
3702
See L<DBIx::Custom::Where> to know how to create where clause.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3703

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3704
=head1 ENVIRONMENTAL VARIABLES
3705

            
3706
=head2 C<DBIX_CUSTOM_DEBUG>
3707

            
3708
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3709
executed SQL and bind values are printed to STDERR.
3710

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3715
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3716

            
3717
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3718

            
3719
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3720

            
3721
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3722
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3723

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3724
=head1 DEPRECATED FUNCTIONALITY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3725

            
3726
L<DBIx::Custom>
3727

            
cleanup
Yuki Kimoto authored on 2012-01-20
3728
  # Attribute methods
3729
  tag_parse # will be removed 2017/1/1
3730
  default_dbi_option # will be removed 2017/1/1
3731
  dbi_option # will be removed 2017/1/1
3732
  data_source # will be removed at 2017/1/1
3733
  dbi_options # will be removed at 2017/1/1
3734
  filter_check # will be removed at 2017/1/1
3735
  reserved_word_quote # will be removed at 2017/1/1
3736
  cache_method # will be removed at 2017/1/1
3737
  
3738
  # Methods
3739
  update_timestamp # will be removed at 2017/1/1
3740
  insert_timestamp # will be removed at 2017/1/1
3741
  method # will be removed at 2017/1/1
3742
  assign_param # will be removed at 2017/1/1
3743
  update_param # will be removed at 2017/1/1
3744
  insert_param # will be removed at 2017/1/1
3745
  create_query # will be removed at 2017/1/1
3746
  apply_filter # will be removed at 2017/1/1
3747
  select_at # will be removed at 2017/1/1
3748
  delete_at # will be removed at 2017/1/1
3749
  update_at # will be removed at 2017/1/1
3750
  insert_at # will be removed at 2017/1/1
3751
  register_tag # will be removed at 2017/1/1
3752
  default_bind_filter # will be removed at 2017/1/1
3753
  default_fetch_filter # will be removed at 2017/1/1
3754
  insert_param_tag # will be removed at 2017/1/1
3755
  register_tag # will be removed at 2017/1/1
3756
  register_tag_processor # will be removed at 2017/1/1
3757
  update_param_tag # will be removed at 2017/1/1
3758
  
3759
  # Options
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3760
  insert method created_at option # will be removed 2017/3/1
3761
  update method updated_at option # will be removed 2017/3/1
cleanup
Yuki Kimoto authored on 2012-01-20
3762
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3763
  execute method id option # will be removed 2017/1/1
3764
  update timestamp option # will be removed 2017/1/1
3765
  insert timestamp option # will be removed 2017/1/1
3766
  select method where_param option # will be removed 2017/1/1
3767
  delete method where_param option # will be removed 2017/1/1
3768
  update method where_param option # will be removed 2017/1/1
3769
  insert method param option # will be removed at 2017/1/1
3770
  insert method id option # will be removed at 2017/1/1
3771
  select method relation option # will be removed at 2017/1/1
3772
  select method column option [COLUMN, as => ALIAS] format
3773
    # will be removed at 2017/1/1
3774
  execute method's sqlfilter option # will be removed at 2017/1/1
3775
  
3776
  # Others
3777
  execute($query, ...) # execute method receiving query object.
3778
                       # this is removed at 2017/1/1
3779
  execute("select * from {= title}"); # execute method's
3780
                                      # tag parsing functionality
3781
                                      # will be removed at 2017/1/1
3782
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3783

            
3784
L<DBIx::Custom::Model>
3785

            
cleanup
Yuki Kimoto authored on 2012-01-20
3786
  # Attribute methods
3787
  execute # will be removed at 2017/1/1
3788
  method # will be removed at 2017/1/1
3789
  filter # will be removed at 2017/1/1
3790
  name # will be removed at 2017/1/1
3791
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3792

            
3793
L<DBIx::Custom::Query>
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
3794

            
3795
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3796
  
3797
  # Attribute methods
3798
  default_filter # will be removed at 2017/1/1
3799
  table # will be removed at 2017/1/1
3800
  filters # will be removed at 2017/1/1
3801
  
3802
  # Methods
3803
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3804

            
3805
L<DBIx::Custom::QueryBuilder>
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3806

            
3807
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3808
  
3809
  # Attribute methods
3810
  tags # will be removed at 2017/1/1
3811
  tag_processors # will be removed at 2017/1/1
3812
  
3813
  # Methods
3814
  register_tag # will be removed at 2017/1/1
3815
  register_tag_processor # will be removed at 2017/1/1
3816
  
3817
  # Others
3818
  build_query("select * from {= title}"); # tag parsing functionality
3819
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3820

            
3821
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3822
  
3823
  # Attribute methods
3824
  filter_check # will be removed at 2017/1/1
3825
  
3826
  # Methods
3827
  fetch_first # will be removed at 2017/2/1
3828
  fetch_hash_first # will be removed 2017/2/1
3829
  filter_on # will be removed at 2017/1/1
3830
  filter_off # will be removed at 2017/1/1
3831
  end_filter # will be removed at 2017/1/1
3832
  remove_end_filter # will be removed at 2017/1/1
3833
  remove_filter # will be removed at 2017/1/1
3834
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3835

            
3836
L<DBIx::Custom::Tag>
3837

            
cleanup
Yuki Kimoto authored on 2012-01-20
3838
  This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3839

            
micro optimization
Yuki Kimoto authored on 2011-11-07
3840
L<DBIx::Custom::Order>
3841

            
cleanup
Yuki Kimoto authored on 2012-01-20
3842
  # Other
3843
  prepend method array reference receiving
3844
    $order->prepend(['book', 'desc']); # will be removed 2017/1/1
micro optimization
Yuki Kimoto authored on 2011-11-07
3845

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3846
=head1 BACKWARDS COMPATIBILITY POLICY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3847

            
3848
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3849
except for attribute method.
3850
You can check all DEPRECATED functionalities by document.
3851
DEPRECATED functionality is removed after five years,
3852
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
3853
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3854

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

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

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

            
3861
C<< <kimoto.yuki at gmail.com> >>
3862

            
3863
L<http://github.com/yuki-kimoto/DBIx-Custom>
3864

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3865
=head1 AUTHOR
3866

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

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

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

            
3873
This program is free software; you can redistribute it and/or modify it
3874
under the same terms as Perl itself.
3875

            
3876
=cut