DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3355 lines | 86.917kb
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

            
prepare oracle test
Yuki Kimoto authored on 2011-08-15
4
our $VERSION = '0.1716';
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) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
199
            my $driver = $self->_driver;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
200
            my $quote = $driver eq 'odbc' ? '[]'
201
                       :$driver eq 'mysql' ? '`'
202
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
203
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
204
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
205
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
206
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
207
    }
208
}
209

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

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

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

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

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

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

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

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
302
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
303
    
cleanup
Yuki Kimoto authored on 2011-08-15
304
    # Tables
added SQL Server test
Yuki Kimoto authored on 2011-08-14
305
    my %tables;
cleanup
Yuki Kimoto authored on 2011-08-15
306
    $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
307

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

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

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
338
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
339
  allow_update_all bind_type column filter id join param prefix primary_key
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
340
  query relation sqlfilter table table_alias type type_rule_off type_rule1_off
simplified arguments check
Yuki Kimoto authored on 2011-07-11
341
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
342

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
379
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
380
    
381
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
382
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
383
    
cleanup
Yuki Kimoto authored on 2011-04-02
384
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
385
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
386
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
387
    
micro optimization
Yuki Kimoto authored on 2011-07-30
388
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
389
    $tables = $self->_remove_duplicate_table($tables, $main_table)
390
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
391
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
392
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
393
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
394
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
395
        foreach my $i (1, 2) {
396
            unless ($type_rule_off_parts->{$i}) {
397
                $type_filters->{$i} = {};
398
                foreach my $alias (keys %$table_alias) {
399
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
400
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
401
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
402
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
403
                    }
404
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
405
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
406
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
407
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
408
        }
409
    }
cleanup
Yuki Kimoto authored on 2011-04-02
410
    
