DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3896 lines | 96.469kb
- "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

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
5
our $VERSION = '0.27';
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;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
16
use DBIx::Custom::Util qw/_array_to_hash _subname _deprecate/;
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 default_s...
Yuki Kimoto authored on 2012-03-02
23
has [qw/connector dsn default_schema 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) = @_;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
233
  _deprecate('0.24', "delete method where_param option is DEPRECATED!")
cleanup
Yuki Kimoto authored on 2012-01-20
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 ||= [];
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
281
    _deprecate('0.24', "DBIx::Custom::Model filter method is DEPRECATED!")
cleanup
Yuki Kimoto authored on 2012-01-20
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
      $tables->{$schema}{$table}++;
308
    });
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
309

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

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

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

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

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

            
457
  # Merge id to parameter
458
  if (defined $opt{id}) {
459
    my $statement = $query->{statement};
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
460
    _deprecate('0.24', "execute method id option is DEPRECATED!")
461
      unless $statement;
cleanup
Yuki Kimoto authored on 2012-01-20
462
    croak "execute id option must be specified with primary_key option"
463
      unless $opt{primary_key};
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
464
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key} eq 'ARRAY';
465
    $opt{id} = [$opt{id}] unless ref $opt{id} eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2012-01-20
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 = @_;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
688
  _deprecate('0.24', "insert method param option is DEPRECATED!")
689
    if $opt{param};
cleanup
Yuki Kimoto authored on 2012-01-20
690
  $params ||= delete $opt{param} || {};
691
  
692
  my $multi;
693
  if (ref $params eq 'ARRAY') { $multi = 1 }
694
  else { $params = [$params] }
695
  
696
  # Timestamp(DEPRECATED!)
697
  if (!$multi && $opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
698
    _deprecate('0.24', "insert timestamp option is DEPRECATED! use ctime option");
cleanup
Yuki Kimoto authored on 2012-01-20
699
    my $columns = $insert_timestamp->[0];
700
    $columns = [$columns] unless ref $columns eq 'ARRAY';
701
    my $value = $insert_timestamp->[1];
702
    $value = $value->() if ref $value eq 'CODE';
703
    $params->[0]->{$_} = $value for @$columns;
704
  }
705

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1124
sub setup_model {
improved test
Yuki Kimoto authored on 2012-03-01
1125
  my ($self, %opt) = @_;
cleanup
Yuki Kimoto authored on 2012-01-20
1126
  
1127
  # Setup model
1128
  $self->each_column(
1129
    sub {
1130
      my ($self, $table, $column, $column_info) = @_;
cleanup
Yuki Kimoto authored on 2012-03-02
1131
      my $schema = $column_info->{TABLE_SCHEM};
improved test
Yuki Kimoto authored on 2012-03-01
1132
      
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
1133
      my $default_schema = $self->default_schema;
1134
      
cleanup
Yuki Kimoto authored on 2012-01-20
1135
      if (my $model = $self->models->{$table}) {
fixed setup method logic
Yuki Kimoto authored on 2012-03-02
1136
        if (!defined $default_schema || $default_schema eq $schema) {
1137
          push @{$model->columns}, $column;
1138
        }
1139
      }
1140
      if (my $fullqualified_model = $self->models->{"$schema.$table"}) {
1141
        push @{$fullqualified_model->columns}, $column;
cleanup
Yuki Kimoto authored on 2012-01-20
1142
      }
1143
    }
1144
  );
1145
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1146
}
1147

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

            
1156
  my $columns = $sth->{NAME};
1157
  my $data_types = $sth->{TYPE};
1158
  
1159
  for (my $i = 0; $i < @$columns; $i++) {
1160
    my $column = $columns->[$i];
1161
    my $data_type = lc $data_types->[$i];
1162
    print "$column: $data_type\n";
1163
  }
update pod
Yuki Kimoto authored on 2011-08-10
1164
}
1165

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1181
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1182
  my $self = shift;
1183
  
1184
  my %tables;
1185
  $self->each_table(sub { $tables{$_[1]}++ });
1186
  print join("\n", sort keys %tables) . "\n";
1187
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1188
}
1189

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1262
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1263
  my $self = shift;
1264

            
1265
  # Options
1266
  my $param = @_ % 2 ? shift : undef;
1267
  my %opt = @_;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1268
  _deprecate('0.24', "update param option is DEPRECATED!") if $opt{param};
1269
  _deprecate('0.24', "update method where_param option is DEPRECATED!")
cleanup
Yuki Kimoto authored on 2012-01-20
1270
    if $opt{where_param};
1271
  $param ||= $opt{param} || {};
1272
  
1273
  # Don't allow update all rows
1274
  croak qq{update method where option must be specified } . _subname
1275
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1276
  
1277
  # Timestamp(DEPRECATED!)
1278
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1279
    _deprecate('0.24', "update timestamp option is DEPRECATED! use mtime");
cleanup
Yuki Kimoto authored on 2012-01-20
1280
    my $columns = $update_timestamp->[0];
1281
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1282
    my $value = $update_timestamp->[1];
1283
    $value = $value->() if ref $value eq 'CODE';
1284
    $param->{$_} = $value for @$columns;
1285
  }
1286

            
1287
  # Created time and updated time
1288
  my @timestamp_cleanup;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1289
  _deprecate('0.24', "update method update_at option is DEPRECATED! " .
1290
      "use mtime option instead.")
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1291
    if $opt{updated_at};
1292
  $opt{mtime} ||= $opt{updated_at};
1293
  if (defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
1294
    my $now = $self->now;
1295
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1296
    $param->{$opt{mtime}} = $self->now->();
1297
    push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
1298
  }
1299

            
1300
  # Assign clause
1301
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1302
  
1303
  # Where
1304
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1305
    delete $opt{id}, $opt{primary_key}, $opt{table});
1306
  
1307
  # Update statement
1308
  my $sql = "update ";
1309
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1310
  $sql .= $self->_tq($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
1311
  
1312
  # Execute query
1313
  $opt{statement} = 'update';
1314
  $opt{cleanup} = \@timestamp_cleanup;
1315
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1316
}
1317

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1320
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1321
  my ($self, $param, %opt) = @_;
1322
  croak "update_or_insert method need primary_key and id option "
1323
    unless defined $opt{id} && defined $opt{primary_key};
1324
  my $statement_opt = $opt{option} || {};
1325

            
1326
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1327
  if (@$rows == 0) {
1328
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1329
  }
1330
  elsif (@$rows == 1) {
1331
    return 0 unless keys %$param;
1332
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1333
  }
1334
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1335
}
1336

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1337
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1338
  my $self = shift;
1339
  
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1340
  _deprecate('0.24', "update_timestamp method is DEPRECATED! use now method");
