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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
4
our $VERSION = '0.1731';
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/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

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

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

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

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
122
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
123
    my ($self, $param, $opts) = @_;
124
    
125
    my $wrap = $opts->{wrap} || {};
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
    
127
    # Create set tag
128
    my @params;
129
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
130
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
131
        croak qq{"$column" is not safety column name } . _subname
132
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
133
        my $column_quote = $self->_q($column);
134
        $column_quote =~ s/\./$self->_q(".")/e;
updated pod
Yuki Kimoto authored on 2011-09-02
135
        my $func = $wrap->{$column} || sub { $_[0] };
136
        push @params,
137
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
138
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
139
    }
140
    my $tag = join(', ', @params);
141
    
142
    return $tag;
143
}
144

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
170
sub connect {
cleanup
Yuki Kimoto authored on 2011-08-16
171
    my $self = ref $_[0] ? shift : shift->new(@_);
172
    
173
    my $connector = $self->connector;
174
    
175
    if (!ref $connector && $connector) {
176
        require DBIx::Connector;
177
        
178
        my $dsn = $self->dsn;
179
        my $user = $self->user;
180
        my $password = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
181
        my $option = $self->_option;
cleanup
Yuki Kimoto authored on 2011-08-16
182
        my $connector = DBIx::Connector->new($dsn, $user, $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
183
          {%{$self->default_option} , %$option});
cleanup
Yuki Kimoto authored on 2011-08-16
184
        $self->connector($connector);
185
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
186
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
187
    # Connect
188
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
189
    
packaging one directory
yuki-kimoto authored on 2009-11-16
190
    return $self;
191
}
192

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
193
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] }
194

            
update pod
Yuki Kimoto authored on 2011-03-13
195
sub dbh {
196
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
197
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
198
    # Set
199
    if (@_) {
200
        $self->{dbh} = $_[0];
201
        
202
        return $self;
203
    }
204
    
205
    # Get
206
    else {
207
        # From Connction manager
208
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
209
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
210
              unless ref $connector && $connector->can('dbh');
211
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
212
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
213
        }
214
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
215
        # Connect
216
        $self->{dbh} ||= $self->_connect;
217
        
218
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
219
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
220
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
221
            my $quote =  $driver eq 'odbc' ? '[]'
222
                       : $driver eq 'ado' ? '[]'
223
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
224
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
225
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
226
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
227
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
228
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
229
    }
230
}
231

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

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
235
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
236
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
237
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
238
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
239
    my $where            = delete $args{where} || {};
240
    my $append           = delete $args{append};
241
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
242
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
243
    my $id = delete $args{id};
244
    my $primary_key = delete $args{primary_key};
245
    croak "update method primary_key option " .
246
          "must be specified when id is specified " . _subname
247
      if defined $id && !defined $primary_key;
248
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
249
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
250
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
251
    # Where
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
252
    $where = $self->_create_param_from_id($id, $primary_key, $table)
253
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
254
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
255
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
256
        $where_clause = "where " . $where->[0];
257
        $where_param = $where->[1];
258
    }
259
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
260
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
261
        $where_param = keys %$where_param
262
                     ? $self->merge_param($where_param, $where->param)
263
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
264
        
265
        # String where
266
        $where_clause = $where->to_string;
267
    }
268
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
269
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
270
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
271

            
cleanup
Yuki Kimoto authored on 2011-04-02
272
    # Delete statement
micro optimization
Yuki Kimoto authored on 2011-09-30
273
    my $sql;
274
    $sql .= "delete ";
275
    $sql .= "$prefix " if defined $prefix;
276
    $sql .= "from " . $self->_q($table) . " $where_clause ";
277
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
278
    
279
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
280
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
281
}
282

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
285
sub DESTROY {}
added helper method
yuki-kimoto authored on 2010-10-17
286

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
287
sub create_model {
288
    my $self = shift;
289
    
cleanup
Yuki Kimoto authored on 2011-04-02
290
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
291
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
292
    $args->{dbi} = $self;
293
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
294
    my $model_name  = delete $args->{name};
295
    my $model_table = delete $args->{table};
296
    $model_name ||= $model_table;
297
    
cleanup
Yuki Kimoto authored on 2011-04-02
298
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
299
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
300
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
301
    $model->name($model_name) unless $model->name;
302
    $model->table($model_table) unless $model->table;
303
    
micro optimization
Yuki Kimoto authored on 2011-07-30
304
    # Apply filter(DEPRECATED logic)
305
    if ($model->{filter}) {
306
        my $filter = ref $model->filter eq 'HASH'
307
                   ? [%{$model->filter}]
308
                   : $model->filter;
309
        $filter ||= [];
310
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
311
          if @$filter;
312
        $self->_apply_filter($model->table, @$filter);
313
    }
314
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
315
    # Set model
316
    $self->model($model->name, $model);
317
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
318
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
319
}
320

            
321
sub each_column {
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
322
    my ($self, $cb, %options) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
323

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
324
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
325
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
326
    if ($user_column_info) {
327
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
328
    }
329
    else {
330
    
331
        my $re = $self->exclude_table || $options{exclude_table};
332
        # Tables
333
        my %tables;
334
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
335

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
336
        # Iterate all tables
337
        my @tables = sort keys %tables;
338
        for (my $i = 0; $i < @tables; $i++) {
339
            my $table = $tables[$i];
340
            
341
            # Iterate all columns
342
            my $sth_columns;
343
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
344
            next if $@;
345
            while (my $column_info = $sth_columns->fetchrow_hashref) {
346
                my $column = $column_info->{COLUMN_NAME};
347
                $self->$cb($table, $column, $column_info);
348
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
349
        }
350
    }
351
}
352

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
353
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
354
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
355
    
cleanup test
Yuki Kimoto authored on 2011-08-16
356
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
357
    
added test
Yuki Kimoto authored on 2011-08-16
358
    # Iterate tables
359
    if ($user_table_infos) {
360
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
361
    }
362
    else {
363
        my $re = $self->exclude_table || $option{exclude};
364
        my $sth_tables = $self->dbh->table_info;
365
        while (my $table_info = $sth_tables->fetchrow_hashref) {
366
            
367
            # Table
368
            my $table = $table_info->{TABLE_NAME};
369
            next if defined $re && $table =~ /$re/;
370
            $self->$cb($table, $table_info);
371
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
372
    }
373
}
374

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
375
our %VALID_ARGS = map { $_ => 1 } qw/append after_build_sql allow_delete_all
simplified arguments check
Yuki Kimoto authored on 2011-07-11
376
  allow_update_all bind_type column filter id join param prefix primary_key
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
377
  query relation sqlfilter table table_alias timestamp type type_rule_off
378
  type_rule1_off type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
379

            
380
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
381
    my $self = shift;
382
    my $query = shift;
383
    my $param;
384
    $param = shift if @_ % 2;
385
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
386
    
cleanup
Yuki Kimoto authored on 2011-04-02
387
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
388
    my $p = delete $args{param} || {};
389
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
390
    my $tables = delete $args{table} || [];
391
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
392
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
393
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
394
    my $bind_type = delete $args{bind_type} || delete $args{type};
395
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
396
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
397
    my $type_rule_off_parts = {
398
        1 => delete $args{type_rule1_off},
399
        2 => delete $args{type_rule2_off}
400
    };
cleanup
Yuki Kimoto authored on 2011-06-09
401
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
402
    my $table_alias = delete $args{table_alias} || {};
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
403
    my $after_build_sql = $args{after_build_sql} || $args{sqlfilter};
404
    warn "sqlfilter option is DEPRECATED" if $args{sqlfilter};
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
405
    my $id = delete $args{id};
406
    my $primary_key = delete $args{primary_key};
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
407
    croak "execute method primary_key option " .
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
408
          "must be specified when id is specified " . _subname
409
      if defined $id && !defined $primary_key;
410
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
411

            
cleanup
Yuki Kimoto authored on 2011-03-09
412
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
413
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
414
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
415
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
416
    }
417
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
418
    $query = $self->_create_query($query, $after_build_sql) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
419
    
420
    # Save query
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
421
    if (ref $query eq 'DBIx::Custom::Result') { $DB::single = 1 }
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
422
    $self->last_sql($query->sql);
423

            
cleanup
Yuki Kimoto authored on 2011-06-09
424
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
425
    
426
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
427
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
428
    