micro optimization
Yuki Kimoto authored on 2011-07-30
411
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
412
    if ($self->{filter}{on}) {
413
        my $applied_filter = {};
414
        foreach my $table (@$tables) {
415
            $applied_filter = {
416
                %$applied_filter,
417
                %{$self->{filter}{out}->{$table} || {}}
418
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
419
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
420
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
421
    }
422
    
cleanup
Yuki Kimoto authored on 2011-04-02
423
    # Replace filter name to code
424
    foreach my $column (keys %$filter) {
425
        my $name = $filter->{$column};
426
        if (!defined $name) {
427
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
428
        }
cleanup
Yuki Kimoto authored on 2011-04-02
429
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
430
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
431
            unless exists $self->filters->{$name};
432
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
433
        }
434
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
435
    
cleanup
Yuki Kimoto authored on 2011-04-02
436
    # Create bind values
437
    my $bind = $self->_create_bind_values(
438
        $param,
439
        $query->columns,
440
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
441
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
442
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
443
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
444

            
cleanup
yuki-kimoto authored on 2010-10-17
445
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
446
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
447
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
448
    eval {
449
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
450
            my $bind_type = $bind->[$i]->{bind_type};
451
            $sth->bind_param(
452
                $i + 1,
453
                $bind->[$i]->{value},
454
                $bind_type ? $bind_type : ()
455
            );
cleanup
Yuki Kimoto authored on 2011-03-21
456
        }
457
        $affected = $sth->execute;
458
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
459
    
micro optimization
Yuki Kimoto authored on 2011-07-30
460
    $self->_croak($@, qq{. Following SQL is executed.\n}
461
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
462
    
improved debug message
Yuki Kimoto authored on 2011-05-23
463
    # DEBUG message
464
    if (DEBUG) {
465
        print STDERR "SQL:\n" . $query->sql . "\n";
466
        my @output;
467
        foreach my $b (@$bind) {
468
            my $value = $b->{value};
469
            $value = 'undef' unless defined $value;
470
            $value = encode(DEBUG_ENCODING(), $value)
471
              if utf8::is_utf8($value);
472
            push @output, $value;
473
        }
474
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
475
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
476
    
cleanup
Yuki Kimoto authored on 2011-04-02
477
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
478
    if ($sth->{NUM_OF_FIELDS}) {
479
        
micro optimization
Yuki Kimoto authored on 2011-07-30
480
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
481
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
482
        if ($self->{filter}{on}) {
483
            $filter->{in}  = {};
484
            $filter->{end} = {};
485
            push @$tables, $main_table if $main_table;
486
            foreach my $table (@$tables) {
487
                foreach my $way (qw/in end/) {
488
                    $filter->{$way} = {
489
                        %{$filter->{$way}},
490
                        %{$self->{filter}{$way}{$table} || {}}
491
                    };
492
                }
cleanup
Yuki Kimoto authored on 2011-04-02
493
            }
cleanup
Yuki Kimoto authored on 2011-01-12
494
        }
495
        
496
        # Result
497
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
498
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
499
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
500
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
501
            filter => $filter->{in} || {},
502
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
503
            type_rule => {
504
                from1 => $self->type_rule->{from1},
505
                from2 => $self->type_rule->{from2}
506
            },
cleanup
yuki-kimoto authored on 2010-10-17
507
        );
508

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
775
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
776
sub not_exists { $not_exists }
777

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1108
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1109
}
1110

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

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

            
1139
        # Create query
1140
        my $builder = $self->query_builder;
1141
        $query = $builder->build_query($source);
1142

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

            
1149
        # Save query to cache
1150
        $self->cache_method->(
1151
            $self, $source,
1152
            {
1153
                sql     => $query->sql, 
1154
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1155
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1156
            }
1157
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1158
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1159

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

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

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

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

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

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

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

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

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

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

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

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

            
1431
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1432
}
1433

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1826
=head1 NAME
1827

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

            
1830
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1831

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1901
Named place holder support
1902

            
1903
=item *
1904

            
cleanup
Yuki Kimoto authored on 2011-07-29
1905
Model support
1906

            
1907
=item *
1908

            
1909
Connection manager support
1910

            
1911
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1912

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

            
1917
=item *
1918

            
1919
Filtering by data type or column name(EXPERIMENTAL)
1920

            
1921
=item *
1922

            
1923
Create C<order by> clause flexibly(EXPERIMENTAL)
1924

            
1925
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1926

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1978
=head2 C<default_dbi_option>
1979

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

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

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

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

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

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

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

            
2001
    my $last_sql = $dbi->last_sql;
2002
    $dbi = $dbi->last_sql($last_sql);
2003

            
2004
Get last successed SQL executed by C<execute> method.
2005

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2035
You can set quote pair.
2036

            
2037
    $dbi->quote('[]');
2038

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

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

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

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

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

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

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

            
2056
    my $separator = $self->separator;
2057
    $dbi = $self->separator($separator);
2058

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

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

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

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

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

            
2076
    my $tag_parse = $dbi->tag_parse(0);
2077
    $dbi = $dbi->tag_parse;
2078

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2123
Create column clause. The follwoing column clause is created.
2124

            
2125
    book.author as "book.author",
2126
    book.title as "book.title"
2127

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

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

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

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

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

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

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

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

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

            
2170
   $dbi->model('book')->select(...);
2171

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

            
2174
    my $dbh = $dbi->dbh;
2175

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

            
2179
=head2 C<each_column>
2180

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2252
    select * from where title = "aa\\:bb";
2253

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

            
2256
=over 4
2257

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

            
2260
Specify database bind data type.
2261

            
2262
    bind_type => [image => DBI::SQL_BLOB]
2263
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2264

            
2265
This is used to bind parameter by C<bind_param> of statment handle.
2266

            
2267
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2268

            
update pod
Yuki Kimoto authored on 2011-03-13
2269
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2270
    
2271
    filter => {
2272
        title  => sub { uc $_[0] }
2273
        author => sub { uc $_[0] }
2274
    }
update pod
Yuki Kimoto authored on 2011-03-13
2275

            
updated pod
Yuki Kimoto authored on 2011-06-09
2276
    # Filter name
2277
    filter => {
2278
        title  => 'upper_case',
2279
        author => 'upper_case'
2280
    }
2281
        
2282
    # At once
2283
    filter => [
2284
        [qw/title author/]  => sub { uc $_[0] }
2285
    ]
2286

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

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

            
2294
    query => 1
2295

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

            
2299
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2300
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2301
    my $columns = $query->columns;
2302
    
2303
If you want to execute SQL fast, you can do the following way.
2304

            
2305
    my $query;
2306
    foreach my $row (@$rows) {
2307
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2308
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2309
    }
2310

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

            
2314
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
2315
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2316
    
2317
    my $query;
2318
    my $sth;
2319
    foreach my $row (@$rows) {
2320
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2321
      $sth ||= $query->sth;
2322
      $sth->execute(map { $row->{$_} } sort keys %$row);
2323
    }
2324

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2329
=item C<sqlfilter EXPERIMENTAL> 
2330

            
2331
SQL filter function.
2332

            
2333
    sqlfilter => $code_ref
2334

            
2335
This option is generally for Oracle and SQL Server paging process.
2336
    
2337
    my $limit = sub {
2338
        my ($sql, $count, $offset) = @_;
2339
        
2340
        my $min = $offset + 1;
2341
        my $max = $offset + $count;
2342
        
2343
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2344
        
2345
        return $sql;
2346
    }
2347
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2348
        my $sql = shift;
2349
        return $limit->($sql, 100, 50);
2350
    })
2351

            
updated pod
Yuki Kimoto authored on 2011-06-09
2352
=item C<table>
2353
    
2354
    table => 'author'
2355

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2363
    # Same
2364
    $dbi->execute(
2365
      "select * from book where title = :book.title and author = :book.author",
2366
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2367

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

            
2370
    table_alias => {user => 'hiker'}
2371

            
2372
Table alias. Key is real table name, value is alias table name.
2373
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2374
on alias table name.
2375

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

            
2378
    type_rule_off => 1
2379

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

            
2382
=item C<type_rule1_off> EXPERIMENTAL
2383

            
2384
    type_rule1_off => 1
2385

            
2386
Turn C<into1> type rule off.
2387

            
2388
=item C<type_rule2_off> EXPERIMENTAL
2389

            
2390
    type_rule2_off => 1
2391

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2404
=over 4
2405

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

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

            
2410
=item C<filter>
2411

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2416
    id => 4
2417
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2418

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2422
    $dbi->delete(
2423
        parimary_key => ['id1', 'id2'],
2424
        id => [4, 5],
2425
        table => 'book',
2426
    );
update pod
Yuki Kimoto authored on 2011-03-13
2427

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

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

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

            
2434
    prefix => 'some'
2435

            
2436
prefix before table name section.
2437

            
2438
    delete some from book
2439

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2444
=item C<sqlfilter EXPERIMENTAL>
2445

            
2446
Same as C<execute> method's C<sqlfilter> option.
2447

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2452
Table name.
2453

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

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

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

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

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

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

            
2466
=item C<type_rule_off> EXPERIMENTAL
2467

            
2468
Same as C<execute> method's C<type_rule_off> option.
2469

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

            
2472
    type_rule1_off => 1
2473

            
2474
Same as C<execute> method's C<type_rule1_off> option.
2475

            
2476
=item C<type_rule2_off> EXPERIMENTAL
2477

            
2478
    type_rule2_off => 1
2479

            
2480
Same as C<execute> method's C<type_rule2_off> option.
2481

            
updated pod
Yuki Kimoto authored on 2011-06-08
2482
=back
update pod
Yuki Kimoto authored on 2011-03-13
2483

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2491
=head2 C<insert>
2492

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

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

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

            
2501
    {date => \"NOW()"}
2502

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

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

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

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

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

            
2513
Same as C<execute> method's C<bind_type> option.
2514

            
update pod
Yuki Kimoto authored on 2011-03-13
2515
=item C<filter>
2516

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

            
2519
=item C<id>
2520

            
updated document
Yuki Kimoto authored on 2011-06-09
2521
    id => 4
2522
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2523

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2527
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2528
        {title => 'Perl', author => 'Ken'}
2529
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2530
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2531
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2532
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2533

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

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

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

            
2543
    prefix => 'or replace'
2544

            
2545
prefix before table name section
2546

            
2547
    insert or replace into book
2548

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

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

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

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

            
2558
Same as C<execute> method's C<query> option.
2559

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2560
=item C<sqlfilter EXPERIMENTAL>
2561

            
2562
Same as C<execute> method's C<sqlfilter> option.
2563

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

            
2566
    table => 'book'
2567

            
2568
Table name.
2569

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

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

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

            
2576
    type_rule1_off => 1
2577

            
2578
Same as C<execute> method's C<type_rule1_off> option.
2579

            
2580
=item C<type_rule2_off> EXPERIMENTAL
2581

            
2582
    type_rule2_off => 1
2583

            
2584
Same as C<execute> method's C<type_rule2_off> option.
2585

            
update pod
Yuki Kimoto authored on 2011-03-13
2586
=back
2587

            
2588
=over 4
2589

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2605
    lib / MyModel.pm
2606
        / MyModel / book.pm
2607
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2608

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

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

            
2613
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2614
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2615
    
2616
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2617

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2622
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2623
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2624
    
2625
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2626

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2629
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2630
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2631
    
2632
    1;
2633
    
updated pod
Yuki Kimoto authored on 2011-06-21
2634
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2635

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

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

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

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

            
2645
    my $map_param = $dbi->map_param(
2646
        {id => 1, authro => 'Ken', price => 1900},
2647
        'id' => 'book.id',
2648
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2649
        'price' => [
2650
            'book.price', {if => sub { length $_[0] }}
2651
        ]
2652
    );
2653

            
2654
Map paramters to other key and value. First argument is original
2655
parameter. this is hash reference. Rest argument is mapping.
2656
By default, Mapping is done if the value length is not zero.
2657

            
2658
=over 4
2659

            
2660
=item Key mapping
2661

            
2662
    'id' => 'book.id'
2663

            
2664
This is only key mapping. Value is same as original one.
2665

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

            
2668
=item Key and value mapping
2669

            
2670
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2671

            
2672
This is key and value mapping. Frist element of array reference
2673
is mapped key name, second element is code reference to map the value.
2674

            
2675
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2676
      if value length is not zero.
2677

            
2678
=item Condition
2679

            
2680
    'price' => ['book.price', {if => 'exists'}]
2681
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2682
    'price' => ['book.price', {if => sub { defined shift }}]
2683

            
2684
If you need condition, you can sepecify it. this is code reference
2685
or 'exists'. By default, condition is the following one.
2686

            
2687
    sub { defined $_[0] && length $_[0] }
2688

            
2689
=back
2690

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

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

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

            
2697
    {key1 => [1, 1], key2 => 2}
2698

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

            
2701
    $dbi->method(
2702
        update_or_insert => sub {
2703
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2704
            
2705
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2706
        },
2707
        find_or_create   => sub {
2708
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2709
            
2710
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2711
        }
2712
    );
2713

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

            
2716
    $dbi->update_or_insert;
2717
    $dbi->find_or_create;
2718

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

            
2721
    my $model = $dbi->model('book');
2722

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

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

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

            
2729
Create column clause for myself. The follwoing column clause is created.
2730

            
2731
    book.author as author,
2732
    book.title as title
2733

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2736
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2737
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2738
        user => 'ken',
2739
        password => '!LFKD%$&',
2740
        dbi_option => {mysql_enable_utf8 => 1}
2741
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2742

            
2743
Create a new L<DBIx::Custom> object.
2744

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

            
2747
    my $not_exists = $dbi->not_exists;
2748

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

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

            
2754
    my $order = $dbi->order;
2755

            
2756
Create a new L<DBIx::Custom::Order> object.
2757

            
cleanup
yuki-kimoto authored on 2010-10-17
2758
=head2 C<register_filter>
2759

            
update pod
Yuki Kimoto authored on 2011-03-13
2760
    $dbi->register_filter(
2761
        # Time::Piece object to database DATE format
2762
        tp_to_date => sub {
2763
            my $tp = shift;
2764
            return $tp->strftime('%Y-%m-%d');
2765
        },
2766
        # database DATE format to Time::Piece object
2767
        date_to_tp => sub {
2768
           my $date = shift;
2769
           return Time::Piece->strptime($date, '%Y-%m-%d');
2770
        }
2771
    );
cleanup
yuki-kimoto authored on 2010-10-17
2772
    
update pod
Yuki Kimoto authored on 2011-03-13
2773
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2774

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

            
2777
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2778
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2779
            date => sub { ... },
2780
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2781
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2782
        into2 => {
2783
            date => sub { ... },
2784
            datetime => sub { ... }
2785
        },
2786
        from1 => {
2787
            # DATE
2788
            9 => sub { ... },
2789
            # DATETIME or TIMESTAMP
2790
            11 => sub { ... },
2791
        }
2792
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2793
            # DATE
2794
            9 => sub { ... },
2795
            # DATETIME or TIMESTAMP
2796
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2797
        }
2798
    );
2799

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2815
=over 4
2816

            
2817
=item 1. column name
2818

            
2819
    issue_date
2820
    issue_datetime
2821

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

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

            
2826
    book.issue_date
2827
    book.issue_datetime
2828

            
2829
=back
2830

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

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

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

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

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

            
2843
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2844
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2845
            [qw/DATE DATETIME/] => sub { ... },
2846
        ],
