DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3246 lines | 84.078kb
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 test
Yuki Kimoto authored on 2011-08-06
4
our $VERSION = '0.1711';
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/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

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

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

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

            
76
sub show_datatype {
77
    my ($self, $table) = @_;
78
    
79
    
80
}
81

            
82
sub show_typename {
83
    
84
}
85

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

            
added helper method
yuki-kimoto authored on 2010-10-17
101
our $AUTOLOAD;
102
sub AUTOLOAD {
103
    my $self = shift;
104

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
143
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
144
    my $self = shift;
145
    my $option = pop if ref $_[-1] eq 'HASH';
146
    my $real_table = shift;
147
    my $columns = shift;
148
    my $table = $option->{alias} || $real_table;
149
    
150
    # Columns
151
    unless ($columns) {
152
        $columns ||= $self->model($real_table)->columns;
153
    }
added helper method
yuki-kimoto authored on 2010-10-17
154
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
155
    # Separator
156
    my $separator = $self->separator;
157
    
cleanup
Yuki Kimoto authored on 2011-04-02
158
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
159
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
160
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
161
    push @column, $self->_q($table) . "." . $self->_q($_) .
162
      " as " . $self->_q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
163
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
164
    
165
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
166
}
167

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
264
sub DESTROY {
265

            
266
}
added helper method
yuki-kimoto authored on 2010-10-17
267

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

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

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
304
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
305
    
306
    # Iterate all tables
307
    my $sth_tables = $self->dbh->table_info;
308
    while (my $table_info = $sth_tables->fetchrow_hashref) {
309
        
310
        # Table
311
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
312
        next if defined $re && $table =~ /$re/;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
313
        
314
        # Iterate all columns
315
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
316
        while (my $column_info = $sth_columns->fetchrow_hashref) {
317
            my $column = $column_info->{COLUMN_NAME};
318
            $self->$cb($table, $column, $column_info);
319
        }
320
    }
321
}
322

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
323

            
324

            
325

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
fixed if is not converted to...
Yuki Kimoto authored on 2011-08-09
764
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
765
sub not_exists { $not_exists }
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
766

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
767
sub order {
768
    my $self = shift;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
769
    return DBIx::Custom::Order->new(dbi => $self, @_);
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
770
}
771

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
772
sub query_builder {
773
    my $self = shift;
774
    my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
775
    
776
    # DEPRECATED
777
    $builder->register_tag(
778
        '?'     => \&DBIx::Custom::Tag::placeholder,
779
        '='     => \&DBIx::Custom::Tag::equal,
780
        '<>'    => \&DBIx::Custom::Tag::not_equal,
781
        '>'     => \&DBIx::Custom::Tag::greater_than,
782
        '<'     => \&DBIx::Custom::Tag::lower_than,
783
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
784
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
785
        'like'  => \&DBIx::Custom::Tag::like,
786
        'in'    => \&DBIx::Custom::Tag::in,
787
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
788
        'update_param' => \&DBIx::Custom::Tag::update_param
789
    );
790
    $builder->register_tag($self->{_tags} || {});
791
    return $builder;
792
}
793

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

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

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

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

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

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
952
sub type_rule {
953
    my $self = shift;
954
    
955
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
956
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
957
        
958
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
959
        foreach my $i (1 .. 2) {
960
            my $into = "into$i";
961
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
962
            $self->{type_rule} = $type_rule;
963
            $self->{"_$into"} = {};
964
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
965
                croak qq{type name of $into section must be lower case}
966
                  if $type_name =~ /[A-Z]/;
967
            }
968
            $self->each_column(sub {
969
                my ($dbi, $table, $column, $column_info) = @_;
970
                
971
                my $type_name = lc $column_info->{TYPE_NAME};
972
                if ($type_rule->{$into} &&
973
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
974
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
975
                    return unless exists $type_rule->{$into}->{$type_name};
976
                    if  (defined $filter && ref $filter ne 'CODE') 
977
                    {
978
                        my $fname = $filter;
979
                        croak qq{Filter "$fname" is not registered" } . _subname
980
                          unless exists $self->filters->{$fname};
981
                        
982
                        $filter = $self->filters->{$fname};
983
                    }
984

            
micro optimization
Yuki Kimoto authored on 2011-07-30
985
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
986
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
987
                }
988
            });
989
        }
990

            
991
        # From
992
        foreach my $i (1 .. 2) {
993
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
994
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
995
                croak qq{data type of from$i section must be lower case or number}
996
                  if $data_type =~ /[A-Z]/;
997
                my $fname = $type_rule->{"from$i"}{$data_type};
998
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
999
                    croak qq{Filter "$fname" is not registered" } . _subname
1000
                      unless exists $self->filters->{$fname};
1001
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1002
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1003
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1004
            }
1005
        }
1006
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1007
        return $self;
1008
    }
1009
    
1010
    return $self->{type_rule} || {};
1011
}
1012

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1016
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1017
    my $param;
1018
    $param = shift if @_ % 2;
1019
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1020
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1021
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1022
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1023
    my $p = delete $args{param} || {};
1024
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1025
    my $where = delete $args{where} || {};
1026
    my $where_param = delete $args{where_param} || {};
1027
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1028
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1029
    my $id = delete $args{id};
1030
    my $primary_key = delete $args{primary_key};
1031
    croak "update method primary_key option " .
1032
          "must be specified when id is specified " . _subname
1033
      if defined $id && !defined $primary_key;
1034
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1035
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1036

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

            
1040
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1041
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1042
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1043
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1044
        $where_clause = "where " . $where->[0];
1045
        $where_param = $where->[1];
1046
    }
1047
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1048
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1049
        $where_param = keys %$where_param
1050
                     ? $self->merge_param($where_param, $where->param)
1051
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1052
        
1053
        # String where
1054
        $where_clause = $where->to_string;
1055
    }
1056
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1057
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1058
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1059
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1060
    # Merge param
1061
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1062
    
cleanup
Yuki Kimoto authored on 2011-04-02
1063
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1064
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1065
    push @sql, "update";
1066
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1067
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1068
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1069
    
cleanup
Yuki Kimoto authored on 2011-01-27
1070
    # SQL
1071
    my $sql = join(' ', @sql);
