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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
506
        return $result;
507
    }
cleanup
Yuki Kimoto authored on 2011-04-02
508
    
509
    # Not select statement
510
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
511
}
512

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
534
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
535
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
536
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
537
        $param = $self->merge_param($id_param, $param);
538
    }
539

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
573
sub include_model {
574
    my ($self, $name_space, $model_infos) = @_;
575
    
cleanup
Yuki Kimoto authored on 2011-04-02
576
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
577
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
578
    
579
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
580
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
581

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

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

            
664
        # Map parameter
665
        my $value;
666
        if (ref $condition eq 'CODE') {
667
            $map_param->{$map_key} = $value_cb->($param->{$key})
668
              if $condition->($param->{$key});
669
        }
670
        elsif ($condition eq 'exists') {
671
            $map_param->{$map_key} = $value_cb->($param->{$key})
672
              if exists $param->{$key};
673
        }
674
        else { croak qq/Condition must be code reference or "exists" / . _subname }
675
    }
676
    
677
    return $map_param;
678
}
679

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
704
sub method {
705
    my $self = shift;
706
    
cleanup
Yuki Kimoto authored on 2011-04-02
707
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
708
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
709
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
710
    
711
    return $self;
712
}
713

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

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

            
added dbi_options attribute
kimoto authored on 2010-12-20
744
sub new {
745
    my $self = shift->SUPER::new(@_);
746
    
cleanup
Yuki Kimoto authored on 2011-04-02
747
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
748
    my @attrs = keys %$self;
749
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
750
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
751
          unless $self->can($attr);
752
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
753

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
754
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
755
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
756
        '?'     => \&DBIx::Custom::Tag::placeholder,
757
        '='     => \&DBIx::Custom::Tag::equal,
758
        '<>'    => \&DBIx::Custom::Tag::not_equal,
759
        '>'     => \&DBIx::Custom::Tag::greater_than,
760
        '<'     => \&DBIx::Custom::Tag::lower_than,
761
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
762
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
763
        'like'  => \&DBIx::Custom::Tag::like,
764
        'in'    => \&DBIx::Custom::Tag::in,
765
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
766
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
767
    };
768
    
769
    return $self;
770
}
771

            
772
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
773
sub not_exists { $not_exists }
774

            
775
sub order {
776
    my $self = shift;
777
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
778
}
779

            
cleanup
yuki-kimoto authored on 2010-10-17
780
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
781
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
782
    
783
    # Register filter
784
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
785
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
786
    
cleanup
Yuki Kimoto authored on 2011-04-02
787
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
788
}
packaging one directory
yuki-kimoto authored on 2009-11-16
789

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
923
sub setup_model {
924
    my $self = shift;
925
    
cleanup
Yuki Kimoto authored on 2011-04-02
926
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
927
    $self->each_column(
928
        sub {
929
            my ($self, $table, $column, $column_info) = @_;
930
            if (my $model = $self->models->{$table}) {
931
                push @{$model->columns}, $column;
932
            }
933
        }
934
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
935
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
936
}
937

            
update pod
Yuki Kimoto authored on 2011-08-10
938
sub show_datatype {
939
    my ($self, $table) = @_;
940
    croak "Table name must be specified" unless defined $table;
941
    print "$table\n";
942
    
943
    my $result = $self->select(table => $table, where => "'0' <> '0'");
944
    my $sth = $result->sth;
945

            
946
    my $columns = $sth->{NAME};
947
    my $data_types = $sth->{TYPE};
948
    
949
    for (my $i = 0; $i < @$columns; $i++) {
950
        my $column = $columns->[$i];
951
        my $data_type = $data_types->[$i];
952
        print "$column: $data_type\n";
953
    }
954
}
955

            
956
sub show_typename {
957
    my ($self, $t) = @_;
958
    croak "Table name must be specified" unless defined $t;
959
    print "$t\n";
960
    
961
    $self->each_column(sub {
962
        my ($self, $table, $column, $infos) = @_;
963
        return unless $table eq $t;
964
        my $typename = $infos->{TYPE_NAME};
965
        print "$column: $typename\n";
966
    });
967
    
968
    return $self;
969
}
970

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1004
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1005
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1006
                }
1007
            });
1008
        }
1009

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1098
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1099
    my ($self, $param, $opt) = @_;
1100
    
cleanup
Yuki Kimoto authored on 2011-04-02
1101
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1102
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1103
    $tag = "set $tag" unless $opt->{no_set};
1104

            
cleanup
Yuki Kimoto authored on 2011-04-02
1105
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1106
}
1107

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1110
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1111
    
updated pod
Yuki Kimoto authored on 2011-06-21
1112
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1113
    
updated pod
Yuki Kimoto authored on 2011-06-21
1114
    # Cache
1115
    my $cache = $self->cache;
1116
    
1117
    # Query
1118
    my $query;
1119
    
1120
    # Get cached query
1121
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1122
        
updated pod
Yuki Kimoto authored on 2011-06-21
1123
        # Get query
1124
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1125
        
updated pod
Yuki Kimoto authored on 2011-06-21
1126
        # Create query