cleanup
Yuki Kimoto authored on 2011-04-02
429
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
430
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
431
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
432

            
433
    if (defined $id) {
434
        my $id_param = $self->_create_param_from_id($id, $primary_key, $main_table);
435
        $param = $self->merge_param($id_param, $param);
436
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
437
    
micro optimization
Yuki Kimoto authored on 2011-07-30
438
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
439
    $tables = $self->_remove_duplicate_table($tables, $main_table)
440
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
441
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
442
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
443
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
444
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
445
        foreach my $i (1, 2) {
446
            unless ($type_rule_off_parts->{$i}) {
447
                $type_filters->{$i} = {};
448
                foreach my $alias (keys %$table_alias) {
449
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
450
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
451
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
452
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
453
                    }
454
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
455
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
456
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
457
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
458
        }
459
    }
cleanup
Yuki Kimoto authored on 2011-04-02
460
    
micro optimization
Yuki Kimoto authored on 2011-07-30
461
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
462
    if ($self->{filter}{on}) {
463
        my $applied_filter = {};
464
        foreach my $table (@$tables) {
465
            $applied_filter = {
466
                %$applied_filter,
467
                %{$self->{filter}{out}->{$table} || {}}
468
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
469
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
470
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
471
    }
472
    
cleanup
Yuki Kimoto authored on 2011-04-02
473
    # Replace filter name to code
474
    foreach my $column (keys %$filter) {
475
        my $name = $filter->{$column};
476
        if (!defined $name) {
477
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
478
        }
cleanup
Yuki Kimoto authored on 2011-04-02
479
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
480
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
481
            unless exists $self->filters->{$name};
482
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
483
        }
484
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
485
    
cleanup
Yuki Kimoto authored on 2011-04-02
486
    # Create bind values
487
    my $bind = $self->_create_bind_values(
488
        $param,
489
        $query->columns,
490
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
491
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
492
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
493
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
494

            
cleanup
yuki-kimoto authored on 2010-10-17
495
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
496
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
497
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
498
    eval {
499
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
500
            my $bind_type = $bind->[$i]->{bind_type};
501
            $sth->bind_param(
502
                $i + 1,
503
                $bind->[$i]->{value},
504
                $bind_type ? $bind_type : ()
505
            );
cleanup
Yuki Kimoto authored on 2011-03-21
506
        }
507
        $affected = $sth->execute;
508
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
509
    
micro optimization
Yuki Kimoto authored on 2011-07-30
510
    $self->_croak($@, qq{. Following SQL is executed.\n}
511
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
512
    
improved debug message
Yuki Kimoto authored on 2011-05-23
513
    # DEBUG message
514
    if (DEBUG) {
515
        print STDERR "SQL:\n" . $query->sql . "\n";
516
        my @output;
517
        foreach my $b (@$bind) {
518
            my $value = $b->{value};
519
            $value = 'undef' unless defined $value;
520
            $value = encode(DEBUG_ENCODING(), $value)
521
              if utf8::is_utf8($value);
522
            push @output, $value;
523
        }
524
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
525
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
526
    
cleanup
Yuki Kimoto authored on 2011-04-02
527
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
528
    if ($sth->{NUM_OF_FIELDS}) {
529
        
micro optimization
Yuki Kimoto authored on 2011-07-30
530
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
531
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
532
        if ($self->{filter}{on}) {
533
            $filter->{in}  = {};
534
            $filter->{end} = {};
535
            push @$tables, $main_table if $main_table;
536
            foreach my $table (@$tables) {
537
                foreach my $way (qw/in end/) {
538
                    $filter->{$way} = {
539
                        %{$filter->{$way}},
540
                        %{$self->{filter}{$way}{$table} || {}}
541
                    };
542
                }
cleanup
Yuki Kimoto authored on 2011-04-02
543
            }
cleanup
Yuki Kimoto authored on 2011-01-12
544
        }
545
        
546
        # Result
547
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
548
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
549
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
550
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
551
            filter => $filter->{in} || {},
552
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
553
            type_rule => {
554
                from1 => $self->type_rule->{from1},
555
                from2 => $self->type_rule->{from2}
556
            },
cleanup
yuki-kimoto authored on 2010-10-17
557
        );
558

            
559
        return $result;
560
    }
cleanup
Yuki Kimoto authored on 2011-04-02
561
    
562
    # Not select statement
563
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
564
}
565

            
added test
Yuki Kimoto authored on 2011-08-16
566
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
567
    my ($self, %args) = @_;
568
    
569
    my $exclude = delete $args{exclude};
570
    croak qq/"$_" is wrong option/ for keys %args;
571
    
added test
Yuki Kimoto authored on 2011-08-16
572
    my $table_info = [];
573
    $self->each_table(
574
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
575
        exclude => $exclude
576
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
577
    
cleanup test
Yuki Kimoto authored on 2011-08-16
578
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
579
}
580

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
581
sub get_column_info {
582
    my ($self, %args) = @_;
583
    
584
    my $exclude_table = delete $args{exclude_table};
585
    croak qq/"$_" is wrong option/ for keys %args;
586
    
587
    my $column_info = [];
588
    $self->each_column(
589
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
590
        exclude_table => $exclude_table
591
    );
592
    
593
    return [
594
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
595
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
596
}
597

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
598
sub helper {
599
    my $self = shift;
600
    
601
    # Register method
602
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
603
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
604
    
605
    return $self;
606
}
607

            
cleanup
yuki-kimoto authored on 2010-10-17
608
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
609
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
610
    
cleanup
yuki-kimoto authored on 2010-10-17
611
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
612
    my $param;
613
    $param = shift if @_ % 2;
614
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
615
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
616
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
617
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
618
    my $p = delete $args{param} || {};
619
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
620
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
621
    my $id = delete $args{id};
622
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
623
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
624
          "must be specified when id is specified " . _subname
625
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
626
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
627
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
628
    my $wrap = delete $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
629
    my $timestamp = $args{timestamp};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
630
    delete $args{where};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
631
    
632
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
633
    if ($timestamp && (my $insert_timestamp = $self->insert_timestamp)) {
634
        my $columns = $insert_timestamp->[0];
635
        $columns = [$columns] unless ref $columns eq 'ARRAY';
636
        my $value = $insert_timestamp->[1];
637
        $value = $value->() if ref $value eq 'CODE';
638
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
639
    }
cleanup
Yuki Kimoto authored on 2011-04-02
640

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
641
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
642
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
643
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
644
        $param = $self->merge_param($id_param, $param);
645
    }
646

            
cleanup
Yuki Kimoto authored on 2011-04-02
647
    # Insert statement
micro optimization
Yuki Kimoto authored on 2011-09-30
648
    my $sql;
649
    $sql .= "insert ";
650
    $sql .= "$prefix " if defined $prefix;
651
    $sql .= "into " . $self->_q($table) . " "
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
652
      . $self->values_clause($param, {wrap => $wrap}) . " ";
micro optimization
Yuki Kimoto authored on 2011-09-30
653
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
654
    
655
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
656
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
657
}
658

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
659
sub update_or_insert {
660
    my $self = shift;
661

            
662
    # Arguments
663
    my $param  = shift;
664
    my %args = @_;
665
    my $id = delete $args{id};
666
    my $primary_key = delete $args{primary_key};
667
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
668
    croak "update_or_insert method need primary_key option " .
669
          "when id is specified" . _subname
670
      if defined $id && !defined $primary_key;
671
    my $table  = delete $args{table};
672
    croak qq{"table" option must be specified } . _subname
673
      unless defined $table;
674
    my $select_option = delete $args{select_option};
675
    
676
    my $rows = $self->select(table => $table, id => $id,
677
        primary_key => $primary_key, %$select_option)->all;
678
    
679
    croak "selected row count must be one or zero" . _subname
680
      if @$rows > 1;
681
    
682
    my $row = $rows->[0];
683
    my @options = (table => $table);
684
    push @options, id => $id, primary_key => $primary_key if defined $id;
685
    push @options, %args;
686
    
687
    if ($row) {
688
        return $self->update($param, @options);
689
    }
690
    else {
691
        return $self->insert($param, @options);
692
    }
693
}
694

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
695
sub insert_timestamp {
696
    my $self = shift;
697
    
698
    if (@_) {
699
        $self->{insert_timestamp} = [@_];
700
        
701
        return $self;
702
    }
703
    return $self->{insert_timestamp};
704
}
705

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
706
sub include_model {
707
    my ($self, $name_space, $model_infos) = @_;
708
    
cleanup
Yuki Kimoto authored on 2011-04-02
709
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
710
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
711
    
712
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
713
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
714

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
715
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
716
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
717
          if $name_space =~ /[^\w:]/;
718
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
719
        croak qq{Name space module "$name_space.pm" is needed. $@ }
720
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
721
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
722
        
723
        # Search model modules
724
        my $path = $INC{"$name_space.pm"};
725
        $path =~ s/\.pm$//;
726
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
727
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
728
        $model_infos = [];
729
        while (my $module = readdir $dh) {
730
            push @$model_infos, $module
731
              if $module =~ s/\.pm$//;
732
        }
733
        close $dh;
734
    }
735
    
cleanup
Yuki Kimoto authored on 2011-04-02
736
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
737
    foreach my $model_info (@$model_infos) {
738
        
cleanup
Yuki Kimoto authored on 2011-04-02
739
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
740
        my $model_class;
741
        my $model_name;
742
        my $model_table;
743
        if (ref $model_info eq 'HASH') {
744
            $model_class = $model_info->{class};
745
            $model_name  = $model_info->{name};
746
            $model_table = $model_info->{table};
747
            
748
            $model_name  ||= $model_class;
749
            $model_table ||= $model_name;
750
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
751
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
752
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
753
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
754
          if $mclass =~ /[^\w:]/;
755
        unless ($mclass->can('isa')) {
756
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
757
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
758
        }
759
        
cleanup
Yuki Kimoto authored on 2011-04-02
760
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
761
        my $args = {};
762
        $args->{model_class} = $mclass if $mclass;
763
        $args->{name}        = $model_name if $model_name;
764
        $args->{table}       = $model_table if $model_table;
765
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
766
    }
767
    
768
    return $self;
769
}
770

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
771
sub like_value { sub { "%$_[0]%" } }
772

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
773
sub mapper {
774
    my $self = shift;
775
    return DBIx::Custom::Mapper->new(@_);
776
}
777

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
778
sub merge_param {
779
    my ($self, @params) = @_;
780
    
cleanup
Yuki Kimoto authored on 2011-04-02
781
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
782
    my $merge = {};
783
    foreach my $param (@params) {
784
        foreach my $column (keys %$param) {
785
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
786
            
787
            if (exists $merge->{$column}) {
788
                $merge->{$column} = [$merge->{$column}]
789
                  unless ref $merge->{$column} eq 'ARRAY';
790
                push @{$merge->{$column}},
791
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
792
            }
793
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
794
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
795
            }
796
        }
797
    }
798
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
799
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
800
}
801

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
802
sub model {
803
    my ($self, $name, $model) = @_;
804
    
cleanup
Yuki Kimoto authored on 2011-04-02
805
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
806
    if ($model) {
807
        $self->models->{$name} = $model;
808
        return $self;
809
    }
810
    
811
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
812
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
813
      unless $self->models->{$name};
814
    
cleanup
Yuki Kimoto authored on 2011-04-02
815
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
816
    return $self->models->{$name};
817
}
818

            
cleanup
Yuki Kimoto authored on 2011-03-21
819
sub mycolumn {
820
    my ($self, $table, $columns) = @_;
821
    
cleanup
Yuki Kimoto authored on 2011-04-02
822
    # Create column clause
823
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
824
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
825
    push @column, $self->_q($table) . "." . $self->_q($_) .
826
      " as " . $self->_q($_)
827
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
828
    
829
    return join (', ', @column);
830
}
831

            
added dbi_options attribute
kimoto authored on 2010-12-20
832
sub new {
833
    my $self = shift->SUPER::new(@_);
834
    
cleanup
Yuki Kimoto authored on 2011-04-02
835
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
836
    my @attrs = keys %$self;
837
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
838
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
839
          unless $self->can($attr);
840
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
841

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
842
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
843
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
844
        '?'     => \&DBIx::Custom::Tag::placeholder,
845
        '='     => \&DBIx::Custom::Tag::equal,
846
        '<>'    => \&DBIx::Custom::Tag::not_equal,
847
        '>'     => \&DBIx::Custom::Tag::greater_than,
848
        '<'     => \&DBIx::Custom::Tag::lower_than,
849
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
850
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
851
        'like'  => \&DBIx::Custom::Tag::like,
852
        'in'    => \&DBIx::Custom::Tag::in,
853
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
854
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
855
    };
856
    
857
    return $self;
858
}
859

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
860
sub not_exists { DBIx::Custom::NotExists->singleton }
cleanup
Yuki Kimoto authored on 2011-08-13
861

            
862
sub order {
863
    my $self = shift;
864
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
865
}
866

            
cleanup
yuki-kimoto authored on 2010-10-17
867
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
868
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
869
    
870
    # Register filter
871
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
872
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
873
    
cleanup
Yuki Kimoto authored on 2011-04-02
874
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
875
}
packaging one directory
yuki-kimoto authored on 2009-11-16
876

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
880
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
881
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
882
    my $tables = ref $table eq 'ARRAY' ? $table
883
               : defined $table ? [$table]
884
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
885
    my $columns   = delete $args{column};
886
    my $where     = delete $args{where} || {};
887
    my $append    = delete $args{append};