2847
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2848

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2851
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2852
        table  => 'book',
2853
        column => ['author', 'title'],
2854
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2855
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2856
    
updated document
Yuki Kimoto authored on 2011-06-09
2857
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2858

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

            
2861
=over 4
2862

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2867
Append statement to last of SQL.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2868

            
2869
=item C<bind_type>
2870

            
2871
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2872
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2873
=item C<column>
2874
    
updated document
Yuki Kimoto authored on 2011-06-09
2875
    column => 'author'
2876
    column => ['author', 'title']
2877

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2886
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2887
        {book => [qw/author title/]},
2888
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2889
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2890

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

            
2893
    book.author as "book.author",
2894
    book.title as "book.title",
2895
    person.name as "person.name",
2896
    person.age as "person.age"
2897

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

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

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

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

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

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

            
2913
=item C<id>
2914

            
2915
    id => 4
2916
    id => [4, 5]
2917

            
2918
ID corresponding to C<primary_key>.
2919
You can select rows by C<id> and C<primary_key>.
2920

            
2921
    $dbi->select(
2922
        parimary_key => ['id1', 'id2'],
2923
        id => [4, 5],
2924
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2925
    );
2926

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2929
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2930
        where => {id1 => 4, id2 => 5},
2931
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2932
    );
2933
    