1127
        if ($q) {
1128
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1129
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1130
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1131
    }
1132
    
1133
    # Create query
1134
    unless ($query) {
1135

            
1136
        # Create query
1137
        my $builder = $self->query_builder;
1138
        $query = $builder->build_query($source);
1139

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1282
sub _croak {
1283
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1284
    
1285
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1286
    $append ||= "";
1287
    
1288
    # Verbose
1289
    if ($Carp::Verbose) { croak $error }
1290
    
1291
    # Not verbose
1292
    else {
1293
        
1294
        # Remove line and module infromation
1295
        my $at_pos = rindex($error, ' at ');
1296
        $error = substr($error, 0, $at_pos);
1297
        $error =~ s/\s+$//;
1298
        croak "$error$append";
1299
    }
1300
}
1301

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1302
sub _need_tables {
1303
    my ($self, $tree, $need_tables, $tables) = @_;
1304
    
cleanup
Yuki Kimoto authored on 2011-04-02
1305
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1306
    foreach my $table (@$tables) {
1307
        if ($tree->{$table}) {
1308
            $need_tables->{$table} = 1;
1309
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1310
        }
1311
    }
1312
}
1313

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1314
sub _push_join {
1315
    my ($self, $sql, $join, $join_tables) = @_;
1316
    
cleanup
Yuki Kimoto authored on 2011-04-02
1317
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1318
    return unless @$join;
1319
    
cleanup
Yuki Kimoto authored on 2011-04-02
1320
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1321
    my $tree = {};
1322
    for (my $i = 0; $i < @$join; $i++) {
1323
        
cleanup
Yuki Kimoto authored on 2011-07-28
1324
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1325
        my $join_clause;;
1326
        my $option;
1327
        if (ref $join->[$i] eq 'HASH') {
1328
            $join_clause = $join->[$i]->{clause};
1329
            $option = {table => $join->[$i]->{table}};
1330
        }
1331
        else {
1332
            $join_clause = $join->[$i];
1333
            $option = {};
1334
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1335

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1379
sub _quote {
1380
    my $self = shift;
1381
    
1382
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1383
         : defined $self->quote ? $self->quote
1384
         : '';
1385
}
1386

            
cleanup
Yuki Kimoto authored on 2011-07-29
1387
sub _q {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1388
    my ($self, $value) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1389
    
1390
    my $quote = $self->_quote;
1391
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1392
    my $p;
1393
    if (defined $quote && length $quote > 1) {
1394
        $p = substr($quote, 1, 1);
1395
    }
1396
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1397
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1398
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1399
}
1400

            
cleanup
Yuki Kimoto authored on 2011-04-02
1401
sub _remove_duplicate_table {
1402
    my ($self, $tables, $main_table) = @_;
1403
    
1404
    # Remove duplicate table
1405
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1406
    delete $tables{$main_table} if $main_table;
1407
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1408
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1409
    if (my $q = $self->_quote) {
1410
        $q = quotemeta($q);
1411
        $_ =~ s/[$q]//g for @$new_tables;
1412
    }
1413

            
1414
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1415
}
1416

            
cleanup
Yuki Kimoto authored on 2011-04-02
1417
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1418
    my ($self, $source) = @_;
1419
    
cleanup
Yuki Kimoto authored on 2011-04-02
1420
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1421
    my $tables = [];
1422
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1423
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1424
    my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1425
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)");
1426
    my $table_re = $q ? qr/(?:^|[^$safety_character])$quoted_safety_character_re?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1427
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1428
    while ($source =~ /$table_re/g) {
1429
        push @$tables, $1;
1430
    }
1431
    
1432
    return $tables;
1433
}
1434

            
cleanup
Yuki Kimoto authored on 2011-04-02
1435
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1436
    my ($self, $where) = @_;
1437
    
cleanup
Yuki Kimoto authored on 2011-04-02
1438
    my $obj;
1439
    
1440
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1441
    if (ref $where eq 'HASH') {
1442
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1443
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1444
        foreach my $column (keys %$where) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1445
            my $column_quote = $self->_q($column);
1446
            $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1447
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1448
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1449
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1450
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1451
    
1452
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1453
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1454
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1455
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1456
    
updated pod
Yuki Kimoto authored on 2011-06-21
1457
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1458
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1459
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1460
            clause => $where->[0],
1461
            param  => $where->[1]
1462
        );
1463
    }
1464
    
cleanup
Yuki Kimoto authored on 2011-04-02
1465
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1466
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1467
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1468
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1469
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1470
    
cleanup
Yuki Kimoto authored on 2011-04-02
1471
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1472
}
1473

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

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

            
1544
# DEPRECATED!
1545
sub create_query {
1546
    warn "create_query is DEPRECATED! use query option of each method";
1547
    shift->_create_query(@_);
1548
}
1549

            
cleanup
Yuki Kimoto authored on 2011-06-13
1550
# DEPRECATED!
1551
sub apply_filter {
1552
    my $self = shift;
1553
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1554
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1555
    return $self->_apply_filter(@_);
1556
}
1557

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1565
    # Arguments
1566
    my $primary_keys = delete $args{primary_key};
