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

            
fixed documentation miss abo...
Yuki Kimoto authored on 2012-09-17
5
our $VERSION = '0.27';
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
- added DBIX_CUSTOM_SUPPRESS...
Yuki Kimoto authored on 2012-03-19
16
use DBIx::Custom::Util qw/_array_to_hash _subname _deprecate/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2243
=item *
2244

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

            
2247
=item *
2248

            
2249
Connection manager support
2250

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

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

            
2257
=item *
2258

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

            
2261
=item *
2262

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

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

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

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

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

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

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

            
2277
  my $async_conf = $dbi->async_conf;
2278
  $dbi = $dbi->async_conf($conf);
2279

            
2280
Setting when C<async> option is used.
2281

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

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

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

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

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

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

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

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

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

            
2319
Note that L<DBIx::Connector> must be installed.
2320

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

            
2323
  my $default_schema = $self->default_schema;
2324
  $dbi = $self->default_schema('public');
2325

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2373
Get last successed SQL executed by C<execute> method.
2374

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2409
=head2 C<password>
2410

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2431
You can set quote pair.
2432

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2502
You can set the following data.
2503

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

            
2509
Usually, you can set return value of C<get_table_info>.
2510

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2556
Database async access. L<AnyEvent> is required.
2557

            
2558
This is C<mysql> async access example.
2559

            
2560
  use AnyEvent;
2561

            
2562
  my $cond = AnyEvent->condvar;
2563

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

            
2569
  my $count = 0;
2570

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

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

            
2597
  $cond->recv;
2598

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

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

            
2603
Create column clause. The follwoing column clause is created.
2604

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

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

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

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

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

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

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

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

            
2635
Get rows count.
2636

            
2637
Options is same as C<select> method's ones.
2638

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

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

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

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

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

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

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

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

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

            
2665
Execute delete statement.
2666

            
2667
The following opitons are available.
2668

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

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

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

            
2676
=item C<id>
2677

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

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

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

            
2690
The above is same as the followin one.
2691

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

            
2694
=item C<prefix>
2695

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

            
2698
prefix before table name section.
2699

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

            
2702
=item C<table>
2703

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

            
2706
Table name.
2707

            
2708
=item C<where>
2709

            
2710
Same as C<select> method's C<where> option.
2711

            
2712
=back
2713

            
2714
=head2 C<delete_all>
2715

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

            
2718
Execute delete statement for all rows.
2719
Options is same as C<delete>.
2720

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2812
B<OPTIONS>
2813

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

            
2816
=over 4
2817

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

            
2820
You can filter sql after the sql is build.
2821

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

            
2824
The following one is one example.
2825

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

            
2834
The following SQL is executed.
2835

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2838
=item C<append>
2839

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

            
2842
Append some statement after SQL.
2843

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

            
2846
  prepare_attr => {async => 1}
2847

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

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

            
2853
Specify database bind data type.
2854

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

            
2858
This is used to bind parameter by C<bind_param> of statment handle.
2859

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2955
Turn C<into1> type rule off.
2956

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

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

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

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

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

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

            
2969
get column infomation except for one which match C<exclude_table> pattern.
2970

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

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

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

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

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

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

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

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

            
3000
Register helper. These helper is called directly from L<DBIx::Custom> object.
3001

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

            
cleanup
yuki-kimoto authored on 2010-10-17
3004
=head2 C<insert>
3005

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3029
B<options>
3030

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3080
prefix before table name section
3081

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

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

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

            
3088
Table name.
3089

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

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

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

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

            
3098
placeholder wrapped string.
3099

            
3100
If the following statement
3101

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

            
3105
is executed, the following SQL is executed.
3106

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

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

            
3111
=over 4
3112

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3158
  lib / MyModel.pm
3159
      / MyModel / main / book.pm
3160
                       / company.pm
3161

            
3162
  my $main_book = $self->model('main.book');
3163

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

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

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

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

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

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

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

            
3178
Create a new L<DBIx::Custom::Mapper> object.
3179

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

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

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

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

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

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

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

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

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

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

            
3201
Create column clause for myself. The follwoing column clause is created.
3202

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

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

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

            
3215
Create a new L<DBIx::Custom> object.
3216

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

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

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

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

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

            
3228
Create a new L<DBIx::Custom::Order> object.
3229

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

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

            
3234
Quote string by value of C<quote>.
3235

            
cleanup
yuki-kimoto authored on 2010-10-17
3236
=head2 C<register_filter>
3237

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3347
Prefix of column cluase
3348

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3398
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3399

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

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

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

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

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

            
3443
=head2 C<type_rule>
3444

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

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

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

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

            
3478
C<into2> is executed after C<into1>.
3479

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

            
3483
=over 4
3484

            
3485
=item 1. column name
3486

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

            
3490
This need C<table> option in each method.
3491

            
3492
=item 2. table name and column name, separator is dot
3493

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

            
3497
=back
3498

            
3499
You get all type name used in database by C<available_typename>.
3500

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

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

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

            
3509
You can also specify multiple types at once.
3510

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3562
prefix before table name section
3563

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

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

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

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

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

            
3574
Same as C<select> method's C<where> option.
3575

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

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

            
3580
placeholder wrapped string.
3581

            
3582
If the following statement
3583

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

            
3587
is executed, the following SQL is executed.
3588

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3599
=back
update pod
Yuki Kimoto authored on 2011-03-13
3600

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3623
Update or insert.
3624

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3629
C<OPTIONS>
3630

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

            
3634
=over 4
3635

            
3636
=item C<option>
3637

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

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

            
3653
=over 4
3654

            
3655
=item C<select_option>
3656

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

            
3659
select method option,
3660
select method is used to check the row is already exists.
3661

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

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

            
3666
Show data type of the columns of specified table.
3667

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

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

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

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

            
3678
Show tables.
3679

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

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

            
3684
Show type name of the columns of specified table.
3685

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

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

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

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

            
3696
Create values clause.
3697

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

            
3700
You can use this in insert statement.
3701

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

            
3704
=head2 C<where>
3705

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

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

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

            
3716
=head2 C<DBIX_CUSTOM_DEBUG>
3717

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

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

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

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

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

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

            
3732
  $ENV{DBIX_CUSTOM_SUPPRESS_DEPRECATION} = '0.25';
3733

            
3734
Suppress deprecation warnings before specified version.
3735

            
3736
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3737

            
3738
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3739

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

            
3742
L<DBIx::Custom>
3743

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

            
3800
L<DBIx::Custom::Model>
3801

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

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

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

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

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

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

            
3853
L<DBIx::Custom::Tag>
3854

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

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

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

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

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

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

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

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

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

            
3879
C<< <kimoto.yuki at gmail.com> >>
3880

            
3881
L<http://github.com/yuki-kimoto/DBIx-Custom>
3882

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3883
=head1 AUTHOR
3884

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

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

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

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

            
3894
=cut