888
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
889
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
890
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
891
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
892
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
893
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
894
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
895
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
896
      if keys %$param;
897
    my $where_param = delete $args{where_param} || $param || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
898
    my $id = delete $args{id};
899
    my $primary_key = delete $args{primary_key};
900
    croak "update method primary_key option " .
901
          "must be specified when id is specified " . _subname
902
      if defined $id && !defined $primary_key;
903
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
904
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
905
    
cleanup
Yuki Kimoto authored on 2011-03-09
906
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
907
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
908
    
cleanup
Yuki Kimoto authored on 2011-04-02
909
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
910
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
911
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
912
    # Prefix
micro optimization
Yuki Kimoto authored on 2011-09-30
913
    $sql .= "$prefix " if defined $prefix;
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
914
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
915
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
916
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
917
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
918
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
919
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
920
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
921
            }
922
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
923
                if (@$column == 3 && $column->[1] eq 'as') {
924
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
925
                    splice @$column, 1, 1;
926
                }
927
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
928
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
929
            }
cleanup
Yuki Kimoto authored on 2011-04-02
930
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
931
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
932
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
933
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
934
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
935
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
936
    
937
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
938
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-03-30
939
    if ($relation) {
940
        my $found = {};
941
        foreach my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
942
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
943
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
944
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
945
    }
cleanup
Yuki Kimoto authored on 2011-03-30
946
    else {
947
        my $main_table = $tables->[-1] || '';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
948
        $sql .= $self->_q($main_table) . ' ';
cleanup
Yuki Kimoto authored on 2011-03-30
949
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
950
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-04-25
951
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
952
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
953

            
cleanup
Yuki Kimoto authored on 2011-04-02
954
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
955
    unshift @$tables,
956
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
957
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
958
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
959
    my $where_clause = '';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
960
    $where = $self->_create_param_from_id($id, $primary_key, $tables->[-1])
961
      if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
962
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
963
        $where_clause = "where " . $where->[0];
964
        $where_param = $where->[1];
965
    }
966
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
967
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
968
        $where_param = keys %$where_param
969
                     ? $self->merge_param($where_param, $where->param)
970
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
971
        
972
        # String where
973
        $where_clause = $where->to_string;
974
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
975
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
976
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
977
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
978
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
979
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
980
    # Push join
micro optimization
Yuki Kimoto authored on 2011-09-30
981
    $self->_push_join(\$sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
982
    
cleanup
Yuki Kimoto authored on 2011-03-09
983
    # Add where clause
micro optimization
Yuki Kimoto authored on 2011-09-30
984
    $sql .= "$where_clause ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
985
    
cleanup
Yuki Kimoto authored on 2011-03-08
986
    # Relation(DEPRECATED!);
micro optimization
Yuki Kimoto authored on 2011-09-30
987
    $self->_push_relation(\$sql, $tables, $relation, $where_clause eq '' ? 1 : 0)
988
      if $relation;
cleanup
Yuki Kimoto authored on 2011-03-08
989
    
cleanup
Yuki Kimoto authored on 2011-04-02
990
    # Append
micro optimization
Yuki Kimoto authored on 2011-09-30
991
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
992
    
993
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
994
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
995
    
996
    return $result;
997
}
998

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
999
sub setup_model {
1000
    my $self = shift;
1001
    
cleanup
Yuki Kimoto authored on 2011-04-02
1002
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1003
    $self->each_column(
1004
        sub {
1005
            my ($self, $table, $column, $column_info) = @_;
1006
            if (my $model = $self->models->{$table}) {
1007
                push @{$model->columns}, $column;
1008
            }
1009
        }
1010
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1011
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1012
}
1013

            
update pod
Yuki Kimoto authored on 2011-08-10
1014
sub show_datatype {
1015
    my ($self, $table) = @_;
1016
    croak "Table name must be specified" unless defined $table;
1017
    print "$table\n";
1018
    
1019
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1020
    my $sth = $result->sth;
1021

            
1022
    my $columns = $sth->{NAME};
1023
    my $data_types = $sth->{TYPE};
1024
    
1025
    for (my $i = 0; $i < @$columns; $i++) {
1026
        my $column = $columns->[$i];
1027
        my $data_type = $data_types->[$i];
1028
        print "$column: $data_type\n";
1029
    }
1030
}
1031

            
1032
sub show_typename {
1033
    my ($self, $t) = @_;
1034
    croak "Table name must be specified" unless defined $t;
1035
    print "$t\n";
1036
    
1037
    $self->each_column(sub {
1038
        my ($self, $table, $column, $infos) = @_;
1039
        return unless $table eq $t;
1040
        my $typename = $infos->{TYPE_NAME};
1041
        print "$column: $typename\n";
1042
    });
1043
    
1044
    return $self;
1045
}
1046

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1047
sub show_tables {
1048
    my $self = shift;
1049
    
1050
    my %tables;
1051
    $self->each_table(sub { $tables{$_[1]}++ });
1052
    print join("\n", sort keys %tables) . "\n";
1053
    return $self;
1054
}
1055

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1056
sub type_rule {
1057
    my $self = shift;
1058
    
1059
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1060
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1061
        
1062
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1063
        foreach my $i (1 .. 2) {
1064
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1065
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1066
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1067
            $self->{type_rule} = $type_rule;
1068
            $self->{"_$into"} = {};
1069
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1070
                croak qq{type name of $into section must be lower case}
1071
                  if $type_name =~ /[A-Z]/;
1072
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1073
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1074
            $self->each_column(sub {
1075
                my ($dbi, $table, $column, $column_info) = @_;
1076
                
1077
                my $type_name = lc $column_info->{TYPE_NAME};
1078
                if ($type_rule->{$into} &&
1079
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1080
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1081
                    return unless exists $type_rule->{$into}->{$type_name};
1082
                    if  (defined $filter && ref $filter ne 'CODE') 
1083
                    {
1084
                        my $fname = $filter;
1085
                        croak qq{Filter "$fname" is not registered" } . _subname
1086
                          unless exists $self->filters->{$fname};
1087
                        
1088
                        $filter = $self->filters->{$fname};
1089
                    }
1090

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1091
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1092
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1093
                }
1094
            });
1095
        }
1096

            
1097
        # From
1098
        foreach my $i (1 .. 2) {
1099
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1100
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1101
                croak qq{data type of from$i section must be lower case or number}
1102
                  if $data_type =~ /[A-Z]/;
1103
                my $fname = $type_rule->{"from$i"}{$data_type};
1104
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1105
                    croak qq{Filter "$fname" is not registered" } . _subname
1106
                      unless exists $self->filters->{$fname};
1107
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1108
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1109
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1110
            }
1111
        }
1112
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1113
        return $self;
1114
    }
1115
    
1116
    return $self->{type_rule} || {};
1117
}
1118

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1122
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1123
    my $param;
1124
    $param = shift if @_ % 2;
1125
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1126
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1127
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1128
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1129
    my $p = delete $args{param} || {};
1130
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1131
    my $where = delete $args{where} || {};
1132
    my $where_param = delete $args{where_param} || {};
1133
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1134
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1135
    my $id = delete $args{id};
1136
    my $primary_key = delete $args{primary_key};
1137
    croak "update method primary_key option " .
1138
          "must be specified when id is specified " . _subname
1139
      if defined $id && !defined $primary_key;
1140
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1141
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
1142
    my $wrap = delete $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1143
    my $timestamp = $args{timestamp};
1144
    
1145
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1146
    if ($timestamp && (my $update_timestamp = $self->update_timestamp)) {
1147
        my $columns = $update_timestamp->[0];
1148
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1149
        my $value = $update_timestamp->[1];
1150
        $value = $value->() if ref $value eq 'CODE';
1151
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1152
    }
1153

            
cleanup
yuki-kimoto authored on 2010-10-17
1154
    # Update clause
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1155
    my $assign_clause = $self->assign_clause($param, {wrap => $wrap});
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1156

            
1157
    # Where
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1158
    $where = $self->_create_param_from_id($id, $primary_key, $table)
1159
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1160
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1161
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1162
        $where_clause = "where " . $where->[0];
1163
        $where_param = $where->[1];
1164
    }
1165
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1166
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1167
        $where_param = keys %$where_param
1168
                     ? $self->merge_param($where_param, $where->param)
1169
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1170
        
1171
        # String where
1172
        $where_clause = $where->to_string;
1173
    }
1174
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1175
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1176
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1177
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1178
    # Merge param
1179
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1180
    
cleanup
Yuki Kimoto authored on 2011-04-02
1181
    # Update statement
micro optimization
Yuki Kimoto authored on 2011-09-30
1182
    my $sql;
1183
    $sql .= "update ";
1184
    $sql .= "$prefix " if defined $prefix;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1185
    $sql .= $self->_q($table) . " set $assign_clause $where_clause ";
micro optimization
Yuki Kimoto authored on 2011-09-30
1186
    $sql .= $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
1187
    
cleanup
yuki-kimoto authored on 2010-10-17
1188
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1189
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1190
}
1191

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1194
sub update_timestamp {
1195
    my $self = shift;
1196
    
1197
    if (@_) {
1198
        $self->{update_timestamp} = [@_];
1199
        
1200
        return $self;
1201
    }
1202
    return $self->{update_timestamp};
1203
}
1204

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1205
sub values_clause {
1206
    my ($self, $param, $opts) = @_;
1207
    
1208
    my $wrap = $opts->{wrap} || {};
1209
    
1210
    # Create insert parameter tag
1211
    my $safety = $self->safety_character;
1212
    my @columns;
1213
    my @placeholders;
1214
    foreach my $column (sort keys %$param) {
1215
        croak qq{"$column" is not safety column name } . _subname
1216
          unless $column =~ /^[$safety\.]+$/;
1217
        my $column_quote = $self->_q($column);
1218
        $column_quote =~ s/\./$self->_q(".")/e;
1219
        push @columns, $column_quote;
1220
        
1221
        my $func = $wrap->{$column} || sub { $_[0] };
1222
        push @placeholders,
1223
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1224
        : $func->(":$column");
1225
    }
1226
    
1227
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1228
           '(' . join(', ', @placeholders) . ')'
1229
}
1230

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1233
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1234
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1235
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1236
    
updated pod
Yuki Kimoto authored on 2011-06-21
1237
    # Cache
1238
    my $cache = $self->cache;
1239
    
1240
    # Query
1241
    my $query;
1242
    
1243
    # Get cached query
1244
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1245
        
updated pod
Yuki Kimoto authored on 2011-06-21
1246
        # Get query
1247
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1248
        
updated pod
Yuki Kimoto authored on 2011-06-21
1249
        # Create query
1250
        if ($q) {
1251
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1252
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1253
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1254
    }
1255
    
1256
    # Create query