1072
    
cleanup
yuki-kimoto authored on 2010-10-17
1073
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1074
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1075
}
1076

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1079
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1080
    my ($self, $param, $opt) = @_;
1081
    
cleanup
Yuki Kimoto authored on 2011-04-02
1082
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1083
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1084
    $tag = "set $tag" unless $opt->{no_set};
1085

            
cleanup
Yuki Kimoto authored on 2011-04-02
1086
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1087
}
1088

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1091
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1092
    
updated pod
Yuki Kimoto authored on 2011-06-21
1093
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1094
    
updated pod
Yuki Kimoto authored on 2011-06-21
1095
    # Cache
1096
    my $cache = $self->cache;
1097
    
1098
    # Query
1099
    my $query;
1100
    
1101
    # Get cached query
1102
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1103
        
updated pod
Yuki Kimoto authored on 2011-06-21
1104
        # Get query
1105
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1106
        
updated pod
Yuki Kimoto authored on 2011-06-21
1107
        # Create query
1108
        if ($q) {
1109
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1110
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1111
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1112
    }
1113
    
1114
    # Create query
1115
    unless ($query) {
1116

            
1117
        # Create query
1118
        my $builder = $self->query_builder;
1119
        $query = $builder->build_query($source);
1120

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

            
1127
        # Save query to cache
1128
        $self->cache_method->(
1129
            $self, $source,
1130
            {
1131
                sql     => $query->sql, 
1132
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1133
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1134
            }
1135
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1136
    }
1137
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1138
    # Save sql
1139
    $self->last_sql($query->sql);
1140
    
updated pod
Yuki Kimoto authored on 2011-06-21
1141
    # Prepare statement handle
1142
    my $sth;
1143
    eval { $sth = $self->dbh->prepare($query->{sql})};
1144
    
1145
    if ($@) {
1146
        $self->_croak($@, qq{. Following SQL is executed.\n}
1147
                        . qq{$query->{sql}\n} . _subname);
1148
    }
1149
    
1150
    # Set statement handle
1151
    $query->sth($sth);
1152
    
1153
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1154
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1155
    
1156
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1157
}
1158

            
cleanup
Yuki Kimoto authored on 2011-04-02
1159
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1160
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1161
    
cleanup
Yuki Kimoto authored on 2011-04-02
1162
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1163
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1164
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1165
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1166
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1167
        
1168
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1169
        my $value;
1170
        if(ref $params->{$column} eq 'ARRAY') {
1171
            my $i = $count->{$column} || 0;
1172
            $i += $not_exists->{$column} || 0;
1173
            my $found;
1174
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1175
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1176
                    $not_exists->{$column}++;
1177
                }
1178
                else  {
1179
                    $value = $params->{$column}->[$k];
1180
                    $found = 1;
1181
                    last
1182
                }
1183
            }
1184
            next unless $found;
1185
        }
1186
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1187
        
cleanup
Yuki Kimoto authored on 2011-01-12
1188
        # Filter
1189
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1190
        $value = $f->($value) if $f;
1191
        
1192
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1193
        foreach my $i (1 .. 2) {
1194
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1195
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1196
            $value = $tf->($value) if $tf;
1197
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1198
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1199
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1200
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1201
        
1202
        # Count up 
1203
        $count->{$column}++;
1204
    }
1205
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1206
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1207
}
1208

            
cleanup
Yuki Kimoto authored on 2011-06-08
1209
sub _create_param_from_id {
1210
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1211
    
cleanup
Yuki Kimoto authored on 2011-06-08
1212
    # Create parameter
1213
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1214
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1215
        $id = [$id] unless ref $id;
1216
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1217
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1218
          unless !ref $id || ref $id eq 'ARRAY';
1219
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1220
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1221
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1222
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1223
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1224
        }
1225
    }
1226
    
cleanup
Yuki Kimoto authored on 2011-06-08
1227
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1228
}
1229

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1230
sub _connect {
1231
    my $self = shift;
1232
    
1233
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1234
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1235
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1236
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1237
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1238
    croak qq{"dsn" must be specified } . _subname
1239
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1240
    my $user        = $self->user;
1241
    my $password    = $self->password;
1242
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1243
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1244
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1245
    
1246
    # Connect
1247
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1248
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1249
        $user,
1250
        $password,
1251
        {
1252
            %{$self->default_dbi_option},
1253
            %$dbi_option
1254
        }
1255
    )};
1256
    
1257
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1258
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1259
    
1260
    return $dbh;
