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

            
added website link
Yuki Kimoto authored on 2012-12-05
2267
=head1 WEB SITE
2268

            
2269
L<DBIx::Custom - Perl O/R Mapper|http://dbix-custom.hateblo.jp>
2270

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

            
improved documents
Yuki Kimoto authored on 2012-11-24
2273
L<DBIx::Custom Documents|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
pod fix
Yuki Kimoto authored on 2011-01-21
2274

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

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

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

            
2281
  my $async_conf = $dbi->async_conf;
2282
  $dbi = $dbi->async_conf($conf);
2283

            
2284
Setting when C<async> option is used.
2285

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

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

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

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

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

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

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

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

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

            
2323
Note that L<DBIx::Connector> must be installed.
2324

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

            
2327
  my $default_schema = $self->default_schema;
2328
  $dbi = $self->default_schema('public');
2329

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2377
Get last successed SQL executed by C<execute> method.
2378

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2413
=head2 C<password>
2414

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2435
You can set quote pair.
2436

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2506
You can set the following data.
2507

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

            
2513
Usually, you can set return value of C<get_table_info>.
2514

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2560
Database async access. L<AnyEvent> is required.
2561

            
2562
This is C<mysql> async access example.
2563

            
2564
  use AnyEvent;
2565

            
2566
  my $cond = AnyEvent->condvar;
2567

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

            
2573
  my $count = 0;
2574

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

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

            
2601
  $cond->recv;
2602

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

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

            
2607
Create column clause. The follwoing column clause is created.
2608

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

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

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

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

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

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

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

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

            
2639
Get rows count.
2640

            
2641
Options is same as C<select> method's ones.
2642

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

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

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

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

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

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

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

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

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

            
2669
Execute delete statement.
2670

            
2671
The following opitons are available.
2672

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

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

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

            
2680
=item C<id>
2681

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

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

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

            
2694
The above is same as the followin one.
2695

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

            
2698
=item C<prefix>
2699

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

            
2702
prefix before table name section.
2703

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

            
2706
=item C<table>
2707

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

            
2710
Table name.
2711

            
2712
=item C<where>
2713

            
2714
Same as C<select> method's C<where> option.
2715

            
2716
=back
2717

            
2718
=head2 C<delete_all>
2719

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

            
2722
Execute delete statement for all rows.
2723
Options is same as C<delete>.
2724

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2816
B<OPTIONS>
2817

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

            
2820
=over 4
2821

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

            
2824
You can filter sql after the sql is build.
2825

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

            
2828
The following one is one example.
2829

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

            
2838
The following SQL is executed.
2839

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2842
=item C<append>
2843

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

            
2846
Append some statement after SQL.
2847

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

            
2850
  prepare_attr => {async => 1}
2851

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

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

            
2857
Specify database bind data type.
2858

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

            
2862
This is used to bind parameter by C<bind_param> of statment handle.
2863

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2941
=item C<table_alias>
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 => {worker => 'user'} # {ALIAS => TABLE}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2944

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

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

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

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

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

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

            
2959
Turn C<into1> type rule off.
2960

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

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

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

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

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

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

            
2973
get column infomation except for one which match C<exclude_table> pattern.
2974

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

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

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

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

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

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

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

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

            
3004
Register helper. These helper is called directly from L<DBIx::Custom> object.
3005

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

            
cleanup
yuki-kimoto authored on 2010-10-17
3008
=head2 C<insert>
3009

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3033
B<options>
3034

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

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

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

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

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

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3050
=item C<ctime>
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
  ctime => 'created_time'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3053

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

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

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

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

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

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

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

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

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

            
3084
prefix before table name section
3085

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

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

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

            
3092
Table name.
3093

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

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

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

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

            
3102
placeholder wrapped string.
3103

            
3104
If the following statement
3105

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

            
3109
is executed, the following SQL is executed.
3110

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3113
=back
3114

            
3115
=over 4
3116

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3162
  lib / MyModel.pm
3163
      / MyModel / main / book.pm
3164
                       / company.pm
3165

            
3166
  my $main_book = $self->model('main.book');
3167

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

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

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

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

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

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

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

            
3182
Create a new L<DBIx::Custom::Mapper> object.
3183

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

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

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

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

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

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

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

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

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

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

            
3205
Create column clause for myself. The follwoing column clause is created.
3206

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

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

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

            
3219
Create a new L<DBIx::Custom> object.
3220

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

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

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

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

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

            
3232
Create a new L<DBIx::Custom::Order> object.
3233

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

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

            
3238
Quote string by value of C<quote>.
3239

            
cleanup
yuki-kimoto authored on 2010-10-17
3240
=head2 C<register_filter>
3241

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3351
Prefix of column cluase
3352

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3402
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3403

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

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

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

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

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

            
3447
=head2 C<type_rule>
3448

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

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

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

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

            
3482
C<into2> is executed after C<into1>.
3483

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

            
3487
=over 4
3488

            
3489
=item 1. column name
3490

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

            
3494
This need C<table> option in each method.
3495

            
3496
=item 2. table name and column name, separator is dot
3497

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

            
3501
=back
3502

            
3503
You get all type name used in database by C<available_typename>.
3504

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

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

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

            
3513
You can also specify multiple types at once.
3514

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3566
prefix before table name section
3567

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

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

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

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

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

            
3578
Same as C<select> method's C<where> option.
3579

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

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

            
3584
placeholder wrapped string.
3585

            
3586
If the following statement
3587

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

            
3591
is executed, the following SQL is executed.
3592

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3595
=item C<mtime>
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
  mtime => 'modified_time'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3598

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3603
=back
update pod
Yuki Kimoto authored on 2011-03-13
3604

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3627
Update or insert.
3628

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3633
C<OPTIONS>
3634

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

            
3638
=over 4
3639

            
3640
=item C<option>
3641

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

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

            
3657
=over 4
3658

            
3659
=item C<select_option>
3660

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

            
3663
select method option,
3664
select method is used to check the row is already exists.
3665

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

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

            
3670
Show data type of the columns of specified table.
3671

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

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

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

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

            
3682
Show tables.
3683

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

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

            
3688
Show type name of the columns of specified table.
3689

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

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

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

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

            
3700
Create values clause.
3701

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

            
3704
You can use this in insert statement.
3705

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

            
3708
=head2 C<where>
3709

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

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

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

            
3720
=head2 C<DBIX_CUSTOM_DEBUG>
3721

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

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

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

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

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

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

            
3736
  $ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25';
3737

            
3738
Suppress deprecation warnings before specified version.
3739

            
3740
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3741

            
3742
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3743

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

            
3746
L<DBIx::Custom>
3747

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

            
3804
L<DBIx::Custom::Model>
3805

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

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

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

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

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

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

            
3857
L<DBIx::Custom::Tag>
3858

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

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

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

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

            
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
3869
If a feature is DEPRECATED, you can know it by DEPRECATED warnings.
3870
DEPRECATED feature is removed after C<five years>,
3871
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
3872
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3873

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

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

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

            
improved documents
Yuki Kimoto authored on 2012-11-24
3881
Please tell me bugs if you find bug.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
3882

            
3883
C<< <kimoto.yuki at gmail.com> >>
3884

            
3885
L<http://github.com/yuki-kimoto/DBIx-Custom>
3886

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3887
=head1 AUTHOR
3888

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

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

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

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

            
3898
=cut