1257
    unless ($query) {
1258

            
1259
        # Create query
1260
        my $builder = $self->query_builder;
1261
        $query = $builder->build_query($source);
1262

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

            
1269
        # Save query to cache
1270
        $self->cache_method->(
1271
            $self, $source,
1272
            {
1273
                sql     => $query->sql, 
1274
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1275
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1276
            }
1277
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1278
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1279

            
1280
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1281
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1282
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1283
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1284
        $query->sql($sql);
1285
    }
1286
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1287
    # Save sql
1288
    $self->last_sql($query->sql);
1289
    
updated pod
Yuki Kimoto authored on 2011-06-21
1290
    # Prepare statement handle
1291
    my $sth;
1292
    eval { $sth = $self->dbh->prepare($query->{sql})};
1293
    
1294
    if ($@) {
1295
        $self->_croak($@, qq{. Following SQL is executed.\n}
1296
                        . qq{$query->{sql}\n} . _subname);
1297
    }
1298
    
1299
    # Set statement handle
1300
    $query->sth($sth);
1301
    
1302
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1303
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1304
    
1305
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1306
}
1307

            
cleanup
Yuki Kimoto authored on 2011-04-02
1308
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1309
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1310
    
cleanup
Yuki Kimoto authored on 2011-04-02
1311
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1312
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1313
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1314
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1315
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1316
        
1317
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1318
        my $value;
1319
        if(ref $params->{$column} eq 'ARRAY') {
1320
            my $i = $count->{$column} || 0;
1321
            $i += $not_exists->{$column} || 0;
1322
            my $found;
1323
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1324
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1325
                    $not_exists->{$column}++;
1326
                }
1327
                else  {
1328
                    $value = $params->{$column}->[$k];
1329
                    $found = 1;
1330
                    last
1331
                }
1332
            }
1333
            next unless $found;
1334
        }
1335
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1336
        
cleanup
Yuki Kimoto authored on 2011-01-12
1337
        # Filter
1338
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1339
        $value = $f->($value) if $f;
1340
        
1341
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1342
        foreach my $i (1 .. 2) {
1343
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1344
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1345
            $value = $tf->($value) if $tf;
1346
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1347
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1348
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1349
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1350
        
1351
        # Count up 
1352
        $count->{$column}++;
1353
    }
1354
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1355
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1356
}
1357

            
cleanup
Yuki Kimoto authored on 2011-06-08
1358
sub _create_param_from_id {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1359
    my ($self, $id, $primary_keys, $table) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1360
    
cleanup
Yuki Kimoto authored on 2011-06-08
1361
    # Create parameter
1362
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1363
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1364
        $id = [$id] unless ref $id;
1365
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1366
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1367
          unless !ref $id || ref $id eq 'ARRAY';
1368
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1369
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1370
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1371
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1372
           my $key = $primary_keys->[$i];
1373
           $key = "$table." . $key if $table;
1374
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1375
        }
1376
    }
1377
    
cleanup
Yuki Kimoto authored on 2011-06-08
1378
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1379
}
1380

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1381
sub _connect {
1382
    my $self = shift;
1383
    
1384
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1385
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1386
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1387
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1388
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1389
    croak qq{"dsn" must be specified } . _subname
1390
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1391
    my $user        = $self->user;
1392
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1393
    my $option = $self->_option;
1394
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1395
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1396
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1397
    my $dbh;
1398
    eval {
1399
        $dbh = DBI->connect(
1400
            $dsn,
1401
            $user,
1402
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1403
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1404
        );
1405
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1406
    
1407
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1408
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1409
    
1410
    return $dbh;
1411
}
1412

            
cleanup
yuki-kimoto authored on 2010-10-17
1413
sub _croak {
1414
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1415
    
1416
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1417
    $append ||= "";
1418
    
1419
    # Verbose
1420
    if ($Carp::Verbose) { croak $error }
1421
    
1422
    # Not verbose
1423
    else {
1424
        
1425
        # Remove line and module infromation
1426
        my $at_pos = rindex($error, ' at ');
1427
        $error = substr($error, 0, $at_pos);
1428
        $error =~ s/\s+$//;
1429
        croak "$error$append";
1430
    }
1431
}
1432

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1435
sub _need_tables {
1436
    my ($self, $tree, $need_tables, $tables) = @_;
1437
    
cleanup
Yuki Kimoto authored on 2011-04-02
1438
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1439
    foreach my $table (@$tables) {
1440
        if ($tree->{$table}) {
1441
            $need_tables->{$table} = 1;
1442
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1443
        }
1444
    }
1445
}
1446

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1447
sub _option {
1448
    my $self = shift;
1449
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1450
    warn "dbi_options is DEPRECATED! use option instead\n"
1451
      if keys %{$self->dbi_options};
1452
    warn "dbi_option is DEPRECATED! use option instead\n"
1453
      if keys %{$self->dbi_option};
1454
    return $option;
1455
}
1456

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1457
sub _push_join {
1458
    my ($self, $sql, $join, $join_tables) = @_;
1459
    
cleanup
Yuki Kimoto authored on 2011-04-02
1460
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1461
    return unless @$join;
1462
    
cleanup
Yuki Kimoto authored on 2011-04-02
1463
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1464
    my $tree = {};
1465
    for (my $i = 0; $i < @$join; $i++) {
1466
        
cleanup
Yuki Kimoto authored on 2011-07-28
1467
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1468
        my $join_clause;;
1469
        my $option;
1470
        if (ref $join->[$i] eq 'HASH') {
1471
            $join_clause = $join->[$i]->{clause};
1472
            $option = {table => $join->[$i]->{table}};
1473
        }
1474
        else {
1475
            $join_clause = $join->[$i];
1476
            $option = {};
1477
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1478

            
1479
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1480
        my $table1;
1481
        my $table2;
1482
        if (my $table = $option->{table}) {
1483
            $table1 = $table->[0];
1484
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1485
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1486
        else {
1487
            my $q = $self->_quote;
1488
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1489
            $j_clause =~ s/'.+?'//g;
1490
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1491
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1492
            
1493
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1494
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1495
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1496
            for my $clause (@j_clauses) {
1497
                if ($clause =~ $join_re) {
1498
                    $table1 = $1;
1499
                    $table2 = $2;
1500
                    last;
1501
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1502
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1503
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1504
        croak qq{join clause must have two table name after "on" keyword. } .
1505
              qq{"$join_clause" is passed }  . _subname
1506
          unless defined $table1 && defined $table2;
1507
        croak qq{right side table of "$join_clause" must be unique }
1508
            . _subname
1509
          if exists $tree->{$table2};
1510
        croak qq{Same table "$table1" is specified} . _subname
1511
          if $table1 eq $table2;
1512
        $tree->{$table2}
1513
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1514
    }
1515
    
cleanup
Yuki Kimoto authored on 2011-04-02
1516
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1517
    my $need_tables = {};
1518
    $self->_need_tables($tree, $need_tables, $join_tables);
1519
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1520
    
1521
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1522
    foreach my $need_table (@need_tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1523
        $$sql .= $tree->{$need_table}{join} . ' ';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1524
    }
1525
}
cleanup
Yuki Kimoto authored on 2011-03-08
1526

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1527
sub _quote {
1528
    my $self = shift;
1529
    
1530
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1531
         : defined $self->quote ? $self->quote
1532
         : '';
1533
}
1534

            
cleanup
Yuki Kimoto authored on 2011-07-29
1535
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1536
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1537
    
1538
    my $quote = $self->_quote;
1539
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1540
    my $p;
1541
    if (defined $quote && length $quote > 1) {
1542
        $p = substr($quote, 1, 1);
1543
    }
1544
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1545
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1546
    if ($quotemeta) {
1547
        $q = quotemeta($q);
1548
        $p = quotemeta($p);
1549
    }
1550
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1551
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1552
}
1553

            
cleanup
Yuki Kimoto authored on 2011-04-02
1554
sub _remove_duplicate_table {
1555
    my ($self, $tables, $main_table) = @_;
1556
    
1557
    # Remove duplicate table
1558
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1559
    delete $tables{$main_table} if $main_table;
1560
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1561
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1562
    if (my $q = $self->_quote) {
1563
        $q = quotemeta($q);
1564
        $_ =~ s/[$q]//g for @$new_tables;
1565
    }
1566

            
1567
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1568
}
1569

            
cleanup
Yuki Kimoto authored on 2011-04-02
1570
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1571
    my ($self, $source) = @_;
1572
    
cleanup
Yuki Kimoto authored on 2011-04-02
1573
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1574
    my $tables = [];
1575
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1576
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1577
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1578
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1579
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1580
    while ($source =~ /$table_re/g) {
1581
        push @$tables, $1;
1582
    }
1583
    
1584
    return $tables;
1585
}
1586

            
cleanup
Yuki Kimoto authored on 2011-04-02
1587
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1588
    my ($self, $where) = @_;
1589
    
cleanup
Yuki Kimoto authored on 2011-04-02
1590
    my $obj;
1591
    
1592
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1593
    if (ref $where eq 'HASH') {
1594
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1595
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1596
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1597
            my $table;
1598
            my $c;
1599
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1600
                $table = $1;
1601
                $c = $2;
1602
            }
1603
            
1604
            my $table_quote;
1605
            $table_quote = $self->_q($table) if defined $table;
1606
            my $column_quote = $self->_q($c);
1607
            $column_quote = $table_quote . '.' . $column_quote
1608
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1609
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1610
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1611
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1612
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1613
    
1614
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1615
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1616
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1617
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1618
    
updated pod
Yuki Kimoto authored on 2011-06-21
1619
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1620
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1621
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1622
            clause => $where->[0],
1623
            param  => $where->[1]
1624
        );
1625
    }
1626
    
cleanup
Yuki Kimoto authored on 2011-04-02
1627
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1628
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1629
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1630
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1631
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1632
    
cleanup
Yuki Kimoto authored on 2011-04-02
1633
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1634
}
1635

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

            
1639
    # Initialize filters
1640
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1641
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1642
    $self->{filter}{out} ||= {};
1643
    $self->{filter}{in} ||= {};
1644
    $self->{filter}{end} ||= {};
1645
    
1646
    # Usage
1647
    my $usage = "Usage: \$dbi->apply_filter(" .
1648
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1649
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1650
    
1651
    # Apply filter
1652
    for (my $i = 0; $i < @cinfos; $i += 2) {
1653
        
1654
        # Column
1655
        my $column = $cinfos[$i];
1656
        if (ref $column eq 'ARRAY') {
1657
            foreach my $c (@$column) {
1658
                push @cinfos, $c, $cinfos[$i + 1];
1659
            }
1660
            next;
1661
        }
1662
        
1663
        # Filter infomation
1664
        my $finfo = $cinfos[$i + 1] || {};
1665
        croak "$usage (table: $table) " . _subname
1666
          unless  ref $finfo eq 'HASH';
1667
        foreach my $ftype (keys %$finfo) {
1668
            croak "$usage (table: $table) " . _subname
1669
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1670
        }
1671
        
1672
        # Set filters
1673
        foreach my $way (qw/in out end/) {
1674
        
1675
            # Filter
1676
            my $filter = $finfo->{$way};
1677
            
1678
            # Filter state
1679
            my $state = !exists $finfo->{$way} ? 'not_exists'
1680
                      : !defined $filter        ? 'not_defined'
1681
                      : ref $filter eq 'CODE'   ? 'code'
1682
                      : 'name';
1683
            
1684
            # Filter is not exists
1685
            next if $state eq 'not_exists';
1686
            
1687
            # Check filter name
1688
            croak qq{Filter "$filter" is not registered } . _subname
1689
              if  $state eq 'name'
1690
               && ! exists $self->filters->{$filter};
1691
            
1692
            # Set filter
1693
            my $f = $state eq 'not_defined' ? undef
1694
                  : $state eq 'code'        ? $filter
1695
                  : $self->filters->{$filter};
1696
            $self->{filter}{$way}{$table}{$column} = $f;
1697
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1698
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1699
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1700
        }
1701
    }
1702
    
1703
    return $self;
1704
}
1705

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1706
# DEPRECATED!
1707
has 'data_source';
1708
has dbi_options => sub { {} };
1709
has filter_check  => 1;
1710
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1711
has dbi_option => sub { {} };
1712
has default_dbi_option => sub {
1713
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1714
    return shift->default_option;
1715
};
1716

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1717
# DEPRECATED!
1718
sub method {
1719
    warn "method is DEPRECATED! use helper instead";
1720
    return shift->helper(@_);
1721
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1722

            
1723
# DEPRECATED!
1724
sub assign_param {
1725
    my $self = shift;
1726
    warn "assing_param is DEPRECATED! use assign_clause instead";
1727
    return $self->assign_clause(@_);
1728
}
1729

            
1730
# DEPRECATED
1731
sub update_param {
1732
    my ($self, $param, $opts) = @_;
1733
    
1734
    warn "update_param is DEPRECATED! use assing_clause instead.";
1735
    
1736
    # Create update parameter tag
1737
    my $tag = $self->assign_clause($param, $opts);
1738
    $tag = "set $tag" unless $opts->{no_set};
1739

            
1740
    return $tag;
1741
}
1742

            
updated pod
Yuki Kimoto authored on 2011-06-21
1743
# DEPRECATED!
1744
sub create_query {
1745
    warn "create_query is DEPRECATED! use query option of each method";
1746
    shift->_create_query(@_);
1747
}
1748

            
cleanup
Yuki Kimoto authored on 2011-06-13
1749
# DEPRECATED!
1750
sub apply_filter {
1751
    my $self = shift;
1752
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1753
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1754
    return $self->_apply_filter(@_);
1755
}
1756

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1764
    # Arguments
1765
    my $primary_keys = delete $args{primary_key};
1766
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1767
    my $where = delete $args{where};
1768
    my $param = delete $args{param};
1769
    
1770
    # Check arguments
1771
    foreach my $name (keys %args) {
1772
        croak qq{"$name" is wrong option } . _subname
1773
          unless $SELECT_AT_ARGS{$name};
1774
    }
1775
    
1776
    # Table
1777
    croak qq{"table" option must be specified } . _subname
1778
      unless $args{table};
1779
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1780
    
1781
    # Create where parameter
1782
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1783
    
1784
    return $self->select(where => $where_param, %args);
1785
}
1786

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

            
1792
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1793
    