1567
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1568
    my $where = delete $args{where};
1569
    my $param = delete $args{param};
1570
    
1571
    # Check arguments
1572
    foreach my $name (keys %args) {
1573
        croak qq{"$name" is wrong option } . _subname
1574
          unless $SELECT_AT_ARGS{$name};
1575
    }
1576
    
1577
    # Table
1578
    croak qq{"table" option must be specified } . _subname
1579
      unless $args{table};
1580
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1581
    
1582
    # Create where parameter
1583
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1584
    
1585
    return $self->select(where => $where_param, %args);
1586
}
1587

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

            
1593
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1594
    
1595
    # Arguments
1596
    my $primary_keys = delete $args{primary_key};
1597
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1598
    my $where = delete $args{where};
1599
    
1600
    # Check arguments
1601
    foreach my $name (keys %args) {
1602
        croak qq{"$name" is wrong option } . _subname
1603
          unless $DELETE_AT_ARGS{$name};
1604
    }
1605
    
1606
    # Create where parameter
1607
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1608
    
1609
    return $self->delete(where => $where_param, %args);
1610
}
1611

            
cleanup
Yuki Kimoto authored on 2011-06-08
1612
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1613
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1614
sub update_at {
1615
    my $self = shift;
1616

            
1617
    warn "update_at is DEPRECATED! use update and id option instead";
1618
    
1619
    # Arguments
1620
    my $param;
1621
    $param = shift if @_ % 2;
1622
    my %args = @_;
1623
    my $primary_keys = delete $args{primary_key};
1624
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1625
    my $where = delete $args{where};
1626
    my $p = delete $args{param} || {};
1627
    $param  ||= $p;
1628
    
1629
    # Check arguments
1630
    foreach my $name (keys %args) {
1631
        croak qq{"$name" is wrong option } . _subname
1632
          unless $UPDATE_AT_ARGS{$name};
1633
    }
1634
    
1635
    # Create where parameter
1636
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1637
    
1638
    return $self->update(where => $where_param, param => $param, %args);
1639
}
1640

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1641
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1642
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1643
sub insert_at {
1644
    my $self = shift;
1645
    
1646
    warn "insert_at is DEPRECATED! use insert and id option instead";
1647
    
1648
    # Arguments
1649
    my $param;
1650
    $param = shift if @_ % 2;
1651
    my %args = @_;
1652
    my $primary_key = delete $args{primary_key};
1653
    $primary_key = [$primary_key] unless ref $primary_key;
1654
    my $where = delete $args{where};
1655
    my $p = delete $args{param} || {};
1656
    $param  ||= $p;
1657
    
1658
    # Check arguments
1659
    foreach my $name (keys %args) {
1660
        croak qq{"$name" is wrong option } . _subname
1661
          unless $INSERT_AT_ARGS{$name};
1662
    }
1663
    
1664
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1665
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1666
    $param = $self->merge_param($where_param, $param);
1667
    
1668
    return $self->insert(param => $param, %args);
1669
}
1670

            
added warnings
Yuki Kimoto authored on 2011-06-07
1671
# DEPRECATED!
1672
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1673
    my $self = shift;
1674
    
added warnings
Yuki Kimoto authored on 2011-06-07
1675
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1676
    
1677
    # Merge tag
1678
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1679
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1680
    
1681
    return $self;
1682
}
1683

            
1684
# DEPRECATED!
1685
sub register_tag_processor {
1686
    my $self = shift;
1687
    warn "register_tag_processor is DEPRECATED!";
1688
    # Merge tag
1689
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1690
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1691
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1692
}
1693

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1694
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1695
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1696
has dbi_options => sub { {} };
1697
has filter_check  => 1;
1698
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1699

            
cleanup
Yuki Kimoto authored on 2011-01-25
1700
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1701
sub default_bind_filter {
1702
    my $self = shift;
1703
    
cleanup
Yuki Kimoto authored on 2011-06-13
1704
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1705
    
cleanup
Yuki Kimoto authored on 2011-01-12
1706
    if (@_) {
1707
        my $fname = $_[0];
1708
        
1709
        if (@_ && !$fname) {
1710
            $self->{default_out_filter} = undef;
1711
        }
1712
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1713
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1714
              unless exists $self->filters->{$fname};
1715
        
1716
            $self->{default_out_filter} = $self->filters->{$fname};
1717
        }
1718
        return $self;
1719
    }
1720
    
1721
    return $self->{default_out_filter};
1722
}
1723

            
cleanup
Yuki Kimoto authored on 2011-01-25
1724
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1725
sub default_fetch_filter {
1726
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1727

            
cleanup
Yuki Kimoto authored on 2011-06-13
1728
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1729
    
1730
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1731
        my $fname = $_[0];
1732

            
cleanup
Yuki Kimoto authored on 2011-01-12
1733
        if (@_ && !$fname) {
1734
            $self->{default_in_filter} = undef;
1735
        }
1736
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1737
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1738
              unless exists $self->filters->{$fname};
1739
        
1740
            $self->{default_in_filter} = $self->filters->{$fname};
1741
        }
1742
        
1743
        return $self;
1744
    }
1745
    
