DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3314 lines | 86.037kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
cleanup
Yuki Kimoto authored on 2011-08-13
4
our $VERSION = '0.1714';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
20
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
21
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
23
has [qw/connector dsn password quote user exclude_table/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
24
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
25
    cache_method => sub {
26
        sub {
27
            my $self = shift;
28
            
29
            $self->{_cached} ||= {};
30
            
31
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
32
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
33
            }
34
            else {
update pod
Yuki Kimoto authored on 2011-03-13
35
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
36
            }
37
        }
update pod
Yuki Kimoto authored on 2011-03-13
38
    },
39
    dbi_option => sub { {} },
40
    default_dbi_option => sub {
41
        {
42
            RaiseError => 1,
43
            PrintError => 0,
44
            AutoCommit => 1
45
        }
46
    },
fix tests
Yuki Kimoto authored on 2011-01-13
47
    filters => sub {
48
        {
49
            encode_utf8 => sub { encode_utf8($_[0]) },
50
            decode_utf8 => sub { decode_utf8($_[0]) }
51
        }
update pod
Yuki Kimoto authored on 2011-03-13
52
    },
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
53
    last_sql => '',
update pod
Yuki Kimoto authored on 2011-03-13
54
    models => sub { {} },
cleanup
Yuki Kimoto authored on 2011-08-13
55
    query_builder => sub {
56
        my $self = shift;
57
        my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
58
        weaken $builder->{dbi};
59
        return $builder;
60
    },
update pod
Yuki Kimoto authored on 2011-03-13
61
    result_class  => 'DBIx::Custom::Result',
62
    safety_character => '\w',
cleanup test
Yuki Kimoto authored on 2011-08-10
63
    separator => '.',
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
64
    stash => sub { {} },
65
    tag_parse => 1;
cleanup
yuki-kimoto authored on 2010-10-17
66

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
98
our $AUTOLOAD;
99
sub AUTOLOAD {
100
    my $self = shift;
101

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
102
    # Method name
103
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
104

            
cleanup
Yuki Kimoto authored on 2011-04-02
105
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
106
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
107
    if (my $method = $self->{_methods}->{$mname}) {
108
        return $self->$method(@_)
109
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
110
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
111
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
112
    }
113
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
114
        croak qq{Can't locate object method "$mname" via "$package" }
115
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
116
    }
added helper method
yuki-kimoto authored on 2010-10-17
117
}
118

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
119
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
120
    my ($self, $param) = @_;
121
    
122
    # Create set tag
123
    my @params;
124
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
125
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
        croak qq{"$column" is not safety column name } . _subname
127
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
128
        my $column_quote = $self->_q($column);
129
        $column_quote =~ s/\./$self->_q(".")/e;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
130
        push @params, ref $param->{$column} eq 'SCALAR'
131
          ? "$column_quote = " . ${$param->{$column}}
132
          : "$column_quote = :$column";
133

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
134
    }
135
    my $tag = join(', ', @params);
136
    
137
    return $tag;
138
}
139

            
cleanup
Yuki Kimoto authored on 2011-03-21
140
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
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 ($columns) {
149
        $columns ||= $self->model($real_table)->columns;
150
    }
added helper method
yuki-kimoto authored on 2010-10-17
151
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
152
    # Separator
153
    my $separator = $self->separator;
154
    
cleanup
Yuki Kimoto authored on 2011-04-02
155
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
156
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
157
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
158
    push @column, $self->_q($table) . "." . $self->_q($_) .
159
      " as " . $self->_q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
160
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
161
    
162
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
163
}
164

            
packaging one directory
yuki-kimoto authored on 2009-11-16
165
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
166
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
167
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
168
    # Connect
169
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
170
    
packaging one directory
yuki-kimoto authored on 2009-11-16
171
    return $self;
172
}
173

            
update pod
Yuki Kimoto authored on 2011-03-13
174
sub dbh {
175
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
176
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
177
    # Set
178
    if (@_) {
179
        $self->{dbh} = $_[0];
180
        
181
        return $self;
182
    }
183
    
184
    # Get
185
    else {
186
        # From Connction manager
187
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
188
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
189
              unless ref $connector && $connector->can('dbh');
190
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
191
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
192
        }
193
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
194
        # Connect
195
        $self->{dbh} ||= $self->_connect;
196
        
197
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
198
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
199
            my $driver = lc $self->{dbh}->{Driver}->{Name};
200
            my $quote = $driver eq 'odbc' ? '[]'
201
                       :$driver eq 'mysql' ? '`'
202
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
203
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
204
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
205
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
206
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
207
    }
208
}
209

            
cleanup
yuki-kimoto authored on 2010-10-17
210
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
211
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
212

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
213
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
214
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
215
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
216
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
217
    my $where            = delete $args{where} || {};
218
    my $append           = delete $args{append};
219
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
220
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
221
    my $id = delete $args{id};
222
    my $primary_key = delete $args{primary_key};
223
    croak "update method primary_key option " .
224
          "must be specified when id is specified " . _subname
225
      if defined $id && !defined $primary_key;
226
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
227
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
228
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
229
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
230
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
231
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
232
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
233
        $where_clause = "where " . $where->[0];
234
        $where_param = $where->[1];
235
    }
236
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
237
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
238
        $where_param = keys %$where_param
239
                     ? $self->merge_param($where_param, $where->param)
240
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
241
        
242
        # String where
243
        $where_clause = $where->to_string;
244
    }
245
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
246
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
247
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
248

            
cleanup
Yuki Kimoto authored on 2011-04-02
249
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
250
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
251
    push @sql, "delete";
252
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
253
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
254
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
255
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
256
    
257
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
258
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
259
}
260

            
cleanup
yuki-kimoto authored on 2010-10-17
261
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
262

            
cleanup
Yuki Kimoto authored on 2011-08-13
263
sub DESTROY { }
added helper method
yuki-kimoto authored on 2010-10-17
264

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
265
sub create_model {
266
    my $self = shift;
267
    
cleanup
Yuki Kimoto authored on 2011-04-02
268
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
269
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
270
    $args->{dbi} = $self;
271
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
272
    my $model_name  = delete $args->{name};
273
    my $model_table = delete $args->{table};
274
    $model_name ||= $model_table;
275
    
cleanup
Yuki Kimoto authored on 2011-04-02
276
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
277
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
278
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
279
    $model->name($model_name) unless $model->name;
280
    $model->table($model_table) unless $model->table;
281
    
micro optimization
Yuki Kimoto authored on 2011-07-30
282
    # Apply filter(DEPRECATED logic)
283
    if ($model->{filter}) {
284
        my $filter = ref $model->filter eq 'HASH'
285
                   ? [%{$model->filter}]
286
                   : $model->filter;
287
        $filter ||= [];
288
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
289
          if @$filter;
290
        $self->_apply_filter($model->table, @$filter);
291
    }
292
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
293
    # Set model
294
    $self->model($model->name, $model);
295
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
296
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
297
}
298

            
299
sub each_column {
300
    my ($self, $cb) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
301

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
302
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
303
    
added SQL Server test
Yuki Kimoto authored on 2011-08-14
304
    my %tables;
305
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
306
    # Iterate all tables
307
    my $sth_tables = $self->dbh->table_info;
308
    while (my $table_info = $sth_tables->fetchrow_hashref) {
309
        # Table
310
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
311
        next if defined $re && $table =~ /$re/;
added SQL Server test
Yuki Kimoto authored on 2011-08-14
312
        $tables{$table}++;
313
    }
314

            
315
    # Iterate all tables
316
    my @tables = sort keys %tables;
317
    for (my $i = 0; $i < @tables; $i++) {
318
        my $table = $tables[$i];
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
319
        
320
        # Iterate all columns
321
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
322
        while (my $column_info = $sth_columns->fetchrow_hashref) {
323
            my $column = $column_info->{COLUMN_NAME};
324
            $self->$cb($table, $column, $column_info);
325
        }
326
    }
327
}
328

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
329
sub each_table {
330
    my ($self, $cb) = @_;
331
    
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
332
    my $re = $self->exclude_table;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
333
    
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
334
    # Iterate all tables
335
    my $sth_tables = $self->dbh->table_info;
336
    while (my $table_info = $sth_tables->fetchrow_hashref) {
337
        
338
        # Table
339
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
340
        next if defined $re && $table =~ /$re/;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
341
        $self->$cb($table, $table_info);
342
    }
343
}
344

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
345
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
346
  allow_update_all bind_type column filter id join param prefix primary_key
347
  query relation table table_alias type type_rule_off type_rule1_off
348
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
349

            
350
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
351
    my $self = shift;
352
    my $query = shift;
353
    my $param;
354
    $param = shift if @_ % 2;
355
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
356
    
cleanup
Yuki Kimoto authored on 2011-04-02
357
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
358
    my $p = delete $args{param} || {};
359
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
360
    my $tables = delete $args{table} || [];
361
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
362
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
363
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
364
    my $bind_type = delete $args{bind_type} || delete $args{type};
365
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
366
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
367
    my $type_rule_off_parts = {
368
        1 => delete $args{type_rule1_off},
369
        2 => delete $args{type_rule2_off}
370
    };
cleanup
Yuki Kimoto authored on 2011-06-09
371
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
372
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
373
    
cleanup
Yuki Kimoto authored on 2011-03-09
374
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
375
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
376
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
377
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
378
    }
379
    
cleanup
Yuki Kimoto authored on 2011-04-02
380
    # Create query
updated pod
Yuki Kimoto authored on 2011-06-21
381
    $query = $self->_create_query($query) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
382
    
383
    # Save query
384
    $self->last_sql($query->sql);
385

            
cleanup
Yuki Kimoto authored on 2011-06-09
386
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
387
    
388
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
389
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
390
    
cleanup
Yuki Kimoto authored on 2011-04-02
391
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
392
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
393
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
394
    
micro optimization
Yuki Kimoto authored on 2011-07-30
395
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
396
    $tables = $self->_remove_duplicate_table($tables, $main_table)
397
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
398
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
399
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
400
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
401
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
402
        foreach my $i (1, 2) {
403
            unless ($type_rule_off_parts->{$i}) {
404
                $type_filters->{$i} = {};
405
                foreach my $alias (keys %$table_alias) {
406
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
407
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
408
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
409
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
410
                    }
411
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
412
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
413
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
414
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
415
        }
416
    }
cleanup
Yuki Kimoto authored on 2011-04-02
417
    