1794
    # Arguments
1795
    my $primary_keys = delete $args{primary_key};
1796
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1797
    my $where = delete $args{where};
1798
    
1799
    # Check arguments
1800
    foreach my $name (keys %args) {
1801
        croak qq{"$name" is wrong option } . _subname
1802
          unless $DELETE_AT_ARGS{$name};
1803
    }
1804
    
1805
    # Create where parameter
1806
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1807
    
1808
    return $self->delete(where => $where_param, %args);
1809
}
1810

            
cleanup
Yuki Kimoto authored on 2011-06-08
1811
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1812
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1813
sub update_at {
1814
    my $self = shift;
1815

            
1816
    warn "update_at is DEPRECATED! use update and id option instead";
1817
    
1818
    # Arguments
1819
    my $param;
1820
    $param = shift if @_ % 2;
1821
    my %args = @_;
1822
    my $primary_keys = delete $args{primary_key};
1823
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1824
    my $where = delete $args{where};
1825
    my $p = delete $args{param} || {};
1826
    $param  ||= $p;
1827
    
1828
    # Check arguments
1829
    foreach my $name (keys %args) {
1830
        croak qq{"$name" is wrong option } . _subname
1831
          unless $UPDATE_AT_ARGS{$name};
1832
    }
1833
    
1834
    # Create where parameter
1835
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1836
    
1837
    return $self->update(where => $where_param, param => $param, %args);
1838
}
1839

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1840
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1841
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1842
sub insert_at {
1843
    my $self = shift;
1844
    
1845
    warn "insert_at is DEPRECATED! use insert and id option instead";
1846
    
1847
    # Arguments
1848
    my $param;
1849
    $param = shift if @_ % 2;
1850
    my %args = @_;
1851
    my $primary_key = delete $args{primary_key};
1852
    $primary_key = [$primary_key] unless ref $primary_key;
1853
    my $where = delete $args{where};
1854
    my $p = delete $args{param} || {};
1855
    $param  ||= $p;
1856
    
1857
    # Check arguments
1858
    foreach my $name (keys %args) {
1859
        croak qq{"$name" is wrong option } . _subname
1860
          unless $INSERT_AT_ARGS{$name};
1861
    }
1862
    
1863
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1864
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1865
    $param = $self->merge_param($where_param, $param);
1866
    
1867
    return $self->insert(param => $param, %args);
1868
}
1869

            
added warnings
Yuki Kimoto authored on 2011-06-07
1870
# DEPRECATED!
1871
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1872
    my $self = shift;
1873
    
added warnings
Yuki Kimoto authored on 2011-06-07
1874
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1875
    
1876
    # Merge tag
1877
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1878
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1879
    
1880
    return $self;
1881
}
1882

            
1883
# DEPRECATED!
1884
sub register_tag_processor {
1885
    my $self = shift;
1886
    warn "register_tag_processor is DEPRECATED!";
1887
    # Merge tag
1888
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1889
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1890
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1891
}
1892

            
cleanup
Yuki Kimoto authored on 2011-01-25
1893
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1894
sub default_bind_filter {
1895
    my $self = shift;
1896
    
cleanup
Yuki Kimoto authored on 2011-06-13
1897
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1898
    
cleanup
Yuki Kimoto authored on 2011-01-12
1899
    if (@_) {
1900
        my $fname = $_[0];
1901
        
1902
        if (@_ && !$fname) {
1903
            $self->{default_out_filter} = undef;
1904
        }
1905
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1906
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1907
              unless exists $self->filters->{$fname};
1908
        
1909
            $self->{default_out_filter} = $self->filters->{$fname};
1910
        }
1911
        return $self;
1912
    }
1913
    
1914
    return $self->{default_out_filter};
1915
}
1916

            
cleanup
Yuki Kimoto authored on 2011-01-25
1917
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1918
sub default_fetch_filter {
1919
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1920

            
cleanup
Yuki Kimoto authored on 2011-06-13
1921
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1922
    
1923
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1924
        my $fname = $_[0];
1925

            
cleanup
Yuki Kimoto authored on 2011-01-12
1926
        if (@_ && !$fname) {
1927
            $self->{default_in_filter} = undef;
1928
        }
1929
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1930
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1931
              unless exists $self->filters->{$fname};
1932
        
1933
            $self->{default_in_filter} = $self->filters->{$fname};
1934
        }
1935
        
1936
        return $self;
1937
    }
1938
    
many changed
Yuki Kimoto authored on 2011-01-23
1939
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1940
}
1941

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1942
# DEPRECATED!
1943
sub insert_param {
1944
    my $self = shift;
1945
    warn "insert_param is DEPRECATED! use values_clause instead";
1946
    return $self->values_clause(@_);
1947
}
1948

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1949
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1950
sub insert_param_tag {
1951
    warn "insert_param_tag is DEPRECATED! " .
1952
         "use insert_param instead!";
1953
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1954
}
1955

            
1956
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1957
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1958
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1959
         "use update_param instead";
1960
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1961
}
cleanup
Yuki Kimoto authored on 2011-03-08
1962
# DEPRECATED!
1963
sub _push_relation {
1964
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1965
    
1966
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1967
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1968
        foreach my $rcolumn (keys %$relation) {
1969
            my $table1 = (split (/\./, $rcolumn))[0];
1970
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1971
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1972
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1973
        }
1974
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1975
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1976
}
1977

            
1978
# DEPRECATED!
1979
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1980
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1981
    
1982
    if (keys %{$relation || {}}) {
1983
        foreach my $rcolumn (keys %$relation) {
1984
            my $table1 = (split (/\./, $rcolumn))[0];
1985
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1986
            my $table1_exists;
1987
            my $table2_exists;
1988
            foreach my $table (@$tables) {
1989
                $table1_exists = 1 if $table eq $table1;
1990
                $table2_exists = 1 if $table eq $table2;
1991
            }
1992
            unshift @$tables, $table1 unless $table1_exists;
1993
            unshift @$tables, $table2 unless $table2_exists;
1994
        }
1995
    }
1996
}
1997

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2000
=head1 NAME
2001

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2004
=head1 SYNOPSIS
cleanup
yuki-kimoto authored on 2010-08-05
2005

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2006
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2007
    
2008
    # Connect
2009
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2010
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2011
        user => 'ken',
2012
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2013
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2014
    );
cleanup
yuki-kimoto authored on 2010-08-05
2015

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2016
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2017
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2018
    
2019
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2020
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2021
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2022
    
2023
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2024
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2025

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2030
    # Select, more complex
2031
    my $result = $dbi->select(
2032
        table  => 'book',
2033
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
2034
            {book => [qw/title author/]},
2035
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2036
        ],
2037
        where  => {'book.author' => 'Ken'},
2038
        join => ['left outer join company on book.company_id = company.id'],
2039
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2040
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2041
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2042
    # Fetch
2043
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2044
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2045
    }
2046
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2047
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2048
    while (my $row = $result->fetch_hash) {
2049
        
2050
    }
2051
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2052
    # Execute SQL with parameter.
2053
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2054
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2055
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2056
    );
2057
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2058
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2059

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2075
Named place holder support
2076

            
2077
=item *
2078

            
cleanup
Yuki Kimoto authored on 2011-07-29
2079
Model support
2080

            
2081
=item *
2082

            
2083
Connection manager support
2084

            
2085
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2086

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

            
2091
=item *
2092

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2093
Filtering by data type or column name
cleanup
Yuki Kimoto authored on 2011-07-29
2094

            
2095
=item *
2096

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2097
Create C<order by> clause flexibly
cleanup
Yuki Kimoto authored on 2011-07-29
2098

            
2099
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2100

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2101
=head1 DOCUMENTATION
pod fix
Yuki Kimoto authored on 2011-01-21
2102

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2108
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2109
L<DBIx::Custom::Result>,
2110
L<DBIx::Custom::Query>,
2111
L<DBIx::Custom::Where>,
2112
L<DBIx::Custom::Model>,
2113
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2114

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

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

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

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

            
2125
This is L<DBIx::Connector> example. Please pass
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2126
C<default_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2127

            
2128
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2129
        "dbi:mysql:database=$database",