cleanup
Yuki Kimoto authored on 2012-01-20
1341
  
1342
  if (@_) {
1343
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1344
    
cleanup
Yuki Kimoto authored on 2012-01-20
1345
    return $self;
1346
  }
1347
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1348
}
1349

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1402
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1403
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1404
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1405
  
1406
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1407
  
1408
  # Cache
1409
  my $cache = $self->{cache};
1410
  
1411
  # Query
1412
  my $query;
1413
  
1414
  # Get cached query
1415
  if ($cache) {
1416
    
1417
    # Get query
1418
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1419
    
1420
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1421
    if ($q) {
1422
      $query = DBIx::Custom::Query->new($q);
1423
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1424
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1425
  }
1426
  
1427
  # Create query
1428
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1429

            
cleanup
Yuki Kimoto authored on 2012-01-20
1430
    # Create query
1431
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1432
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1433

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

            
1458
      # Create query
1459
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1460
    }
1461
    
1462
    # Save query to cache
1463
    $self->cache_method->(
1464
      $self, $source,
1465
      {
1466
        sql     => $query->{sql}, 
1467
        columns => $query->{columns},
1468
        tables  => $query->{tables} || []
1469
      }
1470
    ) if $cache;
1471
  }
1472

            
1473
  # Filter SQL
1474
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1475
  
1476
  # Save sql
1477
  $self->{last_sql} = $query->{sql};
1478
  
1479
  # Prepare statement handle
1480
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1481
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1482
  
1483
  if ($@) {
1484
    $self->_croak($@, qq{. Following SQL is executed.\n}
1485
                    . qq{$query->{sql}\n} . _subname);
1486
  }
1487
  
1488
  # Set statement handle
1489
  $query->{sth} = $sth;
1490
  
1491
  # Set filters
1492
  $query->{filters} = $self->{filters} || $self->filters;
1493
  
1494
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1495
}
1496

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

            
1553
sub _id_to_param {
1554
  my ($self, $id, $primary_keys, $table) = @_;
1555
  
1556
  # Check primary key
1557
  croak "primary_key option " .
1558
        "must be specified when id option is used" . _subname
1559
    unless defined $primary_keys;
1560
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1561
  
1562
  # Create parameter
1563
  my $param = {};
1564
  if (defined $id) {
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
1565
    $id = [$id] unless ref $id eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2012-01-20
1566
    for(my $i = 0; $i < @$id; $i++) {
1567
      my $key = $primary_keys->[$i];
1568
      $key = "$table." . $key if $table;
1569
      $param->{$key} = $id->[$i];
1570
    }
1571
  }
1572
  
1573
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1574
}
1575

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1576
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1577
  my $self = shift;
1578
  
1579
  # Attributes
1580
  my $dsn = $self->data_source;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1581
  _deprecate('0.24', "data_source is DEPRECATED!\n")
cleanup
Yuki Kimoto authored on 2012-01-20
1582
    if $dsn;
1583
  $dsn ||= $self->dsn;
1584
  croak qq{"dsn" must be specified } . _subname
1585
    unless $dsn;
1586
  my $user        = $self->user;
1587
  my $password    = $self->password;
1588
  my $option = $self->_option;
1589
  $option = {%{$self->default_option}, %$option};
1590
  
1591
  # Connect
1592
  my $dbh;
1593
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1594
  
1595
  # Connect error
1596
  croak "$@ " . _subname if $@;
1597
  
1598
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1599
}
1600

            
cleanup
yuki-kimoto authored on 2010-10-17
1601
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1602
  my ($self, $error, $append) = @_;
1603
  
1604
  # Append
1605
  $append ||= "";
1606
  
1607
  # Verbose
1608
  if ($Carp::Verbose) { croak $error }
1609
  
1610
  # Not verbose
1611
  else {
1612
    # Remove line and module infromation
1613
    my $at_pos = rindex($error, ' at ');
1614
    $error = substr($error, 0, $at_pos);
1615
    $error =~ s/\s+$//;
1616
    croak "$error$append";
1617
  }
cleanup
yuki-kimoto authored on 2010-10-17
1618
}
1619

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1622
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1623
  my ($self, $tree, $need_tables, $tables) = @_;
1624
  
1625
  # Get needed tables
1626
  for my $table (@$tables) {
1627
    if ($tree->{$table}) {
1628
      $need_tables->{$table} = 1;
1629
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1630
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1631
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1632
}
1633

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1634
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1635
  my $self = shift;
1636
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1637
  _deprecate('0.24', "dbi_options is DEPRECATED! use option instead\n")
cleanup
Yuki Kimoto authored on 2012-01-20
1638
    if keys %{$self->dbi_options};
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1639
  _deprecate('0.24', "dbi_option is DEPRECATED! use option instead\n")
cleanup
Yuki Kimoto authored on 2012-01-20
1640
    if keys %{$self->dbi_option};
1641
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1642
}
1643

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1644
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1645
  my ($self, $sql, $join, $join_tables) = @_;
1646
  
1647
  $join = [$join] unless ref $join eq 'ARRAY';
1648
  
1649
  # No join
1650
  return unless @$join;
1651
  
1652
  # Push join clause
1653
  my $tree = {};