micro optimization
Yuki Kimoto authored on 2011-07-30
418
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
419
    if ($self->{filter}{on}) {
420
        my $applied_filter = {};
421
        foreach my $table (@$tables) {
422
            $applied_filter = {
423
                %$applied_filter,
424
                %{$self->{filter}{out}->{$table} || {}}
425
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
426
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
427
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
428
    }
429
    
cleanup
Yuki Kimoto authored on 2011-04-02
430
    # Replace filter name to code
431
    foreach my $column (keys %$filter) {
432
        my $name = $filter->{$column};
433
        if (!defined $name) {
434
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
435
        }
cleanup
Yuki Kimoto authored on 2011-04-02
436
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
437
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
438
            unless exists $self->filters->{$name};
439
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
440
        }
441
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
442
    
cleanup
Yuki Kimoto authored on 2011-04-02
443
    # Create bind values
444
    my $bind = $self->_create_bind_values(
445
        $param,
446
        $query->columns,
447
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
448
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
449
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
450
    );
cleanup
yuki-kimoto authored on 2010-10-17
451
    
452
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
453
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
454
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
455
    eval {
456
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
457
            my $bind_type = $bind->[$i]->{bind_type};
458
            $sth->bind_param(
459
                $i + 1,
460
                $bind->[$i]->{value},
461
                $bind_type ? $bind_type : ()
462
            );
cleanup
Yuki Kimoto authored on 2011-03-21
463
        }
464
        $affected = $sth->execute;
465
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
466
    
micro optimization
Yuki Kimoto authored on 2011-07-30
467
    $self->_croak($@, qq{. Following SQL is executed.\n}
468
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
469
    
improved debug message
Yuki Kimoto authored on 2011-05-23
470
    # DEBUG message
471
    if (DEBUG) {
472
        print STDERR "SQL:\n" . $query->sql . "\n";
473
        my @output;
474
        foreach my $b (@$bind) {
475
            my $value = $b->{value};
476
            $value = 'undef' unless defined $value;
477
            $value = encode(DEBUG_ENCODING(), $value)
478
              if utf8::is_utf8($value);
479
            push @output, $value;
480
        }
481
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
482
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
483
    
cleanup
Yuki Kimoto authored on 2011-04-02
484
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
485
    if ($sth->{NUM_OF_FIELDS}) {
486
        
micro optimization
Yuki Kimoto authored on 2011-07-30
487
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
488
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
489
        if ($self->{filter}{on}) {
490
            $filter->{in}  = {};
491
            $filter->{end} = {};
492
            push @$tables, $main_table if $main_table;
493
            foreach my $table (@$tables) {
494
                foreach my $way (qw/in end/) {
495
                    $filter->{$way} = {
496
                        %{$filter->{$way}},
497
                        %{$self->{filter}{$way}{$table} || {}}
498
                    };
499
                }
cleanup
Yuki Kimoto authored on 2011-04-02
500
            }
cleanup
Yuki Kimoto authored on 2011-01-12
501
        }
502
        
503
        # Result
504
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
505
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
506
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
507
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
508
            filter => $filter->{in} || {},
509
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
510
            type_rule => {
511
                from1 => $self->type_rule->{from1},
512
                from2 => $self->type_rule->{from2}
513
            },
cleanup
yuki-kimoto authored on 2010-10-17
514
        );
515

            
516
        return $result;
517
    }
cleanup
Yuki Kimoto authored on 2011-04-02
518
    
519
    # Not select statement
520
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
521
}
522

            
523
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
524
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
525
    
cleanup
yuki-kimoto authored on 2010-10-17
526
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
527
    my $param;
528
    $param = shift if @_ % 2;
529
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
530
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
531
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
532
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
533
    my $p = delete $args{param} || {};
534
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
535
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
536
    my $id = delete $args{id};
537
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
538
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
539
          "must be specified when id is specified " . _subname
540
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
541
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
542
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
543

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
544
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
545
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
546
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
547
        $param = $self->merge_param($id_param, $param);
548
    }
549

            
cleanup
Yuki Kimoto authored on 2011-04-02
550
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
551
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
552
    push @sql, "insert";
553
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
554
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
555
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
556
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
557
    
558
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
559
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
560
}
561

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
562
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
563
    my ($self, $param) = @_;
564
    
cleanup
Yuki Kimoto authored on 2011-04-02
565
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
566
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
567
    my @columns;
568
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
569
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
570
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
571
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
572
        my $column_quote = $self->_q($column);
573
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
574
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
575
        push @placeholders, ref $param->{$column} eq 'SCALAR'
576
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
577
    }
578
    
cleanup
Yuki Kimoto authored on 2011-04-02
579
    return '(' . join(', ', @columns) . ') ' . 'values ' .
580
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
581
}
582

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
583
sub include_model {
584
    my ($self, $name_space, $model_infos) = @_;
585
    
cleanup
Yuki Kimoto authored on 2011-04-02
586
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
587
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
588
    
589
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
590
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
591

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
592
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
593
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
594
          if $name_space =~ /[^\w:]/;
595
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
596
        croak qq{Name space module "$name_space.pm" is needed. $@ }
597
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
598
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
599
        
600
        # Search model modules
601
        my $path = $INC{"$name_space.pm"};
602
        $path =~ s/\.pm$//;
603
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
604
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
605
        $model_infos = [];
606
        while (my $module = readdir $dh) {
607
            push @$model_infos, $module
608
              if $module =~ s/\.pm$//;
609
        }
610
        close $dh;
611
    }
612
    
cleanup
Yuki Kimoto authored on 2011-04-02
613
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
614
    foreach my $model_info (@$model_infos) {
615
        
cleanup
Yuki Kimoto authored on 2011-04-02
616
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
617
        my $model_class;
618
        my $model_name;
619
        my $model_table;
620
        if (ref $model_info eq 'HASH') {
621
            $model_class = $model_info->{class};
622
            $model_name  = $model_info->{name};
623
            $model_table = $model_info->{table};
624
            
625
            $model_name  ||= $model_class;
626
            $model_table ||= $model_name;
627
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
628
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
629
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
630
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
631
          if $mclass =~ /[^\w:]/;
632
        unless ($mclass->can('isa')) {
633
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
634
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
635
        }
636
        
cleanup
Yuki Kimoto authored on 2011-04-02
637
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
638
        my $args = {};
639
        $args->{model_class} = $mclass if $mclass;
640
        $args->{name}        = $model_name if $model_name;
641
        $args->{table}       = $model_table if $model_table;
642
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
643
    }
644
    
645
    return $self;
646
}
647

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
648
sub map_param {
649
    my $self = shift;
650
    my $param = shift;
651
    my %map = @_;
652
    
653
    # Mapping
654
    my $map_param = {};
655
    foreach my $key (keys %map) {
656
        my $value_cb;
657
        my $condition;
658
        my $map_key;
659
        
660
        # Get mapping information
661
        if (ref $map{$key} eq 'ARRAY') {
662
            foreach my $some (@{$map{$key}}) {
663
                $map_key = $some unless ref $some;
664
                $condition = $some->{if} if ref $some eq 'HASH';
665
                $value_cb = $some if ref $some eq 'CODE';
666
            }
667
        }
668
        else {
669
            $map_key = $map{$key};
670
        }
671
        $value_cb ||= sub { $_[0] };
672
        $condition ||= sub { defined $_[0] && length $_[0] };
673

            
674
        # Map parameter
675
        my $value;
676
        if (ref $condition eq 'CODE') {
677
            $map_param->{$map_key} = $value_cb->($param->{$key})
678
              if $condition->($param->{$key});
679
        }
680
        elsif ($condition eq 'exists') {
681
            $map_param->{$map_key} = $value_cb->($param->{$key})
682
              if exists $param->{$key};
683
        }
684
        else { croak qq/Condition must be code reference or "exists" / . _subname }
685
    }
686
    
687
    return $map_param;
688
}
689

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
690
sub merge_param {
691
    my ($self, @params) = @_;
692
    
cleanup
Yuki Kimoto authored on 2011-04-02
693
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
694
    my $merge = {};
695
    foreach my $param (@params) {
696
        foreach my $column (keys %$param) {
697
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
698
            
699
            if (exists $merge->{$column}) {
700
                $merge->{$column} = [$merge->{$column}]
701
                  unless ref $merge->{$column} eq 'ARRAY';
702
                push @{$merge->{$column}},
703
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
704
            }
705
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
706
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
707
            }
708
        }
709
    }
710
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
711
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
712
}
713

            
cleanup
Yuki Kimoto authored on 2011-03-21
714
sub method {
715
    my $self = shift;
716
    
cleanup
Yuki Kimoto authored on 2011-04-02
717
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
718
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
719
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
720
    
721
    return $self;
722
}
723

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
724
sub model {
725
    my ($self, $name, $model) = @_;
726
    
cleanup
Yuki Kimoto authored on 2011-04-02
727
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
728
    if ($model) {
729
        $self->models->{$name} = $model;
730
        return $self;
731
    }
732
    
733
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
734
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
735
      unless $self->models->{$name};
736
    
cleanup
Yuki Kimoto authored on 2011-04-02
737
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
738
    return $self->models->{$name};
739
}
740

            
cleanup
Yuki Kimoto authored on 2011-03-21
741
sub mycolumn {
742
    my ($self, $table, $columns) = @_;
743
    
cleanup
Yuki Kimoto authored on 2011-04-02
744
    # Create column clause
745
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
746
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
747
    push @column, $self->_q($table) . "." . $self->_q($_) .
748
      " as " . $self->_q($_)
749
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
750
    
751
    return join (', ', @column);
752
}
753

            
added dbi_options attribute
kimoto authored on 2010-12-20
754
sub new {
755
    my $self = shift->SUPER::new(@_);
756
    
cleanup
Yuki Kimoto authored on 2011-04-02
757
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
758
    my @attrs = keys %$self;
759
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
760
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
761
          unless $self->can($attr);
762
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
763

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
764
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
765
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
766
        '?'     => \&DBIx::Custom::Tag::placeholder,
767
        '='     => \&DBIx::Custom::Tag::equal,
768
        '<>'    => \&DBIx::Custom::Tag::not_equal,
769
        '>'     => \&DBIx::Custom::Tag::greater_than,
770
        '<'     => \&DBIx::Custom::Tag::lower_than,
771
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
772
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
773
        'like'  => \&DBIx::Custom::Tag::like,
774
        'in'    => \&DBIx::Custom::Tag::in,
775
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
776
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
777
    };
778
    
779
    return $self;
780
}
781

            
782
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
783
sub not_exists { $not_exists }
784

            
785
sub order {
786
    my $self = shift;
787
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
788
}
789

            
cleanup
yuki-kimoto authored on 2010-10-17
790
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
791
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
792
    
793
    # Register filter
794
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
795
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
796
    
cleanup
Yuki Kimoto authored on 2011-04-02
797
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
798
}
packaging one directory
yuki-kimoto authored on 2009-11-16
799

            
800
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
801
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
802

            
refactoring select
yuki-kimoto authored on 2010-04-28
803
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
804
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
805
    my $tables = ref $table eq 'ARRAY' ? $table
806
               : defined $table ? [$table]
807
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
808
    my $columns   = delete $args{column};
809
    my $where     = delete $args{where} || {};
810
    my $append    = delete $args{append};
811
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
812
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
813
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
814
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
815
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
816
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
817
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
818
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
819
      if keys %$param;
820
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
821
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
822
    my $id = delete $args{id};
823
    my $primary_key = delete $args{primary_key};
824
    croak "update method primary_key option " .
825
          "must be specified when id is specified " . _subname
826
      if defined $id && !defined $primary_key;
827
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
828
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
829
    
cleanup
Yuki Kimoto authored on 2011-03-09
830
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
831
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
832
    
cleanup
Yuki Kimoto authored on 2011-04-02
833
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
834
    my @sql;
835
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
836
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
837
    # Prefix
838
    push @sql, $prefix if defined $prefix;
839
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
840
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
841
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
842
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
843
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
844
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
845
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
846
            }
847
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
848
                if (@$column == 3 && $column->[1] eq 'as') {
849
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
850
                    splice @$column, 1, 1;
851
                }
852
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
853
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
854
            }
cleanup
Yuki Kimoto authored on 2011-04-02
855
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
856
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
857
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
858
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
859
    }
860
    else { push @sql, '*' }
861
    
862
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
863
    push @sql, 'from';