many changed
Yuki Kimoto authored on 2011-01-23
1746
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1747
}
1748

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1749
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1750
sub insert_param_tag {
1751
    warn "insert_param_tag is DEPRECATED! " .
1752
         "use insert_param instead!";
1753
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1754
}
1755

            
1756
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1757
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1758
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1759
         "use update_param instead";
1760
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1761
}
cleanup
Yuki Kimoto authored on 2011-03-08
1762
# DEPRECATED!
1763
sub _push_relation {
1764
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1765
    
1766
    if (keys %{$relation || {}}) {
1767
        push @$sql, $need_where ? 'where' : 'and';
1768
        foreach my $rcolumn (keys %$relation) {
1769
            my $table1 = (split (/\./, $rcolumn))[0];
1770
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1771
            push @$tables, ($table1, $table2);
1772
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1773
        }
1774
    }
1775
    pop @$sql if $sql->[-1] eq 'and';    
1776
}
1777

            
1778
# DEPRECATED!
1779
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1780
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1781
    
1782
    if (keys %{$relation || {}}) {
1783
        foreach my $rcolumn (keys %$relation) {
1784
            my $table1 = (split (/\./, $rcolumn))[0];
1785
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1786
            my $table1_exists;
1787
            my $table2_exists;
1788
            foreach my $table (@$tables) {
1789
                $table1_exists = 1 if $table eq $table1;
1790
                $table2_exists = 1 if $table eq $table2;
1791
            }
1792
            unshift @$tables, $table1 unless $table1_exists;
1793
            unshift @$tables, $table2 unless $table2_exists;
1794
        }
1795
    }
1796
}
1797

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1800
=head1 NAME
1801

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

            
1804
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1805

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1806
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1807
    
1808
    # Connect
1809
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1810
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1811
        user => 'ken',
1812
        password => '!LFKD%$&',
1813
        dbi_option => {mysql_enable_utf8 => 1}
1814
    );
cleanup
yuki-kimoto authored on 2010-08-05
1815

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1816
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1817
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1818
    
1819
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1820
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1821
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1822
    
1823
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1824
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1825

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1830
    # Select, more complex
1831
    my $result = $dbi->select(
1832
        table  => 'book',
1833
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1834
            {book => [qw/title author/]},
1835
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1836
        ],
1837
        where  => {'book.author' => 'Ken'},
1838
        join => ['left outer join company on book.company_id = company.id'],
1839
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1840
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1841
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1842
    # Fetch
1843
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1844
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1845
    }
1846
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1847
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1848
    while (my $row = $result->fetch_hash) {
1849
        
1850
    }
1851
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1852
    # Execute SQL with parameter.
1853
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1854
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1855
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1856
    );
1857
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1858
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1859

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1875
Named place holder support
1876

            
1877
=item *
1878

            
cleanup
Yuki Kimoto authored on 2011-07-29
1879
Model support
1880

            
1881
=item *
1882

            
1883
Connection manager support
1884

            
1885
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1886

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

            
1891
=item *
1892

            
1893
Filtering by data type or column name(EXPERIMENTAL)
1894

            
1895
=item *
1896

            
1897
Create C<order by> clause flexibly(EXPERIMENTAL)
1898

            
1899
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1900

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1908
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1909
L<DBIx::Custom::Result>,
1910
L<DBIx::Custom::Query>,
1911
L<DBIx::Custom::Where>,
1912
L<DBIx::Custom::Model>,
1913
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1914

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

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

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

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

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

            
1928
    my $connector = DBIx::Connector->new(
1929
        "dbi:mysql:database=$DATABASE",
1930
        $USER,
1931
        $PASSWORD,
1932
        DBIx::Custom->new->default_dbi_option
1933
    );
1934
    
updated pod
Yuki Kimoto authored on 2011-06-21
1935
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1936

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

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

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

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

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

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

            
1952
=head2 C<default_dbi_option>
1953

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1960
    {
1961
        RaiseError => 1,
1962
        PrintError => 0,
1963
        AutoCommit => 1,
1964
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1965

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

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

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

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

            
1975
    my $last_sql = $dbi->last_sql;
1976
    $dbi = $dbi->last_sql($last_sql);
1977

            
1978
Get last successed SQL executed by C<execute> method.
1979

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1987
=head2 C<password>
1988

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2009
You can set quote pair.
2010

            
2011
    $dbi->quote('[]');
2012

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

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

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

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

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

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

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

            
2030
    my $separator = $self->separator;
2031
    $dbi = $self->separator($separator);
2032

            
2033
Separator whichi join table and column.
2034
This is used by C<column> and C<mycolumn> method.
2035

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

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

            
2041
Regex matching system table.
2042
this regex match is used by C<each_table> method and C<each_column> method
2043
System table is ignored.
2044
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2045
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2046
The performance is up.
2047

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

            
2050
    my $tag_parse = $dbi->tag_parse(0);
2051
    $dbi = $dbi->tag_parse;
2052

            
2053
Enable DEPRECATED tag parsing functionality, default to 1.
2054
If you want to disable tag parsing functionality, set to 0.
2055

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2097
Create column clause. The follwoing column clause is created.
2098

            
2099
    book.author as "book.author",
2100
    book.title as "book.title"
2101

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2104
    # Separator is double underbar
2105
    $dbi->separator('__');
2106
    
2107
    book.author as "book__author",
2108
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2109

            
cleanup
Yuki Kimoto authored on 2011-06-13
2110
    # Separator is hyphen
2111
    $dbi->separator('-');
2112
    
2113
    book.author as "book-author",
2114
    book.title as "book-title"
2115
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2116
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2117

            
update pod
Yuki Kimoto authored on 2011-03-13
2118
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2119
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2120
        user => 'ken',
2121
        password => '!LFKD%$&',
2122
        dbi_option => {mysql_enable_utf8 => 1}
2123
    );