updated document
Yuki Kimoto authored on 2011-06-09
2934
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2935

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

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

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

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

            
2948
    prefix => 'SQL_CALC_FOUND_ROWS'
2949

            
2950
Prefix of column cluase
2951

            
2952
    select SQL_CALC_FOUND_ROWS title, author from book;
2953

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

            
2956
    join => [
2957
        'left outer join company on book.company_id = company_id',
2958
        'left outer join location on company.location_id = location.id'
2959
    ]
2960
        
2961
Join clause. If column cluase or where clause contain table name like "company.name",
2962
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2963

            
2964
    $dbi->select(
2965
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2966
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2967
        where => {'company.name' => 'Orange'},
2968
        join => [
2969
            'left outer join company on book.company_id = company.id',
2970
            'left outer join location on company.location_id = location.id'
2971
        ]
2972
    );
2973

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2977
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2978
    from book
2979
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2980
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2981

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

            
2985
    $dbi->select(
2986
        table => 'book',
2987
        column => ['company.location_id as location_id'],
2988
        where => {'company.name' => 'Orange'},
2989
        join => [
2990
            {
2991
                clause => 'left outer join location on company.location_id = location.id',
2992
                table => ['company', 'location']
2993
            }
2994
        ]
2995
    );
2996

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

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3008
=item C<sqlfilter EXPERIMENTAL>
updated pod
Yuki Kimoto authored on 2011-06-08
3009

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3010
Same as C<execute> method's C<sqlfilter> option
updated pod
Yuki Kimoto authored on 2011-06-08
3011

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3016
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3017

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

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

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

            
3024
    type_rule1_off => 1