1261
}
1262

            
cleanup
yuki-kimoto authored on 2010-10-17
1263
sub _croak {
1264
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1265
    
1266
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1267
    $append ||= "";
1268
    
1269
    # Verbose
1270
    if ($Carp::Verbose) { croak $error }
1271
    
1272
    # Not verbose
1273
    else {
1274
        
1275
        # Remove line and module infromation
1276
        my $at_pos = rindex($error, ' at ');
1277
        $error = substr($error, 0, $at_pos);
1278
        $error =~ s/\s+$//;
1279
        croak "$error$append";
1280
    }
1281
}
1282

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1283
sub _need_tables {
1284
    my ($self, $tree, $need_tables, $tables) = @_;
1285
    
cleanup
Yuki Kimoto authored on 2011-04-02
1286
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1287
    foreach my $table (@$tables) {
1288
        if ($tree->{$table}) {
1289
            $need_tables->{$table} = 1;
1290
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1291
        }
1292
    }
1293
}
1294

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1295
sub _push_join {
1296
    my ($self, $sql, $join, $join_tables) = @_;
1297
    
cleanup
Yuki Kimoto authored on 2011-04-02
1298
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1299
    return unless @$join;
1300
    
cleanup
Yuki Kimoto authored on 2011-04-02
1301
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1302
    my $tree = {};
1303
    for (my $i = 0; $i < @$join; $i++) {
1304
        
cleanup
Yuki Kimoto authored on 2011-07-28
1305
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1306
        my $join_clause;;
1307
        my $option;
1308
        if (ref $join->[$i] eq 'HASH') {
1309
            $join_clause = $join->[$i]->{clause};
1310
            $option = {table => $join->[$i]->{table}};
1311
        }
1312
        else {
1313
            $join_clause = $join->[$i];
1314
            $option = {};
1315
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1316

            
1317
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1318
        my $table1;
1319
        my $table2;
1320
        if (my $table = $option->{table}) {
1321
            $table1 = $table->[0];
1322
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1323
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1324
        else {
1325
            my $q = $self->_quote;
1326
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1327
            $j_clause =~ s/'.+?'//g;
1328
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1329
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1330
            my $c = $self->safety_character;
1331
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1332
            if ($j_clause =~ $join_re) {
1333
                $table1 = $1;
1334
                $table2 = $2;
1335
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1336
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1337
        croak qq{join clause must have two table name after "on" keyword. } .
1338
              qq{"$join_clause" is passed }  . _subname
1339
          unless defined $table1 && defined $table2;
1340
        croak qq{right side table of "$join_clause" must be unique }
1341
            . _subname
1342
          if exists $tree->{$table2};
1343
        croak qq{Same table "$table1" is specified} . _subname
1344
          if $table1 eq $table2;
1345
        $tree->{$table2}
1346
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1347
    }
1348
    
cleanup
Yuki Kimoto authored on 2011-04-02
1349
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1350
    my $need_tables = {};
1351
    $self->_need_tables($tree, $need_tables, $join_tables);
1352
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1353
    
1354
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1355
    foreach my $need_table (@need_tables) {
1356
        push @$sql, $tree->{$need_table}{join};
1357
    }
1358
}
cleanup
Yuki Kimoto authored on 2011-03-08
1359

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1360
sub _quote {
1361
    my $self = shift;
1362
    
1363
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1364
         : defined $self->quote ? $self->quote
1365
         : '';
1366
}
1367

            
cleanup
Yuki Kimoto authored on 2011-07-29
1368
sub _q {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1369
    my ($self, $value) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1370
    
1371
    my $quote = $self->_quote;
1372
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1373
    my $p;
1374
    if (defined $quote && length $quote > 1) {
1375
        $p = substr($quote, 1, 1);
1376
    }
1377
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1378
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1379
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1380
}
1381

            
cleanup
Yuki Kimoto authored on 2011-04-02
1382
sub _remove_duplicate_table {
1383
    my ($self, $tables, $main_table) = @_;
1384
    
1385
    # Remove duplicate table
1386
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1387
    delete $tables{$main_table} if $main_table;
1388
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1389
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1390
    if (my $q = $self->_quote) {
1391
        $q = quotemeta($q);
1392
        $_ =~ s/[$q]//g for @$new_tables;
1393
    }
1394

            
1395
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1396
}
1397

            
cleanup
Yuki Kimoto authored on 2011-04-02
1398
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1399
    my ($self, $source) = @_;
1400
    
cleanup
Yuki Kimoto authored on 2011-04-02
1401
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1402
    my $tables = [];
1403
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1404
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1405
    my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1406
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)");
1407
    my $table_re = $q ? qr/(?:^|[^$safety_character])$quoted_safety_character_re?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1408
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1409
    while ($source =~ /$table_re/g) {
1410
        push @$tables, $1;
1411
    }
1412
    
1413
    return $tables;
1414
}
1415

            
cleanup
Yuki Kimoto authored on 2011-04-02
1416
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1417
    my ($self, $where) = @_;
1418
    
cleanup
Yuki Kimoto authored on 2011-04-02
1419
    my $obj;
1420
    
1421
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1422
    if (ref $where eq 'HASH') {
1423
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1424
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1425
        foreach my $column (keys %$where) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1426
            my $column_quote = $self->_q($column);
1427
            $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1428
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1429
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1430
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1431
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1432
    
1433
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1434
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1435
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1436
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1437
    
updated pod
Yuki Kimoto authored on 2011-06-21
1438
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1439
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1440
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1441
            clause => $where->[0],
1442
            param  => $where->[1]
1443
        );
1444
    }
1445
    
cleanup
Yuki Kimoto authored on 2011-04-02
1446
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1447
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1448
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1449
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1450
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1451
    
cleanup
Yuki Kimoto authored on 2011-04-02
1452
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1453
}
1454

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

            
1458
    # Initialize filters
1459
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1460
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1461
    $self->{filter}{out} ||= {};
1462
    $self->{filter}{in} ||= {};
1463
    $self->{filter}{end} ||= {};
1464
    
1465
    # Usage
1466
    my $usage = "Usage: \$dbi->apply_filter(" .
1467
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1468
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1469
    
1470
    # Apply filter
1471
    for (my $i = 0; $i < @cinfos; $i += 2) {
1472
        
1473
        # Column
1474
        my $column = $cinfos[$i];
1475
        if (ref $column eq 'ARRAY') {
1476
            foreach my $c (@$column) {
1477
                push @cinfos, $c, $cinfos[$i + 1];
1478
            }
1479
            next;
1480
        }
1481
        
1482
        # Filter infomation
1483
        my $finfo = $cinfos[$i + 1] || {};
1484
        croak "$usage (table: $table) " . _subname
1485
          unless  ref $finfo eq 'HASH';
1486
        foreach my $ftype (keys %$finfo) {
1487
            croak "$usage (table: $table) " . _subname
1488
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1489
        }
1490
        
1491
        # Set filters
1492
        foreach my $way (qw/in out end/) {
1493
        
1494
            # Filter
1495
            my $filter = $finfo->{$way};
1496
            
1497
            # Filter state
1498
            my $state = !exists $finfo->{$way} ? 'not_exists'
1499
                      : !defined $filter        ? 'not_defined'
1500
                      : ref $filter eq 'CODE'   ? 'code'
1501
                      : 'name';
1502
            
1503
            # Filter is not exists
1504
            next if $state eq 'not_exists';
1505
            
1506
            # Check filter name
1507
            croak qq{Filter "$filter" is not registered } . _subname
1508
              if  $state eq 'name'
1509
               && ! exists $self->filters->{$filter};
1510
            
1511
            # Set filter
1512
            my $f = $state eq 'not_defined' ? undef
1513
                  : $state eq 'code'        ? $filter
1514
                  : $self->filters->{$filter};
1515
            $self->{filter}{$way}{$table}{$column} = $f;
1516
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1517
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1518
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1519
        }
1520
    }
1521
    
1522
    return $self;