2124

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2133
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2134
        table => 'book',
2135
        primary_key => 'id',
2136
        join => [
2137
            'inner join company on book.comparny_id = company.id'
2138
        ],
2139
    );
2140

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

            
2144
   $dbi->model('book')->select(...);
2145

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

            
2148
    my $dbh = $dbi->dbh;
2149

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

            
2153
=head2 C<each_column>
2154

            
2155
    $dbi->each_column(
2156
        sub {
2157
            my ($dbi, $table, $column, $column_info) = @_;
2158
            
2159
            my $type = $column_info->{TYPE_NAME};
2160
            
2161
            if ($type eq 'DATE') {
2162
                # ...
2163
            }
2164
        }
2165
    );
2166

            
2167
Iterate all column informations of all table from database.
2168
Argument is callback when one column is found.
2169
Callback receive four arguments, dbi object, table name,
2170
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2171

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

            
2174
    $dbi->each_table(
2175
        sub {
2176
            my ($dbi, $table, $table_info) = @_;
2177
            
2178
            my $table_name = $table_info->{TABLE_NAME};
2179
        }
2180
    );
2181

            
2182
Iterate all table informationsfrom database.
2183
Argument is callback when one table is found.
2184
Callback receive three arguments, dbi object, table name,
2185
table information.
2186

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

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

            
2194
    my $result = $dbi->execute(
2195
      "select * from book where title = :book.title and author like :book.author",
2196
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2197
    );
2198

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2205
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2206
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2207
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2208
    select * from book where title = :title and author like :author
2209
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2210
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2211
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2212

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2216
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2217
    select * from book where :title{=} and :author{like}
2218
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2219
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2220
    select * from where title = ? and author like ?;
2221

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

            
2226
    select * from where title = "aa\\:bb";
2227

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

            
2230
=over 4
2231

            
2232
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2233
    
2234
    filter => {
2235
        title  => sub { uc $_[0] }
2236
        author => sub { uc $_[0] }
2237
    }
update pod
Yuki Kimoto authored on 2011-03-13
2238

            
updated pod
Yuki Kimoto authored on 2011-06-09
2239
    # Filter name
2240
    filter => {
2241
        title  => 'upper_case',
2242
        author => 'upper_case'
2243
    }
2244
        
2245
    # At once
2246
    filter => [
2247
        [qw/title author/]  => sub { uc $_[0] }
2248
    ]
2249

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

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

            
2257
    query => 1
2258

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

            
2262
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2263
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2264
    my $columns = $query->columns;
2265
    
2266
If you want to execute SQL fast, you can do the following way.
2267

            
2268
    my $query;
2269
    foreach my $row (@$rows) {
2270
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2271
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2272
    }
2273

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

            
2277
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
2278
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2279
    
2280
    my $query;
2281
    my $sth;
2282
    foreach my $row (@$rows) {
2283
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2284
      $sth ||= $query->sth;
2285
      $sth->execute(map { $row->{$_} } sort keys %$row);
2286
    }
2287

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2292
=item C<table>
2293
    
2294
    table => 'author'
2295

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2303
    # Same