1654
  for (my $i = 0; $i < @$join; $i++) {
1655
    
1656
    # Arrange
1657
    my $join_clause;;
1658
    my $option;
1659
    if (ref $join->[$i] eq 'HASH') {
1660
      $join_clause = $join->[$i]->{clause};
1661
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1662
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1663
    else {
1664
      $join_clause = $join->[$i];
1665
      $option = {};
1666
    };
1667

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1714
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1715
  my $self = shift;
1716
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1717
}
1718

            
cleanup
Yuki Kimoto authored on 2011-04-02
1719
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1720
  my ($self, $tables, $main_table) = @_;
1721
  
1722
  # Remove duplicate table
1723
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1724
  delete $tables{$main_table} if $main_table;
1725
  
1726
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1727
  if (my $q = $self->_quote) {
1728
    $q = quotemeta($q);
1729
    $_ =~ s/[$q]//g for @$new_tables;
1730
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1731

            
cleanup
Yuki Kimoto authored on 2012-01-20
1732
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1733
}
1734

            
cleanup
Yuki Kimoto authored on 2011-04-02
1735
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1736
  my ($self, $source) = @_;
1737
  
1738
  # Search tables
1739
  my $tables = [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1740
  my ($q, $p) = $self->_qp(quotemeta => 1);
1741
  $source =~ s/$q//g;
1742
  $source =~ s/$p//g;
1743
  my $c = $self->safety_character;
1744
  
1745
  while ($source =~ /((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/g) {
1746
    push @$tables, $1;
1747
  }
cleanup
Yuki Kimoto authored on 2012-01-20
1748
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1749
}
1750

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

            
1754
  $where ||= {};
1755
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1756
  $where_param ||= {};
1757
  my $w = {};
1758

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

            
1795
    if (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2012-01-20
1796
    elsif (ref $where eq 'ARRAY') {
1797
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1798
    }
1799
    
1800
    # Check where argument
1801
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1802
        . qq{or array reference, which contains where clause and parameter}
1803
        . _subname
1804
      unless ref $obj eq 'DBIx::Custom::Where';
1805

            
cleanup
Yuki Kimoto authored on 2012-02-28
1806
    $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2012-01-20
1807
    $w->{param} = keys %$where_param
1808
      ? $self->merge_param($where_param, $obj->param)
1809
      : $obj->param;
1810
  }
1811
  elsif ($where) {
1812
    $w->{clause} = "where $where";
1813
    $w->{param} = $where_param;
1814
  }
1815
  
1816
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1817
}
1818

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1886
# DEPRECATED!
1887
has 'data_source';
1888
has dbi_options => sub { {} };
1889
has filter_check  => 1;
1890
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1891
has dbi_option => sub { {} };
1892
has default_dbi_option => sub {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1893
  _deprecate('0.24', "default_dbi_option is DEPRECATED! use default_option instead");
cleanup
Yuki Kimoto authored on 2012-01-20
1894
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1895
};
1896

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1897
# DEPRECATED
1898
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1899
 my $self = shift;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1900
 _deprecate('0.24', "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1901
   "environment variable");
cleanup
Yuki Kimoto authored on 2012-01-20
1902
  if (@_) {
1903
    $self->{tag_parse} = $_[0];
1904
    return $self;
1905
  }
1906
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1907
}
1908

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1909
# DEPRECATED!
1910
sub method {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1911
  _deprecate('0.24', "method is DEPRECATED! use helper instead");
cleanup
Yuki Kimoto authored on 2012-01-20
1912
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1913
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1914

            
1915
# DEPRECATED!
1916
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1917
  my $self = shift;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1918
  _deprecate('0.24', "assing_param is DEPRECATED! use assign_clause instead");
cleanup
Yuki Kimoto authored on 2012-01-20
1919
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1920
}
1921

            
1922
# DEPRECATED
1923
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1924
  my ($self, $param, $opts) = @_;
1925
  
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1926
  _deprecate('0.24', "update_param is DEPRECATED! use assign_clause instead.");
cleanup
Yuki Kimoto authored on 2012-01-20
1927
  
1928
  # Create update parameter tag
1929
  my $tag = $self->assign_clause($param, $opts);
1930
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1931

            
cleanup
Yuki Kimoto authored on 2012-01-20
1932
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1933
}
1934

            
updated pod
Yuki Kimoto authored on 2011-06-21
1935
# DEPRECATED!
1936
sub create_query {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1937
  _deprecate('0.24', "create_query is DEPRECATED! use query option of each method");
cleanup
Yuki Kimoto authored on 2012-01-20
1938
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1939
}
1940

            
cleanup
Yuki Kimoto authored on 2011-06-13
1941
# DEPRECATED!
1942
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1943
  my $self = shift;
1944
  
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1945
  _deprecate('0.24', "apply_filter is DEPRECATED!");
cleanup
Yuki Kimoto authored on 2012-01-20
1946
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1947
}
1948

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

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1953
  _deprecate('0.24', "select_at is DEPRECATED! use select method id option instead");
cleanup
Yuki Kimoto authored on 2012-01-20
1954

            
1955
  # Options
1956
  my $primary_keys = delete $opt{primary_key};
1957
  my $where = delete $opt{where};
1958
  my $param = delete $opt{param};
1959
  
1960
  # Table
1961
  croak qq{"table" option must be specified } . _subname
1962
    unless $opt{table};
1963
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1964
  
1965
  # Create where parameter
1966
  my $where_param = $self->_id_to_param($where, $primary_keys);
1967
  
1968
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1969
}
1970

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

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1975
  _deprecate('0.24', "delete_at is DEPRECATED! use delete method id option instead");
cleanup
Yuki Kimoto authored on 2012-01-20
1976
  
1977
  # Options
1978
  my $primary_keys = delete $opt{primary_key};
1979
  my $where = delete $opt{where};
1980
  
1981
  # Create where parameter
1982
  my $where_param = $self->_id_to_param($where, $primary_keys);
1983
  
1984
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1985
}
1986

            
cleanup
Yuki Kimoto authored on 2011-06-08
1987
# DEPRECATED!
1988
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1989
  my $self = shift;
1990

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
1991
  _deprecate('0.24', "update_at is DEPRECATED! use update method id option instead");
cleanup
Yuki Kimoto authored on 2012-01-20
1992
  
1993
  # Options
1994
  my $param;
1995
  $param = shift if @_ % 2;
1996
  my %opt = @_;
1997
  my $primary_keys = delete $opt{primary_key};
1998
  my $where = delete $opt{where};
1999
  my $p = delete $opt{param} || {};
2000
  $param  ||= $p;
2001
  
2002
  # Create where parameter
2003
  my $where_param = $self->_id_to_param($where, $primary_keys);
2004
  
2005
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
2006
}
2007

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2008
# DEPRECATED!
2009
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
2010
  my $self = shift;
2011
  
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2012
  _deprecate('0.24', "insert_at is DEPRECATED! use insert method id option instead");
cleanup
Yuki Kimoto authored on 2012-01-20
2013
  
2014
  # Options
2015
  my $param;
2016
  $param = shift if @_ % 2;
2017
  my %opt = @_;
2018
  my $primary_key = delete $opt{primary_key};
fixed bug that when id optio...
Yuki Kimoto authored on 2012-07-11
2019
  $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2012-01-20
2020
  my $where = delete $opt{where};
2021
  my $p = delete $opt{param} || {};
2022
  $param  ||= $p;
2023
  
2024
  # Create where parameter
2025
  my $where_param = $self->_id_to_param($where, $primary_key);
2026
  $param = $self->merge_param($where_param, $param);
2027
  
2028
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2029
}
2030

            
added warnings
Yuki Kimoto authored on 2011-06-07
2031
# DEPRECATED!
2032
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2033
  my $self = shift;
2034
  
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2035
  _deprecate('0.24', "register_tag is DEPRECATED!");
cleanup
Yuki Kimoto authored on 2012-01-20
2036
  
2037
  # Merge tag
2038
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2039
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
2040
  
2041
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
2042
}
2043

            
2044
# DEPRECATED!
2045
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
2046
  my $self = shift;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2047
  _deprecate('0.24', "register_tag_processor is DEPRECATED!");
cleanup
Yuki Kimoto authored on 2012-01-20
2048
  # Merge tag