864
    if ($relation) {
865
        my $found = {};
866
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
867
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
868
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
869
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
870
    }
cleanup
Yuki Kimoto authored on 2011-03-30
871
    else {
872
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
873
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
874
    }
875
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
876
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
877
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
878

            
cleanup
Yuki Kimoto authored on 2011-04-02
879
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
880
    unshift @$tables,
881
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
882
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
883
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
884
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
885
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
886
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
887
        $where_clause = "where " . $where->[0];
888
        $where_param = $where->[1];
889
    }
890
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
891
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
892
        $where_param = keys %$where_param
893
                     ? $self->merge_param($where_param, $where->param)
894
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
895
        
896
        # String where
897
        $where_clause = $where->to_string;
898
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
899
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
900
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
901
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
902
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
903
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
904
    # Push join
905
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
906
    
cleanup
Yuki Kimoto authored on 2011-03-09
907
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
908
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
909
    
cleanup
Yuki Kimoto authored on 2011-03-08
910
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
911
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
912
    
cleanup
Yuki Kimoto authored on 2011-04-02
913
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
914
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
915
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
916
    # Wrap
917
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
918
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
919
          unless ref $wrap eq 'ARRAY';
920
        unshift @sql, $wrap->[0];
921
        push @sql, $wrap->[1];
922
    }
923
    
cleanup
Yuki Kimoto authored on 2011-01-27
924
    # SQL
925
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
926
    
927
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
928
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
929
    
930
    return $result;
931
}
932

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
933
sub setup_model {
934
    my $self = shift;
935
    
cleanup
Yuki Kimoto authored on 2011-04-02
936
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
937
    $self->each_column(
938
        sub {
939
            my ($self, $table, $column, $column_info) = @_;
940
            if (my $model = $self->models->{$table}) {
941
                push @{$model->columns}, $column;
942
            }
943
        }
944
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
945
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
946
}
947

            
update pod
Yuki Kimoto authored on 2011-08-10
948
sub show_datatype {
949
    my ($self, $table) = @_;
950
    croak "Table name must be specified" unless defined $table;
951
    print "$table\n";
952
    
953
    my $result = $self->select(table => $table, where => "'0' <> '0'");
954
    my $sth = $result->sth;
955

            
956
    my $columns = $sth->{NAME};
957
    my $data_types = $sth->{TYPE};
958
    
959
    for (my $i = 0; $i < @$columns; $i++) {
960
        my $column = $columns->[$i];
961
        my $data_type = $data_types->[$i];
962
        print "$column: $data_type\n";
963
    }
964
}
965

            
966
sub show_typename {
967
    my ($self, $t) = @_;
968
    croak "Table name must be specified" unless defined $t;
969
    print "$t\n";
970
    
971
    $self->each_column(sub {
972
        my ($self, $table, $column, $infos) = @_;
973
        return unless $table eq $t;
974
        my $typename = $infos->{TYPE_NAME};
975
        print "$column: $typename\n";
976
    });
977
    
978
    return $self;
979
}
980

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
981
sub type_rule {
982
    my $self = shift;
983
    
984
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
985
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
986
        
987
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
988
        foreach my $i (1 .. 2) {
989
            my $into = "into$i";
990
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
991
            $self->{type_rule} = $type_rule;
992
            $self->{"_$into"} = {};
993
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
994
                croak qq{type name of $into section must be lower case}
995
                  if $type_name =~ /[A-Z]/;
996
            }
997
            $self->each_column(sub {
998
                my ($dbi, $table, $column, $column_info) = @_;
999
                
1000
                my $type_name = lc $column_info->{TYPE_NAME};
1001
                if ($type_rule->{$into} &&
1002
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1003
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1004
                    return unless exists $type_rule->{$into}->{$type_name};
1005
                    if  (defined $filter && ref $filter ne 'CODE') 
1006
                    {
1007
                        my $fname = $filter;
1008
                        croak qq{Filter "$fname" is not registered" } . _subname
1009
                          unless exists $self->filters->{$fname};
1010
                        
1011
                        $filter = $self->filters->{$fname};
1012
                    }
1013

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1014
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1015
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1016
                }
1017
            });
1018
        }
1019

            
1020
        # From
1021
        foreach my $i (1 .. 2) {
1022
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1023
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1024
                croak qq{data type of from$i section must be lower case or number}
1025
                  if $data_type =~ /[A-Z]/;
1026
                my $fname = $type_rule->{"from$i"}{$data_type};
1027
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1028
                    croak qq{Filter "$fname" is not registered" } . _subname
1029
                      unless exists $self->filters->{$fname};
1030
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1031
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1032
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1033
            }
1034
        }
1035
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1036
        return $self;
1037
    }
1038
    
1039
    return $self->{type_rule} || {};
1040
}
1041

            
cleanup
yuki-kimoto authored on 2010-10-17
1042
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1043
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1044

            
cleanup
yuki-kimoto authored on 2010-10-17
1045
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1046
    my $param;
1047
    $param = shift if @_ % 2;
1048
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1049
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1050
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1051
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1052
    my $p = delete $args{param} || {};
1053
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1054
    my $where = delete $args{where} || {};
1055
    my $where_param = delete $args{where_param} || {};
1056
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1057
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1058
    my $id = delete $args{id};
1059
    my $primary_key = delete $args{primary_key};
1060
    croak "update method primary_key option " .
1061
          "must be specified when id is specified " . _subname
1062
      if defined $id && !defined $primary_key;
1063
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1064
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1065

            
cleanup
yuki-kimoto authored on 2010-10-17
1066
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1067
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1068

            
1069
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1070
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1071
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1072
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1073
        $where_clause = "where " . $where->[0];
1074
        $where_param = $where->[1];
1075
    }
1076
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1077
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1078
        $where_param = keys %$where_param
1079
                     ? $self->merge_param($where_param, $where->param)
1080
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1081
        
1082
        # String where
1083
        $where_clause = $where->to_string;
1084
    }
1085
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1086
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1087
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1088
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1089
    # Merge param
1090
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1091
    
cleanup
Yuki Kimoto authored on 2011-04-02
1092
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1093
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1094
    push @sql, "update";
1095
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1096
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1097
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1098
    
cleanup
Yuki Kimoto authored on 2011-01-27
1099
    # SQL
1100
    my $sql = join(' ', @sql);
1101
    
cleanup
yuki-kimoto authored on 2010-10-17
1102
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1103
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1104
}
1105

            
cleanup
yuki-kimoto authored on 2010-10-17
1106
sub update_all { shift->update(allow_update_all => 1, @_) };
1107

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1108
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1109
    my ($self, $param, $opt) = @_;
1110
    
cleanup
Yuki Kimoto authored on 2011-04-02
1111
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1112
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1113
    $tag = "set $tag" unless $opt->{no_set};
1114

            
cleanup
Yuki Kimoto authored on 2011-04-02
1115
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1116
}
1117

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1120
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1121
    
updated pod
Yuki Kimoto authored on 2011-06-21
1122
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1123
    
updated pod
Yuki Kimoto authored on 2011-06-21
1124
    # Cache
1125
    my $cache = $self->cache;
1126
    
1127
    # Query
1128
    my $query;
1129
    
1130
    # Get cached query
1131
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1132
        
updated pod
Yuki Kimoto authored on 2011-06-21
1133
        # Get query
1134
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1135
        
updated pod
Yuki Kimoto authored on 2011-06-21
1136
        # Create query
1137
        if ($q) {
1138
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1139
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1140
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1141
    }
1142
    
1143
    # Create query
1144
    unless ($query) {
1145

            
1146
        # Create query
1147
        my $builder = $self->query_builder;
1148
        $query = $builder->build_query($source);
1149

            
1150
        # Remove reserved word quote
1151
        if (my $q = $self->_quote) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1152
            $q = quotemeta($q);
1153
            $_ =~ s/[$q]//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1154
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1155

            
1156
        # Save query to cache
1157
        $self->cache_method->(
1158
            $self, $source,
1159
            {
1160
                sql     => $query->sql, 
1161
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1162
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1163
            }
1164
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1165
    }
1166
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1167
    # Save sql
1168
    $self->last_sql($query->sql);
1169
    
updated pod
Yuki Kimoto authored on 2011-06-21
1170
    # Prepare statement handle
1171
    my $sth;
1172
    eval { $sth = $self->dbh->prepare($query->{sql})};
1173
    
1174
    if ($@) {
1175
        $self->_croak($@, qq{. Following SQL is executed.\n}
1176
                        . qq{$query->{sql}\n} . _subname);
1177
    }
1178
    
1179
    # Set statement handle
1180
    $query->sth($sth);
1181
    
1182
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1183
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1184
    
1185
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1186
}
1187

            
cleanup
Yuki Kimoto authored on 2011-04-02
1188
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1189
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1190
    
cleanup
Yuki Kimoto authored on 2011-04-02
1191
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1192
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1193
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1194
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1195
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1196
        
1197
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1198
        my $value;
1199
        if(ref $params->{$column} eq 'ARRAY') {
1200
            my $i = $count->{$column} || 0;
1201
            $i += $not_exists->{$column} || 0;
1202
            my $found;
1203
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1204
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1205
                    $not_exists->{$column}++;
1206
                }
1207
                else  {
1208
                    $value = $params->{$column}->[$k];
1209
                    $found = 1;
1210
                    last
1211
                }
1212
            }
1213
            next unless $found;
1214
        }
1215
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1216
        
cleanup
Yuki Kimoto authored on 2011-01-12
1217
        # Filter
1218
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1219
        $value = $f->($value) if $f;
1220
        
1221
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1222
        foreach my $i (1 .. 2) {
1223
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1224
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1225
            $value = $tf->($value) if $tf;
1226
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1227
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1228
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1229
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1230
        
1231
        # Count up 
1232
        $count->{$column}++;
1233
    }
1234
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1235
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1236
}
1237

            
cleanup
Yuki Kimoto authored on 2011-06-08
1238
sub _create_param_from_id {
1239
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1240
    
cleanup
Yuki Kimoto authored on 2011-06-08
1241
    # Create parameter
1242
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1243
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1244
        $id = [$id] unless ref $id;
1245
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1246
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1247
          unless !ref $id || ref $id eq 'ARRAY';
1248
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1249
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1250
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1251
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1252
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1253
        }
1254
    }
1255
    
cleanup
Yuki Kimoto authored on 2011-06-08
1256
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1257
}
1258

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1259
sub _connect {
1260
    my $self = shift;
1261
    
1262
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1263
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1264
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1265
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1266
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1267
    croak qq{"dsn" must be specified } . _subname
1268
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1269
    my $user        = $self->user;
1270
    my $password    = $self->password;
1271
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1272
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1273
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1274
    
1275
    # Connect
1276
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1277
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1278
        $user,
1279
        $password,
1280
        {
1281
            %{$self->default_dbi_option},
1282
            %$dbi_option
1283
        }
1284
    )};
1285
    
1286
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1287
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1288
    
1289
    return $dbh;