2304
    $dbi->execute(
2305
      "select * from book where title = :book.title and author = :book.author",
2306
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2307

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

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

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

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

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

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

            
2321
    table_alias => {user => 'hiker'}
2322

            
2323
Table alias. Key is real table name, value is alias table name.
2324
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2325
on alias table name.
2326

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

            
2329
    type_rule_off => 1
2330

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

            
2333
=item C<type_rule1_off> EXPERIMENTAL
2334

            
2335
    type_rule1_off => 1
2336

            
2337
Turn C<into1> type rule off.
2338

            
2339
=item C<type_rule2_off> EXPERIMENTAL
2340

            
2341
    type_rule2_off => 1
2342

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2355
=over 4
2356

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

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

            
2361
=item C<filter>
2362

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2367
    id => 4
2368
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2369

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2373
    $dbi->delete(
2374
        parimary_key => ['id1', 'id2'],
2375
        id => [4, 5],
2376
        table => 'book',
2377
    );
update pod
Yuki Kimoto authored on 2011-03-13
2378

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

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

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

            
2385
    prefix => 'some'
2386

            
2387
prefix before table name section.
2388

            
2389
    delete some from book
2390

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2399
Table name.
2400

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

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

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

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

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

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

            
2413
=item C<type_rule_off> EXPERIMENTAL
2414

            
2415
Same as C<execute> method's C<type_rule_off> option.
2416

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

            
2419
    type_rule1_off => 1
2420

            
2421
Same as C<execute> method's C<type_rule1_off> option.
2422

            
2423
=item C<type_rule2_off> EXPERIMENTAL
2424

            
2425
    type_rule2_off => 1
2426

            
2427
Same as C<execute> method's C<type_rule2_off> option.
2428

            
updated pod
Yuki Kimoto authored on 2011-06-08
2429
=back
update pod
Yuki Kimoto authored on 2011-03-13
2430

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

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

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

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

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

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

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

            
2448
    {date => \"NOW()"}
2449

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

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

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

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

            
2458
=item C<filter>
2459

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

            
2462
=item C<id>
2463

            
updated document
Yuki Kimoto authored on 2011-06-09
2464
    id => 4
2465
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2466

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2470
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2471
        {title => 'Perl', author => 'Ken'}
2472
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2473
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2474
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2475
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2476

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

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

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

            
2486
    prefix => 'or replace'
2487

            
2488
prefix before table name section
2489

            
2490
    insert or replace into book
2491

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

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

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

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

            
2501
Same as C<execute> method's C<query> option.
2502

            
2503
=item C<table>
2504

            
2505
    table => 'book'
2506

            
2507
Table name.
2508

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

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

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

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

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

            
2519
    type_rule1_off => 1
2520

            
2521
Same as C<execute> method's C<type_rule1_off> option.
2522

            
2523
=item C<type_rule2_off> EXPERIMENTAL
2524

            
2525
    type_rule2_off => 1
2526

            
2527
Same as C<execute> method's C<type_rule2_off> option.
2528

            
update pod
Yuki Kimoto authored on 2011-03-13
2529
=back
2530

            
2531
=over 4
2532

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2548
    lib / MyModel.pm
2549
        / MyModel / book.pm
2550
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2551

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

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

            
2556
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2557
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2558
    
2559
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2560

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2565
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2566
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2567
    
2568
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2569

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2572
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2573
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2574
    
2575
    1;
2576
    
updated pod
Yuki Kimoto authored on 2011-06-21
2577
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2578

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

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

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

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

            
2588
    my $map_param = $dbi->map_param(
2589
        {id => 1, authro => 'Ken', price => 1900},
2590
        'id' => 'book.id',
2591
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2592
        'price' => [
2593
            'book.price', {if => sub { length $_[0] }}
2594
        ]
2595
    );
2596

            
2597
Map paramters to other key and value. First argument is original
2598
parameter. this is hash reference. Rest argument is mapping.
2599
By default, Mapping is done if the value length is not zero.
2600

            
2601
=over 4
2602

            
2603
=item Key mapping
2604

            
2605
    'id' => 'book.id'
2606

            
2607
This is only key mapping. Value is same as original one.
2608

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

            
2611
=item Key and value mapping
2612

            
2613
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2614

            
2615
This is key and value mapping. Frist element of array reference
2616
is mapped key name, second element is code reference to map the value.
2617

            
2618
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2619
      if value length is not zero.
2620

            
2621
=item Condition
2622

            
2623
    'price' => ['book.price', {if => 'exists'}]
2624
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2625
    'price' => ['book.price', {if => sub { defined shift }}]
2626

            
2627
If you need condition, you can sepecify it. this is code reference
2628
or 'exists'. By default, condition is the following one.
2629

            
2630
    sub { defined $_[0] && length $_[0] }
2631

            
2632
=back
2633

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

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

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

            
2640
    {key1 => [1, 1], key2 => 2}
2641

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

            
2644
    $dbi->method(
2645
        update_or_insert => sub {
2646
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2647
            
2648
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2649
        },
2650
        find_or_create   => sub {
2651
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2652
            
2653
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2654
        }
2655
    );
2656

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

            
2659
    $dbi->update_or_insert;
2660
    $dbi->find_or_create;
2661

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

            
2664
    my $model = $dbi->model('book');
2665

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

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

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

            
2672
Create column clause for myself. The follwoing column clause is created.
2673

            
2674
    book.author as author,
2675
    book.title as title
2676

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2679
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2680
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2681
        user => 'ken',
2682
        password => '!LFKD%$&',
2683
        dbi_option => {mysql_enable_utf8 => 1}
2684
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2685

            
2686
Create a new L<DBIx::Custom> object.
2687

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

            
2690
    my $not_exists = $dbi->not_exists;
2691

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

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

            
2697
    my $order = $dbi->order;
2698

            
2699
Create a new L<DBIx::Custom::Order> object.
2700

            
cleanup
yuki-kimoto authored on 2010-10-17
2701
=head2 C<register_filter>
2702

            
update pod
Yuki Kimoto authored on 2011-03-13
2703
    $dbi->register_filter(
2704
        # Time::Piece object to database DATE format
2705
        tp_to_date => sub {
2706
            my $tp = shift;
2707
            return $tp->strftime('%Y-%m-%d');
2708
        },
2709
        # database DATE format to Time::Piece object
2710
        date_to_tp => sub {
2711
           my $date = shift;
2712
           return Time::Piece->strptime($date, '%Y-%m-%d');
2713
        }
2714
    );
cleanup
yuki-kimoto authored on 2010-10-17
2715
    
update pod
Yuki Kimoto authored on 2011-03-13
2716
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2717

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

            
2720
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2721
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2722
            date => sub { ... },
2723
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2724
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2725
        into2 => {
2726
            date => sub { ... },
2727
            datetime => sub { ... }
2728
        },
2729
        from1 => {
2730
            # DATE
2731
            9 => sub { ... },
2732
            # DATETIME or TIMESTAMP
2733
            11 => sub { ... },
2734
        }
2735
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2736
            # DATE
2737
            9 => sub { ... },
2738
            # DATETIME or TIMESTAMP
2739
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2740
        }