1523
}
1524

            
1525
# DEPRECATED!
1526
sub create_query {
1527
    warn "create_query is DEPRECATED! use query option of each method";
1528
    shift->_create_query(@_);
1529
}
1530

            
cleanup
Yuki Kimoto authored on 2011-06-13
1531
# DEPRECATED!
1532
sub apply_filter {
1533
    my $self = shift;
1534
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1535
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1536
    return $self->_apply_filter(@_);
1537
}
1538

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1546
    # Arguments
1547
    my $primary_keys = delete $args{primary_key};
1548
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1549
    my $where = delete $args{where};
1550
    my $param = delete $args{param};
1551
    
1552
    # Check arguments
1553
    foreach my $name (keys %args) {
1554
        croak qq{"$name" is wrong option } . _subname
1555
          unless $SELECT_AT_ARGS{$name};
1556
    }
1557
    
1558
    # Table
1559
    croak qq{"table" option must be specified } . _subname
1560
      unless $args{table};
1561
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1562
    
1563
    # Create where parameter
1564
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1565
    
1566
    return $self->select(where => $where_param, %args);
1567
}
1568

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

            
1574
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1575
    
1576
    # Arguments
1577
    my $primary_keys = delete $args{primary_key};
1578
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1579
    my $where = delete $args{where};
1580
    
1581
    # Check arguments
1582
    foreach my $name (keys %args) {
1583
        croak qq{"$name" is wrong option } . _subname
1584
          unless $DELETE_AT_ARGS{$name};
1585
    }
1586
    
1587
    # Create where parameter
1588
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1589
    
1590
    return $self->delete(where => $where_param, %args);
1591
}
1592

            
cleanup
Yuki Kimoto authored on 2011-06-08
1593
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1594
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1595
sub update_at {
1596
    my $self = shift;
1597

            
1598
    warn "update_at is DEPRECATED! use update and id option instead";
1599
    
1600
    # Arguments
1601
    my $param;
1602
    $param = shift if @_ % 2;
1603
    my %args = @_;
1604
    my $primary_keys = delete $args{primary_key};
1605
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1606
    my $where = delete $args{where};
1607
    my $p = delete $args{param} || {};
1608
    $param  ||= $p;
1609
    
1610
    # Check arguments
1611
    foreach my $name (keys %args) {
1612
        croak qq{"$name" is wrong option } . _subname
1613
          unless $UPDATE_AT_ARGS{$name};
1614
    }
1615
    
1616
    # Create where parameter
1617
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1618
    
1619
    return $self->update(where => $where_param, param => $param, %args);
1620
}
1621

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1622
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1623
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1624
sub insert_at {
1625
    my $self = shift;
1626
    
1627
    warn "insert_at is DEPRECATED! use insert and id option instead";
1628
    
1629
    # Arguments
1630
    my $param;
1631
    $param = shift if @_ % 2;
1632
    my %args = @_;
1633
    my $primary_key = delete $args{primary_key};
1634
    $primary_key = [$primary_key] unless ref $primary_key;
1635
    my $where = delete $args{where};
1636
    my $p = delete $args{param} || {};
1637
    $param  ||= $p;
1638
    
1639
    # Check arguments
1640
    foreach my $name (keys %args) {
1641
        croak qq{"$name" is wrong option } . _subname
1642
          unless $INSERT_AT_ARGS{$name};
1643
    }
1644
    
1645
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1646
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1647
    $param = $self->merge_param($where_param, $param);
1648
    
1649
    return $self->insert(param => $param, %args);
1650
}
1651

            
added warnings
Yuki Kimoto authored on 2011-06-07
1652
# DEPRECATED!
1653
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1654
    my $self = shift;
1655
    
added warnings
Yuki Kimoto authored on 2011-06-07
1656
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1657
    
1658
    # Merge tag
1659
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1660
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1661
    
1662
    return $self;
1663
}
1664

            
1665
# DEPRECATED!
1666
sub register_tag_processor {
1667
    my $self = shift;
1668
    warn "register_tag_processor is DEPRECATED!";
1669
    # Merge tag
1670
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1671
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1672
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1673
}
1674

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1675
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1676
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1677
has dbi_options => sub { {} };
1678
has filter_check  => 1;
1679
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1680

            
cleanup
Yuki Kimoto authored on 2011-01-25
1681
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1682
sub default_bind_filter {
1683
    my $self = shift;
1684
    
cleanup
Yuki Kimoto authored on 2011-06-13
1685
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1686
    
cleanup
Yuki Kimoto authored on 2011-01-12
1687
    if (@_) {
1688
        my $fname = $_[0];
1689
        
1690
        if (@_ && !$fname) {
1691
            $self->{default_out_filter} = undef;
1692
        }
1693
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1694
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1695
              unless exists $self->filters->{$fname};
1696
        
1697
            $self->{default_out_filter} = $self->filters->{$fname};
1698
        }
1699
        return $self;
1700
    }
1701
    
1702
    return $self->{default_out_filter};
1703
}
1704

            
cleanup
Yuki Kimoto authored on 2011-01-25
1705
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1706
sub default_fetch_filter {
1707
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1708

            
cleanup
Yuki Kimoto authored on 2011-06-13
1709
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1710
    
1711
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1712
        my $fname = $_[0];
1713

            
cleanup
Yuki Kimoto authored on 2011-01-12
1714
        if (@_ && !$fname) {
1715
            $self->{default_in_filter} = undef;
1716
        }
1717
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1718
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1719
              unless exists $self->filters->{$fname};
1720
        
1721
            $self->{default_in_filter} = $self->filters->{$fname};
1722
        }
1723
        
1724
        return $self;
1725
    }
1726
    
many changed
Yuki Kimoto authored on 2011-01-23
1727
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1728
}
1729

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1730
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1731
sub insert_param_tag {
1732
    warn "insert_param_tag is DEPRECATED! " .
1733
         "use insert_param instead!";
1734
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1735
}
1736

            
1737
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1738
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1739
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1740
         "use update_param instead";