2130
        $user,
2131
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2132
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2133
    );
2134
    
updated pod
Yuki Kimoto authored on 2011-06-21
2135
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2136

            
cleanup
Yuki Kimoto authored on 2011-08-16
2137
If C<connector> is set to 1 when connect method is called,
2138
L<DBIx::Connector> is automatically set to C<connector>
2139

            
2140
    my $dbi = DBIx::Custom->connect(
2141
      dsn => $dsn, user => $user, password => $password, connector => 1);
2142
    
2143
    my $connector = $dbi->connector; # DBIx::Connector
2144

            
2145
Note that L<DBIx::Connector> must be installed.
2146

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2154
=head2 C<option>
added dbi_options attribute
kimoto authored on 2010-12-20
2155

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2156
    my $option = $dbi->option;
2157
    $dbi = $dbi->option($option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2158

            
updated pod
Yuki Kimoto authored on 2011-06-21
2159
L<DBI> option, used when C<connect> method is executed.
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2160
Each value in option override the value of C<default_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2161

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2162
=head2 C<default_option>
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2163

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2164
    my $default_option = $dbi->default_option;
2165
    $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2166

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2170
    {
2171
        RaiseError => 1,
2172
        PrintError => 0,
2173
        AutoCommit => 1,
2174
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2175

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

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

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

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

            
2185
    my $last_sql = $dbi->last_sql;
2186
    $dbi = $dbi->last_sql($last_sql);
2187

            
2188
Get last successed SQL executed by C<execute> method.
2189

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2197
=head2 C<password>
2198

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

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

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

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

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

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

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

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

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

            
2221
    $dbi->quote('[]');
2222

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2232
    my $safety_character = $dbi->safety_character;
2233
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2234

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2240
    my $separator = $dbi->separator;
2241
    $dbi = $dbi->separator('-');
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2242

            
2243
Separator which join table name and column name.
2244
This have effect to C<column> and C<mycolumn> method,
2245
and C<select> method's column option.
cleanup test
Yuki Kimoto authored on 2011-08-10
2246

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2247
Default to C<.>.
cleanup test
Yuki Kimoto authored on 2011-08-10
2248

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2249
=head2 C<exclude_table>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2250

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2251
    my $exclude_table = $dbi->exclude_table;
2252
    $dbi = $dbi->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2253

            
updated pod
Yuki Kimoto authored on 2011-09-27
2254
Excluded table regex.
2255
C<each_column>, C<each_table>, C<type_rule>,
2256
and C<setup_model> methods ignore matching tables.
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2257

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

            
2260
    my $tag_parse = $dbi->tag_parse(0);
2261
    $dbi = $dbi->tag_parse;
2262

            
2263
Enable DEPRECATED tag parsing functionality, default to 1.
2264
If you want to disable tag parsing functionality, set to 0.
2265

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2273
=head2 C<user_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2274

            
2275
    my $user_column_info = $dbi->user_column_info;
2276
    $dbi = $dbi->user_column_info($user_column_info);
2277

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2278
You can set the date like the following one.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2279

            
2280
    [
2281
        {table => 'book', column => 'title', info => {...}},
2282
        {table => 'author', column => 'name', info => {...}}
2283
    ]
2284

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2285
Usually, you set return value of C<get_column_info>.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2286

            
2287
    my $user_column_info
2288
      = $dbi->get_column_info(exclude_table => qr/^system/);
2289
    $dbi->user_column_info($user_column_info);
2290

            
2291
If C<user_column_info> is set, C<each_column> use C<user_column_info>
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2292
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2293

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2294
=head2 C<user_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2295

            
2296
    my $user_table_info = $dbi->user_table_info;
2297
    $dbi = $dbi->user_table_info($user_table_info);
2298

            
2299
You can set the following data.
2300

            
2301
    [
2302
        {table => 'book', info => {...}},
2303
        {table => 'author', info => {...}}
2304
    ]
2305

            
2306
Usually, you can set return value of C<get_table_info>.
2307

            
2308
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2309
    $dbi->user_table_info($user_table_info);
2310

            
2311
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2312
to find table info.
2313

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2320
=head2 C<available_datatype>
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2321

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2327
=head2 C<available_typename>
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2328

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2334
=head2 C<assign_clause>
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2335

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2336
    my $assign_clause = $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2337

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2338
Create assign clause
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2339

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2342
This is used to create update clause.
2343

            
2344
    "update book set " . $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2345

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

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

            
2350
Create column clause. The follwoing column clause is created.
2351

            
2352
    book.author as "book.author",
2353
    book.title as "book.title"
2354

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2357
    # Separator is hyphen
2358
    $dbi->separator('-');
2359
    
2360
    book.author as "book-author",
2361
    book.title as "book-title"
2362
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2363
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2364

            
update pod
Yuki Kimoto authored on 2011-03-13
2365
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2366
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2367
        user => 'ken',
2368
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2369
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2370
    );
2371

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2378
=head2 C<count>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2379

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2380
    my $count = $dbi->count(table => 'book');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2381

            
2382
Get rows count.
2383

            
2384
Options is same as C<select> method's ones.
2385

            
2386
=head2 C<create_model>
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2387

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2388
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2389
        table => 'book',
2390
        primary_key => 'id',
2391
        join => [
2392
            'inner join company on book.comparny_id = company.id'
2393
        ],
2394
    );
2395

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

            
2399
   $dbi->model('book')->select(...);
2400

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

            
2403
    my $dbh = $dbi->dbh;
2404

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

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2408
=head2 C<delete>
2409

            
2410
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2411

            
2412
Execute delete statement.
2413

            
2414
The following opitons are available.
2415

            
2416
=over 4
2417

            
2418
=item C<append>
2419

            
2420
Same as C<select> method's C<append> option.
2421

            
2422
=item C<filter>
2423

            
2424
Same as C<execute> method's C<filter> option.
2425

            
2426
=item C<id>
2427

            
2428
    id => 4
2429
    id => [4, 5]
2430

            
2431
ID corresponding to C<primary_key>.
2432
You can delete rows by C<id> and C<primary_key>.
2433

            
2434
    $dbi->delete(
2435
        parimary_key => ['id1', 'id2'],
2436
        id => [4, 5],
2437
        table => 'book',
2438
    );
2439

            
2440
The above is same as the followin one.
2441

            
2442
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
2443

            
2444
=item C<prefix>
2445

            
2446
    prefix => 'some'
2447

            
2448
prefix before table name section.
2449

            
2450
    delete some from book
2451

            
2452
=item C<query>
2453

            
2454
Same as C<execute> method's C<query> option.
2455

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2456
=item C<after_build_sql>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2457

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2458
Same as C<execute> method's C<after_build_sql> option.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2459

            
2460
=item C<table>
2461

            
2462
    table => 'book'
2463

            
2464
Table name.
2465

            
2466
=item C<where>
2467

            
2468
Same as C<select> method's C<where> option.
2469

            
2470
=item C<primary_key>
2471

            
2472
See C<id> option.
2473

            
2474
=item C<bind_type>
2475

            
2476
Same as C<execute> method's C<bind_type> option.
2477

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2478
=item C<type_rule_off>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2479

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2482
=item C<type_rule1_off>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2483

            
2484
    type_rule1_off => 1
2485

            
2486
Same as C<execute> method's C<type_rule1_off> option.
2487

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2488
=item C<type_rule2_off>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2489

            
2490
    type_rule2_off => 1
2491

            
2492
Same as C<execute> method's C<type_rule2_off> option.
2493

            
2494
=back
2495

            
2496
=head2 C<delete_all>
2497

            
2498
    $dbi->delete_all(table => $table);
2499

            
2500
Execute delete statement for all rows.
2501
Options is same as C<delete>.
2502

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2503
=head2 C<each_column>
2504

            
2505
    $dbi->each_column(
2506
        sub {
2507
            my ($dbi, $table, $column, $column_info) = @_;
2508
            
2509
            my $type = $column_info->{TYPE_NAME};
2510
            
2511
            if ($type eq 'DATE') {
2512
                # ...
2513
            }
2514
        }
2515
    );
2516

            
improved pod
Yuki Kimoto authored on 2011-10-14
2517
Iterate all column informations in database.
2518
Argument is callback which is executed when one column is found.
2519
Callback receive four arguments. C<DBIx::Custom object>, C<table name>,
2520
C<column name>, and C<column information>.
2521

            
2522
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2523
infromation, you can improve the performance of C<each_column> in
2524
the following way.
2525

            
2526
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
2527
    $dbi->user_column_info($column_info);
2528
    $dbi->each_column(sub { ... });
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2529

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

            
2532
    $dbi->each_table(
2533
        sub {
2534
            my ($dbi, $table, $table_info) = @_;
2535
            
2536
            my $table_name = $table_info->{TABLE_NAME};
2537
        }
2538
    );
2539

            
improved pod
Yuki Kimoto authored on 2011-10-14
2540
Iterate all table informationsfrom in database.
2541
Argument is callback which is executed when one table is found.
2542
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2543
C<table information>.
2544

            
2545
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2546
infromation, you can improve the performance of C<each_table> in
2547
the following way.
2548

            
2549
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
2550
    $dbi->user_table_info($table_info);
2551
    $dbi->each_table(sub { ... });
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2552

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

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

            
2560
    my $result = $dbi->execute(
2561
      "select * from book where title = :book.title and author like :book.author",
2562
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2563
    );
2564

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2571
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2572
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2573
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2574
    select * from book where title = :title and author like :author
2575
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2576
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2577
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2578

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2582
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2583
    select * from book where :title{=} and :author{like}
2584
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2585
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2586
    select * from where title = ? and author like ?;
2587

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

            
2592
    select * from where title = "aa\\:bb";
2593

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

            
2596
=over 4
2597

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

            
2600
Specify database bind data type.
2601

            
2602
    bind_type => [image => DBI::SQL_BLOB]
2603
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2604

            
2605
This is used to bind parameter by C<bind_param> of statment handle.
2606

            
2607
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2608

            
update pod
Yuki Kimoto authored on 2011-03-13
2609
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2610
    
2611
    filter => {
2612
        title  => sub { uc $_[0] }
2613
        author => sub { uc $_[0] }
2614
    }
update pod
Yuki Kimoto authored on 2011-03-13
2615

            
updated pod
Yuki Kimoto authored on 2011-06-09
2616
    # Filter name
2617
    filter => {
2618
        title  => 'upper_case',
2619
        author => 'upper_case'
2620
    }
2621
        
2622
    # At once
2623
    filter => [
2624
        [qw/title author/]  => sub { uc $_[0] }
2625
    ]