2049
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2050
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
2051
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
2052
}
2053

            
cleanup
Yuki Kimoto authored on 2011-01-25
2054
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2055
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2056
  my $self = shift;
2057
  
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2058
  _deprecate('0.24', "default_bind_filter is DEPRECATED!");
cleanup
Yuki Kimoto authored on 2012-01-20
2059
  
2060
  if (@_) {
2061
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
2062
    
cleanup
Yuki Kimoto authored on 2012-01-20
2063
    if (@_ && !$fname) {
2064
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
2065
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2066
    else {
2067
      croak qq{Filter "$fname" is not registered}
2068
        unless exists $self->filters->{$fname};
2069
  
2070
      $self->{default_out_filter} = $self->filters->{$fname};
2071
    }
2072
    return $self;
2073
  }
2074
  
2075
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2076
}
2077

            
cleanup
Yuki Kimoto authored on 2011-01-25
2078
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2079
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2080
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2081

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2082
  _deprecate('0.24', "default_fetch_filter is DEPRECATED!");
cleanup
Yuki Kimoto authored on 2012-01-20
2083
  
2084
  if (@_) {
2085
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
2086

            
cleanup
Yuki Kimoto authored on 2012-01-20
2087
    if (@_ && !$fname) {
2088
      $self->{default_in_filter} = undef;
2089
    }
2090
    else {
2091
      croak qq{Filter "$fname" is not registered}
2092
        unless exists $self->filters->{$fname};
2093
  
2094
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2095
    }
2096
    
cleanup
Yuki Kimoto authored on 2012-01-20
2097
    return $self;
2098
  }
2099
  
2100
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2101
}
2102

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2103
# DEPRECATED!
2104
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2105
  my $self = shift;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2106
  _deprecate('0.24', "insert_param is DEPRECATED! use values_clause instead");
cleanup
Yuki Kimoto authored on 2012-01-20
2107
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2108
}
2109

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2110
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2111
sub insert_param_tag {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2112
  _deprecate('0.24', "insert_param_tag is DEPRECATED! " .
2113
    "use insert_param instead!");
cleanup
Yuki Kimoto authored on 2012-01-20
2114
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2115
}
2116

            
2117
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2118
sub update_param_tag {
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
2119
  _deprecate('0.24', "update_param_tag is DEPRECATED! " .
2120
    "use update_param instead");
cleanup
Yuki Kimoto authored on 2012-01-20
2121
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2122
}
cleanup
Yuki Kimoto authored on 2011-03-08
2123
# DEPRECATED!
2124
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
2125
  my ($self, $sql, $tables, $relation, $need_where) = @_;
2126
  
2127
  if (keys %{$relation || {}}) {
2128
    $$sql .= $need_where ? 'where ' : 'and ';
2129
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2130
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2131
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2132
      push @$tables, ($table1, $table2);
2133
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2134
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2135
  }
2136
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2137
}
2138

            
2139
# DEPRECATED!
2140
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2141
  my ($self, $tables, $relation) = @_;
2142
  
2143
  if (keys %{$relation || {}}) {
2144
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2145
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2146
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2147
      my $table1_exists;
2148
      my $table2_exists;
2149
      for my $table (@$tables) {
2150
        $table1_exists = 1 if $table eq $table1;
2151
        $table2_exists = 1 if $table eq $table2;
2152
      }
2153
      unshift @$tables, $table1 unless $table1_exists;
2154
      unshift @$tables, $table2 unless $table2_exists;
2155
    }
2156
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2157
}
2158

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2161
=head1 NAME
2162

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2167
  use DBIx::Custom;
2168
  
2169
  # Connect
2170
  my $dbi = DBIx::Custom->connect(
2171
    dsn => "dbi:mysql:database=dbname",
2172
    user => 'ken',
2173
    password => '!LFKD%$&',
2174
    option => {mysql_enable_utf8 => 1}
2175
  );
2176

            
2177
  # Insert 
2178
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2179
  
2180
  # Update 
2181
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2182
    where  => {id => 5});
2183
  
2184
  # Delete
2185
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2186

            
2187
  # Select
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2188
  #   select title, author from book where author = ?
2189
  my $result = $dbi->select(
2190
    ['title', 'author'],
2191
    table  => 'book',
2192
    where  => {author => 'Ken'}
2193
  );
cleanup
Yuki Kimoto authored on 2012-01-20
2194

            
2195
  # Select, more complex
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2196
  #   select book.title as book.title,
2197
  #     book.author as book.author,
2198
  #     comnapy.name as company.name
2199
  #   form book
2200
  #     left outer join company on book.company_id = company.id
2201
  #   where book.author = ?
2202
  #   order by id limit 0, 5
cleanup
Yuki Kimoto authored on 2012-01-20
2203
  my $result = $dbi->select(
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2204
    [
cleanup
Yuki Kimoto authored on 2012-01-20
2205
      {book => [qw/title author/]},
2206
      {company => ['name']}
2207
    ],
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2208
    table  => 'book',
cleanup
Yuki Kimoto authored on 2012-01-20
2209
    where  => {'book.author' => 'Ken'},
2210
    join => ['left outer join company on book.company_id = company.id'],
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2211
    append => 'order by id limit 0, 5'
cleanup
Yuki Kimoto authored on 2012-01-20
2212
  );
2213
  
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2214
  # Get all rows or only one row
2215
  my $rows = $result->all;
2216
  my $row = $result->one;
cleanup
Yuki Kimoto authored on 2012-01-20
2217
  
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2218
  # Execute SQL.
2219
  my $result = $dbi->execute(
cleanup
Yuki Kimoto authored on 2012-01-20
2220
    "select id from book where author = :author and title like :title",
2221
    {author => 'ken', title => '%Perl%'}
2222
  );
2223
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2224
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2225

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2241
Named place holder support
2242

            
2243
=item *
2244

            
cleanup
Yuki Kimoto authored on 2011-07-29
2245
Model support
2246

            
2247
=item *
2248

            
2249
Connection manager support
2250

            
2251
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2252

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

            
2257
=item *
2258

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

            
2261
=item *
2262

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

            
2265
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2266

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2267
=head1 DOCUMENTS
pod fix
Yuki Kimoto authored on 2011-01-21
2268

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2269
L<DBIx::Custom Documents|https://github.com/yuki-kimoto/DBIx-Custom/wiki/DBIx::Custom-Documents>
pod fix
Yuki Kimoto authored on 2011-01-21
2270

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2271
L<DBIx::Custom API reference|http://search.cpan.org/~kimoto/DBIx-Custom/>
cleanup
Yuki Kimoto authored on 2011-07-29
2272

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2273
L<DBIx::Custom Examples|Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
updated document
yuki-kimoto authored on 2010-08-08
2274

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

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

            
2279
  my $async_conf = $dbi->async_conf;