1741
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1742
}
cleanup
Yuki Kimoto authored on 2011-03-08
1743
# DEPRECATED!
1744
sub _push_relation {
1745
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1746
    
1747
    if (keys %{$relation || {}}) {
1748
        push @$sql, $need_where ? 'where' : 'and';
1749
        foreach my $rcolumn (keys %$relation) {
1750
            my $table1 = (split (/\./, $rcolumn))[0];
1751
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1752
            push @$tables, ($table1, $table2);
1753
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1754
        }
1755
    }
1756
    pop @$sql if $sql->[-1] eq 'and';    
1757
}
1758

            
1759
# DEPRECATED!
1760
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1761
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1762
    
1763
    if (keys %{$relation || {}}) {
1764
        foreach my $rcolumn (keys %$relation) {
1765
            my $table1 = (split (/\./, $rcolumn))[0];
1766
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1767
            my $table1_exists;
1768
            my $table2_exists;
1769
            foreach my $table (@$tables) {
1770
                $table1_exists = 1 if $table eq $table1;
1771
                $table2_exists = 1 if $table eq $table2;
1772
            }
1773
            unshift @$tables, $table1 unless $table1_exists;
1774
            unshift @$tables, $table2 unless $table2_exists;
1775
        }
1776
    }
1777
}
1778

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1781
=head1 NAME
1782

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

            
1785
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1786

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1787
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1788
    
1789
    # Connect
1790
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1791
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1792
        user => 'ken',
1793
        password => '!LFKD%$&',
1794
        dbi_option => {mysql_enable_utf8 => 1}
1795
    );
cleanup
yuki-kimoto authored on 2010-08-05
1796

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1797
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1798
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1799
    
1800
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1801
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1802
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1803
    
1804
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1805
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1806

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1811
    # Select, more complex
1812
    my $result = $dbi->select(
1813
        table  => 'book',
1814
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1815
            {book => [qw/title author/]},
1816
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1817
        ],
1818
        where  => {'book.author' => 'Ken'},
1819
        join => ['left outer join company on book.company_id = company.id'],
1820
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1821
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1822
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1823
    # Fetch
1824
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1825
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1826
    }
1827
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1828
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1829
    while (my $row = $result->fetch_hash) {
1830
        
1831
    }
1832
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1833
    # Execute SQL with parameter.
1834
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1835
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1836
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1837
    );
1838
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1839
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1840

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1856
Named place holder support
1857

            
1858
=item *
1859

            
cleanup
Yuki Kimoto authored on 2011-07-29
1860
Model support
1861

            
1862
=item *
1863

            
1864
Connection manager support
1865

            
1866
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1867

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

            
1872
=item *
1873

            
1874
Filtering by data type or column name(EXPERIMENTAL)
1875

            
1876
=item *
1877

            
1878
Create C<order by> clause flexibly(EXPERIMENTAL)
1879

            
1880
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1881

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1889
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1890
L<DBIx::Custom::Result>,
1891
L<DBIx::Custom::Query>,
1892
L<DBIx::Custom::Where>,
1893
L<DBIx::Custom::Model>,
1894
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1895

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

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

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

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

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

            
1909
    my $connector = DBIx::Connector->new(
1910
        "dbi:mysql:database=$DATABASE",
1911
        $USER,
1912
        $PASSWORD,
1913
        DBIx::Custom->new->default_dbi_option
1914
    );
1915
    
updated pod
Yuki Kimoto authored on 2011-06-21
1916
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1917

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

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

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

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

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

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

            
1933
=head2 C<default_dbi_option>
1934

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1941
    {
1942
        RaiseError => 1,
1943
        PrintError => 0,
1944
        AutoCommit => 1,
1945
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1946

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

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

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

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

            
1956
    my $last_sql = $dbi->last_sql;
1957
    $dbi = $dbi->last_sql($last_sql);
1958

            
1959
Get last successed SQL executed by C<execute> method.
1960

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1968
=head2 C<password>
1969

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
1990
You can set quote pair.
1991

            
1992
    $dbi->quote('[]');
1993

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

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

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

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

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

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

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

            
2011
    my $separator = $self->separator;
2012
    $dbi = $self->separator($separator);
2013

            
2014
Separator whichi join table and column.
2015
This is used by C<column> and C<mycolumn> method.
2016

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

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

            
2022
Regex matching system table.
2023
this regex match is used by C<each_table> method and C<each_column> method
2024
System table is ignored.
2025
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2026
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2027
The performance is up.
2028

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

            
2031
    my $tag_parse = $dbi->tag_parse(0);
2032
    $dbi = $dbi->tag_parse;
2033

            
2034
Enable DEPRECATED tag parsing functionality, default to 1.
2035
If you want to disable tag parsing functionality, set to 0.
2036

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2078
Create column clause. The follwoing column clause is created.
2079

            
2080
    book.author as "book.author",
2081
    book.title as "book.title"
2082

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2085
    # Separator is double underbar
2086
    $dbi->separator('__');
2087
    
2088
    book.author as "book__author",
2089
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2090

            
cleanup
Yuki Kimoto authored on 2011-06-13
2091
    # Separator is hyphen
2092
    $dbi->separator('-');
2093
    
2094
    book.author as "book-author",
2095
    book.title as "book-title"
2096
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2097
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2098

            
update pod
Yuki Kimoto authored on 2011-03-13
2099
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2100
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2101
        user => 'ken',
2102
        password => '!LFKD%$&',
2103
        dbi_option => {mysql_enable_utf8 => 1}
2104
    );
2105

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2114
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2115
        table => 'book',
2116
        primary_key => 'id',
2117
        join => [
2118
            'inner join company on book.comparny_id = company.id'
2119
        ],
2120
    );
2121

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

            
2125
   $dbi->model('book')->select(...);
2126

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

            
2129
    my $dbh = $dbi->dbh;
2130

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

            
2134
=head2 C<each_column>
2135

            
2136
    $dbi->each_column(
2137
        sub {
2138
            my ($dbi, $table, $column, $column_info) = @_;
2139
            
2140
            my $type = $column_info->{TYPE_NAME};
2141
            
2142
            if ($type eq 'DATE') {
2143
                # ...
2144
            }
2145
        }
2146
    );