1290
}
1291

            
cleanup
yuki-kimoto authored on 2010-10-17
1292
sub _croak {
1293
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1294
    
1295
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1296
    $append ||= "";
1297
    
1298
    # Verbose
1299
    if ($Carp::Verbose) { croak $error }
1300
    
1301
    # Not verbose
1302
    else {
1303
        
1304
        # Remove line and module infromation
1305
        my $at_pos = rindex($error, ' at ');
1306
        $error = substr($error, 0, $at_pos);
1307
        $error =~ s/\s+$//;
1308
        croak "$error$append";
1309
    }
1310
}
1311

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1312
sub _need_tables {
1313
    my ($self, $tree, $need_tables, $tables) = @_;
1314
    
cleanup
Yuki Kimoto authored on 2011-04-02
1315
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1316
    foreach my $table (@$tables) {
1317
        if ($tree->{$table}) {
1318
            $need_tables->{$table} = 1;
1319
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1320
        }
1321
    }
1322
}
1323

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1324
sub _push_join {
1325
    my ($self, $sql, $join, $join_tables) = @_;
1326
    
cleanup
Yuki Kimoto authored on 2011-04-02
1327
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1328
    return unless @$join;
1329
    
cleanup
Yuki Kimoto authored on 2011-04-02
1330
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1331
    my $tree = {};
1332
    for (my $i = 0; $i < @$join; $i++) {
1333
        
cleanup
Yuki Kimoto authored on 2011-07-28
1334
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1335
        my $join_clause;;
1336
        my $option;
1337
        if (ref $join->[$i] eq 'HASH') {
1338
            $join_clause = $join->[$i]->{clause};
1339
            $option = {table => $join->[$i]->{table}};
1340
        }
1341
        else {
1342
            $join_clause = $join->[$i];
1343
            $option = {};
1344
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1345

            
1346
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1347
        my $table1;
1348
        my $table2;
1349
        if (my $table = $option->{table}) {
1350
            $table1 = $table->[0];
1351
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1352
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1353
        else {
1354
            my $q = $self->_quote;
1355
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1356
            $j_clause =~ s/'.+?'//g;
1357
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1358
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1359
            my $c = $self->safety_character;
1360
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1361
            if ($j_clause =~ $join_re) {
1362
                $table1 = $1;
1363
                $table2 = $2;
1364
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1365
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1366
        croak qq{join clause must have two table name after "on" keyword. } .
1367
              qq{"$join_clause" is passed }  . _subname
1368
          unless defined $table1 && defined $table2;
1369
        croak qq{right side table of "$join_clause" must be unique }
1370
            . _subname
1371
          if exists $tree->{$table2};
1372
        croak qq{Same table "$table1" is specified} . _subname
1373
          if $table1 eq $table2;
1374
        $tree->{$table2}
1375
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1376
    }
1377
    
cleanup
Yuki Kimoto authored on 2011-04-02
1378
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1379
    my $need_tables = {};
1380
    $self->_need_tables($tree, $need_tables, $join_tables);
1381
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1382
    
1383
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1384
    foreach my $need_table (@need_tables) {
1385
        push @$sql, $tree->{$need_table}{join};
1386
    }
1387
}
cleanup
Yuki Kimoto authored on 2011-03-08
1388

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1389
sub _quote {
1390
    my $self = shift;
1391
    
1392
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1393
         : defined $self->quote ? $self->quote
1394
         : '';
1395
}
1396

            
cleanup
Yuki Kimoto authored on 2011-07-29
1397
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1398
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1399
    
1400
    my $quote = $self->_quote;
1401
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1402
    my $p;
1403
    if (defined $quote && length $quote > 1) {
1404
        $p = substr($quote, 1, 1);
1405
    }
1406
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1407
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1408
    if ($quotemeta) {
1409
        $q = quotemeta($q);
1410
        $p = quotemeta($p);
1411
    }
1412
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1413
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1414
}
1415

            
cleanup
Yuki Kimoto authored on 2011-04-02
1416
sub _remove_duplicate_table {
1417
    my ($self, $tables, $main_table) = @_;
1418
    
1419
    # Remove duplicate table
1420
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1421
    delete $tables{$main_table} if $main_table;
1422
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1423
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1424
    if (my $q = $self->_quote) {
1425
        $q = quotemeta($q);
1426
        $_ =~ s/[$q]//g for @$new_tables;
1427
    }
1428

            
1429
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1430
}
1431

            
cleanup
Yuki Kimoto authored on 2011-04-02
1432
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1433
    my ($self, $source) = @_;
1434
    
cleanup
Yuki Kimoto authored on 2011-04-02
1435
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1436
    my $tables = [];
1437
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1438
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1439
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1440
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1441
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1442
    while ($source =~ /$table_re/g) {
1443
        push @$tables, $1;
1444
    }
1445
    
1446
    return $tables;
1447
}
1448

            
cleanup
Yuki Kimoto authored on 2011-04-02
1449
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1450
    my ($self, $where) = @_;
1451
    
cleanup
Yuki Kimoto authored on 2011-04-02
1452
    my $obj;
1453
    
1454
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1455
    if (ref $where eq 'HASH') {
1456
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1457
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1458
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1459
            my $table;
1460
            my $c;
1461
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1462
                $table = $1;
1463
                $c = $2;
1464
            }
1465
            
1466
            my $table_quote;
1467
            $table_quote = $self->_q($table) if defined $table;
1468
            my $column_quote = $self->_q($c);
1469
            $column_quote = $table_quote . '.' . $column_quote
1470
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1471
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1472
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1473
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1474
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1475
    
1476
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1477
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1478
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1479
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1480
    
updated pod
Yuki Kimoto authored on 2011-06-21
1481
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1482
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1483
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1484
            clause => $where->[0],
1485
            param  => $where->[1]
1486
        );
1487
    }
1488
    
cleanup
Yuki Kimoto authored on 2011-04-02
1489
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1490
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1491
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1492
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1493
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1494
    
cleanup
Yuki Kimoto authored on 2011-04-02
1495
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1496
}
1497

            
updated pod
Yuki Kimoto authored on 2011-06-21
1498
sub _apply_filter {
1499
    my ($self, $table, @cinfos) = @_;
1500

            
1501
    # Initialize filters
1502
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1503
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1504
    $self->{filter}{out} ||= {};
1505
    $self->{filter}{in} ||= {};
1506
    $self->{filter}{end} ||= {};
1507
    
1508
    # Usage
1509
    my $usage = "Usage: \$dbi->apply_filter(" .
1510
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1511
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1512
    
1513
    # Apply filter
1514
    for (my $i = 0; $i < @cinfos; $i += 2) {
1515
        
1516
        # Column
1517
        my $column = $cinfos[$i];
1518
        if (ref $column eq 'ARRAY') {
1519
            foreach my $c (@$column) {
1520
                push @cinfos, $c, $cinfos[$i + 1];
1521
            }
1522
            next;
1523
        }
1524
        
1525
        # Filter infomation
1526
        my $finfo = $cinfos[$i + 1] || {};
1527
        croak "$usage (table: $table) " . _subname
1528
          unless  ref $finfo eq 'HASH';
1529
        foreach my $ftype (keys %$finfo) {
1530
            croak "$usage (table: $table) " . _subname
1531
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1532
        }
1533
        
1534
        # Set filters
1535
        foreach my $way (qw/in out end/) {
1536
        
1537
            # Filter
1538
            my $filter = $finfo->{$way};
1539
            
1540
            # Filter state
1541
            my $state = !exists $finfo->{$way} ? 'not_exists'
1542
                      : !defined $filter        ? 'not_defined'
1543
                      : ref $filter eq 'CODE'   ? 'code'
1544
                      : 'name';
1545
            
1546
            # Filter is not exists
1547
            next if $state eq 'not_exists';
1548
            
1549
            # Check filter name
1550
            croak qq{Filter "$filter" is not registered } . _subname
1551
              if  $state eq 'name'
1552
               && ! exists $self->filters->{$filter};
1553
            
1554
            # Set filter
1555
            my $f = $state eq 'not_defined' ? undef
1556
                  : $state eq 'code'        ? $filter
1557
                  : $self->filters->{$filter};
1558
            $self->{filter}{$way}{$table}{$column} = $f;
1559
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1560
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1561
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1562
        }
1563
    }
1564
    
1565
    return $self;
1566
}
1567

            
1568
# DEPRECATED!
1569
sub create_query {
1570
    warn "create_query is DEPRECATED! use query option of each method";
1571
    shift->_create_query(@_);
1572
}
1573

            
cleanup
Yuki Kimoto authored on 2011-06-13
1574
# DEPRECATED!
1575
sub apply_filter {
1576
    my $self = shift;
1577
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1578
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1579
    return $self->_apply_filter(@_);
1580
}
1581

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1582
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1583
our %SELECT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1584
sub select_at {
1585
    my ($self, %args) = @_;
1586

            
updated pod
Yuki Kimoto authored on 2011-06-08
1587
    warn "select_at is DEPRECATED! use update and id option instead";
1588

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1589
    # Arguments
1590
    my $primary_keys = delete $args{primary_key};
1591
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1592
    my $where = delete $args{where};
1593
    my $param = delete $args{param};
1594
    
1595
    # Check arguments
1596
    foreach my $name (keys %args) {
1597
        croak qq{"$name" is wrong option } . _subname
1598
          unless $SELECT_AT_ARGS{$name};
1599
    }
1600
    
1601
    # Table
1602
    croak qq{"table" option must be specified } . _subname
1603
      unless $args{table};
1604
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1605
    
1606
    # Create where parameter
1607
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1608
    
1609
    return $self->select(where => $where_param, %args);
1610
}
1611

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1612
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1613
our %DELETE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1614
sub delete_at {
1615
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1616

            
1617
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1618
    
1619
    # Arguments
1620
    my $primary_keys = delete $args{primary_key};
1621
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1622
    my $where = delete $args{where};
1623
    
1624
    # Check arguments
1625
    foreach my $name (keys %args) {
1626
        croak qq{"$name" is wrong option } . _subname
1627
          unless $DELETE_AT_ARGS{$name};
1628
    }
1629
    
1630
    # Create where parameter
1631
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1632
    
1633
    return $self->delete(where => $where_param, %args);
1634
}
1635

            
cleanup
Yuki Kimoto authored on 2011-06-08
1636
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1637
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1638
sub update_at {
1639
    my $self = shift;
1640

            
1641
    warn "update_at is DEPRECATED! use update and id option instead";
1642
    
1643
    # Arguments
1644
    my $param;
1645
    $param = shift if @_ % 2;
1646
    my %args = @_;
1647
    my $primary_keys = delete $args{primary_key};
1648
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1649
    my $where = delete $args{where};
1650
    my $p = delete $args{param} || {};
1651
    $param  ||= $p;
1652
    
1653
    # Check arguments
1654
    foreach my $name (keys %args) {
1655
        croak qq{"$name" is wrong option } . _subname
1656
          unless $UPDATE_AT_ARGS{$name};
1657
    }
1658
    
1659
    # Create where parameter
1660
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1661
    
1662
    return $self->update(where => $where_param, param => $param, %args);
1663
}
1664

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1665
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1666
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1667
sub insert_at {
1668
    my $self = shift;
1669
    
1670
    warn "insert_at is DEPRECATED! use insert and id option instead";
1671
    
1672
    # Arguments
1673
    my $param;
1674
    $param = shift if @_ % 2;
1675
    my %args = @_;
1676
    my $primary_key = delete $args{primary_key};
1677
    $primary_key = [$primary_key] unless ref $primary_key;
1678
    my $where = delete $args{where};
1679
    my $p = delete $args{param} || {};
1680
    $param  ||= $p;
1681
    
1682
    # Check arguments
1683
    foreach my $name (keys %args) {
1684
        croak qq{"$name" is wrong option } . _subname
1685
          unless $INSERT_AT_ARGS{$name};
1686
    }
1687
    
1688
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1689
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1690
    $param = $self->merge_param($where_param, $param);
1691
    
1692
    return $self->insert(param => $param, %args);
1693
}
1694

            
added warnings
Yuki Kimoto authored on 2011-06-07
1695
# DEPRECATED!
1696
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1697
    my $self = shift;