2626

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2632
=item C<id>
2633

            
2634
    id => 4
2635
    id => [4, 5]
2636

            
2637
ID corresponding to C<primary_key>.
2638
You can delete rows by C<id> and C<primary_key>.
2639

            
2640
    $dbi->execute(
2641
        "select * from book where id1 = :id1 and id2 = :id2",
2642
        {},
2643
        parimary_key => ['id1', 'id2'],
2644
        id => [4, 5],
2645
    );
2646

            
2647
The above is same as the followin one.
2648

            
2649
    $dbi->execute(
2650
        "select * from book where id1 = :id1 and id2 = :id2",
2651
        {id1 => 4, id2 => 5}
2652
    );
2653

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

            
2656
    query => 1
2657

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

            
2661
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2662
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2663
    my $columns = $query->columns;
2664
    
2665
If you want to execute SQL fast, you can do the following way.
2666

            
2667
    my $query;
2668
    foreach my $row (@$rows) {
2669
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2670
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2671
    }
2672

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

            
2676
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
2677
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2678
    
2679
    my $query;
2680
    my $sth;
2681
    foreach my $row (@$rows) {
2682
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2683
      $sth ||= $query->sth;
2684
      $sth->execute(map { $row->{$_} } sort keys %$row);
2685
    }
2686

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2691
=item C<primary_key>
2692

            
2693
See C<id> option.
2694

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2695
=item C<after_build_sql> 
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2696

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2697
You can filter sql after the sql is build.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2698

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2699
    after_build_sql => $code_ref
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2700

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2701
The following one is one example.
2702

            
2703
    $dbi->select(
2704
        table => 'book',
2705
        column => 'distinct(name)',
2706
        after_build_sql => sub {
2707
            "select count(*) from ($_[0]) as t1"
2708
        }
2709
    );
2710

            
2711
The following SQL is executed.
2712

            
2713
    select count(*) from (select distinct(name) from book) as t1;
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2714

            
updated pod
Yuki Kimoto authored on 2011-06-09
2715
=item C<table>
2716
    
2717
    table => 'author'
2718

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2726
    # Same
2727
    $dbi->execute(
2728
      "select * from book where title = :book.title and author = :book.author",
2729
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2730

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2731
=item C<table_alias>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2732

            
2733
    table_alias => {user => 'hiker'}
2734

            
2735
Table alias. Key is real table name, value is alias table name.
2736
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2737
on alias table name.
2738

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2739
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2740

            
2741
    type_rule_off => 1
2742

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2745
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2746

            
2747
    type_rule1_off => 1
2748

            
2749
Turn C<into1> type rule off.
2750

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2751
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2752

            
2753
    type_rule2_off => 1
2754

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2759
=head2 C<get_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2760

            
improved pod
Yuki Kimoto authored on 2011-10-14
2761
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2762

            
2763
get column infomation except for one which match C<exclude_table> pattern.
2764

            
2765
    [
2766
        {table => 'book', column => 'title', info => {...}},
2767
        {table => 'author', column => 'name' info => {...}}
2768
    ]
2769

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2770
=head2 C<get_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2771

            
improved pod
Yuki Kimoto authored on 2011-10-14
2772
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2773

            
added test
Yuki Kimoto authored on 2011-08-16
2774
get table infomation except for one which match C<exclude> pattern.
2775

            
2776
    [
2777
        {table => 'book', info => {...}},
2778
        {table => 'author', info => {...}}
2779
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2780

            
added test
Yuki Kimoto authored on 2011-08-16
2781
You can set this value to C<user_table_info>.
update pod
Yuki Kimoto authored on 2011-03-13
2782

            
cleanup
yuki-kimoto authored on 2010-10-17
2783
=head2 C<insert>
2784

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

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

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

            
2793
    {date => \"NOW()"}
2794

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

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

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

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

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

            
2805
Same as C<execute> method's C<bind_type> option.
2806

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

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

            
2811
=item C<id>
2812

            
updated document
Yuki Kimoto authored on 2011-06-09
2813
    id => 4
2814
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2815

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2819
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2820
        {title => 'Perl', author => 'Ken'}
2821
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2822
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2823
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2824
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2825

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

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

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

            
2835
    prefix => 'or replace'
2836

            
2837
prefix before table name section
2838

            
2839
    insert or replace into book
2840

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

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

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

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

            
2850
Same as C<execute> method's C<query> option.
2851

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2852
=item C<after_build_sql>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2853

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2854
Same as C<execute> method's C<after_build_sql> option.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2855

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

            
2858
    table => 'book'
2859

            
2860
Table name.
2861

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2862
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2863

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2866
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
2867

            
2868
    timestamp => 1
2869

            
2870
If this value is set to 1,
2871
automatically created timestamp column is set based on
2872
C<timestamp> attribute's C<insert> value.
2873

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2874
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2875

            
2876
    type_rule1_off => 1
2877

            
2878
Same as C<execute> method's C<type_rule1_off> option.
2879

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2880
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2881

            
2882
    type_rule2_off => 1
2883

            
2884
Same as C<execute> method's C<type_rule2_off> option.
2885

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2886
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
2887

            
2888
    wrap => {price => sub { "max($_[0])" }}
2889

            
2890
placeholder wrapped string.
2891

            
2892
If the following statement
2893

            
2894
    $dbi->insert({price => 100}, table => 'book',
2895
      {price => sub { "$_[0] + 5" }});
2896

            
2897
is executed, the following SQL is executed.
2898

            
2899
    insert into book price values ( ? + 5 );
2900

            
update pod
Yuki Kimoto authored on 2011-03-13
2901
=back
2902

            
2903
=over 4
2904

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2912
    lib / MyModel.pm
2913
        / MyModel / book.pm
2914
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2915

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

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

            
2920
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2921
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2922
    
2923
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2924

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2929
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2930
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2931
    
2932
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2933

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2936
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2937
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2938
    
2939
    1;
2940
    
updated pod
Yuki Kimoto authored on 2011-06-21
2941
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2942

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2950
=head2 C<insert_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2951

            
2952
    $dbi->insert_timestamp(
2953
      [qw/created_at updated_at/] => sub { localtime });
2954

            
2955
Parameter for timestamp columns when C<insert> method is executed
2956
with C<timestamp> option.
2957

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2958
If multiple column are specified, same value is used.
2959

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2960
=head2 C<like_value EXPERIMENTAL>
2961

            
2962
    my $like_value = $dbi->like_value
2963

            
2964
Constant code reference for the like value.
2965

            
2966
    sub { "%$_[0]%" }
2967

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2968
=head2 C<mapper>
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2969

            
2970
    my $mapper = $dbi->mapper(param => $param);
2971

            
2972
Create a new L<DBIx::Custom::Mapper> object.
2973

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

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

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

            
2980
    {key1 => [1, 1], key2 => 2}
2981

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
2982
=head2 C<helper>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2983

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
2984
    $dbi->helper(
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2985
        update_or_insert => sub {
2986
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2987
            
2988
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2989
        },
2990
        find_or_create   => sub {
2991
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2992
            
2993
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2994
        }
2995
    );
2996

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
2997
Register helper. These helper is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2998

            
2999
    $dbi->update_or_insert;
3000
    $dbi->find_or_create;
3001

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

            
3004
    my $model = $dbi->model('book');
3005

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
3010
    my $column = $dbi->mycolumn(book => ['author', 'title']);
cleanup
Yuki Kimoto authored on 2011-03-21
3011

            
3012
Create column clause for myself. The follwoing column clause is created.
3013

            
3014
    book.author as author,
3015
    book.title as title
3016

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3019
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
3020
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
3021
        user => 'ken',
3022
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3023
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
3024
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3025

            
3026
Create a new L<DBIx::Custom> object.
3027

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

            
3030
    my $not_exists = $dbi->not_exists;
3031

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3035
=head2 C<order>
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3036

            
3037
    my $order = $dbi->order;
3038

            
3039
Create a new L<DBIx::Custom::Order> object.
3040

            
cleanup
yuki-kimoto authored on 2010-10-17
3041
=head2 C<register_filter>
3042

            
update pod
Yuki Kimoto authored on 2011-03-13
3043
    $dbi->register_filter(
3044
        # Time::Piece object to database DATE format
3045
        tp_to_date => sub {
3046
            my $tp = shift;
3047
            return $tp->strftime('%Y-%m-%d');
3048
        },
3049
        # database DATE format to Time::Piece object
3050
        date_to_tp => sub {
3051
           my $date = shift;
3052
           return Time::Piece->strptime($date, '%Y-%m-%d');
3053
        }
3054
    );
cleanup
yuki-kimoto authored on 2010-10-17
3055
    
update pod
Yuki Kimoto authored on 2011-03-13
3056
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3057

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3058
=head2 C<type_rule>
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3059

            
3060
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3061
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3062
            date => sub { ... },
3063
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3064
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3065
        into2 => {
3066
            date => sub { ... },
3067
            datetime => sub { ... }
3068
        },
3069
        from1 => {
3070
            # DATE
3071
            9 => sub { ... },
3072
            # DATETIME or TIMESTAMP
3073
            11 => sub { ... },
3074
        }
3075
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3076
            # DATE
3077
            9 => sub { ... },
3078
            # DATETIME or TIMESTAMP
3079
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3080
        }
3081
    );
3082

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3098
=over 4
3099

            
3100
=item 1. column name
3101

            
3102
    issue_date
3103
    issue_datetime
3104

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

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

            
3109
    book.issue_date
3110
    book.issue_datetime
3111

            
3112
=back
3113

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

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

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

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

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

            
3126
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3127
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3128
            [qw/DATE DATETIME/] => sub { ... },
3129
        ],
3130
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3131

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3134
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3135
        table  => 'book',
3136
        column => ['author', 'title'],
3137
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3138
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3139
    
updated document
Yuki Kimoto authored on 2011-06-09
3140
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3141

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

            
3144
=over 4
3145

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

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

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

            
3152
=item C<bind_type>
3153

            
3154
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3155
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3156
=item C<column>
3157
    
updated document
Yuki Kimoto authored on 2011-06-09
3158
    column => 'author'
3159
    column => ['author', 'title']
3160

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3169
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3170
        {book => [qw/author title/]},
3171
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3172
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3173

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

            
3176
    book.author as "book.author",
3177
    book.title as "book.title",
3178
    person.name as "person.name",
3179
    person.age as "person.age"
3180

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

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

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

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

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

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

            
3196
=item C<id>
3197

            
3198
    id => 4
3199
    id => [4, 5]
3200

            
3201
ID corresponding to C<primary_key>.
3202
You can select rows by C<id> and C<primary_key>.
3203

            
3204
    $dbi->select(
3205
        parimary_key => ['id1', 'id2'],
3206
        id => [4, 5],
3207
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3208
    );
3209

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3212
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3213
        where => {id1 => 4, id2 => 5},
3214
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3215
    );
3216
    