2741
    );
2742

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2758
=over 4
2759

            
2760
=item 1. column name
2761

            
2762
    issue_date
2763
    issue_datetime
2764

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

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

            
2769
    book.issue_date
2770
    book.issue_datetime
2771

            
2772
=back
2773

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

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

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

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

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

            
2786
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2787
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2788
            [qw/DATE DATETIME/] => sub { ... },
2789
        ],
2790
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2791

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2794
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2795
        table  => 'book',
2796
        column => ['author', 'title'],
2797
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2798
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2799
    
updated document
Yuki Kimoto authored on 2011-06-09
2800
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2801

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

            
2804
=over 4
2805

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2810
Append statement to last of SQL.
2811
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2812
=item C<column>
2813
    
updated document
Yuki Kimoto authored on 2011-06-09
2814
    column => 'author'
2815
    column => ['author', 'title']
2816

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2825
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2826
        {book => [qw/author title/]},
2827
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2828
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2829

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

            
2832
    book.author as "book.author",
2833
    book.title as "book.title",
2834
    person.name as "person.name",
2835
    person.age as "person.age"
2836

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

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

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

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

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

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

            
2852
=item C<id>
2853

            
2854
    id => 4
2855
    id => [4, 5]
2856

            
2857
ID corresponding to C<primary_key>.
2858
You can select rows by C<id> and C<primary_key>.
2859

            
2860
    $dbi->select(
2861
        parimary_key => ['id1', 'id2'],
2862
        id => [4, 5],
2863
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2864
    );
2865

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2868
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2869
        where => {id1 => 4, id2 => 5},
2870
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2871
    );
2872
    
updated document
Yuki Kimoto authored on 2011-06-09
2873
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2874

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

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

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

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

            
2887
    prefix => 'SQL_CALC_FOUND_ROWS'
2888

            
2889
Prefix of column cluase
2890

            
2891
    select SQL_CALC_FOUND_ROWS title, author from book;
2892

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

            
2895
    join => [
2896
        'left outer join company on book.company_id = company_id',
2897
        'left outer join location on company.location_id = location.id'
2898
    ]
2899
        
2900
Join clause. If column cluase or where clause contain table name like "company.name",
2901
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2902

            
2903
    $dbi->select(
2904
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2905
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2906
        where => {'company.name' => 'Orange'},
2907
        join => [
2908
            'left outer join company on book.company_id = company.id',
2909
            'left outer join location on company.location_id = location.id'
2910
        ]
2911
    );
2912

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2916
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2917
    from book
2918
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2919
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2920

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

            
2924
    $dbi->select(
2925
        table => 'book',
2926
        column => ['company.location_id as location_id'],
2927
        where => {'company.name' => 'Orange'},
2928
        join => [
2929
            {
2930
                clause => 'left outer join location on company.location_id = location.id',
2931
                table => ['company', 'location']
2932
            }
2933
        ]
2934
    );
2935

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2955
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2956

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

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

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

            
2963
    type_rule1_off => 1
2964

            
2965
Same as C<execute> method's C<type_rule1_off> option.
2966

            
2967
=item C<type_rule2_off> EXPERIMENTAL
2968

            
2969
    type_rule2_off => 1
2970

            
2971
Same as C<execute> method's C<type_rule2_off> option.
2972

            
updated document
Yuki Kimoto authored on 2011-06-09
2973
=item C<where>
2974
    
2975
    # Hash refrence
2976
    where => {author => 'Ken', 'title' => 'Perl'}
2977
    
2978
    # DBIx::Custom::Where object
2979
    where => $dbi->where(
2980
        clause => ['and', 'author = :author', 'title like :title'],
2981
        param  => {author => 'Ken', title => '%Perl%'}
2982
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2983
    
2984
    # Array reference 1 (array reference, hash referenc). same as above
2985
    where => [
2986
        ['and', 'author = :author', 'title like :title'],
2987
        {author => 'Ken', title => '%Perl%'}
2988
    ];    
2989
    
2990
    # Array reference 2 (String, hash reference)
2991
    where => [
2992
        'title like :title',
2993
        {title => '%Perl%'}
2994
    ]
2995
    
2996
    # String
2997
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2998

            
updated document
Yuki Kimoto authored on 2011-06-09
2999
Where clause.
3000
    
improved pod
Yuki Kimoto authored on 2011-04-19
3001
=item C<wrap> EXPERIMENTAL
3002

            
3003
Wrap statement. This is array reference.
3004

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

            
3007
This option is for Oracle and SQL Server paging process.
3008

            
update pod
Yuki Kimoto authored on 2011-03-12
3009
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3010

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

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

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

            
3017
If you want to set constant value to row data, use scalar reference
3018
as parameter value.
3019

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3024
=over 4
3025

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3036
    id => 4
3037
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3038

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3042
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3043
        {title => 'Perl', author => 'Ken'}
3044
        parimary_key => ['id1', 'id2'],
3045
        id => [4, 5],
3046
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3047
    );