2280
  $dbi = $dbi->async_conf($conf);
2281

            
2282
Setting when C<async> option is used.
2283

            
2284
  # MySQL
2285
  $dbi->async_conf({
2286
    prepare_attr => {async => 1},
2287
    fh => sub { shift->dbh->mysql_fd }
2288
  })
2289

            
2290
C<prepare_attr> is DBI's C<prepare> method second argument,
2291
C<fh> is callback that return file handle to watch.
2292

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2304
  my $connector = DBIx::Connector->new(
2305
    "dbi:mysql:database=$database",
2306
    $user,
2307
    $password,
2308
    DBIx::Custom->new->default_option
2309
  );
2310
  
2311
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2312

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2316
  my $dbi = DBIx::Custom->connect(
2317
    dsn => $dsn, user => $user, password => $password, connector => 1);
2318
  
2319
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2320

            
2321
Note that L<DBIx::Connector> must be installed.
2322

            
added EXPERIMENTAL default_s...
Yuki Kimoto authored on 2012-03-02
2323
=head2 C<default_schema> EXPERIMETNAL
2324

            
2325
  my $default_schema = $self->default_schema;
2326
  $dbi = $self->default_schema('public');
2327

            
2328
schema name. if database has multiple schema,
2329
type_rule->{into} filter don't work well.
2330

            
2331
If you set C<default_schema>, type_rule->{into} filter work well.
2332

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2342
  my $default_option = $dbi->default_option;
2343
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2344

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2348
  {
2349
    RaiseError => 1,
2350
    PrintError => 0,
2351
    AutoCommit => 1,
2352
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2353

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

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

            
2359
Excluded table regex.
2360
C<each_column>, C<each_table>, C<type_rule>,
2361
and C<setup_model> methods ignore matching tables.
2362

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

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

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

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

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

            
2375
Get last successed SQL executed by C<execute> method.
2376

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2384
  sub {
2385
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2386
    $mon++;
2387
    $year += 1900;
2388
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2389
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2390

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

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

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

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

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

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

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

            
2408
L<DBI> option, used when C<connect> method is executed.
2409
Each value in option override the value of C<default_option>.
2410

            
cleanup
yuki-kimoto authored on 2010-10-17
2411
=head2 C<password>
2412

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2433
You can set quote pair.
2434

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2446
  my $safety_character = $dbi->safety_character;
2447
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2448

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

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

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

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

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

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

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

            
2468
Enable DEPRECATED tag parsing functionality, default to 1.
2469
If you want to disable tag parsing functionality, set to 0.
2470

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2485
  [
2486
    {table => 'book', column => 'title', info => {...}},
2487
    {table => 'author', column => 'name', info => {...}}
2488
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2489

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2492
  my $user_column_info
2493
    = $dbi->get_column_info(exclude_table => qr/^system/);
2494
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2495

            
2496
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
2497
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2498

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2501
  my $user_table_info = $dbi->user_table_info;
2502
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2503

            
2504
You can set the following data.
2505

            
cleanup
Yuki Kimoto authored on 2012-01-20
2506
  [
2507
    {table => 'book', info => {...}},
2508
    {table => 'author', info => {...}}
2509
  ]
added test
Yuki Kimoto authored on 2011-08-16
2510

            
2511
Usually, you can set return value of C<get_table_info>.
2512

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

            
2516
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2517
to find table info.
2518

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2553
  async => sub {
2554
    my ($dbi, $result) = @_;
2555
    ...
2556
  };
2557

            
2558
Database async access. L<AnyEvent> is required.
2559

            
2560
This is C<mysql> async access example.
2561

            
2562
  use AnyEvent;
2563

            
2564
  my $cond = AnyEvent->condvar;
2565

            
2566
  my $timer = AnyEvent->timer(
2567
    interval => 1,
2568
    cb => sub { 1 }
2569
  );
2570

            
2571
  my $count = 0;
2572

            
2573
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2574
    prepare_attr => {async => 1}, statement => 'select',
2575
    async => sub {
2576
      my ($dbi, $result) = @_;
2577
      my $row = $result->fetch_one;
2578
      is($row->[1], 3, 'before');
2579
      $cond->send if ++$count == 2;
2580
    }
2581
  );
2582

            
2583
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2584
    async => sub {
2585
      my ($dbi, $result) = @_;
2586
      my $row = $result->fetch_one;
2587
      is($row->[0], 1, 'after1');
2588
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2589
        async => sub {
2590
          my ($dbi, $result) = @_;
2591
          my $row = $result->fetch_one;
2592
          is($row->[0], 1, 'after2');
2593
          $cond->send if ++$count == 2;
2594
        }
2595
      )
2596
    }
2597
  );
2598

            
2599
  $cond->recv;
2600

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

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

            
2605
Create column clause. The follwoing column clause is created.
2606

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2612
  # Separator is hyphen
2613
  $dbi->separator('-');
2614
  
2615
  book.author as "book-author",
2616
  book.title as "book-title"
2617
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2618
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2619

            
cleanup
Yuki Kimoto authored on 2012-01-20
2620
  my $dbi = DBIx::Custom->connect(
2621
    dsn => "dbi:mysql:database=dbname",
2622
    user => 'ken',
2623
    password => '!LFKD%$&',
2624
    option => {mysql_enable_utf8 => 1}
2625
  );