updated document
Yuki Kimoto authored on 2011-06-09
3217
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3218

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

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

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

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

            
3231
    prefix => 'SQL_CALC_FOUND_ROWS'
3232

            
3233
Prefix of column cluase
3234

            
3235
    select SQL_CALC_FOUND_ROWS title, author from book;
3236

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

            
3239
    join => [
3240
        'left outer join company on book.company_id = company_id',
3241
        'left outer join location on company.location_id = location.id'
3242
    ]
3243
        
3244
Join clause. If column cluase or where clause contain table name like "company.name",
3245
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3246

            
3247
    $dbi->select(
3248
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3249
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3250
        where => {'company.name' => 'Orange'},
3251
        join => [
3252
            'left outer join company on book.company_id = company.id',
3253
            'left outer join location on company.location_id = location.id'
3254
        ]
3255
    );
3256

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3260
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3261
    from book
3262
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3263
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3264

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3265
You can specify two table by yourself. This is useful when join parser can't parse
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3266
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3267

            
3268
    $dbi->select(
3269
        table => 'book',
3270
        column => ['company.location_id as location_id'],
3271
        where => {'company.name' => 'Orange'},
3272
        join => [
3273
            {
3274
                clause => 'left outer join location on company.location_id = location.id',
3275
                table => ['company', 'location']
3276
            }
3277
        ]
3278
    );
3279

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

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

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3291
=item C<after_build_sql>
updated pod
Yuki Kimoto authored on 2011-06-08
3292

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3293
Same as C<execute> method's C<after_build_sql> option
updated pod
Yuki Kimoto authored on 2011-06-08
3294

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3299
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3300

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3301
=item C<type_rule_off>
updated pod
Yuki Kimoto authored on 2011-06-08
3302

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3305
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3306

            
3307
    type_rule1_off => 1
3308

            
3309
Same as C<execute> method's C<type_rule1_off> option.
3310

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3311
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3312

            
3313
    type_rule2_off => 1
3314

            
3315
Same as C<execute> method's C<type_rule2_off> option.
3316

            
updated document
Yuki Kimoto authored on 2011-06-09
3317
=item C<where>
3318
    
3319
    # Hash refrence
3320
    where => {author => 'Ken', 'title' => 'Perl'}
3321
    
3322
    # DBIx::Custom::Where object
3323
    where => $dbi->where(
3324
        clause => ['and', 'author = :author', 'title like :title'],
3325
        param  => {author => 'Ken', title => '%Perl%'}
3326
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3327
    
3328
    # Array reference 1 (array reference, hash referenc). same as above
3329
    where => [
3330
        ['and', 'author = :author', 'title like :title'],
3331
        {author => 'Ken', title => '%Perl%'}
3332
    ];    
3333
    
3334
    # Array reference 2 (String, hash reference)
3335
    where => [
3336
        'title like :title',
3337
        {title => '%Perl%'}
3338
    ]
3339
    
3340
    # String
3341
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3342

            
updated document
Yuki Kimoto authored on 2011-06-09
3343
Where clause.
3344
    
update pod
Yuki Kimoto authored on 2011-03-12
3345
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3346

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

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

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

            
3353
If you want to set constant value to row data, use scalar reference
3354
as parameter value.
3355

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3360
=over 4
3361

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

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

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

            
3368
Same as C<execute> method's C<bind_type> option.
3369

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3376
    id => 4
3377
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3378

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3382
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3383
        {title => 'Perl', author => 'Ken'}
3384
        parimary_key => ['id1', 'id2'],
3385
        id => [4, 5],
3386
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3387
    );
update pod
Yuki Kimoto authored on 2011-03-13
3388

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3391
    $dbi->update(
3392
        {title => 'Perl', author => 'Ken'}
3393
        where => {id1 => 4, id2 => 5},
3394
        table => 'book'
3395
    );
update pod
Yuki Kimoto authored on 2011-03-13
3396

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

            
3399
    prefix => 'or replace'
3400

            
3401
prefix before table name section
3402

            
3403
    update or replace book
3404

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

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

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3416
=item C<after_build_sql>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3417

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3418
Same as C<execute> method's C<after_build_sql> option.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3419

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3426
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
3427

            
3428
    timestamp => 1
3429

            
3430
If this value is set to 1,
3431
automatically updated timestamp column is set based on
3432
C<timestamp> attribute's C<update> value.
3433

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3434
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3435

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3438
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3439

            
3440
    type_rule1_off => 1
3441

            
3442
Same as C<execute> method's C<type_rule1_off> option.
3443

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3444
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3445

            
3446
    type_rule2_off => 1
3447

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

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

            
3452
Same as C<select> method's C<where> option.
3453

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3454
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
3455

            
3456
    wrap => {price => sub { "max($_[0])" }}
3457

            
3458
placeholder wrapped string.
3459

            
3460
If the following statement
3461

            
3462
    $dbi->update({price => 100}, table => 'book',
3463
      {price => sub { "$_[0] + 5" }});
3464

            
3465
is executed, the following SQL is executed.
3466

            
3467
    update book set price =  ? + 5;
3468

            
updated pod
Yuki Kimoto authored on 2011-06-08
3469
=back
update pod
Yuki Kimoto authored on 2011-03-13
3470

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3478
=head2 C<update_or_insert EXPERIMENTAL>
3479
    
3480
    # Where
3481
    $dbi->update_or_insert(
3482
        {id => 1, title => 'Perl'},
3483
        table => 'book',
3484
        where => {id => 1},
3485
        select_option => {append => 'for update'}
3486
    );
3487
    
3488
    # ID
3489
    $dbi->update_or_insert(
3490
        {title => 'Perl'},
3491
        table => 'book',
3492
        id => 1,
3493
        primary_key => 'id',
3494
        select_option => {append => 'for update'}
3495
    );
3496
    
3497
Update or insert.
3498

            
3499
In both examples, the following SQL is executed.
3500

            
3501
    # In case insert
3502
    insert into book (id, title) values (?, ?)
3503
    
3504
    # In case update
3505
    update book set (id = ?, title = ?) where book.id = ?
3506

            
3507
The following opitons are available adding to C<update> option.
3508

            
3509
=over 4
3510

            
3511
=item C<select_option>
3512

            
3513
    select_option => {append => 'for update'}
3514

            
3515
select method option,
3516
select method is used to check the row is already exists.
3517

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3518
=head2 C<update_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3519

            
3520
    $dbi->update_timestamp(updated_at => sub { localtime });
3521

            
3522
Parameter for timestamp columns when C<update> method is executed
3523
with C<timestamp> option.
3524

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

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

            
3532
Create a new L<DBIx::Custom::Where> object.
3533

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3541
=head2 C<show_datatype>
update pod
Yuki Kimoto authored on 2011-08-10
3542

            
3543
    $dbi->show_datatype($table);
3544

            
3545
Show data type of the columns of specified table.
3546

            
3547
    book
3548
    title: 5
3549
    issue_date: 91
3550

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

            
- removed EXPERIMENTAL the f...
Yuki Kimoto authored on 2011-09-12
3553
=head2 C<show_tables>
test cleanup
Yuki Kimoto authored on 2011-08-15
3554

            
3555
    $dbi->show_tables;
3556

            
3557
Show tables.
3558

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3559
=head2 C<show_typename>
update pod
Yuki Kimoto authored on 2011-08-10
3560

            
3561
    $dbi->show_typename($table);
3562

            
3563
Show type name of the columns of specified table.
3564

            
3565
    book
3566
    title: varchar
3567
    issue_date: date
3568

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3571
=head1 ENVIRONMENTAL VARIABLES
3572

            
3573
=head2 C<DBIX_CUSTOM_DEBUG>
3574

            
3575
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3576
executed SQL and bind values are printed to STDERR.
3577

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

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3582
=head1 DEPRECATED FUNCTIONALITY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3583

            
3584
L<DBIx::Custom>
3585

            
3586
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3587
    default_dbi_option # will be removed 2017/1/1
3588
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3589
    data_source # will be removed at 2017/1/1
3590
    dbi_options # will be removed at 2017/1/1
3591
    filter_check # will be removed at 2017/1/1
3592
    reserved_word_quote # will be removed at 2017/1/1
3593
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3594
    
3595
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3596
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3597
    assign_param # will be removed at 2017/1/1
3598
    update_param # will be removed at 2017/1/1
3599
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3600
    create_query # will be removed at 2017/1/1
3601
    apply_filter # will be removed at 2017/1/1
3602
    select_at # will be removed at 2017/1/1
3603
    delete_at # will be removed at 2017/1/1
3604
    update_at # will be removed at 2017/1/1
3605
    insert_at # will be removed at 2017/1/1
3606
    register_tag # will be removed at 2017/1/1
3607
    default_bind_filter # will be removed at 2017/1/1
3608
    default_fetch_filter # will be removed at 2017/1/1
3609
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3610
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3611
    register_tag_processor # will be removed at 2017/1/1
3612
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3613
    
3614
    # Options
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3615
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3616
    select method relation option # will be removed at 2017/1/1
3617
    select method param option # will be removed at 2017/1/1
3618
    select method column option [COLUMN, as => ALIAS] format
3619
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3620
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3621
    
3622
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3623
    execute("select * from {= title}"); # execute method's
3624
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3625
                                        # will be removed at 2017/1/1
3626
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3627

            
3628
L<DBIx::Custom::Model>
3629

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3630
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3631
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3632
    filter # will be removed at 2017/1/1
3633
    name # will be removed at 2017/1/1
3634
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3635

            
3636
L<DBIx::Custom::Query>
3637
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3638
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3639
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3640
    table # will be removed at 2017/1/1
3641
    filters # will be removed at 2017/1/1
3642
    
3643
    # Methods
3644
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3645

            
3646
L<DBIx::Custom::QueryBuilder>
3647
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3648
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3649
    tags # will be removed at 2017/1/1
3650
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3651
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3652
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3653
    register_tag # will be removed at 2017/1/1
3654
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3655
    
3656
    # Others
3657
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3658
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3659

            
3660
L<DBIx::Custom::Result>
3661
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3662
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3663
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3664
    
3665
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3666
    end_filter # will be removed at 2017/1/1
3667
    remove_end_filter # will be removed at 2017/1/1
3668
    remove_filter # will be removed at 2017/1/1
3669
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3670

            
3671
L<DBIx::Custom::Tag>
3672

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3675
=head1 BACKWARDS COMPATIBILITY POLICY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3676

            
3677
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3678
except for attribute method.
3679
You can check all DEPRECATED functionalities by document.
3680
DEPRECATED functionality is removed after five years,
3681
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
3682
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3683

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

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

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

            
3690
C<< <kimoto.yuki at gmail.com> >>
3691

            
3692
L<http://github.com/yuki-kimoto/DBIx-Custom>
3693

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3694
=head1 AUTHOR
3695

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

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

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

            
3702
This program is free software; you can redistribute it and/or modify it
3703
under the same terms as Perl itself.
3704

            
3705
=cut