3025

            
3026
Same as C<execute> method's C<type_rule1_off> option.
3027

            
3028
=item C<type_rule2_off> EXPERIMENTAL
3029

            
3030
    type_rule2_off => 1
3031

            
3032
Same as C<execute> method's C<type_rule2_off> option.
3033

            
updated document
Yuki Kimoto authored on 2011-06-09
3034
=item C<where>
3035
    
3036
    # Hash refrence
3037
    where => {author => 'Ken', 'title' => 'Perl'}
3038
    
3039
    # DBIx::Custom::Where object
3040
    where => $dbi->where(
3041
        clause => ['and', 'author = :author', 'title like :title'],
3042
        param  => {author => 'Ken', title => '%Perl%'}
3043
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3044
    
3045
    # Array reference 1 (array reference, hash referenc). same as above
3046
    where => [
3047
        ['and', 'author = :author', 'title like :title'],
3048
        {author => 'Ken', title => '%Perl%'}
3049
    ];    
3050
    
3051
    # Array reference 2 (String, hash reference)
3052
    where => [
3053
        'title like :title',
3054
        {title => '%Perl%'}
3055
    ]
3056
    
3057
    # String
3058
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3059

            
updated document
Yuki Kimoto authored on 2011-06-09
3060
Where clause.
3061
    
improved pod
Yuki Kimoto authored on 2011-04-19
3062
=item C<wrap> EXPERIMENTAL
3063

            
3064
Wrap statement. This is array reference.
3065

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3066
    wrap => ['select * from (', ') as t where ROWNUM < 10']
improved pod
Yuki Kimoto authored on 2011-04-19
3067

            
3068
This option is for Oracle and SQL Server paging process.
3069

            
update pod
Yuki Kimoto authored on 2011-03-12
3070
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3071

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

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

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

            
3078
If you want to set constant value to row data, use scalar reference
3079
as parameter value.
3080

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3085
=over 4
3086

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

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

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

            
3093
Same as C<execute> method's C<bind_type> option.
3094

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3101
    id => 4
3102
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3103

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3107
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3108
        {title => 'Perl', author => 'Ken'}
3109
        parimary_key => ['id1', 'id2'],
3110
        id => [4, 5],
3111
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3112
    );
