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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
682
sub insert {
cleanup
Yuki Kimoto authored on 2012-01-20
683
  my $self = shift;
684
  
685
  # Options
686
  my $params = @_ % 2 ? shift : undef;
687
  my %opt = @_;
- 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};
735
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
736
    $opt{id} = [$opt{id}] unless ref $opt{id};
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:]/;
854
    unless ($mclass->can('isa')) {
855
      eval "use $mclass";
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) {
1565
    $id = [$id] unless ref $id;
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};
2019
  $primary_key = [$primary_key] unless ref $primary_key;
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
2188
  my $result = $dbi->select(table  => 'book',
2189
    column => ['title', 'author'], where  => {author => 'Ken'});
2190

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2236
Named place holder support
2237

            
2238
=item *
2239

            
cleanup
Yuki Kimoto authored on 2011-07-29
2240
Model support
2241

            
2242
=item *
2243

            
2244
Connection manager support
2245

            
2246
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2247

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

            
2252
=item *
2253

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

            
2256
=item *
2257

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

            
2260
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2261

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2269
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2270
L<DBIx::Custom::Result>,
2271
L<DBIx::Custom::Query>,
2272
L<DBIx::Custom::Where>,
2273
L<DBIx::Custom::Model>,
2274
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2275

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2505
You can set the following data.
2506

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2563
  use AnyEvent;
2564

            
2565
  my $cond = AnyEvent->condvar;
2566

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

            
2572
  my $count = 0;
2573

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

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

            
2600
  $cond->recv;
2601

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

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

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

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

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

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

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

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

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

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

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

            
2638
Get rows count.
2639

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

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

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

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

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

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

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

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

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

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

            
2668
Execute delete statement.
2669

            
2670
The following opitons are available.
2671

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

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

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

            
2679
=item C<id>
2680

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

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

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

            
2693
The above is same as the followin one.
2694

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

            
2697
=item C<prefix>
2698

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

            
2701
prefix before table name section.
2702

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

            
2705
=item C<table>
2706

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

            
2709
Table name.
2710

            
2711
=item C<where>
2712

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

            
2715
=back
2716

            
2717
=head2 C<delete_all>
2718

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2819
=over 4
2820

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

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

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

            
2827
The following one is one example.
2828

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

            
2837
The following SQL is executed.
2838

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

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

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

            
2845
Append some statement after SQL.
2846

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

            
2849
  prepare_attr => {async => 1}
2850

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

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

            
2856
Specify database bind data type.
2857

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2944
Table alias. Key is real table name, value is alias table name.
2945
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2946
on alias table name.
2947

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

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

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

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

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

            
2958
Turn C<into1> type rule off.
2959

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3083
prefix before table name section
3084

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

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

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

            
3091
Table name.
3092

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

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

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

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

            
3101
placeholder wrapped string.
3102

            
3103
If the following statement
3104

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

            
3108
is executed, the following SQL is executed.
3109

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

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

            
3114
=over 4
3115

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3350
Prefix of column cluase
3351

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3446
=head2 C<type_rule>
3447

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

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

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

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

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

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

            
3486
=over 4
3487

            
3488
=item 1. column name
3489

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

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

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

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

            
3500
=back
3501

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

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

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

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

            
3512
You can also specify multiple types at once.
3513

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3565
prefix before table name section
3566

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

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

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

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

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

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

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

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

            
3583
placeholder wrapped string.
3584

            
3585
If the following statement
3586

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

            
3590
is executed, the following SQL is executed.
3591

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3637
=over 4
3638

            
3639
=item C<option>
3640

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

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

            
3656
=over 4
3657

            
3658
=item C<select_option>
3659

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

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

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

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

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

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

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

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

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

            
3681
Show tables.
3682

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

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

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

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

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

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

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

            
3699
Create values clause.
3700

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

            
3703
You can use this in insert statement.
3704

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

            
3707
=head2 C<where>
3708

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

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

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

            
3719
=head2 C<DBIX_CUSTOM_DEBUG>
3720

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

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

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

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

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

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

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

            
3737
Suppress deprecation warnings before specified version.
3738

            
3739
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3740

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

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

            
3745
L<DBIx::Custom>
3746

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3897
=cut