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

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

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

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
91
our $AUTOLOAD;
92
sub AUTOLOAD {
93
    my $self = shift;
94

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

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

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

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
127
    }
128
    my $tag = join(', ', @params);
129
    
130
    return $tag;
131
}
132

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

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

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

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

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
254
sub DESTROY {
255

            
256
}
added helper method
yuki-kimoto authored on 2010-10-17
257

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

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

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

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

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

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

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

            
500
        return $result;
501
    }
cleanup
Yuki Kimoto authored on 2011-04-02
502
    
503
    # Not select statement
504
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
505
}
506

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
528
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
529
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
530
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
531
        $param = $self->merge_param($id_param, $param);
532
    }
533

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
567
sub include_model {
568
    my ($self, $name_space, $model_infos) = @_;
569
    
cleanup
Yuki Kimoto authored on 2011-04-02
570
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
571
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
572
    
573
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
574
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
575

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
698
sub method {
699
    my $self = shift;
700
    
cleanup
Yuki Kimoto authored on 2011-04-02
701
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
702
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
703
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
704
    
705
    return $self;
706
}
707

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

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

            
added dbi_options attribute
kimoto authored on 2010-12-20
738
sub new {
739
    my $self = shift->SUPER::new(@_);
740
    
cleanup
Yuki Kimoto authored on 2011-04-02
741
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
742
    my @attrs = keys %$self;
743
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
744
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
745
          unless $self->can($attr);
746
    }
cleanup
Yuki Kimoto authored on 2011-04-02
747
    
added dbi_options attribute
kimoto authored on 2010-12-20
748
    return $self;
749
}
750

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

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
759
sub query_builder {
760
    my $self = shift;
761
    my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
762
    
763
    # DEPRECATED
764
    $builder->register_tag(
765
        '?'     => \&DBIx::Custom::Tag::placeholder,
766
        '='     => \&DBIx::Custom::Tag::equal,
767
        '<>'    => \&DBIx::Custom::Tag::not_equal,
768
        '>'     => \&DBIx::Custom::Tag::greater_than,
769
        '<'     => \&DBIx::Custom::Tag::lower_than,
770
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
771
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
772
        'like'  => \&DBIx::Custom::Tag::like,
773
        'in'    => \&DBIx::Custom::Tag::in,
774
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
775
        'update_param' => \&DBIx::Custom::Tag::update_param
776
    );
777
    $builder->register_tag($self->{_tags} || {});
778
    return $builder;
779
}
780

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1878
=item *
1879

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

            
1882
=item *
1883

            
1884
Connection manager support
1885

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

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

            
1892
=item *
1893

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

            
1896
=item *
1897

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1953
=head2 C<default_dbi_option>
1954

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2154
=head2 C<each_column>
2155

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2231
=over 4
2232

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

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

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

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

            
2258
    query => 1
2259

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2330
    type_rule_off => 1
2331

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

            
2334
=item C<type_rule1_off> EXPERIMENTAL
2335

            
2336
    type_rule1_off => 1
2337

            
2338
Turn C<into1> type rule off.
2339

            
2340
=item C<type_rule2_off> EXPERIMENTAL
2341

            
2342
    type_rule2_off => 1
2343

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

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

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

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

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

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

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

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

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

            
2362
=item C<filter>
2363

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

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

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

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

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

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

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

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

            
2386
    prefix => 'some'
2387

            
2388
prefix before table name section.
2389

            
2390
    delete some from book
2391

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

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

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

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

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

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

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

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

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

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

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

            
2414
=item C<type_rule_off> EXPERIMENTAL
2415

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

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

            
2420
    type_rule1_off => 1
2421

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

            
2424
=item C<type_rule2_off> EXPERIMENTAL
2425

            
2426
    type_rule2_off => 1
2427

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2459
=item C<filter>
2460

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

            
2463
=item C<id>
2464

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

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

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

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

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

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

            
2487
    prefix => 'or replace'
2488

            
2489
prefix before table name section
2490

            
2491
    insert or replace into book
2492

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

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

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

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

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

            
2504
=item C<table>
2505

            
2506
    table => 'book'
2507

            
2508
Table name.
2509

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

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

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

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

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

            
2520
    type_rule1_off => 1
2521

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

            
2524
=item C<type_rule2_off> EXPERIMENTAL
2525

            
2526
    type_rule2_off => 1
2527

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

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

            
2532
=over 4
2533

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2602
=over 4
2603

            
2604
=item Key mapping
2605

            
2606
    'id' => 'book.id'
2607

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

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

            
2612
=item Key and value mapping
2613

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

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

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

            
2622
=item Condition
2623

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

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

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

            
2633
=back
2634

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2761
=item 1. column name
2762

            
2763
    issue_date
2764
    issue_datetime
2765

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

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

            
2770
    book.issue_date
2771
    book.issue_datetime
2772

            
2773
=back
2774

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

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

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

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

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

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

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

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

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

            
2805
=over 4
2806

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2853
=item C<id>
2854

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

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

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

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

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

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

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

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

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

            
2888
    prefix => 'SQL_CALC_FOUND_ROWS'
2889

            
2890
Prefix of column cluase
2891

            
2892
    select SQL_CALC_FOUND_ROWS title, author from book;
2893

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2964
    type_rule1_off => 1
2965

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

            
2968
=item C<type_rule2_off> EXPERIMENTAL
2969

            
2970
    type_rule2_off => 1
2971

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

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

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

            
3004
Wrap statement. This is array reference.
3005

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3060
    prefix => 'or replace'
3061

            
3062
prefix before table name section
3063

            
3064
    update or replace book
3065

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

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

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

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

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

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

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

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

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

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

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

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

            
3091
=item C<type_rule_off> EXPERIMENTAL
3092

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

            
3095
=item C<type_rule1_off> EXPERIMENTAL
3096

            
3097
    type_rule1_off => 1
3098

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

            
3101
=item C<type_rule2_off> EXPERIMENTAL
3102

            
3103
    type_rule2_off => 1
3104

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

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

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

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

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

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

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

            
3120
Create update parameter tag.
3121

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

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

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

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

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

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

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

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

            
3142
=head2 C<DBIX_CUSTOM_DEBUG>
3143

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

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

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

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

            
3153
    book
3154
    title: 5
3155
    issue_date: 91
3156

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

            
3159
=head2 C<show_typename EXPERIMENTAL>
3160

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

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

            
3165
    book
3166
    title: varchar
3167
    issue_date: date
3168

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

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

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

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

            
3177
L<DBIx::Custom>
3178

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

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

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

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

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

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

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

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

            
3259
=head1 BACKWORD COMPATIBLE POLICY
3260

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

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

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

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

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

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

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

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

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

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

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

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

            
3291
=cut