2147

            
2148
Iterate all column informations of all table from database.
2149
Argument is callback when one column is found.
2150
Callback receive four arguments, dbi object, table name,
2151
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2152

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

            
2155
    $dbi->each_table(
2156
        sub {
2157
            my ($dbi, $table, $table_info) = @_;
2158
            
2159
            my $table_name = $table_info->{TABLE_NAME};
2160
        }
2161
    );
2162

            
2163
Iterate all table informationsfrom database.
2164
Argument is callback when one table is found.
2165
Callback receive three arguments, dbi object, table name,
2166
table information.
2167

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

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

            
2175
    my $result = $dbi->execute(
2176
      "select * from book where title = :book.title and author like :book.author",
2177
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2178
    );
2179

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2186
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2187
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2188
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2189
    select * from book where title = :title and author like :author
2190
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2191
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2192
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2193

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2197
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2198
    select * from book where :title{=} and :author{like}
2199
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2200
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2201
    select * from where title = ? and author like ?;
2202

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

            
2207
    select * from where title = "aa\\:bb";
2208

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

            
2211
=over 4
2212

            
2213
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2214
    
2215
    filter => {
2216
        title  => sub { uc $_[0] }
2217
        author => sub { uc $_[0] }
2218
    }
update pod
Yuki Kimoto authored on 2011-03-13
2219

            
updated pod
Yuki Kimoto authored on 2011-06-09
2220
    # Filter name
2221
    filter => {
2222
        title  => 'upper_case',
2223
        author => 'upper_case'
2224
    }
2225
        
2226
    # At once
2227
    filter => [
2228
        [qw/title author/]  => sub { uc $_[0] }
2229
    ]
2230

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

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

            
2238
    query => 1
2239

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

            
2243
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2244
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2245
    my $columns = $query->columns;
2246
    
2247
If you want to execute SQL fast, you can do the following way.
2248

            
2249
    my $query;
2250
    foreach my $row (@$rows) {
2251
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2252
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2253
    }
2254

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

            
2258
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
2259
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2260
    
2261
    my $query;
2262
    my $sth;
2263
    foreach my $row (@$rows) {
2264
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2265
      $sth ||= $query->sth;
2266
      $sth->execute(map { $row->{$_} } sort keys %$row);
2267
    }
2268

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2273
=item C<table>
2274
    
2275
    table => 'author'
2276

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2284
    # Same
2285
    $dbi->execute(
2286
      "select * from book where title = :book.title and author = :book.author",
2287
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2288

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

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

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

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

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

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

            
2302
    table_alias => {user => 'hiker'}
2303

            
2304
Table alias. Key is real table name, value is alias table name.
2305
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2306
on alias table name.
2307

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

            
2310
    type_rule_off => 1
2311

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

            
2314
=item C<type_rule1_off> EXPERIMENTAL
2315

            
2316
    type_rule1_off => 1
2317

            
2318
Turn C<into1> type rule off.
2319

            
2320
=item C<type_rule2_off> EXPERIMENTAL
2321

            
2322
    type_rule2_off => 1
2323

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2336
=over 4
2337

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

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

            
2342
=item C<filter>
2343

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2348
    id => 4
2349
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2350

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2354
    $dbi->delete(
2355
        parimary_key => ['id1', 'id2'],
2356
        id => [4, 5],
2357
        table => 'book',
2358
    );
update pod
Yuki Kimoto authored on 2011-03-13
2359

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

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

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

            
2366
    prefix => 'some'
2367

            
2368
prefix before table name section.
2369

            
2370
    delete some from book
2371

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2380
Table name.
2381

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

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

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

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

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

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

            
2394
=item C<type_rule_off> EXPERIMENTAL
2395

            
2396
Same as C<execute> method's C<type_rule_off> option.
2397

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

            
2400
    type_rule1_off => 1
2401

            
2402
Same as C<execute> method's C<type_rule1_off> option.
2403

            
2404
=item C<type_rule2_off> EXPERIMENTAL
2405

            
2406
    type_rule2_off => 1
2407

            
2408
Same as C<execute> method's C<type_rule2_off> option.
2409

            
updated pod
Yuki Kimoto authored on 2011-06-08
2410
=back
update pod
Yuki Kimoto authored on 2011-03-13
2411

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2419
=head2 C<insert>
2420

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

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

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

            
2429
    {date => \"NOW()"}
2430

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

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

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

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

            
2439
=item C<filter>
2440

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

            
2443
=item C<id>
2444

            
updated document
Yuki Kimoto authored on 2011-06-09
2445
    id => 4
2446
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2447

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2451
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2452
        {title => 'Perl', author => 'Ken'}
2453
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2454
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2455
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2456
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2457

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

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

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

            
2467
    prefix => 'or replace'
2468

            
2469
prefix before table name section
2470

            
2471
    insert or replace into book
2472

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

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

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

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

            
2482
Same as C<execute> method's C<query> option.
2483

            
2484
=item C<table>
2485

            
2486
    table => 'book'
2487

            
2488
Table name.
2489

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

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

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

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

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

            
2500
    type_rule1_off => 1
2501

            
2502
Same as C<execute> method's C<type_rule1_off> option.
2503

            
2504
=item C<type_rule2_off> EXPERIMENTAL
2505

            
2506
    type_rule2_off => 1
2507

            
2508
Same as C<execute> method's C<type_rule2_off> option.
2509

            
update pod
Yuki Kimoto authored on 2011-03-13
2510
=back
2511

            
2512
=over 4
2513

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2529
    lib / MyModel.pm
2530
        / MyModel / book.pm
2531
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2532

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

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

            
2537
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2538
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2539
    
2540
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2541

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2546
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2547
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2548
    
2549
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2550

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2553
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2554
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2555
    
2556
    1;
2557
    
updated pod
Yuki Kimoto authored on 2011-06-21
2558
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2559

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

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

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

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

            
2569
    my $map_param = $dbi->map_param(
2570
        {id => 1, authro => 'Ken', price => 1900},
2571
        'id' => 'book.id',
2572
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2573
        'price' => [
2574
            'book.price', {if => sub { length $_[0] }}
2575
        ]
2576
    );
2577

            
2578
Map paramters to other key and value. First argument is original
2579
parameter. this is hash reference. Rest argument is mapping.
2580
By default, Mapping is done if the value length is not zero.
2581

            
2582
=over 4
2583

            
2584
=item Key mapping
2585

            
2586
    'id' => 'book.id'
2587

            
2588
This is only key mapping. Value is same as original one.
2589

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

            
2592
=item Key and value mapping
2593

            
2594
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2595

            
2596
This is key and value mapping. Frist element of array reference
2597
is mapped key name, second element is code reference to map the value.
2598

            
2599
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2600
      if value length is not zero.
2601

            
2602
=item Condition
2603

            
2604
    'price' => ['book.price', {if => 'exists'}]
2605
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2606
    'price' => ['book.price', {if => sub { defined shift }}]
2607

            
2608
If you need condition, you can sepecify it. this is code reference
2609
or 'exists'. By default, condition is the following one.
2610

            
2611
    sub { defined $_[0] && length $_[0] }
2612

            
2613
=back
2614

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

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

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

            
2621
    {key1 => [1, 1], key2 => 2}
2622

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

            
2625
    $dbi->method(
2626
        update_or_insert => sub {
2627
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2628
            
2629
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2630
        },
2631
        find_or_create   => sub {
2632
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2633
            
2634
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2635
        }
2636
    );
2637

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

            
2640
    $dbi->update_or_insert;
2641
    $dbi->find_or_create;
2642

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

            
2645
    my $model = $dbi->model('book');
2646

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

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

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

            
2653
Create column clause for myself. The follwoing column clause is created.
2654

            
2655
    book.author as author,
2656
    book.title as title
2657

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2660
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2661
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2662
        user => 'ken',
2663
        password => '!LFKD%$&',
2664
        dbi_option => {mysql_enable_utf8 => 1}
2665
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2666

            
2667
Create a new L<DBIx::Custom> object.
2668

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

            
2671
    my $not_exists = $dbi->not_exists;
2672

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

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

            
2678
    my $order = $dbi->order;
2679

            
2680
Create a new L<DBIx::Custom::Order> object.
2681

            
cleanup
yuki-kimoto authored on 2010-10-17
2682
=head2 C<register_filter>
2683

            
update pod
Yuki Kimoto authored on 2011-03-13
2684
    $dbi->register_filter(
2685
        # Time::Piece object to database DATE format
2686
        tp_to_date => sub {
2687
            my $tp = shift;
2688
            return $tp->strftime('%Y-%m-%d');
2689
        },
2690
        # database DATE format to Time::Piece object
2691
        date_to_tp => sub {
2692
           my $date = shift;
2693
           return Time::Piece->strptime($date, '%Y-%m-%d');
2694
        }
2695
    );
cleanup
yuki-kimoto authored on 2010-10-17
2696
    
update pod
Yuki Kimoto authored on 2011-03-13
2697
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2698

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

            
2701
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2702
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2703
            date => sub { ... },
2704
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2705
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2706
        into2 => {
2707
            date => sub { ... },
2708
            datetime => sub { ... }
2709
        },
2710
        from1 => {
2711
            # DATE
2712
            9 => sub { ... },
2713
            # DATETIME or TIMESTAMP
2714
            11 => sub { ... },
2715
        }
2716
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2717
            # DATE
2718
            9 => sub { ... },
2719
            # DATETIME or TIMESTAMP
2720
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2721
        }