1698
    
added warnings
Yuki Kimoto authored on 2011-06-07
1699
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1700
    
1701
    # Merge tag
1702
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1703
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1704
    
1705
    return $self;
1706
}
1707

            
1708
# DEPRECATED!
1709
sub register_tag_processor {
1710
    my $self = shift;
1711
    warn "register_tag_processor is DEPRECATED!";
1712
    # Merge tag
1713
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1714
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1715
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1716
}
1717

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1718
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1719
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1720
has dbi_options => sub { {} };
1721
has filter_check  => 1;
1722
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1723

            
cleanup
Yuki Kimoto authored on 2011-01-25
1724
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1725
sub default_bind_filter {
1726
    my $self = shift;
1727
    
cleanup
Yuki Kimoto authored on 2011-06-13
1728
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1729
    
cleanup
Yuki Kimoto authored on 2011-01-12
1730
    if (@_) {
1731
        my $fname = $_[0];
1732
        
1733
        if (@_ && !$fname) {
1734
            $self->{default_out_filter} = undef;
1735
        }
1736
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1737
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1738
              unless exists $self->filters->{$fname};
1739
        
1740
            $self->{default_out_filter} = $self->filters->{$fname};
1741
        }
1742
        return $self;
1743
    }
1744
    
1745
    return $self->{default_out_filter};
1746
}
1747

            
cleanup
Yuki Kimoto authored on 2011-01-25
1748
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1749
sub default_fetch_filter {
1750
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1751

            
cleanup
Yuki Kimoto authored on 2011-06-13
1752
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1753
    
1754
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1755
        my $fname = $_[0];
1756

            
cleanup
Yuki Kimoto authored on 2011-01-12
1757
        if (@_ && !$fname) {
1758
            $self->{default_in_filter} = undef;
1759
        }
1760
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1761
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1762
              unless exists $self->filters->{$fname};
1763
        
1764
            $self->{default_in_filter} = $self->filters->{$fname};
1765
        }
1766
        
1767
        return $self;
1768
    }
1769
    
many changed
Yuki Kimoto authored on 2011-01-23
1770
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1771
}
1772

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1773
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1774
sub insert_param_tag {
1775
    warn "insert_param_tag is DEPRECATED! " .
1776
         "use insert_param instead!";
1777
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1778
}
1779

            
1780
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1781
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1782
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1783
         "use update_param instead";
1784
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1785
}
cleanup
Yuki Kimoto authored on 2011-03-08
1786
# DEPRECATED!
1787
sub _push_relation {
1788
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1789
    
1790
    if (keys %{$relation || {}}) {
1791
        push @$sql, $need_where ? 'where' : 'and';
1792
        foreach my $rcolumn (keys %$relation) {
1793
            my $table1 = (split (/\./, $rcolumn))[0];
1794
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1795
            push @$tables, ($table1, $table2);
1796
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1797
        }
1798
    }
1799
    pop @$sql if $sql->[-1] eq 'and';    
1800
}
1801

            
1802
# DEPRECATED!
1803
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1804
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1805
    
1806
    if (keys %{$relation || {}}) {
1807
        foreach my $rcolumn (keys %$relation) {
1808
            my $table1 = (split (/\./, $rcolumn))[0];
1809
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1810
            my $table1_exists;
1811
            my $table2_exists;
1812
            foreach my $table (@$tables) {
1813
                $table1_exists = 1 if $table eq $table1;
1814
                $table2_exists = 1 if $table eq $table2;
1815
            }
1816
            unshift @$tables, $table1 unless $table1_exists;
1817
            unshift @$tables, $table2 unless $table2_exists;
1818
        }
1819
    }
1820
}
1821

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1824
=head1 NAME
1825

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1826
DBIx::Custom - Execute insert, update, delete, and select statement easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1827

            
1828
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1829

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1830
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1831
    
1832
    # Connect
1833
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1834
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1835
        user => 'ken',
1836
        password => '!LFKD%$&',
1837
        dbi_option => {mysql_enable_utf8 => 1}
1838
    );
cleanup
yuki-kimoto authored on 2010-08-05
1839

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1840
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1841
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1842
    
1843
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1844
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1845
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1846
    
1847
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1848
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1849

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1850
    # Select
updated pod
Yuki Kimoto authored on 2011-06-21
1851
    my $result = $dbi->select(table  => 'book',
1852
      column => ['title', 'author'], where  => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1853

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1854
    # Select, more complex
1855
    my $result = $dbi->select(
1856
        table  => 'book',
1857
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1858
            {book => [qw/title author/]},
1859
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1860
        ],
1861
        where  => {'book.author' => 'Ken'},
1862
        join => ['left outer join company on book.company_id = company.id'],
1863
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1864
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1865
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1866
    # Fetch
1867
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1868
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1869
    }
1870
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1871
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1872
    while (my $row = $result->fetch_hash) {
1873
        
1874
    }
1875
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1876
    # Execute SQL with parameter.
1877
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1878
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1879
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1880
    );
1881
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1882
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1883

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1899
Named place holder support
1900

            
1901
=item *
1902

            
cleanup
Yuki Kimoto authored on 2011-07-29
1903
Model support
1904

            
1905
=item *
1906

            
1907
Connection manager support
1908

            
1909
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1910

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

            
1915
=item *
1916

            
1917
Filtering by data type or column name(EXPERIMENTAL)
1918

            
1919
=item *
1920

            
1921
Create C<order by> clause flexibly(EXPERIMENTAL)
1922

            
1923
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1924

            
cleanup
Yuki Kimoto authored on 2011-07-29
1925
=head1 DOCUMENTATIONS
pod fix
Yuki Kimoto authored on 2011-01-21
1926

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1932
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1933
L<DBIx::Custom::Result>,
1934
L<DBIx::Custom::Query>,
1935
L<DBIx::Custom::Where>,
1936
L<DBIx::Custom::Model>,
1937
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1938

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

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

            
1943
    my $connector = $dbi->connector;
micro optimization
Yuki Kimoto authored on 2011-07-30
1944
    $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1945

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

            
1949
This is L<DBIx::Connector> example. Please pass
updated pod
Yuki Kimoto authored on 2011-06-21
1950
C<default_dbi_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1951

            
1952
    my $connector = DBIx::Connector->new(
1953
        "dbi:mysql:database=$DATABASE",
1954
        $USER,
1955
        $PASSWORD,
1956
        DBIx::Custom->new->default_dbi_option
1957
    );
1958
    
updated pod
Yuki Kimoto authored on 2011-06-21
1959
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1960

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

            
1963
    my $dsn = $dbi->dsn;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1964
    $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
1965

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1968
=head2 C<dbi_option>
added dbi_options attribute
kimoto authored on 2010-12-20
1969

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1970
    my $dbi_option = $dbi->dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1971
    $dbi = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1972

            
updated pod
Yuki Kimoto authored on 2011-06-21
1973
L<DBI> option, used when C<connect> method is executed.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1974
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1975

            
1976
=head2 C<default_dbi_option>
1977

            
1978
    my $default_dbi_option = $dbi->default_dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1979
    $dbi = $dbi->default_dbi_option($default_dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1980

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1984
    {
1985
        RaiseError => 1,
1986
        PrintError => 0,
1987
        AutoCommit => 1,
1988
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1989

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1992
    my $filters = $dbi->filters;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1993
    $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1994

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

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

            
1999
    my $last_sql = $dbi->last_sql;
2000
    $dbi = $dbi->last_sql($last_sql);
2001

            
2002
Get last successed SQL executed by C<execute> method.
2003

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

            
2006
    my $models = $dbi->models;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2007
    $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
2008

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2011
=head2 C<password>
2012

            
2013
    my $password = $dbi->password;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2014
    $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
2015

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2020
    my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2021

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2026
     my quote = $dbi->quote;
2027
     $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2028

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2033
You can set quote pair.
2034

            
2035
    $dbi->quote('[]');
2036

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2039
    my $result_class = $dbi->result_class;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2040
    $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
2041

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2046
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2047
    $dbi = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2048

            
update pod
Yuki Kimoto authored on 2011-03-13
2049
Regex of safety character for table and column name, default to '\w'.
cleanup
Yuki Kimoto authored on 2011-03-10
2050
Note that you don't have to specify like '[\w]'.
update pod
Yuki Kimoto authored on 2011-01-27
2051

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

            
2054
    my $separator = $self->separator;
2055
    $dbi = $self->separator($separator);
2056

            
2057
Separator whichi join table and column.
2058
This is used by C<column> and C<mycolumn> method.
2059

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2060
=head2 C<exclude_table EXPERIMENTAL>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2061

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2062
    my $exclude_table = $self->exclude_table;
2063
    $dbi = $self->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2064

            
2065
Regex matching system table.
2066
this regex match is used by C<each_table> method and C<each_column> method
2067
System table is ignored.
2068
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2069
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2070
The performance is up.
2071

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

            
2074
    my $tag_parse = $dbi->tag_parse(0);
2075
    $dbi = $dbi->tag_parse;
2076

            
2077
Enable DEPRECATED tag parsing functionality, default to 1.
2078
If you want to disable tag parsing functionality, set to 0.
2079

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2082
    my $user = $dbi->user;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2083
    $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
2084

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2093
=head2 C<available_datatype> EXPERIMENTAL
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2094

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2095
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2096

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2100
=head2 C<available_typename> EXPERIMENTAL
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2101

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2102
    print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2103

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2107
=head2 C<assign_param> EXPERIMENTAL
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2108

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2109
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2110

            
updated pod
Yuki Kimoto authored on 2011-06-09
2111
Create assign parameter.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2112

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2113
    title = :title, author = :author
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2114

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2115
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2116

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2119
    my $column = $dbi->column(book => ['author', 'title']);
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2120

            
2121
Create column clause. The follwoing column clause is created.
2122

            
2123
    book.author as "book.author",
2124
    book.title as "book.title"
2125

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2128
    # Separator is double underbar
2129
    $dbi->separator('__');
2130
    
2131
    book.author as "book__author",
2132
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2133

            
cleanup
Yuki Kimoto authored on 2011-06-13
2134
    # Separator is hyphen
2135
    $dbi->separator('-');
2136
    
2137
    book.author as "book-author",
2138
    book.title as "book-title"
2139
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2140
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2141

            
update pod
Yuki Kimoto authored on 2011-03-13
2142
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2143
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2144
        user => 'ken',
2145
        password => '!LFKD%$&',
2146
        dbi_option => {mysql_enable_utf8 => 1}
2147
    );
2148

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2155
=head2 create_model
2156

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2157
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2158
        table => 'book',
2159
        primary_key => 'id',
2160
        join => [
2161
            'inner join company on book.comparny_id = company.id'
2162
        ],
2163
    );
2164

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

            
2168
   $dbi->model('book')->select(...);
2169

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

            
2172
    my $dbh = $dbi->dbh;
