DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3735 lines | 96.724kb
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 EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
4
our $VERSION = '0.1732';
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<default_option>
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2155

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2156
    my $default_option = $dbi->default_option;
2157
    $dbi = $dbi->default_option($default_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> default option, used when C<connect> method is executed,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2160
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2161

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2162
    {
2163
        RaiseError => 1,
2164
        PrintError => 0,
2165
        AutoCommit => 1,
2166
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2167

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2168
=head2 C<exclude_table>
2169

            
2170
    my $exclude_table = $dbi->exclude_table;
2171
    $dbi = $dbi->exclude_table(qr/pg_/);
2172

            
2173
Excluded table regex.
2174
C<each_column>, C<each_table>, C<type_rule>,
2175
and C<setup_model> methods ignore matching tables.
2176

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

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

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

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

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

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2198
=head2 C<option>
2199

            
2200
    my $option = $dbi->option;
2201
    $dbi = $dbi->option($option);
2202

            
2203
L<DBI> option, used when C<connect> method is executed.
2204
Each value in option override the value of C<default_option>.
2205

            
cleanup
yuki-kimoto authored on 2010-10-17
2206
=head2 C<password>
2207

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

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

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

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

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

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

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

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

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

            
2230
    $dbi->quote('[]');
2231

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2241
    my $safety_character = $dbi->safety_character;
2242
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2243

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

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

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

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2256
Default to C<.>.
cleanup test
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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2783
=head2 C<helper>
2784

            
2785
    $dbi->helper(
2786
        update_or_insert => sub {
2787
            my $self = shift;
2788
            
2789
            # Process
2790
        },
2791
        find_or_create   => sub {
2792
            my $self = shift;
2793
            
2794
            # Process
2795
        }
2796
    );
2797

            
2798
Register helper. These helper is called directly from L<DBIx::Custom> object.
2799

            
2800
    $dbi->update_or_insert;
2801
    $dbi->find_or_create;
2802

            
cleanup
yuki-kimoto authored on 2010-10-17
2803
=head2 C<insert>
2804

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

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

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

            
2813
    {date => \"NOW()"}
2814

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

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

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

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

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

            
2825
Same as C<execute> method's C<bind_type> option.
2826

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

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

            
2831
=item C<id>
2832

            
updated document
Yuki Kimoto authored on 2011-06-09
2833
    id => 4
2834
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2835

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2839
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2840
        {title => 'Perl', author => 'Ken'}
2841
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2842
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2843
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2844
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2845

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

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

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

            
2855
    prefix => 'or replace'
2856

            
2857
prefix before table name section
2858

            
2859
    insert or replace into book
2860

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

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

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

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

            
2870
Same as C<execute> method's C<query> option.
2871

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

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

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

            
2878
    table => 'book'
2879

            
2880
Table name.
2881

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

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

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

            
2888
    timestamp => 1
2889

            
2890
If this value is set to 1,
2891
automatically created timestamp column is set based on
2892
C<timestamp> attribute's C<insert> value.
2893

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

            
2896
    type_rule1_off => 1
2897

            
2898
Same as C<execute> method's C<type_rule1_off> option.
2899

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

            
2902
    type_rule2_off => 1
2903

            
2904
Same as C<execute> method's C<type_rule2_off> option.
2905

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

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

            
2910
placeholder wrapped string.
2911

            
2912
If the following statement
2913

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

            
2917
is executed, the following SQL is executed.
2918

            
2919
    insert into book price values ( ? + 5 );
2920

            
update pod
Yuki Kimoto authored on 2011-03-13
2921
=back
2922

            
2923
=over 4
2924

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2932
    lib / MyModel.pm
2933
        / MyModel / book.pm
2934
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2935

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

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

            
2940
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2941
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2942
    
2943
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2944

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2949
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2950
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2951
    
2952
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2953

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2956
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2957
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2958
    
2959
    1;
2960
    
updated pod
Yuki Kimoto authored on 2011-06-21
2961
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2962

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2972
$dbi->insert_timestamp(
2973
  [qw/created_at updated_at/]
2974
    => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2975
);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2976

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2977
Timestamp value when C<insert> method is executed
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2978
with C<timestamp> option.
2979

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2980
If C<insert_timestamp> is set and C<insert> method is executed
2981
with C<timestamp> option, column C<created_at> and C<update_at>
2982
is automatically set to the value like "2010-10-11 10:12:54".
2983

            
2984
$dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2985

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

            
2988
    my $like_value = $dbi->like_value
2989

            
2990
Constant code reference for the like value.
2991

            
2992
    sub { "%$_[0]%" }
2993

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

            
2996
    my $mapper = $dbi->mapper(param => $param);
2997

            
2998
Create a new L<DBIx::Custom::Mapper> object.
2999

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

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

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

            
3006
    {key1 => [1, 1], key2 => 2}
3007

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

            
3010
    my $model = $dbi->model('book');
3011

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

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

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

            
3018
Create column clause for myself. The follwoing column clause is created.
3019

            
3020
    book.author as author,
3021
    book.title as title
3022

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

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

            
3032
Create a new L<DBIx::Custom> object.
3033

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

            
3036
    my $not_exists = $dbi->not_exists;
3037

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

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

            
3043
    my $order = $dbi->order;
3044

            
3045
Create a new L<DBIx::Custom::Order> object.
3046

            
cleanup
yuki-kimoto authored on 2010-10-17
3047
=head2 C<register_filter>
3048

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3066
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3067
        table  => 'book',
3068
        column => ['author', 'title'],
3069
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3070
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3071
    
updated document
Yuki Kimoto authored on 2011-06-09
3072
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3073

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

            
3076
=over 4
3077

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

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

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

            
3084
=item C<bind_type>
3085

            
3086
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3087
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3088
=item C<column>
3089
    
updated document
Yuki Kimoto authored on 2011-06-09
3090
    column => 'author'
3091
    column => ['author', 'title']
3092

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3101
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3102
        {book => [qw/author title/]},
3103
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3104
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3105

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

            
3108
    book.author as "book.author",
3109
    book.title as "book.title",
3110
    person.name as "person.name",
3111
    person.age as "person.age"
3112

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

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

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

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

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

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

            
3128
=item C<id>
3129

            
3130
    id => 4
3131
    id => [4, 5]
3132

            
3133
ID corresponding to C<primary_key>.
3134
You can select rows by C<id> and C<primary_key>.
3135

            
3136
    $dbi->select(
3137
        parimary_key => ['id1', 'id2'],
3138
        id => [4, 5],
3139
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3140
    );
3141

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3144
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3145
        where => {id1 => 4, id2 => 5},
3146
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3147
    );
3148
    
updated document
Yuki Kimoto authored on 2011-06-09
3149
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3150

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

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

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

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

            
3163
    prefix => 'SQL_CALC_FOUND_ROWS'
3164

            
3165
Prefix of column cluase
3166

            
3167
    select SQL_CALC_FOUND_ROWS title, author from book;
3168

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

            
3171
    join => [
3172
        'left outer join company on book.company_id = company_id',
3173
        'left outer join location on company.location_id = location.id'
3174
    ]
3175
        
3176
Join clause. If column cluase or where clause contain table name like "company.name",
3177
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3178

            
3179
    $dbi->select(
3180
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3181
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3182
        where => {'company.name' => 'Orange'},
3183
        join => [
3184
            'left outer join company on book.company_id = company.id',
3185
            'left outer join location on company.location_id = location.id'
3186
        ]
3187
    );
3188

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3192
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3193
    from book
3194
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3195
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3196

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3197
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
3198
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3199

            
3200
    $dbi->select(
3201
        table => 'book',
3202
        column => ['company.location_id as location_id'],
3203
        where => {'company.name' => 'Orange'},
3204
        join => [
3205
            {
3206
                clause => 'left outer join location on company.location_id = location.id',
3207
                table => ['company', 'location']
3208
            }
3209
        ]
3210
    );
3211

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3231
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3232

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

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

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

            
3239
    type_rule1_off => 1
3240

            
3241
Same as C<execute> method's C<type_rule1_off> option.
3242

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

            
3245
    type_rule2_off => 1
3246

            
3247
Same as C<execute> method's C<type_rule2_off> option.
3248

            
updated document
Yuki Kimoto authored on 2011-06-09
3249
=item C<where>
3250
    
3251
    # Hash refrence
3252
    where => {author => 'Ken', 'title' => 'Perl'}
3253
    
3254
    # DBIx::Custom::Where object
3255
    where => $dbi->where(
3256
        clause => ['and', 'author = :author', 'title like :title'],
3257
        param  => {author => 'Ken', title => '%Perl%'}
3258
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3259
    
3260
    # Array reference 1 (array reference, hash referenc). same as above
3261
    where => [
3262
        ['and', 'author = :author', 'title like :title'],
3263
        {author => 'Ken', title => '%Perl%'}
3264
    ];    
3265
    
3266
    # Array reference 2 (String, hash reference)
3267
    where => [
3268
        'title like :title',
3269
        {title => '%Perl%'}
3270
    ]
3271
    
3272
    # String
3273
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3274

            
updated document
Yuki Kimoto authored on 2011-06-09
3275
Where clause.
3276
    
update pod
Yuki Kimoto authored on 2011-03-12
3277
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3278

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3279
=head2 C<setup_model>
3280

            
3281
    $dbi->setup_model;
3282

            
3283
Setup all model objects.
3284
C<columns> of model object is automatically set, parsing database information.
3285

            
3286
=head2 C<type_rule>
3287

            
3288
    $dbi->type_rule(
3289
        into1 => {
3290
            date => sub { ... },
3291
            datetime => sub { ... }
3292
        },
3293
        into2 => {
3294
            date => sub { ... },
3295
            datetime => sub { ... }
3296
        },
3297
        from1 => {
3298
            # DATE
3299
            9 => sub { ... },
3300
            # DATETIME or TIMESTAMP
3301
            11 => sub { ... },
3302
        }
3303
        from2 => {
3304
            # DATE
3305
            9 => sub { ... },
3306
            # DATETIME or TIMESTAMP
3307
            11 => sub { ... },
3308
        }
3309
    );
3310

            
3311
Filtering rule when data is send into and get from database.
3312
This has a little complex problem.
3313

            
3314
In C<into1> and C<into2> you can specify
3315
type name as same as type name defined
3316
by create table, such as C<DATETIME> or C<DATE>.
3317

            
3318
Note that type name and data type don't contain upper case.
3319
If these contain upper case charactor, you convert it to lower case.
3320

            
3321
C<into2> is executed after C<into1>.
3322

            
3323
Type rule of C<into1> and C<into2> is enabled on the following
3324
column name.
3325

            
3326
=over 4
3327

            
3328
=item 1. column name
3329

            
3330
    issue_date
3331
    issue_datetime
3332

            
3333
This need C<table> option in each method.
3334

            
3335
=item 2. table name and column name, separator is dot
3336

            
3337
    book.issue_date
3338
    book.issue_datetime
3339

            
3340
=back
3341

            
3342
You get all type name used in database by C<available_typename>.
3343

            
3344
    print $dbi->available_typename;
3345

            
3346
In C<from1> and C<from2> you specify data type, not type name.
3347
C<from2> is executed after C<from1>.
3348
You get all data type by C<available_datatype>.
3349

            
3350
    print $dbi->available_datatype;
3351

            
3352
You can also specify multiple types at once.
3353

            
3354
    $dbi->type_rule(
3355
        into1 => [
3356
            [qw/DATE DATETIME/] => sub { ... },
3357
        ],
3358
    );
3359

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

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

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

            
3366
If you want to set constant value to row data, use scalar reference
3367
as parameter value.
3368

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3373
=over 4
3374

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

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

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

            
3381
Same as C<execute> method's C<bind_type> option.
3382

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3389
    id => 4
3390
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3391

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3395
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3396
        {title => 'Perl', author => 'Ken'}
3397
        parimary_key => ['id1', 'id2'],
3398
        id => [4, 5],
3399
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3400
    );
update pod
Yuki Kimoto authored on 2011-03-13
3401

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3404
    $dbi->update(
3405
        {title => 'Perl', author => 'Ken'}
3406
        where => {id1 => 4, id2 => 5},
3407
        table => 'book'
3408
    );
update pod
Yuki Kimoto authored on 2011-03-13
3409

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

            
3412
    prefix => 'or replace'
3413

            
3414
prefix before table name section
3415

            
3416
    update or replace book
3417

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

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

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

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

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

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

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

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

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

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

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

            
3441
    timestamp => 1
3442

            
3443
If this value is set to 1,
3444
automatically updated timestamp column is set based on
3445
C<timestamp> attribute's C<update> value.
3446

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

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

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

            
3453
    type_rule1_off => 1
3454

            
3455
Same as C<execute> method's C<type_rule1_off> option.
3456

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

            
3459
    type_rule2_off => 1
3460

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

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

            
3465
Same as C<select> method's C<where> option.
3466

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

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

            
3471
placeholder wrapped string.
3472

            
3473
If the following statement
3474

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

            
3478
is executed, the following SQL is executed.
3479

            
3480
    update book set price =  ? + 5;
3481

            
updated pod
Yuki Kimoto authored on 2011-06-08
3482
=back
update pod
Yuki Kimoto authored on 2011-03-13
3483

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3484

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3492
=head2 C<update_or_insert EXPERIMENTAL>
3493
    
3494
    # Where
3495
    $dbi->update_or_insert(
3496
        {id => 1, title => 'Perl'},
3497
        table => 'book',
3498
        where => {id => 1},
3499
        select_option => {append => 'for update'}
3500
    );
3501
    
3502
    # ID
3503
    $dbi->update_or_insert(
3504
        {title => 'Perl'},
3505
        table => 'book',
3506
        id => 1,
3507
        primary_key => 'id',
3508
        select_option => {append => 'for update'}
3509
    );
3510
    
3511
Update or insert.
3512

            
3513
In both examples, the following SQL is executed.
3514

            
3515
    # In case insert
3516
    insert into book (id, title) values (?, ?)
3517
    
3518
    # In case update
3519
    update book set (id = ?, title = ?) where book.id = ?
3520

            
3521
The following opitons are available adding to C<update> option.
3522

            
3523
=over 4
3524

            
3525
=item C<select_option>
3526

            
3527
    select_option => {append => 'for update'}
3528

            
3529
select method option,
3530
select method is used to check the row is already exists.
3531

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3534
    $dbi->update_timestamp(
3535
      updated_at
3536
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
cleanup
Yuki Kimoto authored on 2011-03-09
3537
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3538

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3539
Timestamp value when C<update> method is executed
3540
with C<timestamp> option.
cleanup
Yuki Kimoto authored on 2011-01-12
3541

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3542
If C<insert_timestamp> is set and C<insert> method is executed
3543
with C<timestamp> option, column C<update_at>
3544
is automatically set to the value like "2010-10-11 10:12:54".
cleanup
Yuki Kimoto authored on 2011-01-12
3545

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3546
>|perl|
3547
$dbi->update($param, table => 'book', timestamp => 1);
3548
||<
cleanup
Yuki Kimoto authored on 2011-01-12
3549

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

            
3552
    $dbi->show_datatype($table);
3553

            
3554
Show data type of the columns of specified table.
3555

            
3556
    book
3557
    title: 5
3558
    issue_date: 91
3559

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

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

            
3564
    $dbi->show_tables;
3565

            
3566
Show tables.
3567

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

            
3570
    $dbi->show_typename($table);
3571

            
3572
Show type name of the columns of specified table.
3573

            
3574
    book
3575
    title: varchar
3576
    issue_date: date
3577

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3580
=head2 C<values_clause>
3581

            
3582
    my $values_clause = $dbi->values_clause({title => 'a', age => 2});
3583

            
3584
Create values clause.
3585

            
3586
    (title, author) values (title = :title, age = :age);
3587

            
3588
You can use this in insert statement.
3589

            
3590
    my $insert_sql = "insert into book $values_clause";
3591

            
3592
=head2 C<where>
3593

            
3594
    my $where = $dbi->where(
3595
        clause => ['and', 'title = :title', 'author = :author'],
3596
        param => {title => 'Perl', author => 'Ken'}
3597
    );
3598

            
3599
Create a new L<DBIx::Custom::Where> object.
3600

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

            
3603
=head2 C<DBIX_CUSTOM_DEBUG>
3604

            
3605
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3606
executed SQL and bind values are printed to STDERR.
3607

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

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

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

            
3614
L<DBIx::Custom>
3615

            
3616
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3617
    default_dbi_option # will be removed 2017/1/1
3618
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3619
    data_source # will be removed at 2017/1/1
3620
    dbi_options # will be removed at 2017/1/1
3621
    filter_check # will be removed at 2017/1/1
3622
    reserved_word_quote # will be removed at 2017/1/1
3623
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3624
    
3625
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3626
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3627
    assign_param # will be removed at 2017/1/1
3628
    update_param # will be removed at 2017/1/1
3629
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3630
    create_query # will be removed at 2017/1/1
3631
    apply_filter # will be removed at 2017/1/1
3632
    select_at # will be removed at 2017/1/1
3633
    delete_at # will be removed at 2017/1/1
3634
    update_at # will be removed at 2017/1/1
3635
    insert_at # will be removed at 2017/1/1
3636
    register_tag # will be removed at 2017/1/1
3637
    default_bind_filter # will be removed at 2017/1/1
3638
    default_fetch_filter # will be removed at 2017/1/1
3639
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3640
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3641
    register_tag_processor # will be removed at 2017/1/1
3642
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3643
    
3644
    # Options
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3645
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3646
    select method relation option # will be removed at 2017/1/1
3647
    select method param option # will be removed at 2017/1/1
3648
    select method column option [COLUMN, as => ALIAS] format
3649
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3650
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3651
    
3652
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3653
    execute("select * from {= title}"); # execute method's
3654
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3655
                                        # will be removed at 2017/1/1
3656
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3657

            
3658
L<DBIx::Custom::Model>
3659

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3660
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3661
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3662
    filter # will be removed at 2017/1/1
3663
    name # will be removed at 2017/1/1
3664
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3665

            
3666
L<DBIx::Custom::Query>
3667
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3668
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3669
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3670
    table # will be removed at 2017/1/1
3671
    filters # will be removed at 2017/1/1
3672
    
3673
    # Methods
3674
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3675

            
3676
L<DBIx::Custom::QueryBuilder>
3677
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3678
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3679
    tags # will be removed at 2017/1/1
3680
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3681
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3682
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3683
    register_tag # will be removed at 2017/1/1
3684
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3685
    
3686
    # Others
3687
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3688
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3689

            
3690
L<DBIx::Custom::Result>
3691
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3692
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3693
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3694
    
3695
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3696
    end_filter # will be removed at 2017/1/1
3697
    remove_end_filter # will be removed at 2017/1/1
3698
    remove_filter # will be removed at 2017/1/1
3699
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3700

            
3701
L<DBIx::Custom::Tag>
3702

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

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

            
3707
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3708
except for attribute method.
3709
You can check all DEPRECATED functionalities by document.
3710
DEPRECATED functionality is removed after five years,
3711
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
3712
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3713

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

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

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

            
3720
C<< <kimoto.yuki at gmail.com> >>
3721

            
3722
L<http://github.com/yuki-kimoto/DBIx-Custom>
3723

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3724
=head1 AUTHOR
3725

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

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

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

            
3732
This program is free software; you can redistribute it and/or modify it
3733
under the same terms as Perl itself.
3734

            
3735
=cut