2722
    );
2723

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2739
=over 4
2740

            
2741
=item 1. column name
2742

            
2743
    issue_date
2744
    issue_datetime
2745

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

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

            
2750
    book.issue_date
2751
    book.issue_datetime
2752

            
2753
=back
2754

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

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

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

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

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

            
2767
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2768
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2769
            [qw/DATE DATETIME/] => sub { ... },
2770
        ],
2771
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2772

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2775
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2776
        table  => 'book',
2777
        column => ['author', 'title'],
2778
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2779
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2780
    
updated document
Yuki Kimoto authored on 2011-06-09
2781
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2782

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

            
2785
=over 4
2786

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2791
Append statement to last of SQL.
2792
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2793
=item C<column>
2794
    
updated document
Yuki Kimoto authored on 2011-06-09
2795
    column => 'author'
2796
    column => ['author', 'title']
2797

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2806
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2807
        {book => [qw/author title/]},
2808
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2809
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2810

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

            
2813
    book.author as "book.author",
2814
    book.title as "book.title",
2815
    person.name as "person.name",
2816
    person.age as "person.age"
2817

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

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

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

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

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

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

            
2833
=item C<id>
2834

            
2835
    id => 4
2836
    id => [4, 5]
2837

            
2838
ID corresponding to C<primary_key>.
2839
You can select rows by C<id> and C<primary_key>.
2840

            
2841
    $dbi->select(
2842
        parimary_key => ['id1', 'id2'],
2843
        id => [4, 5],
2844
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2845
    );
2846

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2849
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2850
        where => {id1 => 4, id2 => 5},
2851
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2852
    );
2853
    
updated document
Yuki Kimoto authored on 2011-06-09
2854
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2855

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

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

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

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

            
2868
    prefix => 'SQL_CALC_FOUND_ROWS'
2869

            
2870
Prefix of column cluase
2871

            
2872
    select SQL_CALC_FOUND_ROWS title, author from book;
2873

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

            
2876
    join => [
2877
        'left outer join company on book.company_id = company_id',
2878
        'left outer join location on company.location_id = location.id'
2879
    ]
2880
        
2881
Join clause. If column cluase or where clause contain table name like "company.name",
2882
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2883

            
2884
    $dbi->select(
2885
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2886
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2887
        where => {'company.name' => 'Orange'},
2888
        join => [
2889
            'left outer join company on book.company_id = company.id',
2890
            'left outer join location on company.location_id = location.id'
2891
        ]
2892
    );
2893

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2897
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2898
    from book
2899
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2900
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2901

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

            
2905
    $dbi->select(
2906
        table => 'book',
2907
        column => ['company.location_id as location_id'],
2908
        where => {'company.name' => 'Orange'},
2909
        join => [
2910
            {
2911
                clause => 'left outer join location on company.location_id = location.id',
2912
                table => ['company', 'location']
2913
            }
2914
        ]
2915
    );
2916

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2936
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2937

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

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

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

            
2944
    type_rule1_off => 1
2945

            
2946
Same as C<execute> method's C<type_rule1_off> option.
2947

            
2948
=item C<type_rule2_off> EXPERIMENTAL
2949

            
2950
    type_rule2_off => 1