2173

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

            
2177
=head2 C<each_column>
2178

            
2179
    $dbi->each_column(
2180
        sub {
2181
            my ($dbi, $table, $column, $column_info) = @_;
2182
            
2183
            my $type = $column_info->{TYPE_NAME};
2184
            
2185
            if ($type eq 'DATE') {
2186
                # ...
2187
            }
2188
        }
2189
    );
2190

            
2191
Iterate all column informations of all table from database.
2192
Argument is callback when one column is found.
2193
Callback receive four arguments, dbi object, table name,
2194
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2195

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

            
2198
    $dbi->each_table(
2199
        sub {
2200
            my ($dbi, $table, $table_info) = @_;
2201
            
2202
            my $table_name = $table_info->{TABLE_NAME};
2203
        }
2204
    );
2205

            
2206
Iterate all table informationsfrom database.
2207
Argument is callback when one table is found.
2208
Callback receive three arguments, dbi object, table name,
2209
table information.
2210

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2213
    my $result = $dbi->execute(
updated pod
Yuki Kimoto authored on 2011-06-21
2214
      "select * from book where title = :title and author like :author",
2215
      {title => 'Perl', author => '%Ken%'}
2216
    );
2217

            
2218
    my $result = $dbi->execute(
2219
      "select * from book where title = :book.title and author like :book.author",
2220
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2221
    );
2222

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2229
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2230
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2231
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2232
    select * from book where title = :title and author like :author
2233
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2234
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2235
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2236

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2237
You can specify operator with named placeholder
2238
 by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2239

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2240
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2241
    select * from book where :title{=} and :author{like}
2242
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2243
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2244
    select * from where title = ? and author like ?;
2245

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

            
2250
    select * from where title = "aa\\:bb";
2251

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

            
2254
=over 4
2255

            
2256
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2257
    
2258
    filter => {
2259
        title  => sub { uc $_[0] }
2260
        author => sub { uc $_[0] }
2261
    }
update pod
Yuki Kimoto authored on 2011-03-13
2262

            
updated pod
Yuki Kimoto authored on 2011-06-09
2263
    # Filter name
2264
    filter => {
2265
        title  => 'upper_case',
2266
        author => 'upper_case'
2267
    }
2268
        
2269
    # At once
2270
    filter => [
2271
        [qw/title author/]  => sub { uc $_[0] }
2272
    ]
2273

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

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

            
2281
    query => 1
2282

            
2283
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
cleanup
Yuki Kimoto authored on 2011-07-30
2284
You can check SQL or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2285

            
2286
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2287
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2288
    my $columns = $query->columns;
2289
    
2290
If you want to execute SQL fast, you can do the following way.
2291

            
2292
    my $query;
2293
    foreach my $row (@$rows) {
2294
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2295
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2296
    }
2297

            
2298
Statement handle is reused and SQL parsing is finished,
2299
so you can get more performance than normal way.
cleanup
Yuki Kimoto authored on 2011-07-30
2300

            
2301
If you want to execute SQL as possible as fast and don't need filtering.
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2302
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2303
    
2304
    my $query;
2305
    my $sth;
2306
    foreach my $row (@$rows) {
2307
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2308
      $sth ||= $query->sth;
2309
      $sth->execute(map { $row->{$_} } sort keys %$row);
2310
    }
2311

            
2312
Note that $row must be simple hash reference, such as
2313
{title => 'Perl', author => 'Ken'}.
2314
and don't forget to sort $row values by $row key asc order.
updated document
Yuki Kimoto authored on 2011-06-09
2315

            
updated pod
Yuki Kimoto authored on 2011-06-09
2316
=item C<table>
2317
    
2318
    table => 'author'
2319

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2324
    $dbi->execute("select * from book where title = :title and author = :author",
2325
        {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2326

            
updated pod
Yuki Kimoto authored on 2011-06-21
2327
    # Same
2328
    $dbi->execute(
2329
      "select * from book where title = :book.title and author = :book.author",
2330
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2331

            
updated pod
Yuki Kimoto authored on 2011-06-21
2332
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2333

            
updated pod
Yuki Kimoto authored on 2011-06-21
2334
Specify database bind data type.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2335

            
updated pod
Yuki Kimoto authored on 2011-06-21
2336
    bind_type => [image => DBI::SQL_BLOB]
2337
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2338

            
updated pod
Yuki Kimoto authored on 2011-06-21
2339
This is used to bind parameter by C<bind_param> of statment handle.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2340

            
updated pod
Yuki Kimoto authored on 2011-06-21
2341
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2342

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2343
=item C<table_alias> EXPERIMENTAL
2344

            
2345
    table_alias => {user => 'hiker'}
2346

            
2347
Table alias. Key is real table name, value is alias table name.
2348
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2349
on alias table name.
2350

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2351
=item C<type_rule_off> EXPERIMENTAL
2352

            
2353
    type_rule_off => 1
2354

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

            
2357
=item C<type_rule1_off> EXPERIMENTAL
2358

            
2359
    type_rule1_off => 1
2360

            
2361
Turn C<into1> type rule off.
2362

            
2363
=item C<type_rule2_off> EXPERIMENTAL
2364

            
2365
    type_rule2_off => 1
2366

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

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

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2371
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
2372

            
update pod
Yuki Kimoto authored on 2011-03-13
2373
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2374

            
updated document
Yuki Kimoto authored on 2011-06-09
2375
Execute delete statement.
update pod
Yuki Kimoto authored on 2011-03-13
2376

            
updated document
Yuki Kimoto authored on 2011-06-09
2377
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2378

            
update pod
Yuki Kimoto authored on 2011-03-13
2379
=over 4
2380

            
update pod
Yuki Kimoto authored on 2011-03-13
2381
=item C<append>
2382

            
updated document
Yuki Kimoto authored on 2011-06-09
2383
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2384

            
2385
=item C<filter>
2386

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2387
Same as C<execute> method's C<filter> option.
update pod
Yuki Kimoto authored on 2011-03-13
2388

            
updated document
Yuki Kimoto authored on 2011-06-09
2389
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2390

            
updated document
Yuki Kimoto authored on 2011-06-09
2391
    id => 4
2392
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2393

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2397
    $dbi->delete(
2398
        parimary_key => ['id1', 'id2'],
2399
        id => [4, 5],
2400
        table => 'book',
2401
    );
update pod
Yuki Kimoto authored on 2011-03-13
2402

            
updated document
Yuki Kimoto authored on 2011-06-09
2403
The above is same as the followin one.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2404

            
updated document
Yuki Kimoto authored on 2011-06-09
2405
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2406

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

            
2409
    prefix => 'some'
2410

            
2411
prefix before table name section.
2412

            
2413
    delete some from book
2414

            
updated document
Yuki Kimoto authored on 2011-06-09
2415
=item C<query>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2416

            
updated document
Yuki Kimoto authored on 2011-06-09
2417
Same as C<execute> method's C<query> option.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2418

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2421
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2422

            
updated pod
Yuki Kimoto authored on 2011-06-21
2423
Table name.
2424

            
updated document
Yuki Kimoto authored on 2011-06-09
2425
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2426

            
updated document
Yuki Kimoto authored on 2011-06-09
2427
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2428

            
updated pod
Yuki Kimoto authored on 2011-06-08
2429
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2430

            
updated pod
Yuki Kimoto authored on 2011-06-08
2431
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2432

            
updated pod
Yuki Kimoto authored on 2011-06-21
2433
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2434

            
updated pod
Yuki Kimoto authored on 2011-06-21
2435
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2436

            
2437
=item C<type_rule_off> EXPERIMENTAL
2438

            
2439
Same as C<execute> method's C<type_rule_off> option.
2440

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2441
=item C<type_rule1_off> EXPERIMENTAL
2442

            
2443
    type_rule1_off => 1
2444

            
2445
Same as C<execute> method's C<type_rule1_off> option.
2446

            
2447
=item C<type_rule2_off> EXPERIMENTAL
2448

            
2449
    type_rule2_off => 1
2450

            
2451
Same as C<execute> method's C<type_rule2_off> option.
2452

            
updated pod
Yuki Kimoto authored on 2011-06-08
2453
=back
update pod
Yuki Kimoto authored on 2011-03-13
2454

            
updated pod
Yuki Kimoto authored on 2011-06-08
2455
=head2 C<delete_all>
update pod
Yuki Kimoto authored on 2011-03-13
2456

            
updated pod
Yuki Kimoto authored on 2011-06-08
2457
    $dbi->delete_all(table => $table);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2458

            
updated document
Yuki Kimoto authored on 2011-06-09
2459
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
2460
Options is same as C<delete>.
update pod
Yuki Kimoto authored on 2011-03-13
2461

            
cleanup
yuki-kimoto authored on 2010-10-17
2462
=head2 C<insert>
2463

            
cleanup
Yuki Kimoto authored on 2011-06-09
2464
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2465

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

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

            
2472
    {date => \"NOW()"}
2473

            
cleanup
Yuki Kimoto authored on 2011-06-09
2474
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2475

            
cleanup
Yuki Kimoto authored on 2011-06-09
2476
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2477

            
update pod
Yuki Kimoto authored on 2011-03-13
2478
=item C<append>
2479

            
cleanup
Yuki Kimoto authored on 2011-06-09
2480
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2481

            
2482
=item C<filter>
2483

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2484
Same as C<execute> method's C<filter> option.
2485

            
2486
=item C<id>
2487

            
updated document
Yuki Kimoto authored on 2011-06-09
2488
    id => 4
2489
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2490

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2494
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2495
        {title => 'Perl', author => 'Ken'}
2496
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2497
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2498
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2499
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2500

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2503
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2504
        {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2505
        table => 'book'
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2506
    );
update pod
Yuki Kimoto authored on 2011-03-13
2507

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

            
2510
    prefix => 'or replace'
2511

            
2512
prefix before table name section
2513

            
2514
    insert or replace into book
2515

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2516
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2517

            
updated document
Yuki Kimoto authored on 2011-06-09
2518
    primary_key => 'id'
2519
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2520

            
updated document
Yuki Kimoto authored on 2011-06-09
2521
Primary key. This is used by C<id> option.
cleanup
Yuki Kimoto authored on 2011-06-09
2522

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

            
2525
Same as C<execute> method's C<query> option.
2526

            
2527
=item C<table>
2528

            
2529
    table => 'book'
2530

            
2531
Table name.
2532

            
updated pod
Yuki Kimoto authored on 2011-06-21
2533
=item C<bind_type>
cleanup
yuki-kimoto authored on 2010-10-17
2534

            
updated pod
Yuki Kimoto authored on 2011-06-21
2535
Same as C<execute> method's C<bind_type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2536

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2537
=item C<type_rule_off> EXPERIMENTAL
2538

            
updated document
Yuki Kimoto authored on 2011-06-09
2539
Same as C<execute> method's C<type_rule_off> option.
update pod
Yuki Kimoto authored on 2011-03-13
2540

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2541
=item C<type_rule1_off> EXPERIMENTAL
2542

            
2543
    type_rule1_off => 1
2544

            
2545
Same as C<execute> method's C<type_rule1_off> option.
2546

            
2547
=item C<type_rule2_off> EXPERIMENTAL
2548

            
2549
    type_rule2_off => 1
2550

            
2551
Same as C<execute> method's C<type_rule2_off> option.
2552

            
update pod
Yuki Kimoto authored on 2011-03-13
2553
=back
2554

            
2555
=over 4
2556

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2557
=head2 C<insert_param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2558

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2559
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2560

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2561
Create insert parameters.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2562

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2563
    (title, author) values (title = :title, age = :age);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2564

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2567
    $dbi->include_model('MyModel');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2568

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2572
    lib / MyModel.pm
2573
        / MyModel / book.pm
2574
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2575

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

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

            
2580
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2581
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2582
    
2583
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2584

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2589
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2590
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2591
    
2592
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2593

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2596
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2597
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2598
    
2599
    1;
2600
    
updated pod
Yuki Kimoto authored on 2011-06-21
2601
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2602

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2605
    my $book_model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
2606
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2607

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
2610
=head2 C<map_param> EXPERIMENTAL
2611

            
2612
    my $map_param = $dbi->map_param(
2613
        {id => 1, authro => 'Ken', price => 1900},
2614
        'id' => 'book.id',
2615
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2616
        'price' => [
2617
            'book.price', {if => sub { length $_[0] }}
2618
        ]
2619
    );
2620

            
2621
Map paramters to other key and value. First argument is original
2622
parameter. this is hash reference. Rest argument is mapping.
2623
By default, Mapping is done if the value length is not zero.
2624

            
2625
=over 4
2626

            
2627
=item Key mapping
2628

            
2629
    'id' => 'book.id'
2630

            
2631
This is only key mapping. Value is same as original one.
2632

            
2633
    (id => 1) is mapped to ('book.id' => 1) if value length is not zero.
2634

            
2635
=item Key and value mapping
2636

            
2637
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2638

            
2639
This is key and value mapping. Frist element of array reference
2640
is mapped key name, second element is code reference to map the value.
2641

            
2642
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2643
      if value length is not zero.
2644

            
2645
=item Condition
2646

            
2647
    'price' => ['book.price', {if => 'exists'}]
2648
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2649
    'price' => ['book.price', {if => sub { defined shift }}]
2650

            
2651
If you need condition, you can sepecify it. this is code reference
2652
or 'exists'. By default, condition is the following one.
2653

            
2654
    sub { defined $_[0] && length $_[0] }
2655

            
2656
=back
2657

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

            
2660
    my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2});
2661

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2662
Merge parameters.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2663

            
2664
    {key1 => [1, 1], key2 => 2}
2665

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2666
=head2 C<method>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2667

            
2668
    $dbi->method(
2669
        update_or_insert => sub {
2670
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2671
            
2672
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2673
        },
2674
        find_or_create   => sub {
2675
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2676
            
2677
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2678
        }
2679
    );
2680

            
update pod
Yuki Kimoto authored on 2011-03-13
2681
Register method. These method is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2682

            
2683
    $dbi->update_or_insert;
2684
    $dbi->find_or_create;
2685

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

            
2688
    my $model = $dbi->model('book');
2689

            
updated pod
Yuki Kimoto authored on 2011-06-21
2690
Get a L<DBIx::Custom::Model> object,
update pod
Yuki Kimoto authored on 2011-03-13
2691

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

            
2694
    my $column = $self->mycolumn(book => ['author', 'title']);
2695

            
2696
Create column clause for myself. The follwoing column clause is created.
2697

            
2698
    book.author as author,
2699
    book.title as title
2700

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2703
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2704
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2705
        user => 'ken',
2706
        password => '!LFKD%$&',
2707
        dbi_option => {mysql_enable_utf8 => 1}
2708
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2709

            
2710
Create a new L<DBIx::Custom> object.
2711

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

            
2714
    my $not_exists = $dbi->not_exists;
2715

            
update pod
Yuki Kimoto authored on 2011-03-13
2716
DBIx::Custom::NotExists object, indicating the column is not exists.
2717
This is used by C<clause> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2718

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2719
=head2 C<order> EXPERIMENTAL
2720

            
2721
    my $order = $dbi->order;
2722

            
2723
Create a new L<DBIx::Custom::Order> object.
2724

            
cleanup
yuki-kimoto authored on 2010-10-17
2725
=head2 C<register_filter>
2726

            
update pod
Yuki Kimoto authored on 2011-03-13
2727
    $dbi->register_filter(
2728
        # Time::Piece object to database DATE format
2729
        tp_to_date => sub {
2730
            my $tp = shift;
2731
            return $tp->strftime('%Y-%m-%d');
2732
        },
2733
        # database DATE format to Time::Piece object
2734
        date_to_tp => sub {
2735
           my $date = shift;
2736
           return Time::Piece->strptime($date, '%Y-%m-%d');
2737
        }
2738
    );
cleanup
yuki-kimoto authored on 2010-10-17
2739
    
update pod
Yuki Kimoto authored on 2011-03-13
2740
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2741

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2742
=head2 C<type_rule> EXPERIMENTAL
2743

            
2744
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2745
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2746
            date => sub { ... },
2747
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2748
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2749
        into2 => {
2750
            date => sub { ... },
2751
            datetime => sub { ... }
2752
        },
2753
        from1 => {
2754
            # DATE
2755
            9 => sub { ... },
2756
            # DATETIME or TIMESTAMP
2757
            11 => sub { ... },
2758
        }
2759
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2760
            # DATE
2761
            9 => sub { ... },
2762
            # DATETIME or TIMESTAMP
2763
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2764
        }