update pod
Yuki Kimoto authored on 2011-03-13
3113

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3116
    $dbi->update(
3117
        {title => 'Perl', author => 'Ken'}
3118
        where => {id1 => 4, id2 => 5},
3119
        table => 'book'
3120
    );
update pod
Yuki Kimoto authored on 2011-03-13
3121

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

            
3124
    prefix => 'or replace'
3125

            
3126
prefix before table name section
3127

            
3128
    update or replace book
3129

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

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3141
=item C<sqlfilter EXPERIMENTAL>
3142

            
3143
Same as C<execute> method's C<sqlfilter> option.
3144

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

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

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

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

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

            
3155
=item C<type_rule1_off> EXPERIMENTAL
3156

            
3157
    type_rule1_off => 1
3158

            
3159
Same as C<execute> method's C<type_rule1_off> option.
3160

            
3161
=item C<type_rule2_off> EXPERIMENTAL
3162

            
3163
    type_rule2_off => 1
3164

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

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

            
3169
Same as C<select> method's C<where> option.
3170

            
updated pod
Yuki Kimoto authored on 2011-06-08
3171
=back
update pod
Yuki Kimoto authored on 2011-03-13
3172

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

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

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

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

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

            
3184
Create update parameter tag.
3185

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

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

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

            
3195
Create a new L<DBIx::Custom::Where> object.
3196

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

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

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

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

            
3206
=head2 C<DBIX_CUSTOM_DEBUG>
3207

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

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

            
3213
    $dbi->show_datatype($table);