update pod
Yuki Kimoto authored on 2011-03-13
2626

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

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

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

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

            
2637
Get rows count.
2638

            
2639
Options is same as C<select> method's ones.
2640

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2643
  my $model = $dbi->create_model(
2644
    table => 'book',
2645
    primary_key => 'id',
2646
    join => [
2647
      'inner join company on book.comparny_id = company.id'
2648
    ],
2649
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2650

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

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

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

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

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

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

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

            
2667
Execute delete statement.
2668

            
2669
The following opitons are available.
2670

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

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

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

            
2678
=item C<id>
2679

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

            
2683
ID corresponding to C<primary_key>.
2684
You can delete rows by C<id> and C<primary_key>.
2685

            
cleanup
Yuki Kimoto authored on 2012-01-20
2686
  $dbi->delete(
2687
    primary_key => ['id1', 'id2'],
2688
    id => [4, 5],
2689
    table => 'book',
2690
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2691

            
2692
The above is same as the followin one.
2693

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

            
2696
=item C<prefix>
2697

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

            
2700
prefix before table name section.
2701

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

            
2704
=item C<table>
2705

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

            
2708
Table name.
2709

            
2710
=item C<where>
2711

            
2712
Same as C<select> method's C<where> option.
2713

            
2714
=back
2715

            
2716
=head2 C<delete_all>
2717

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

            
2720
Execute delete statement for all rows.
2721
Options is same as C<delete>.
2722

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2725
  $dbi->each_column(
2726
    sub {
2727
      my ($dbi, $table, $column, $column_info) = @_;
2728
      
2729
      my $type = $column_info->{TYPE_NAME};
2730
      
2731
      if ($type eq 'DATE') {
2732
          # ...
2733
      }
2734
    }
2735
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2736

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

            
2742
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2743
infromation, you can improve the performance of C<each_column> in
2744
the following way.
2745

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2752
  $dbi->each_table(
2753
    sub {
2754
      my ($dbi, $table, $table_info) = @_;
2755
      
2756
      my $table_name = $table_info->{TABLE_NAME};
2757
    }
2758
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2759

            
improved pod
Yuki Kimoto authored on 2011-10-14
2760
Iterate all table informationsfrom in database.
2761
Argument is callback which is executed when one table is found.
2762
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2763
C<table information>.
2764

            
2765
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2766
infromation, you can improve the performance of C<each_table> in
2767
the following way.
2768

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2791
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2792
  
2793
  # Original
2794
  select * from book where title = :title and author like :author
2795
  
2796
  # Replaced
2797
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2798

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2802
  # Original
2803
  select * from book where :title{=} and :author{like}
2804
  
2805
  # Replaced
2806
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2807

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2814
B<OPTIONS>
2815

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

            
2818
=over 4
2819

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

            
2822
You can filter sql after the sql is build.
2823

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

            
2826
The following one is one example.
2827

            
cleanup
Yuki Kimoto authored on 2012-01-20
2828
  $dbi->select(
2829
    table => 'book',
2830
    column => 'distinct(name)',
2831
    after_build_sql => sub {
2832
      "select count(*) from ($_[0]) as t1"
2833
    }
2834
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2835

            
2836
The following SQL is executed.
2837

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2840
=item C<append>
2841

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

            
2844
Append some statement after SQL.
2845

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

            
2848
  prepare_attr => {async => 1}
2849

            
2850
Statemend handle attributes,
2851
this is L<DBI>'s C<prepare> method second argument.
2852

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

            
2855
Specify database bind data type.
2856

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

            
2860
This is used to bind parameter by C<bind_param> of statment handle.
2861

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2864
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2865
  
2866
  filter => {
2867
    title  => sub { uc $_[0] }
2868
    author => sub { uc $_[0] }
2869
  }
2870

            
2871
  # Filter name
2872
  filter => {
2873
    title  => 'upper_case',
2874
    author => 'upper_case'
2875
  }
2876
      
2877
  # At once
2878
  filter => [
2879
    [qw/title author/]  => sub { uc $_[0] }
2880
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2881

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2894
  my $sql = $query->{sql};
2895
  my $columns = $query->{columns};
2896
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2897
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2898
  
2899
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2900

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

            
2906
This will improved performance when you want to execute same query repeatedly
2907
because generally creating query object is slow.
2908

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2911
  primary_key => 'id'
2912
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2913

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2923
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2924
  
2925
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2926

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

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

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

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

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2941
  table_alias => {worker => 'user'} # {ALIAS => TABLE}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2942

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
2943
Table alias. Key is alias table name, value is real table name, .
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2944
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2945
on alias table name.
2946

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

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

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

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

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

            
2957
Turn C<into1> type rule off.
2958

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

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

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

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

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

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

            
2971
get column infomation except for one which match C<exclude_table> pattern.
2972

            
cleanup
Yuki Kimoto authored on 2012-01-20
2973
  [
2974
    {table => 'book', column => 'title', info => {...}},
2975
    {table => 'author', column => 'name' info => {...}}
2976
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2977

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2984
  [
2985
    {table => 'book', info => {...}},
2986
    {table => 'author', info => {...}}
2987
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2988

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2993
  $dbi->helper(
2994
    find_or_create   => sub {
2995
      my $self = shift;
2996
      
2997
      # Process
2998
    },
2999
    ...
3000
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3001

            
3002
Register helper. These helper is called directly from L<DBIx::Custom> object.
3003

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

            
cleanup
yuki-kimoto authored on 2010-10-17
3006
=head2 C<insert>
3007

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3020
  $dbi->insert(
3021
    [
3022
      {title => 'Perl', author => 'Ken'},
3023
      {title => 'Ruby', author => 'Tom'}
3024
    ],
3025
    table  => 'book'
3026
  );
updated pod
Yuki Kimoto authored on 2011-11-25
3027

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3031
B<options>
3032

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

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

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

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

            
3042
bulk insert is executed if database support bulk insert and 
3043
multiple parameters is passed to C<insert>.
3044
The SQL like the following one is executed.
3045

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

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

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3052
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
3053
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by
3054
C<now> attribute.
3055

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3058
  id => 4
3059
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
3060

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3064
  $dbi->insert(
3065
    {title => 'Perl', author => 'Ken'}
3066
    primary_key => ['id1', 'id2'],
3067
    id => [4, 5],
3068
    table => 'book'
3069
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3070

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3073
  $dbi->insert(
3074
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
3075
    table => 'book'
3076
  );
update pod
Yuki Kimoto authored on 2011-03-13
3077

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

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

            
3082
prefix before table name section
3083

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

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

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

            
3090
Table name.
3091

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

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

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

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

            
3100
placeholder wrapped string.
3101

            
3102
If the following statement
3103

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

            
3107
is executed, the following SQL is executed.
3108

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3111
=back
3112

            
3113
=over 4
3114

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3122
  lib / MyModel.pm
3123
      / MyModel / book.pm
3124
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3125

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3130
  package MyModel;
3131
  use DBIx::Custom::Model -base;
3132
  
3133
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3134

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3139
  package MyModel::book;
3140
  use MyModel -base;
3141
  
3142
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3143

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3146
  package MyModel::company;
3147
  use MyModel -base;
3148
  
3149
  1;
3150
  
updated pod
Yuki Kimoto authored on 2011-06-21
3151
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3152

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

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

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

            
3160
  lib / MyModel.pm
3161
      / MyModel / main / book.pm
3162
                       / company.pm
3163

            
3164
  my $main_book = $self->model('main.book');
3165

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

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

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

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

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

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

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

            
3180
Create a new L<DBIx::Custom::Mapper> object.
3181

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

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

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

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

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

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

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

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

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

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

            
3203
Create column clause for myself. The follwoing column clause is created.
3204

            
cleanup
Yuki Kimoto authored on 2012-01-20
3205
  book.author as author,
3206
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3207

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3210
  my $dbi = DBIx::Custom->new(
3211
    dsn => "dbi:mysql:database=dbname",
3212
    user => 'ken',
3213
    password => '!LFKD%$&',
3214
    option => {mysql_enable_utf8 => 1}
3215
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3216

            
3217
Create a new L<DBIx::Custom> object.
3218

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

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

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

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

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

            
3230
Create a new L<DBIx::Custom::Order> object.
3231

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

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

            
3236
Quote string by value of C<quote>.
3237

            
cleanup
yuki-kimoto authored on 2010-10-17
3238
=head2 C<register_filter>
3239

            
cleanup
Yuki Kimoto authored on 2012-01-20
3240
  $dbi->register_filter(
3241
    # Time::Piece object to database DATE format
3242
    tp_to_date => sub {
3243
      my $tp = shift;
3244
      return $tp->strftime('%Y-%m-%d');
3245
    },
3246
    # database DATE format to Time::Piece object
3247
    date_to_tp => sub {
3248
      my $date = shift;
3249
      return Time::Piece->strptime($date, '%Y-%m-%d');
3250
    }
3251
  );
3252
  
update pod
Yuki Kimoto authored on 2011-03-13
3253
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3254

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3257
  my $result = $dbi->select(
3258
    column => ['author', 'title'],
3259
    table  => 'book',
3260
    where  => {author => 'Ken'},
3261
  );
3262
  
updated document
Yuki Kimoto authored on 2011-06-09
3263
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3264

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3276
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3277
  
3278
  column => 'author'
3279
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3280

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3289
  column => [
3290
    {book => [qw/author title/]},
3291
    {person => [qw/name age/]}
3292
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3293

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3296
  book.author as "book.author",
3297
  book.title as "book.title",
3298
  person.name as "person.name",
3299
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3300

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3304
  column => [
3305
    ['date(book.register_datetime)' => 'book.register_date']
3306
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3307

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3314
  id => 4
3315
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3316

            
3317
ID corresponding to C<primary_key>.
3318
You can select rows by C<id> and C<primary_key>.
3319

            
cleanup
Yuki Kimoto authored on 2012-01-20
3320
  $dbi->select(
3321
    primary_key => ['id1', 'id2'],
3322
    id => [4, 5],
3323
    table => 'book'
3324
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3325

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  $dbi->select(
3329
    where => {id1 => 4, id2 => 5},
3330
    table => 'book'
3331
  );
3332
  
cleanup
Yuki Kimoto authored on 2011-10-20
3333
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3334

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

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

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

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

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

            
3349
Prefix of column cluase
3350

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3355
  join => [
3356
    'left outer join company on book.company_id = company_id',
3357
    'left outer join location on company.location_id = location.id'
3358
  ]
3359
      
updated document
Yuki Kimoto authored on 2011-06-09
3360
Join clause. If column cluase or where clause contain table name like "company.name",
3361
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3362

            
cleanup
Yuki Kimoto authored on 2012-01-20
3363
  $dbi->select(
3364
    table => 'book',
3365
    column => ['company.location_id as location_id'],
3366
    where => {'company.name' => 'Orange'},
3367
    join => [
3368
      'left outer join company on book.company_id = company.id',
3369
      'left outer join location on company.location_id = location.id'
3370
    ]
3371
  );
update pod
Yuki Kimoto authored on 2011-03-12
3372

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3376
  select company.location_id as location_id
3377
  from book
3378
    left outer join company on book.company_id = company.id
3379
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3380

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3381
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
3382
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3383

            
cleanup
Yuki Kimoto authored on 2012-01-20
3384
  $dbi->select(
3385
    table => 'book',
3386
    column => ['company.location_id as location_id'],
3387
    where => {'company.name' => 'Orange'},
3388
    join => [
3389
      {
3390
        clause => 'left outer join location on company.location_id = location.id',
3391
        table => ['company', 'location']
3392
      }
3393
    ]
3394
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3395

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3400
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3401

            
updated document
Yuki Kimoto authored on 2011-06-09
3402
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3403
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3404
  # (1) Hash reference
3405
  where => {author => 'Ken', 'title' => ['Perl', 'Ruby']}
3406
  # -> where author = 'Ken' and title in ('Perl', 'Ruby')
cleanup
Yuki Kimoto authored on 2012-01-20
3407
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3408
  # (2) DBIx::Custom::Where object
cleanup
Yuki Kimoto authored on 2012-01-20
3409
  where => $dbi->where(
3410
    clause => ['and', ':author{=}', ':title{like}'],
3411
    param  => {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3412
  )
3413
  # -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3414
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3415
  # (3) Array reference[Array refenrece, Hash reference]
cleanup
Yuki Kimoto authored on 2012-01-20
3416
  where => [
3417
    ['and', ':author{=}', ':title{like}'],
3418
    {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3419
  ]
3420
  # -> where author = 'Ken' and title like '%Perl%'
3421
  
3422
  # (4) Array reference[String, Hash reference]
3423
  where => [
3424
    ':author{=} and :title{like}',
3425
    {author => 'Ken', title => '%Perl%'}
3426
  ]
3427
  #  -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3428
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3429
  # (5) String
cleanup
Yuki Kimoto authored on 2012-01-20
3430
  where => 'title is null'
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3431
  #  -> where title is null
update pod
Yuki Kimoto authored on 2011-03-12
3432

            
improved where document
Yuki Kimoto authored on 2012-03-01
3433
Where clause.
3434
See also L<DBIx::Custom::Where> to know how to create where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3435
  
update pod
Yuki Kimoto authored on 2011-03-12
3436
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3437

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3440
  $dbi->setup_model;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3441

            
3442
Setup all model objects.
3443
C<columns> of model object is automatically set, parsing database information.
3444

            
3445
=head2 C<type_rule>
3446

            
cleanup
Yuki Kimoto authored on 2012-01-20
3447
  $dbi->type_rule(
3448
    into1 => {
3449
      date => sub { ... },
3450
      datetime => sub { ... }
3451
    },
3452
    into2 => {
3453
      date => sub { ... },
3454
      datetime => sub { ... }
3455
    },
3456
    from1 => {
3457
      # DATE
3458
      9 => sub { ... },
3459
      # DATETIME or TIMESTAMP
3460
      11 => sub { ... },
3461
    }
3462
    from2 => {
3463
      # DATE
3464
      9 => sub { ... },
3465
      # DATETIME or TIMESTAMP
3466
      11 => sub { ... },
3467
    }
3468
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3469

            
3470
Filtering rule when data is send into and get from database.
3471
This has a little complex problem.
3472

            
3473
In C<into1> and C<into2> you can specify
3474
type name as same as type name defined
3475
by create table, such as C<DATETIME> or C<DATE>.
3476

            
3477
Note that type name and data type don't contain upper case.
3478
If these contain upper case charactor, you convert it to lower case.
3479

            
3480
C<into2> is executed after C<into1>.
3481

            
3482
Type rule of C<into1> and C<into2> is enabled on the following
3483
column name.
3484

            
3485
=over 4
3486

            
3487
=item 1. column name
3488

            
cleanup
Yuki Kimoto authored on 2012-01-20
3489
  issue_date
3490
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3491

            
3492
This need C<table> option in each method.
3493

            
3494
=item 2. table name and column name, separator is dot
3495

            
cleanup
Yuki Kimoto authored on 2012-01-20
3496
  book.issue_date
3497
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3498

            
3499
=back
3500

            
3501
You get all type name used in database by C<available_typename>.
3502

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

            
3505
In C<from1> and C<from2> you specify data type, not type name.
3506
C<from2> is executed after C<from1>.
3507
You get all data type by C<available_datatype>.
3508

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

            
3511
You can also specify multiple types at once.
3512

            
cleanup
Yuki Kimoto authored on 2012-01-20
3513
  $dbi->type_rule(
3514
    into1 => [
3515
      [qw/DATE DATETIME/] => sub { ... },
3516
    ],
3517
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3518

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

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

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

            
3525
If you want to set constant value to row data, use scalar reference
3526
as parameter value.
3527

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3545
  $dbi->update(
3546
    {title => 'Perl', author => 'Ken'}
3547
    primary_key => ['id1', 'id2'],
3548
    id => [4, 5],
3549
    table => 'book'
3550
  );
update pod
Yuki Kimoto authored on 2011-03-13
3551

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3554
  $dbi->update(
3555
    {title => 'Perl', author => 'Ken'}
3556
    where => {id1 => 4, id2 => 5},
3557
    table => 'book'
3558
  );
update pod
Yuki Kimoto authored on 2011-03-13
3559

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

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

            
3564
prefix before table name section
3565

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

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

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

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

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

            
3576
Same as C<select> method's C<where> option.
3577

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

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

            
3582
placeholder wrapped string.
3583

            
3584
If the following statement
3585

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

            
3589
is executed, the following SQL is executed.
3590

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3601
=back
update pod
Yuki Kimoto authored on 2011-03-13
3602

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3610
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3611
  
3612
  # ID
3613
  $dbi->update_or_insert(
3614
    {title => 'Perl'},
3615
    table => 'book',
3616
    id => 1,
3617
    primary_key => 'id',
3618
    option => {
3619
      select => {
3620
         append => 'for update'
3621
      }
3622
    }
3623
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3624

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3625
Update or insert.
3626

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3631
C<OPTIONS>
3632

            
3633
C<update_or_insert> method use all common option
3634
in C<select>, C<update>, C<delete>, and has the following new ones.
3635

            
3636
=over 4
3637

            
3638
=item C<option>
3639

            
cleanup
Yuki Kimoto authored on 2012-01-20
3640
  option => {
3641
    select => {
3642
      append => '...'
3643
    },
3644
    insert => {
3645
      prefix => '...'
3646
    },
3647
    update => {
3648
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3649
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3650
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3651

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

            
3655
=over 4
3656

            
3657
=item C<select_option>
3658

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

            
3661
select method option,
3662
select method is used to check the row is already exists.
3663

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

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

            
3668
Show data type of the columns of specified table.
3669

            
cleanup
Yuki Kimoto authored on 2012-01-20
3670
  book
3671
  title: 5
3672
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3673

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

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

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

            
3680
Show tables.
3681

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

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

            
3686
Show type name of the columns of specified table.
3687

            
cleanup
Yuki Kimoto authored on 2012-01-20
3688
  book
3689
  title: varchar
3690
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3691

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

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

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

            
3698
Create values clause.
3699

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

            
3702
You can use this in insert statement.
3703

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

            
3706
=head2 C<where>
3707

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

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

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

            
3718
=head2 C<DBIX_CUSTOM_DEBUG>
3719

            
3720
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3721
executed SQL and bind values are printed to STDERR.
3722

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3727
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3728

            
3729
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3730
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3731

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
3732
=head2 C<DBIX_CUSTOM_SUPPRESS_DEPRECATION>
3733

            
3734
  $ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25';
3735

            
3736
Suppress deprecation warnings before specified version.
3737

            
3738
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3739

            
3740
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3741

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

            
3744
L<DBIx::Custom>
3745

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

            
3802
L<DBIx::Custom::Model>
3803

            
cleanup
Yuki Kimoto authored on 2012-01-20
3804
  # Attribute methods
3805
  execute # will be removed at 2017/1/1
3806
  method # will be removed at 2017/1/1
3807
  filter # will be removed at 2017/1/1
3808
  name # will be removed at 2017/1/1
3809
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3810

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

            
3813
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3814
  
3815
  # Attribute methods
3816
  default_filter # will be removed at 2017/1/1
3817
  table # will be removed at 2017/1/1
3818
  filters # will be removed at 2017/1/1
3819
  
3820
  # Methods
3821
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3822

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

            
3825
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3826
  
3827
  # Attribute methods
3828
  tags # will be removed at 2017/1/1
3829
  tag_processors # will be removed at 2017/1/1
3830
  
3831
  # Methods
3832
  register_tag # will be removed at 2017/1/1
3833
  register_tag_processor # will be removed at 2017/1/1
3834
  
3835
  # Others
3836
  build_query("select * from {= title}"); # tag parsing functionality
3837
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3838

            
3839
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3840
  
3841
  # Attribute methods
3842
  filter_check # will be removed at 2017/1/1
3843
  
3844
  # Methods
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
3845
  column (from 0.25) # will be removed at 2017/2/1
cleanup
Yuki Kimoto authored on 2012-01-20
3846
  fetch_first # will be removed at 2017/2/1
3847
  fetch_hash_first # will be removed 2017/2/1
3848
  filter_on # will be removed at 2017/1/1
3849
  filter_off # will be removed at 2017/1/1
3850
  end_filter # will be removed at 2017/1/1
3851
  remove_end_filter # will be removed at 2017/1/1
3852
  remove_filter # will be removed at 2017/1/1
3853
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3854

            
3855
L<DBIx::Custom::Tag>
3856

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

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

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

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

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
3867
If a feature is DEPRECATED, you can know it by DEPRECATED warnings.
3868
DEPRECATED feature is removed after C<five years>,
3869
but if at least one person use the feature and tell me that thing
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3870
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3871

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
3872
DEPRECATION warnings can be suppressed by C<DBIX_CUSTOM_SUPPRESS_DEPRECATION>
3873
environment variable.
3874

            
3875
EXPERIMENTAL features will be changed without warnings.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3876

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

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

            
3881
C<< <kimoto.yuki at gmail.com> >>
3882

            
3883
L<http://github.com/yuki-kimoto/DBIx-Custom>
3884

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3885
=head1 AUTHOR
3886

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

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

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

            
3893
This program is free software; you can redistribute it and/or modify it
3894
under the same terms as Perl itself.
3895

            
3896
=cut