2765
    );
2766

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2767
Filtering rule when data is send into and get from database.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2768
This has a little complex problem.
cleanup
Yuki Kimoto authored on 2011-06-13
2769

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2770
In C<into1> and C<into2> you can specify
2771
type name as same as type name defined
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2772
by create table, such as C<DATETIME> or C<DATE>.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2773

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2774
Note that type name and data type don't contain upper case.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2775
If these contain upper case charactor, you convert it to lower case.
2776

            
updated pod
Yuki Kimoto authored on 2011-06-21
2777
C<into2> is executed after C<into1>.
2778

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2779
Type rule of C<into1> and C<into2> is enabled on the following
2780
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2781

            
cleanup
Yuki Kimoto authored on 2011-06-13
2782
=over 4
2783

            
2784
=item 1. column name
2785

            
2786
    issue_date
2787
    issue_datetime
2788

            
updated pod
Yuki Kimoto authored on 2011-06-21
2789
This need C<table> option in each method.
2790

            
cleanup
Yuki Kimoto authored on 2011-06-13
2791
=item 2. table name and column name, separator is dot
2792

            
2793
    book.issue_date
2794
    book.issue_datetime
2795

            
2796
=back
2797

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2798
You get all type name used in database by C<available_typename>.
update pod
Yuki Kimoto authored on 2011-06-15
2799

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2800
    print $dbi->available_typename;
update pod
Yuki Kimoto authored on 2011-06-15
2801

            
updated pod
Yuki Kimoto authored on 2011-06-21
2802
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2803
C<from2> is executed after C<from1>.
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2804
You get all data type by C<available_datatype>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2805

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2806
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2807

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2808
You can also specify multiple types at once.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2809

            
2810
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2811
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2812
            [qw/DATE DATETIME/] => sub { ... },
2813
        ],
2814
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2815

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2818
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2819
        table  => 'book',
2820
        column => ['author', 'title'],
2821
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2822
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2823
    
updated document
Yuki Kimoto authored on 2011-06-09
2824
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2825

            
updated document
Yuki Kimoto authored on 2011-06-09
2826
The following opitons are available.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2827

            
2828
=over 4
2829

            
updated document
Yuki Kimoto authored on 2011-06-09
2830
=item C<append>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2831

            
updated document
Yuki Kimoto authored on 2011-06-09
2832
    append => 'order by title'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2833

            
updated document
Yuki Kimoto authored on 2011-06-09
2834
Append statement to last of SQL.
2835
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2836
=item C<column>
2837
    
updated document
Yuki Kimoto authored on 2011-06-09
2838
    column => 'author'
2839
    column => ['author', 'title']
2840

            
2841
Column clause.
updated pod
Yuki Kimoto authored on 2011-06-07
2842
    
updated document
Yuki Kimoto authored on 2011-06-09
2843
if C<column> is not specified, '*' is set.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2844

            
updated document
Yuki Kimoto authored on 2011-06-09
2845
    column => '*'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2846

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2849
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2850
        {book => [qw/author title/]},
2851
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2852
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2853

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

            
2856
    book.author as "book.author",
2857
    book.title as "book.title",
2858
    person.name as "person.name",
2859
    person.age as "person.age"
2860

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2864
    column => [
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2865
        ['date(book.register_datetime)' => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2866
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2867

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

            
2870
    date(book.register_datetime) as "book.register_date"
updated pod
Yuki Kimoto authored on 2011-06-07
2871

            
updated document
Yuki Kimoto authored on 2011-06-09
2872
=item C<filter>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2873

            
updated document
Yuki Kimoto authored on 2011-06-09
2874
Same as C<execute> method's C<filter> option.
2875

            
2876
=item C<id>
2877

            
2878
    id => 4
2879
    id => [4, 5]
2880

            
2881
ID corresponding to C<primary_key>.
2882
You can select rows by C<id> and C<primary_key>.
2883

            
2884
    $dbi->select(
2885
        parimary_key => ['id1', 'id2'],
2886
        id => [4, 5],
2887
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2888
    );
2889

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2892
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2893
        where => {id1 => 4, id2 => 5},
2894
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2895
    );
2896
    
updated document
Yuki Kimoto authored on 2011-06-09
2897
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2898

            
updated document
Yuki Kimoto authored on 2011-06-09
2899
    param => {'table2.key3' => 5}
update pod
Yuki Kimoto authored on 2011-03-12
2900

            
updated document
Yuki Kimoto authored on 2011-06-09
2901
Parameter shown before where clause.
2902
    
2903
For example, if you want to contain tag in join clause, 
2904
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
2905

            
updated document
Yuki Kimoto authored on 2011-06-09
2906
    join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
2907
              ' as table2 on table1.key1 = table2.key1']
2908

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

            
2911
    prefix => 'SQL_CALC_FOUND_ROWS'
2912

            
2913
Prefix of column cluase
2914

            
2915
    select SQL_CALC_FOUND_ROWS title, author from book;
2916

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

            
2919
    join => [
2920
        'left outer join company on book.company_id = company_id',
2921
        'left outer join location on company.location_id = location.id'
2922
    ]
2923
        
2924
Join clause. If column cluase or where clause contain table name like "company.name",
2925
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2926

            
2927
    $dbi->select(
2928
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2929
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2930
        where => {'company.name' => 'Orange'},
2931
        join => [
2932
            'left outer join company on book.company_id = company.id',
2933
            'left outer join location on company.location_id = location.id'
2934
        ]
2935
    );
2936

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2940
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2941
    from book
2942
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2943
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2944

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
2945
You can specify two table by yourself. This is useful when join parser can't parse
cleanup
Yuki Kimoto authored on 2011-07-28
2946
the join clause correctly. This is EXPERIMENTAL.
added join new syntax
Yuki Kimoto authored on 2011-07-28
2947

            
2948
    $dbi->select(
2949
        table => 'book',
2950
        column => ['company.location_id as location_id'],
2951
        where => {'company.name' => 'Orange'},
2952
        join => [
2953
            {
2954
                clause => 'left outer join location on company.location_id = location.id',
2955
                table => ['company', 'location']
2956
            }
2957
        ]
2958
    );
2959

            
updated document
Yuki Kimoto authored on 2011-06-09
2960
=item C<primary_key>
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2961

            
updated document
Yuki Kimoto authored on 2011-06-09
2962
    primary_key => 'id'