3214

            
3215
Show data type of the columns of specified table.
3216

            
3217
    book
3218
    title: 5
3219
    issue_date: 91
3220

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

            
3223
=head2 C<show_typename EXPERIMENTAL>
3224

            
3225
    $dbi->show_typename($table);
3226

            
3227
Show type name of the columns of specified table.
3228

            
3229
    book
3230
    title: varchar
3231
    issue_date: date
3232

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

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

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

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

            
3241
L<DBIx::Custom>
3242

            
3243
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3244
    data_source # will be removed at 2017/1/1
3245
    dbi_options # will be removed at 2017/1/1
3246
    filter_check # will be removed at 2017/1/1
3247
    reserved_word_quote # will be removed at 2017/1/1
3248
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3249
    
3250
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3251
    create_query # will be removed at 2017/1/1
3252
    apply_filter # will be removed at 2017/1/1
3253
    select_at # will be removed at 2017/1/1
3254
    delete_at # will be removed at 2017/1/1
3255
    update_at # will be removed at 2017/1/1
3256
    insert_at # will be removed at 2017/1/1
3257
    register_tag # will be removed at 2017/1/1
3258
    default_bind_filter # will be removed at 2017/1/1
3259
    default_fetch_filter # will be removed at 2017/1/1
3260
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3261
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3262
    register_tag_processor # will be removed at 2017/1/1
3263
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3264
    
3265
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3266
    select method relation option # will be removed at 2017/1/1
3267
    select method param option # will be removed at 2017/1/1
3268
    select method column option [COLUMN, as => ALIAS] format
3269
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3270
    
3271
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3272
    execute("select * from {= title}"); # execute method's
3273
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3274
                                        # will be removed at 2017/1/1
3275
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3276

            
3277
L<DBIx::Custom::Model>
3278

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3279
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3280
    filter # will be removed at 2017/1/1
3281
    name # will be removed at 2017/1/1
3282
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3283

            
3284
L<DBIx::Custom::Query>
3285
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3286
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3287
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3288
    table # will be removed at 2017/1/1
3289
    filters # will be removed at 2017/1/1
3290
    
3291
    # Methods
3292
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3293

            
3294
L<DBIx::Custom::QueryBuilder>
3295
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3296
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3297
    tags # will be removed at 2017/1/1
3298
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3299
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3300
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3301
    register_tag # will be removed at 2017/1/1
3302
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3303
    
3304
    # Others
3305
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3306
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3307

            
3308
L<DBIx::Custom::Result>
3309
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3310
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3311
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3312
    
3313
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3314
    end_filter # will be removed at 2017/1/1
3315
    remove_end_filter # will be removed at 2017/1/1
3316
    remove_filter # will be removed at 2017/1/1
3317
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3318

            
3319
L<DBIx::Custom::Tag>
3320

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

            
3323
=head1 BACKWORD COMPATIBLE POLICY
3324

            
3325
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3326
except for attribute method.
3327
You can check all DEPRECATED functionalities by document.
3328
DEPRECATED functionality is removed after five years,
3329
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
3330
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3331

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

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

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

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

            
3340
C<< <kimoto.yuki at gmail.com> >>
3341

            
3342
L<http://github.com/yuki-kimoto/DBIx-Custom>
3343

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3344
=head1 AUTHOR
3345

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

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

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

            
3352
This program is free software; you can redistribute it and/or modify it
3353
under the same terms as Perl itself.
3354

            
3355
=cut