update pod
Yuki Kimoto authored on 2011-03-13
3048

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3051
    $dbi->update(
3052
        {title => 'Perl', author => 'Ken'}
3053
        where => {id1 => 4, id2 => 5},
3054
        table => 'book'
3055
    );
update pod
Yuki Kimoto authored on 2011-03-13
3056

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

            
3059
    prefix => 'or replace'
3060

            
3061
prefix before table name section
3062

            
3063
    update or replace book
3064

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

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

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

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

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

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

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

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

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

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

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

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

            
3090
=item C<type_rule_off> EXPERIMENTAL
3091

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

            
3094
=item C<type_rule1_off> EXPERIMENTAL
3095

            
3096
    type_rule1_off => 1
3097

            
3098
Same as C<execute> method's C<type_rule1_off> option.
3099

            
3100
=item C<type_rule2_off> EXPERIMENTAL
3101

            
3102
    type_rule2_off => 1
3103

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3106
=back
update pod
Yuki Kimoto authored on 2011-03-13
3107

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

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

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

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

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

            
3119
Create update parameter tag.
3120

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

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

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

            
3130
Create a new L<DBIx::Custom::Where> object.
3131

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

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

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

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

            
3141
=head2 C<DBIX_CUSTOM_DEBUG>
3142

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

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

            
3148
    $dbi->show_datatype($table);
3149

            
3150
Show data type of the columns of specified table.
3151

            
3152
    book
3153
    title: 5
3154
    issue_date: 91
3155

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

            
3158
=head2 C<show_typename EXPERIMENTAL>
3159

            
3160
    $dbi->show_typename($table);
3161

            
3162
Show type name of the columns of specified table.
3163

            
3164
    book
3165
    title: varchar
3166
    issue_date: date
3167

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

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

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

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

            
3176
L<DBIx::Custom>
3177

            
3178
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3179
    data_source # will be removed at 2017/1/1
3180
    dbi_options # will be removed at 2017/1/1
3181
    filter_check # will be removed at 2017/1/1
3182
    reserved_word_quote # will be removed at 2017/1/1
3183
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3184
    
3185
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3186
    create_query # will be removed at 2017/1/1
3187
    apply_filter # will be removed at 2017/1/1
3188
    select_at # will be removed at 2017/1/1
3189
    delete_at # will be removed at 2017/1/1
3190
    update_at # will be removed at 2017/1/1
3191
    insert_at # will be removed at 2017/1/1
3192
    register_tag # will be removed at 2017/1/1
3193
    default_bind_filter # will be removed at 2017/1/1
3194
    default_fetch_filter # will be removed at 2017/1/1
3195
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3196
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3197
    register_tag_processor # will be removed at 2017/1/1
3198
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3199
    
3200
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3201
    select method relation option # will be removed at 2017/1/1
3202
    select method param option # will be removed at 2017/1/1
3203
    select method column option [COLUMN, as => ALIAS] format
3204
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3205
    
3206
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3207
    execute("select * from {= title}"); # execute method's
3208
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3209
                                        # will be removed at 2017/1/1
3210
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3211

            
3212
L<DBIx::Custom::Model>
3213

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3214
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3215
    filter # will be removed at 2017/1/1
3216
    name # will be removed at 2017/1/1
3217
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3218

            
3219
L<DBIx::Custom::Query>
3220
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3221
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3222
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3223
    table # will be removed at 2017/1/1
3224
    filters # will be removed at 2017/1/1
3225
    
3226
    # Methods
3227
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3228

            
3229
L<DBIx::Custom::QueryBuilder>
3230
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3231
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3232
    tags # will be removed at 2017/1/1
3233
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3234
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3235
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3236
    register_tag # will be removed at 2017/1/1
3237
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3238
    
3239
    # Others
3240
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3241
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3242

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

            
3254
L<DBIx::Custom::Tag>
3255

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

            
3258
=head1 BACKWORD COMPATIBLE POLICY
3259

            
3260
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3261
except for attribute method.
3262
You can check all DEPRECATED functionalities by document.
3263
DEPRECATED functionality is removed after five years,
3264
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
3265
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3266

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

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

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

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

            
3275
C<< <kimoto.yuki at gmail.com> >>
3276

            
3277
L<http://github.com/yuki-kimoto/DBIx-Custom>
3278

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3279
=head1 AUTHOR
3280

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

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

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

            
3287
This program is free software; you can redistribute it and/or modify it
3288
under the same terms as Perl itself.
3289

            
3290
=cut