2963
    primary_key => ['id1', 'id2']
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2964

            
updated document
Yuki Kimoto authored on 2011-06-09
2965
Primary key. This is used by C<id> option.
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2966

            
updated document
Yuki Kimoto authored on 2011-06-09
2967
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-12
2968

            
updated document
Yuki Kimoto authored on 2011-06-09
2969
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-12
2970

            
updated pod
Yuki Kimoto authored on 2011-06-21
2971
=item C<bind_type>
updated pod
Yuki Kimoto authored on 2011-06-08
2972

            
cleanup
Yuki Kimoto authored on 2011-07-28
2973
Same as C<execute> method's C<bind_type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2974

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2977
    table => 'book'
updated pod
Yuki Kimoto authored on 2011-06-08
2978

            
updated document
Yuki Kimoto authored on 2011-06-09
2979
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2980

            
updated document
Yuki Kimoto authored on 2011-06-09
2981
=item C<type_rule_off> EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-08
2982

            
updated document
Yuki Kimoto authored on 2011-06-09
2983
Same as C<execute> method's C<type_rule_off> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2984

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2985
=item C<type_rule1_off> EXPERIMENTAL
2986

            
2987
    type_rule1_off => 1
2988

            
2989
Same as C<execute> method's C<type_rule1_off> option.
2990

            
2991
=item C<type_rule2_off> EXPERIMENTAL
2992

            
2993
    type_rule2_off => 1
2994

            
2995
Same as C<execute> method's C<type_rule2_off> option.
2996

            
updated document
Yuki Kimoto authored on 2011-06-09
2997
=item C<where>
2998
    
2999
    # Hash refrence
3000
    where => {author => 'Ken', 'title' => 'Perl'}
3001
    
3002
    # DBIx::Custom::Where object
3003
    where => $dbi->where(
3004
        clause => ['and', 'author = :author', 'title like :title'],
3005
        param  => {author => 'Ken', title => '%Perl%'}
3006
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3007
    
3008
    # Array reference 1 (array reference, hash referenc). same as above
3009
    where => [
3010
        ['and', 'author = :author', 'title like :title'],
3011
        {author => 'Ken', title => '%Perl%'}
3012
    ];    
3013
    
3014
    # Array reference 2 (String, hash reference)
3015
    where => [
3016
        'title like :title',
3017
        {title => '%Perl%'}
3018
    ]
3019
    
3020
    # String
3021
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3022

            
updated document
Yuki Kimoto authored on 2011-06-09
3023
Where clause.
3024
    
improved pod
Yuki Kimoto authored on 2011-04-19
3025
=item C<wrap> EXPERIMENTAL
3026

            
3027
Wrap statement. This is array reference.
3028

            
3029
    $dbi->select(wrap => ['select * from (', ') as t where ROWNUM < 10']);
3030

            
3031
This option is for Oracle and SQL Server paging process.
3032

            
update pod
Yuki Kimoto authored on 2011-03-12
3033
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3034

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3037
    $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
removed reconnect method
yuki-kimoto authored on 2010-05-28
3038

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

            
3041
If you want to set constant value to row data, use scalar reference
3042
as parameter value.
3043

            
3044
    {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3045

            
updated document
Yuki Kimoto authored on 2011-06-09
3046
The following opitons are available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3047

            
update pod
Yuki Kimoto authored on 2011-03-13
3048
=over 4
3049

            
updated document
Yuki Kimoto authored on 2011-06-09
3050
=item C<append>
update pod
Yuki Kimoto authored on 2011-03-13
3051

            
updated document
Yuki Kimoto authored on 2011-06-09
3052
Same as C<select> method's C<append> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3053

            
updated document
Yuki Kimoto authored on 2011-06-09
3054
=item C<filter>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3055

            
updated document
Yuki Kimoto authored on 2011-06-09
3056
Same as C<execute> method's C<filter> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3057

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3060
    id => 4
3061
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3062

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3066
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3067
        {title => 'Perl', author => 'Ken'}
3068
        parimary_key => ['id1', 'id2'],
3069
        id => [4, 5],
3070
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3071
    );
update pod
Yuki Kimoto authored on 2011-03-13
3072

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3075
    $dbi->update(
3076
        {title => 'Perl', author => 'Ken'}
3077
        where => {id1 => 4, id2 => 5},
3078
        table => 'book'
3079
    );
update pod
Yuki Kimoto authored on 2011-03-13
3080

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

            
3083
    prefix => 'or replace'
3084

            
3085
prefix before table name section
3086

            
3087
    update or replace book
3088

            
updated document
Yuki Kimoto authored on 2011-06-09
3089
=item C<primary_key>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
3090

            
updated document
Yuki Kimoto authored on 2011-06-09
3091
    primary_key => 'id'
3092
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
3093

            
updated document
Yuki Kimoto authored on 2011-06-09
3094
Primary key. This is used by C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
3095

            
updated document
Yuki Kimoto authored on 2011-06-09
3096
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
3097

            
updated document
Yuki Kimoto authored on 2011-06-09
3098
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-13
3099

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3102
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
3103

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3106
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
3107

            
updated document
Yuki Kimoto authored on 2011-06-09
3108
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
3109

            
updated pod
Yuki Kimoto authored on 2011-06-21
3110
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3111

            
cleanup
Yuki Kimoto authored on 2011-07-28
3112
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3113

            
3114
=item C<type_rule_off> EXPERIMENTAL
3115

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3116
Same as C<execute> method's C<type_rule_off> option.
3117

            
3118
=item C<type_rule1_off> EXPERIMENTAL
3119

            
3120
    type_rule1_off => 1
3121

            
3122
Same as C<execute> method's C<type_rule1_off> option.
3123

            
3124
=item C<type_rule2_off> EXPERIMENTAL
3125

            
3126
    type_rule2_off => 1
3127

            
3128
Same as C<execute> method's C<type_rule2_off> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3129

            
updated pod
Yuki Kimoto authored on 2011-06-08
3130
=back
update pod
Yuki Kimoto authored on 2011-03-13
3131

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
3134
    $dbi->update_all({title => 'Perl'}, table => 'book', );
update pod
Yuki Kimoto authored on 2011-03-13
3135

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3139
=head2 C<update_param>
update pod
Yuki Kimoto authored on 2011-03-13
3140

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3141
    my $update_param = $dbi->update_param({title => 'a', age => 2});
update pod
Yuki Kimoto authored on 2011-03-13
3142

            
3143
Create update parameter tag.
3144

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3145
    set title = :title, author = :author
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
3146

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
3147
=head2 C<where>
fix tests
Yuki Kimoto authored on 2011-01-18
3148

            
cleanup
Yuki Kimoto authored on 2011-03-09
3149
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3150
        clause => ['and', 'title = :title', 'author = :author'],
cleanup
Yuki Kimoto authored on 2011-03-09
3151
        param => {title => 'Perl', author => 'Ken'}
3152
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3153

            
3154
Create a new L<DBIx::Custom::Where> object.
3155

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
3156
=head2 C<setup_model>
cleanup
Yuki Kimoto authored on 2011-01-12
3157

            
update pod
Yuki Kimoto authored on 2011-03-13
3158
    $dbi->setup_model;
cleanup
Yuki Kimoto authored on 2011-01-12
3159

            
update pod
Yuki Kimoto authored on 2011-03-13
3160
Setup all model objects.
update pod
Yuki Kimoto authored on 2011-03-13
3161
C<columns> of model object is automatically set, parsing database information.
cleanup
Yuki Kimoto authored on 2011-01-12
3162

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
3163
=head1 ENVIRONMENT VARIABLE
3164

            
3165
=head2 C<DBIX_CUSTOM_DEBUG>
3166

            
3167
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
improved debug message
Yuki Kimoto authored on 2011-05-23
3168
executed SQL and bind values are printed to STDERR.
3169

            
update pod
Yuki Kimoto authored on 2011-08-10
3170
=head2 C<show_datatype EXPERIMENTAL>
3171

            
3172
    $dbi->show_datatype($table);
3173

            
3174
Show data type of the columns of specified table.
3175

            
3176
    book
3177
    title: 5
3178
    issue_date: 91
3179

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

            
3182
=head2 C<show_typename EXPERIMENTAL>
3183

            
3184
    $dbi->show_typename($table);
3185

            
3186
Show type name of the columns of specified table.
3187

            
3188
    book
3189
    title: varchar
3190
    issue_date: date
3191

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

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

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3198
=head1 DEPRECATED FUNCTIONALITIES
3199

            
3200
L<DBIx::Custom>
3201

            
3202
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3203
    data_source # will be removed at 2017/1/1
3204
    dbi_options # will be removed at 2017/1/1
3205
    filter_check # will be removed at 2017/1/1
3206
    reserved_word_quote # will be removed at 2017/1/1
3207
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3208
    
3209
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3210
    create_query # will be removed at 2017/1/1
3211
    apply_filter # will be removed at 2017/1/1
3212
    select_at # will be removed at 2017/1/1
3213
    delete_at # will be removed at 2017/1/1
3214
    update_at # will be removed at 2017/1/1
3215
    insert_at # will be removed at 2017/1/1
3216
    register_tag # will be removed at 2017/1/1
3217
    default_bind_filter # will be removed at 2017/1/1
3218
    default_fetch_filter # will be removed at 2017/1/1
3219
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3220
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3221
    register_tag_processor # will be removed at 2017/1/1
3222
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3223
    
3224
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3225
    select method relation option # will be removed at 2017/1/1
3226
    select method param option # will be removed at 2017/1/1
3227
    select method column option [COLUMN, as => ALIAS] format
3228
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3229
    
3230
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3231
    execute("select * from {= title}"); # execute method's
3232
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3233
                                        # will be removed at 2017/1/1
3234
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3235

            
3236
L<DBIx::Custom::Model>
3237

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3238
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3239
    filter # will be removed at 2017/1/1
3240
    name # will be removed at 2017/1/1
3241
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3242

            
3243
L<DBIx::Custom::Query>
3244
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3245
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3246
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3247
    table # will be removed at 2017/1/1
3248
    filters # will be removed at 2017/1/1
3249
    
3250
    # Methods
3251
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3252

            
3253
L<DBIx::Custom::QueryBuilder>
3254
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3255
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3256
    tags # will be removed at 2017/1/1
3257
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3258
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3259
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3260
    register_tag # will be removed at 2017/1/1
3261
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3262
    
3263
    # Others
3264
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3265
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3266

            
3267
L<DBIx::Custom::Result>
3268
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3269
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3270
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3271
    
3272
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3273
    end_filter # will be removed at 2017/1/1
3274
    remove_end_filter # will be removed at 2017/1/1
3275
    remove_filter # will be removed at 2017/1/1
3276
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3277

            
3278
L<DBIx::Custom::Tag>
3279

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3280
    This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3281

            
3282
=head1 BACKWORD COMPATIBLE POLICY
3283

            
3284
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3285
except for attribute method.
3286
You can check all DEPRECATED functionalities by document.
3287
DEPRECATED functionality is removed after five years,
3288
but if at least one person use the functionality and tell me that thing
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3289
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3290

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3293
This policy was changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3294

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

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

            
3299
C<< <kimoto.yuki at gmail.com> >>
3300

            
3301
L<http://github.com/yuki-kimoto/DBIx-Custom>
3302

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3303
=head1 AUTHOR
3304

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

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

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

            
3311
This program is free software; you can redistribute it and/or modify it
3312
under the same terms as Perl itself.
3313

            
3314
=cut