2951

            
2952
Same as C<execute> method's C<type_rule2_off> option.
2953

            
updated document
Yuki Kimoto authored on 2011-06-09
2954
=item C<where>
2955
    
2956
    # Hash refrence
2957
    where => {author => 'Ken', 'title' => 'Perl'}
2958
    
2959
    # DBIx::Custom::Where object
2960
    where => $dbi->where(
2961
        clause => ['and', 'author = :author', 'title like :title'],
2962
        param  => {author => 'Ken', title => '%Perl%'}
2963
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2964
    
2965
    # Array reference 1 (array reference, hash referenc). same as above
2966
    where => [
2967
        ['and', 'author = :author', 'title like :title'],
2968
        {author => 'Ken', title => '%Perl%'}
2969
    ];    
2970
    
2971
    # Array reference 2 (String, hash reference)
2972
    where => [
2973
        'title like :title',
2974
        {title => '%Perl%'}
2975
    ]
2976
    
2977
    # String
2978
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2979

            
updated document
Yuki Kimoto authored on 2011-06-09
2980
Where clause.
2981
    
improved pod
Yuki Kimoto authored on 2011-04-19
2982
=item C<wrap> EXPERIMENTAL
2983

            
2984
Wrap statement. This is array reference.
2985

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

            
2988
This option is for Oracle and SQL Server paging process.
2989

            
update pod
Yuki Kimoto authored on 2011-03-12
2990
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2991

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

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

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

            
2998
If you want to set constant value to row data, use scalar reference
2999
as parameter value.
3000

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3005
=over 4
3006

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3017
    id => 4
3018
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3019

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3023
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3024
        {title => 'Perl', author => 'Ken'}
3025
        parimary_key => ['id1', 'id2'],
3026
        id => [4, 5],
3027
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3028
    );
update pod
Yuki Kimoto authored on 2011-03-13
3029

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3032
    $dbi->update(
3033
        {title => 'Perl', author => 'Ken'}
3034
        where => {id1 => 4, id2 => 5},
3035
        table => 'book'
3036
    );
update pod
Yuki Kimoto authored on 2011-03-13
3037

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

            
3040
    prefix => 'or replace'
3041

            
3042
prefix before table name section
3043

            
3044
    update or replace book
3045

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

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

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

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

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

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

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

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

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

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

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

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

            
3071
=item C<type_rule_off> EXPERIMENTAL
3072

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

            
3075
=item C<type_rule1_off> EXPERIMENTAL
3076

            
3077
    type_rule1_off => 1
3078

            
3079
Same as C<execute> method's C<type_rule1_off> option.
3080

            
3081
=item C<type_rule2_off> EXPERIMENTAL
3082

            
3083
    type_rule2_off => 1
3084

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3087
=back
update pod
Yuki Kimoto authored on 2011-03-13
3088

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

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

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

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

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

            
3100
Create update parameter tag.
3101

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

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

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

            
3111
Create a new L<DBIx::Custom::Where> object.
3112

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

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

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

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

            
3122
=head2 C<DBIX_CUSTOM_DEBUG>
3123

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

            
3127
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3128

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

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

            
3133
L<DBIx::Custom>
3134

            
3135
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3136
    data_source # will be removed at 2017/1/1
3137
    dbi_options # will be removed at 2017/1/1
3138
    filter_check # will be removed at 2017/1/1
3139
    reserved_word_quote # will be removed at 2017/1/1
3140
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3141
    
3142
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3143
    create_query # will be removed at 2017/1/1
3144
    apply_filter # will be removed at 2017/1/1
3145
    select_at # will be removed at 2017/1/1
3146
    delete_at # will be removed at 2017/1/1
3147
    update_at # will be removed at 2017/1/1
3148
    insert_at # will be removed at 2017/1/1
3149
    register_tag # will be removed at 2017/1/1
3150
    default_bind_filter # will be removed at 2017/1/1
3151
    default_fetch_filter # will be removed at 2017/1/1
3152
    insert_param_tag # will be removed at 2017/1/1
3153
    register_tag_processor # will be removed at 2017/1/1
3154
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3155
    
3156
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3157
    select method relation option # will be removed at 2017/1/1
3158
    select method param option # will be removed at 2017/1/1
3159
    select method column option [COLUMN, as => ALIAS] format
3160
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3161
    
3162
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3163
    execute("select * from {= title}"); # execute method's
3164
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3165
                                        # will be removed at 2017/1/1
3166
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3167

            
3168
L<DBIx::Custom::Model>
3169

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3170
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3171
    filter # will be removed at 2017/1/1
3172
    name # will be removed at 2017/1/1
3173
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3174

            
3175
L<DBIx::Custom::Query>
3176
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3177
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3178
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3179
    table # will be removed at 2017/1/1
3180
    filters # will be removed at 2017/1/1
3181
    
3182
    # Methods
3183
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3184

            
3185
L<DBIx::Custom::QueryBuilder>
3186
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3187
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3188
    tags # will be removed at 2017/1/1
3189
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3190
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3191
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3192
    register_tag # will be removed at 2017/1/1
3193
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3194
    
3195
    # Others
3196
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3197
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3198

            
3199
L<DBIx::Custom::Result>
3200
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3201
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3202
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3203
    
3204
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3205
    end_filter # will be removed at 2017/1/1
3206
    remove_end_filter # will be removed at 2017/1/1
3207
    remove_filter # will be removed at 2017/1/1
3208
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3209

            
3210
L<DBIx::Custom::Tag>
3211

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

            
3214
=head1 BACKWORD COMPATIBLE POLICY
3215

            
3216
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3217
except for attribute method.
3218
You can check all DEPRECATED functionalities by document.
3219
DEPRECATED functionality is removed after five years,
3220
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
3221
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3222

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

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

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

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

            
3231
C<< <kimoto.yuki at gmail.com> >>
3232

            
3233
L<http://github.com/yuki-kimoto/DBIx-Custom>
3234

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3235
=head1 AUTHOR
3236

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

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

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

            
3243
This program is free software; you can redistribute it and/or modify it
3244
under the same terms as Perl itself.
3245

            
3246
=cut