DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3587 lines | 94.154kb
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 $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
241
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
242
    my $id = delete $args{id};
243
    my $primary_key = delete $args{primary_key};
244
    croak "update method primary_key option " .
245
          "must be specified when id is specified " . _subname
246
      if defined $id && !defined $primary_key;
247
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
248
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
249
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250
    # Where
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
251
    $where = $self->_create_param_from_id($id, $primary_key, $table)
252
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
253
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
254
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
255
        $where_clause = "where " . $where->[0];
256
        $where_param = $where->[1];
257
    }
258
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
259
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
260
        $where_param = keys %$where_param
261
                     ? $self->merge_param($where_param, $where->param)
262
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
263
        
264
        # String where
265
        $where_clause = $where->to_string;
266
    }
267
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
268
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
269
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
270

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

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

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

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

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

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

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

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

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

            
378
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
379
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-10-20
380
    my $sql = shift;
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
381
    my $param;
382
    $param = shift if @_ % 2;
383
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
384
    
cleanup
Yuki Kimoto authored on 2011-04-02
385
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
386
    my $p = delete $args{param} || {};
387
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
388
    my $tables = delete $args{table} || [];
389
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
390
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
391
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
392
    my $bind_type = delete $args{bind_type} || delete $args{type};
393
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
394
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
395
    my $type_rule_off_parts = {
396
        1 => delete $args{type_rule1_off},
397
        2 => delete $args{type_rule2_off}
398
    };
cleanup
Yuki Kimoto authored on 2011-06-09
399
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
400
    my $table_alias = delete $args{table_alias} || {};
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
401
    my $after_build_sql = $args{after_build_sql} || $args{sqlfilter};
402
    warn "sqlfilter option is DEPRECATED" if $args{sqlfilter};
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
403
    my $id = delete $args{id};
404
    my $primary_key = delete $args{primary_key};
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
405
    croak "execute method primary_key option " .
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
406
          "must be specified when id is specified " . _subname
407
      if defined $id && !defined $primary_key;
408
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-20
409
    my $append = delete $args{append};
cleanup
Yuki Kimoto authored on 2011-10-20
410
    $sql .= $append if defined $append && !ref $sql;
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
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
    
cleanup
Yuki Kimoto authored on 2011-10-20
418
    my $query
419
      = ref $sql ? $sql : $self->_create_query($sql, $after_build_sql);
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
420
    
421
    # Save query
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;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
620
    my $id = delete $args{id};
621
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
622
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
623
          "must be specified when id is specified " . _subname
624
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
625
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
626
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
627
    my $wrap = delete $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
628
    my $timestamp = $args{timestamp};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
629
    delete $args{where};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
630
    
631
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
632
    if ($timestamp && (my $insert_timestamp = $self->insert_timestamp)) {
633
        my $columns = $insert_timestamp->[0];
634
        $columns = [$columns] unless ref $columns eq 'ARRAY';
635
        my $value = $insert_timestamp->[1];
636
        $value = $value->() if ref $value eq 'CODE';
637
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
638
    }
cleanup
Yuki Kimoto authored on 2011-04-02
639

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-08-10
1008
sub show_datatype {
1009
    my ($self, $table) = @_;
1010
    croak "Table name must be specified" unless defined $table;
1011
    print "$table\n";
1012
    
1013
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1014
    my $sth = $result->sth;
1015

            
1016
    my $columns = $sth->{NAME};
1017
    my $data_types = $sth->{TYPE};
1018
    
1019
    for (my $i = 0; $i < @$columns; $i++) {
1020
        my $column = $columns->[$i];
1021
        my $data_type = $data_types->[$i];
1022
        print "$column: $data_type\n";
1023
    }
1024
}
1025

            
1026
sub show_typename {
1027
    my ($self, $t) = @_;
1028
    croak "Table name must be specified" unless defined $t;
1029
    print "$t\n";
1030
    
1031
    $self->each_column(sub {
1032
        my ($self, $table, $column, $infos) = @_;
1033
        return unless $table eq $t;
1034
        my $typename = $infos->{TYPE_NAME};
1035
        print "$column: $typename\n";
1036
    });
1037
    
1038
    return $self;
1039
}
1040

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1041
sub show_tables {
1042
    my $self = shift;
1043
    
1044
    my %tables;
1045
    $self->each_table(sub { $tables{$_[1]}++ });
1046
    print join("\n", sort keys %tables) . "\n";
1047
    return $self;
1048
}
1049

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1085
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1086
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1087
                }
1088
            });
1089
        }
1090

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1186
sub update_timestamp {
1187
    my $self = shift;
1188
    
1189
    if (@_) {
1190
        $self->{update_timestamp} = [@_];
1191
        
1192
        return $self;
1193
    }
1194
    return $self->{update_timestamp};
1195
}
1196

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

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

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

            
1251
        # Create query
1252
        my $builder = $self->query_builder;
1253
        $query = $builder->build_query($source);
1254

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

            
1261
        # Save query to cache
1262
        $self->cache_method->(
1263
            $self, $source,
1264
            {
1265
                sql     => $query->sql, 
1266
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1267
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1268
            }
1269
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1270
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1271

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1427
sub _need_tables {
1428
    my ($self, $tree, $need_tables, $tables) = @_;
1429
    
cleanup
Yuki Kimoto authored on 2011-04-02
1430
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1431
    foreach my $table (@$tables) {
1432
        if ($tree->{$table}) {
1433
            $need_tables->{$table} = 1;
1434
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1435
        }
1436
    }
1437
}
1438

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1439
sub _option {
1440
    my $self = shift;
1441
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1442
    warn "dbi_options is DEPRECATED! use option instead\n"
1443
      if keys %{$self->dbi_options};
1444
    warn "dbi_option is DEPRECATED! use option instead\n"
1445
      if keys %{$self->dbi_option};
1446
    return $option;
1447
}
1448

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1519
sub _quote {
1520
    my $self = shift;
1521
    
1522
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1523
         : defined $self->quote ? $self->quote
1524
         : '';
1525
}
1526

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1546
sub _remove_duplicate_table {
1547
    my ($self, $tables, $main_table) = @_;
1548
    
1549
    # Remove duplicate table
1550
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1551
    delete $tables{$main_table} if $main_table;
1552
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1553
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1554
    if (my $q = $self->_quote) {
1555
        $q = quotemeta($q);
1556
        $_ =~ s/[$q]//g for @$new_tables;
1557
    }
1558

            
1559
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1560
}
1561

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1698
# DEPRECATED!
1699
has 'data_source';
1700
has dbi_options => sub { {} };
1701
has filter_check  => 1;
1702
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1703
has dbi_option => sub { {} };
1704
has default_dbi_option => sub {
1705
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1706
    return shift->default_option;
1707
};
1708

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1709
# DEPRECATED!
1710
sub method {
1711
    warn "method is DEPRECATED! use helper instead";
1712
    return shift->helper(@_);
1713
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1714

            
1715
# DEPRECATED!
1716
sub assign_param {
1717
    my $self = shift;
1718
    warn "assing_param is DEPRECATED! use assign_clause instead";
1719
    return $self->assign_clause(@_);
1720
}
1721

            
1722
# DEPRECATED
1723
sub update_param {
1724
    my ($self, $param, $opts) = @_;
1725
    
1726
    warn "update_param is DEPRECATED! use assing_clause instead.";
1727
    
1728
    # Create update parameter tag
1729
    my $tag = $self->assign_clause($param, $opts);
1730
    $tag = "set $tag" unless $opts->{no_set};
1731

            
1732
    return $tag;
1733
}
1734

            
updated pod
Yuki Kimoto authored on 2011-06-21
1735
# DEPRECATED!
1736
sub create_query {
1737
    warn "create_query is DEPRECATED! use query option of each method";
1738
    shift->_create_query(@_);
1739
}
1740

            
cleanup
Yuki Kimoto authored on 2011-06-13
1741
# DEPRECATED!
1742
sub apply_filter {
1743
    my $self = shift;
1744
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1745
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1746
    return $self->_apply_filter(@_);
1747
}
1748

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1803
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1804
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1805
sub update_at {
1806
    my $self = shift;
1807

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1862
# DEPRECATED!
1863
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1864
    my $self = shift;
1865
    
added warnings
Yuki Kimoto authored on 2011-06-07
1866
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1867
    
1868
    # Merge tag
1869
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1870
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1871
    
1872
    return $self;
1873
}
1874

            
1875
# DEPRECATED!
1876
sub register_tag_processor {
1877
    my $self = shift;
1878
    warn "register_tag_processor is DEPRECATED!";
1879
    # Merge tag
1880
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1881
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1882
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1883
}
1884

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1909
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1910
sub default_fetch_filter {
1911
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1912

            
cleanup
Yuki Kimoto authored on 2011-06-13
1913
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1914
    
1915
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1916
        my $fname = $_[0];
1917

            
cleanup
Yuki Kimoto authored on 2011-01-12
1918
        if (@_ && !$fname) {
1919
            $self->{default_in_filter} = undef;
1920
        }
1921
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1922
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1923
              unless exists $self->filters->{$fname};
1924
        
1925
            $self->{default_in_filter} = $self->filters->{$fname};
1926
        }
1927
        
1928
        return $self;
1929
    }
1930
    
many changed
Yuki Kimoto authored on 2011-01-23
1931
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1932
}
1933

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1934
# DEPRECATED!
1935
sub insert_param {
1936
    my $self = shift;
1937
    warn "insert_param is DEPRECATED! use values_clause instead";
1938
    return $self->values_clause(@_);
1939
}
1940

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1941
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1942
sub insert_param_tag {
1943
    warn "insert_param_tag is DEPRECATED! " .
1944
         "use insert_param instead!";
1945
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1946
}
1947

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1992
=head1 NAME
1993

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2008
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2009
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2010
    
2011
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2012
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2013
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2014
    
2015
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2016
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2017

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
2063
Create C<where> clause flexibly
- 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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2067
Named place holder support
2068

            
2069
=item *
2070

            
cleanup
Yuki Kimoto authored on 2011-07-29
2071
Model support
2072

            
2073
=item *
2074

            
2075
Connection manager support
2076

            
2077
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2078

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

            
2083
=item *
2084

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

            
2087
=item *
2088

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

            
2091
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2092

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2100
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2101
L<DBIx::Custom::Result>,
2102
L<DBIx::Custom::Query>,
2103
L<DBIx::Custom::Where>,
2104
L<DBIx::Custom::Model>,
2105
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2106

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

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

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

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

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

            
2120
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2121
        "dbi:mysql:database=$database",
2122
        $user,
2123
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2124
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2125
    );
2126
    
updated pod
Yuki Kimoto authored on 2011-06-21
2127
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2128

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

            
2132
    my $dbi = DBIx::Custom->connect(
2133
      dsn => $dsn, user => $user, password => $password, connector => 1);
2134
    
2135
    my $connector = $dbi->connector; # DBIx::Connector
2136

            
2137
Note that L<DBIx::Connector> must be installed.
2138

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2154
    {
2155
        RaiseError => 1,
2156
        PrintError => 0,
2157
        AutoCommit => 1,
2158
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2159

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

            
2162
    my $exclude_table = $dbi->exclude_table;
2163
    $dbi = $dbi->exclude_table(qr/pg_/);
2164

            
2165
Excluded table regex.
2166
C<each_column>, C<each_table>, C<type_rule>,
2167
and C<setup_model> methods ignore matching tables.
2168

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

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

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

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

            
2178
    my $last_sql = $dbi->last_sql;
2179
    $dbi = $dbi->last_sql($last_sql);
2180

            
2181
Get last successed SQL executed by C<execute> method.
2182

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

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

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

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

            
2192
    my $option = $dbi->option;
2193
    $dbi = $dbi->option($option);
2194

            
2195
L<DBI> option, used when C<connect> method is executed.
2196
Each value in option override the value of C<default_option>.
2197

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2252
    my $tag_parse = $dbi->tag_parse(0);
2253
    $dbi = $dbi->tag_parse;
2254

            
2255
Enable DEPRECATED tag parsing functionality, default to 1.
2256
If you want to disable tag parsing functionality, set to 0.
2257

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

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

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

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

            
2267
    my $user_column_info = $dbi->user_column_info;
2268
    $dbi = $dbi->user_column_info($user_column_info);
2269

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

            
2272
    [
2273
        {table => 'book', column => 'title', info => {...}},
2274
        {table => 'author', column => 'name', info => {...}}
2275
    ]
2276

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

            
2279
    my $user_column_info
2280
      = $dbi->get_column_info(exclude_table => qr/^system/);
2281
    $dbi->user_column_info($user_column_info);
2282

            
2283
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
2284
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2285

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

            
2288
    my $user_table_info = $dbi->user_table_info;
2289
    $dbi = $dbi->user_table_info($user_table_info);
2290

            
2291
You can set the following data.
2292

            
2293
    [
2294
        {table => 'book', info => {...}},
2295
        {table => 'author', info => {...}}
2296
    ]
2297

            
2298
Usually, you can set return value of C<get_table_info>.
2299

            
2300
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2301
    $dbi->user_table_info($user_table_info);
2302

            
2303
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2304
to find table info.
2305

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2342
Create column clause. The follwoing column clause is created.
2343

            
2344
    book.author as "book.author",
2345
    book.title as "book.title"
2346

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2349
    # Separator is hyphen
2350
    $dbi->separator('-');
2351
    
2352
    book.author as "book-author",
2353
    book.title as "book-title"
2354
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2355
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2356

            
update pod
Yuki Kimoto authored on 2011-03-13
2357
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2358
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2359
        user => 'ken',
2360
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2361
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2362
    );
2363

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

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

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

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

            
2374
Get rows count.
2375

            
2376
Options is same as C<select> method's ones.
2377

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2380
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2381
        table => 'book',
2382
        primary_key => 'id',
2383
        join => [
2384
            'inner join company on book.comparny_id = company.id'
2385
        ],
2386
    );
2387

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

            
2391
   $dbi->model('book')->select(...);
2392

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

            
2395
    my $dbh = $dbi->dbh;
2396

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

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

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

            
2404
Execute delete statement.
2405

            
2406
The following opitons are available.
2407

            
cleanup
Yuki Kimoto authored on 2011-10-20
2408
B<OPTIONS>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2409

            
cleanup
Yuki Kimoto authored on 2011-10-20
2410
C<delete> method use all of C<execute> method's options,
2411
and use the following new ones.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2412

            
cleanup
Yuki Kimoto authored on 2011-10-20
2413
=over 4
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2414

            
2415
=item C<id>
2416

            
2417
    id => 4
2418
    id => [4, 5]
2419

            
2420
ID corresponding to C<primary_key>.
2421
You can delete rows by C<id> and C<primary_key>.
2422

            
2423
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2424
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2425
        id => [4, 5],
2426
        table => 'book',
2427
    );
2428

            
2429
The above is same as the followin one.
2430

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

            
2433
=item C<prefix>
2434

            
2435
    prefix => 'some'
2436

            
2437
prefix before table name section.
2438

            
2439
    delete some from book
2440

            
2441
=item C<table>
2442

            
2443
    table => 'book'
2444

            
2445
Table name.
2446

            
2447
=item C<where>
2448

            
2449
Same as C<select> method's C<where> option.
2450

            
2451
=back
2452

            
2453
=head2 C<delete_all>
2454

            
2455
    $dbi->delete_all(table => $table);
2456

            
2457
Execute delete statement for all rows.
2458
Options is same as C<delete>.
2459

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

            
2462
    $dbi->each_column(
2463
        sub {
2464
            my ($dbi, $table, $column, $column_info) = @_;
2465
            
2466
            my $type = $column_info->{TYPE_NAME};
2467
            
2468
            if ($type eq 'DATE') {
2469
                # ...
2470
            }
2471
        }
2472
    );
2473

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

            
2479
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2480
infromation, you can improve the performance of C<each_column> in
2481
the following way.
2482

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

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

            
2489
    $dbi->each_table(
2490
        sub {
2491
            my ($dbi, $table, $table_info) = @_;
2492
            
2493
            my $table_name = $table_info->{TABLE_NAME};
2494
        }
2495
    );
2496

            
improved pod
Yuki Kimoto authored on 2011-10-14
2497
Iterate all table informationsfrom in database.
2498
Argument is callback which is executed when one table is found.
2499
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2500
C<table information>.
2501

            
2502
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2503
infromation, you can improve the performance of C<each_table> in
2504
the following way.
2505

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

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

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

            
2517
    my $result = $dbi->execute(
2518
      "select * from book where title = :book.title and author like :book.author",
2519
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2520
    );
2521

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2528
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2529
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2530
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2531
    select * from book where title = :title and author like :author
2532
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2533
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2534
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2535

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2536
You can specify operator with named placeholder
fixed pod
Yuki Kimoto authored on 2011-10-20
2537
by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2538

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2539
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2540
    select * from book where :title{=} and :author{like}
2541
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2542
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2543
    select * from where title = ? and author like ?;
2544

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

            
2549
    select * from where title = "aa\\:bb";
2550

            
cleanup
Yuki Kimoto authored on 2011-10-20
2551
B<OPTIONS>
2552

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

            
2555
=over 4
2556

            
cleanup
Yuki Kimoto authored on 2011-10-20
2557
=item C<append>
2558

            
2559
    append => 'order by name'
2560

            
2561
Append some statement after SQL.
2562

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

            
2565
Specify database bind data type.
2566

            
2567
    bind_type => [image => DBI::SQL_BLOB]
2568
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2569

            
2570
This is used to bind parameter by C<bind_param> of statment handle.
2571

            
2572
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2573

            
update pod
Yuki Kimoto authored on 2011-03-13
2574
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2575
    
2576
    filter => {
2577
        title  => sub { uc $_[0] }
2578
        author => sub { uc $_[0] }
2579
    }
update pod
Yuki Kimoto authored on 2011-03-13
2580

            
updated pod
Yuki Kimoto authored on 2011-06-09
2581
    # Filter name
2582
    filter => {
2583
        title  => 'upper_case',
2584
        author => 'upper_case'
2585
    }
2586
        
2587
    # At once
2588
    filter => [
2589
        [qw/title author/]  => sub { uc $_[0] }
2590
    ]
2591

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

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

            
2599
    id => 4
2600
    id => [4, 5]
2601

            
2602
ID corresponding to C<primary_key>.
2603
You can delete rows by C<id> and C<primary_key>.
2604

            
2605
    $dbi->execute(
2606
        "select * from book where id1 = :id1 and id2 = :id2",
2607
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2608
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2609
        id => [4, 5],
2610
    );
2611

            
2612
The above is same as the followin one.
2613

            
2614
    $dbi->execute(
2615
        "select * from book where id1 = :id1 and id2 = :id2",
2616
        {id1 => 4, id2 => 5}
2617
    );
2618

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

            
2621
    query => 1
2622

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

            
2626
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2627
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2628
    my $columns = $query->columns;
2629
    
2630
If you want to execute SQL fast, you can do the following way.
2631

            
2632
    my $query;
2633
    foreach my $row (@$rows) {
2634
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2635
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2636
    }
2637

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

            
2641
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
2642
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2643
    
2644
    my $query;
2645
    my $sth;
2646
    foreach my $row (@$rows) {
2647
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2648
      $sth ||= $query->sth;
2649
      $sth->execute(map { $row->{$_} } sort keys %$row);
2650
    }
2651

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2658
    primary_key => 'id'
2659
    primary_key => ['id1', 'id2']
2660

            
2661
Priamry key. This is used when C<id> option find primary key.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2662

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

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

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

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

            
2671
    $dbi->select(
2672
        table => 'book',
2673
        column => 'distinct(name)',
2674
        after_build_sql => sub {
2675
            "select count(*) from ($_[0]) as t1"
2676
        }
2677
    );
2678

            
2679
The following SQL is executed.
2680

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2683
=item C<table>
2684
    
2685
    table => 'author'
2686

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2694
    # Same
2695
    $dbi->execute(
2696
      "select * from book where title = :book.title and author = :book.author",
2697
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2698

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

            
2701
    table_alias => {user => 'hiker'}
2702

            
2703
Table alias. Key is real table name, value is alias table name.
2704
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2705
on alias table name.
2706

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

            
2709
    type_rule_off => 1
2710

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

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

            
2715
    type_rule1_off => 1
2716

            
2717
Turn C<into1> type rule off.
2718

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

            
2721
    type_rule2_off => 1
2722

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

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

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

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

            
2731
get column infomation except for one which match C<exclude_table> pattern.
2732

            
2733
    [
2734
        {table => 'book', column => 'title', info => {...}},
2735
        {table => 'author', column => 'name' info => {...}}
2736
    ]
2737

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

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

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

            
2744
    [
2745
        {table => 'book', info => {...}},
2746
        {table => 'author', info => {...}}
2747
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2748

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

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

            
2753
    $dbi->helper(
2754
        update_or_insert => sub {
2755
            my $self = shift;
2756
            
2757
            # Process
2758
        },
2759
        find_or_create   => sub {
2760
            my $self = shift;
2761
            
2762
            # Process
2763
        }
2764
    );
2765

            
2766
Register helper. These helper is called directly from L<DBIx::Custom> object.
2767

            
2768
    $dbi->update_or_insert;
2769
    $dbi->find_or_create;
2770

            
cleanup
yuki-kimoto authored on 2010-10-17
2771
=head2 C<insert>
2772

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

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

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

            
2781
    {date => \"NOW()"}
2782

            
cleanup
Yuki Kimoto authored on 2011-10-20
2783
B<options>
2784

            
cleanup
Yuki Kimoto authored on 2011-10-20
2785
C<insert> method use all of C<execute> method's options,
cleanup
Yuki Kimoto authored on 2011-10-20
2786
and use the following new ones.
update pod
Yuki Kimoto authored on 2011-03-13
2787

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2790
=item C<id>
2791

            
updated document
Yuki Kimoto authored on 2011-06-09
2792
    id => 4
2793
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2794

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2798
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2799
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2800
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2801
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2802
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2803
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2804

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

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

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

            
2814
    prefix => 'or replace'
2815

            
2816
prefix before table name section
2817

            
2818
    insert or replace into book
2819

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

            
2822
    table => 'book'
2823

            
2824
Table name.
2825

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

            
2828
    timestamp => 1
2829

            
2830
If this value is set to 1,
2831
automatically created timestamp column is set based on
2832
C<timestamp> attribute's C<insert> value.
2833

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

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

            
2838
placeholder wrapped string.
2839

            
2840
If the following statement
2841

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

            
2845
is executed, the following SQL is executed.
2846

            
2847
    insert into book price values ( ? + 5 );
2848

            
update pod
Yuki Kimoto authored on 2011-03-13
2849
=back
2850

            
2851
=over 4
2852

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2860
    lib / MyModel.pm
2861
        / MyModel / book.pm
2862
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2863

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

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

            
2868
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2869
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2870
    
2871
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2872

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2877
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2878
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2879
    
2880
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2881

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2884
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2885
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2886
    
2887
    1;
2888
    
updated pod
Yuki Kimoto authored on 2011-06-21
2889
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2890

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2914
=head2 C<like_value>
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2915

            
2916
    my $like_value = $dbi->like_value
2917

            
cleanup
Yuki Kimoto authored on 2011-10-20
2918
Code reference which return a value for the like value.
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2919

            
2920
    sub { "%$_[0]%" }
2921

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

            
2924
    my $mapper = $dbi->mapper(param => $param);
2925

            
2926
Create a new L<DBIx::Custom::Mapper> object.
2927

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2932
Merge parameters. The following new parameter is created.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2933

            
2934
    {key1 => [1, 1], key2 => 2}
2935

            
cleanup
Yuki Kimoto authored on 2011-10-20
2936
If same keys contains, the value is converted to array reference.
2937

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

            
2940
    my $model = $dbi->model('book');
2941

            
cleanup
Yuki Kimoto authored on 2011-10-20
2942
Get a L<DBIx::Custom::Model> object
2943
create by C<create_model> or C<include_model>
update pod
Yuki Kimoto authored on 2011-03-13
2944

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

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

            
2949
Create column clause for myself. The follwoing column clause is created.
2950

            
2951
    book.author as author,
2952
    book.title as title
2953

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

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

            
2963
Create a new L<DBIx::Custom> object.
2964

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

            
2967
    my $not_exists = $dbi->not_exists;
2968

            
update pod
Yuki Kimoto authored on 2011-03-13
2969
DBIx::Custom::NotExists object, indicating the column is not exists.
cleanup
Yuki Kimoto authored on 2011-10-20
2970
This is used in C<param> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2971

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

            
2974
    my $order = $dbi->order;
2975

            
2976
Create a new L<DBIx::Custom::Order> object.
2977

            
cleanup
yuki-kimoto authored on 2010-10-17
2978
=head2 C<register_filter>
2979

            
update pod
Yuki Kimoto authored on 2011-03-13
2980
    $dbi->register_filter(
2981
        # Time::Piece object to database DATE format
2982
        tp_to_date => sub {
2983
            my $tp = shift;
2984
            return $tp->strftime('%Y-%m-%d');
2985
        },
2986
        # database DATE format to Time::Piece object
2987
        date_to_tp => sub {
2988
           my $date = shift;
2989
           return Time::Piece->strptime($date, '%Y-%m-%d');
2990
        }
2991
    );
cleanup
yuki-kimoto authored on 2010-10-17
2992
    
update pod
Yuki Kimoto authored on 2011-03-13
2993
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2994

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2997
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2998
        table  => 'book',
2999
        column => ['author', 'title'],
3000
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3001
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3002
    
updated document
Yuki Kimoto authored on 2011-06-09
3003
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3004

            
cleanup
Yuki Kimoto authored on 2011-10-20
3005
B<OPTIONS>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3006

            
cleanup
Yuki Kimoto authored on 2011-10-20
3007
C<select> method use all of C<execute> method's options,
3008
and use the following new ones.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3009

            
cleanup
Yuki Kimoto authored on 2011-10-20
3010
=over 4
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3011

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3012
=item C<column>
3013
    
updated document
Yuki Kimoto authored on 2011-06-09
3014
    column => 'author'
3015
    column => ['author', 'title']
3016

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3025
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3026
        {book => [qw/author title/]},
3027
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3028
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3029

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

            
3032
    book.author as "book.author",
3033
    book.title as "book.title",
3034
    person.name as "person.name",
3035
    person.age as "person.age"
3036

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

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

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

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

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

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

            
3052
=item C<id>
3053

            
3054
    id => 4
3055
    id => [4, 5]
3056

            
3057
ID corresponding to C<primary_key>.
3058
You can select rows by C<id> and C<primary_key>.
3059

            
3060
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3061
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3062
        id => [4, 5],
3063
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3064
    );
3065

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3068
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3069
        where => {id1 => 4, id2 => 5},
3070
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3071
    );
3072
    
cleanup
Yuki Kimoto authored on 2011-10-20
3073
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3074

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

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

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

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

            
3087
    prefix => 'SQL_CALC_FOUND_ROWS'
3088

            
3089
Prefix of column cluase
3090

            
3091
    select SQL_CALC_FOUND_ROWS title, author from book;
3092

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

            
3095
    join => [
3096
        'left outer join company on book.company_id = company_id',
3097
        'left outer join location on company.location_id = location.id'
3098
    ]
3099
        
3100
Join clause. If column cluase or where clause contain table name like "company.name",
3101
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3102

            
3103
    $dbi->select(
3104
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3105
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3106
        where => {'company.name' => 'Orange'},
3107
        join => [
3108
            'left outer join company on book.company_id = company.id',
3109
            'left outer join location on company.location_id = location.id'
3110
        ]
3111
    );
3112

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3116
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3117
    from book
3118
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3119
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3120

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3121
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
3122
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3123

            
3124
    $dbi->select(
3125
        table => 'book',
3126
        column => ['company.location_id as location_id'],
3127
        where => {'company.name' => 'Orange'},
3128
        join => [
3129
            {
3130
                clause => 'left outer join location on company.location_id = location.id',
3131
                table => ['company', 'location']
3132
            }
3133
        ]
3134
    );
3135

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3140
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3141

            
updated document
Yuki Kimoto authored on 2011-06-09
3142
=item C<where>
3143
    
3144
    # Hash refrence
3145
    where => {author => 'Ken', 'title' => 'Perl'}
3146
    
3147
    # DBIx::Custom::Where object
3148
    where => $dbi->where(
3149
        clause => ['and', 'author = :author', 'title like :title'],
3150
        param  => {author => 'Ken', title => '%Perl%'}
3151
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3152
    
3153
    # Array reference 1 (array reference, hash referenc). same as above
3154
    where => [
3155
        ['and', 'author = :author', 'title like :title'],
3156
        {author => 'Ken', title => '%Perl%'}
3157
    ];    
3158
    
3159
    # Array reference 2 (String, hash reference)
3160
    where => [
3161
        'title like :title',
3162
        {title => '%Perl%'}
3163
    ]
3164
    
3165
    # String
3166
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3167

            
cleanup
Yuki Kimoto authored on 2011-10-20
3168
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3169
    
update pod
Yuki Kimoto authored on 2011-03-12
3170
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3171

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

            
3174
    $dbi->setup_model;
3175

            
3176
Setup all model objects.
3177
C<columns> of model object is automatically set, parsing database information.
3178

            
3179
=head2 C<type_rule>
3180

            
3181
    $dbi->type_rule(
3182
        into1 => {
3183
            date => sub { ... },
3184
            datetime => sub { ... }
3185
        },
3186
        into2 => {
3187
            date => sub { ... },
3188
            datetime => sub { ... }
3189
        },
3190
        from1 => {
3191
            # DATE
3192
            9 => sub { ... },
3193
            # DATETIME or TIMESTAMP
3194
            11 => sub { ... },
3195
        }
3196
        from2 => {
3197
            # DATE
3198
            9 => sub { ... },
3199
            # DATETIME or TIMESTAMP
3200
            11 => sub { ... },
3201
        }
3202
    );
3203

            
3204
Filtering rule when data is send into and get from database.
3205
This has a little complex problem.
3206

            
3207
In C<into1> and C<into2> you can specify
3208
type name as same as type name defined
3209
by create table, such as C<DATETIME> or C<DATE>.
3210

            
3211
Note that type name and data type don't contain upper case.
3212
If these contain upper case charactor, you convert it to lower case.
3213

            
3214
C<into2> is executed after C<into1>.
3215

            
3216
Type rule of C<into1> and C<into2> is enabled on the following
3217
column name.
3218

            
3219
=over 4
3220

            
3221
=item 1. column name
3222

            
3223
    issue_date
3224
    issue_datetime
3225

            
3226
This need C<table> option in each method.
3227

            
3228
=item 2. table name and column name, separator is dot
3229

            
3230
    book.issue_date
3231
    book.issue_datetime
3232

            
3233
=back
3234

            
3235
You get all type name used in database by C<available_typename>.
3236

            
3237
    print $dbi->available_typename;
3238

            
3239
In C<from1> and C<from2> you specify data type, not type name.
3240
C<from2> is executed after C<from1>.
3241
You get all data type by C<available_datatype>.
3242

            
3243
    print $dbi->available_datatype;
3244

            
3245
You can also specify multiple types at once.
3246

            
3247
    $dbi->type_rule(
3248
        into1 => [
3249
            [qw/DATE DATETIME/] => sub { ... },
3250
        ],
3251
    );
3252

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

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

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

            
3259
If you want to set constant value to row data, use scalar reference
3260
as parameter value.
3261

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3264
B<OPTIONS>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3265

            
cleanup
Yuki Kimoto authored on 2011-10-20
3266
C<update> method use all of C<execute> method's options,
3267
and use the following new ones.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3268

            
cleanup
Yuki Kimoto authored on 2011-10-20
3269
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3270

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3273
    id => 4
3274
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3275

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3279
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3280
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3281
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3282
        id => [4, 5],
3283
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3284
    );
update pod
Yuki Kimoto authored on 2011-03-13
3285

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3288
    $dbi->update(
3289
        {title => 'Perl', author => 'Ken'}
3290
        where => {id1 => 4, id2 => 5},
3291
        table => 'book'
3292
    );
update pod
Yuki Kimoto authored on 2011-03-13
3293

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

            
3296
    prefix => 'or replace'
3297

            
3298
prefix before table name section
3299

            
3300
    update or replace book
3301

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

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

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

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

            
3310
    timestamp => 1
3311

            
3312
If this value is set to 1,
3313
automatically updated timestamp column is set based on
3314
C<timestamp> attribute's C<update> value.
3315

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

            
3318
Same as C<select> method's C<where> option.
3319

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

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

            
3324
placeholder wrapped string.
3325

            
3326
If the following statement
3327

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

            
3331
is executed, the following SQL is executed.
3332

            
3333
    update book set price =  ? + 5;
3334

            
updated pod
Yuki Kimoto authored on 2011-06-08
3335
=back
update pod
Yuki Kimoto authored on 2011-03-13
3336

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3344
=head2 C<update_or_insert EXPERIMENTAL>
3345
    
3346
    # Where
3347
    $dbi->update_or_insert(
3348
        {id => 1, title => 'Perl'},
3349
        table => 'book',
3350
        where => {id => 1},
3351
        select_option => {append => 'for update'}
3352
    );
3353
    
3354
    # ID
3355
    $dbi->update_or_insert(
3356
        {title => 'Perl'},
3357
        table => 'book',
3358
        id => 1,
3359
        primary_key => 'id',
3360
        select_option => {append => 'for update'}
3361
    );
3362
    
3363
Update or insert.
3364

            
3365
In both examples, the following SQL is executed.
3366

            
3367
    # In case insert
3368
    insert into book (id, title) values (?, ?)
3369
    
3370
    # In case update
3371
    update book set (id = ?, title = ?) where book.id = ?
3372

            
3373
The following opitons are available adding to C<update> option.
3374

            
3375
=over 4
3376

            
3377
=item C<select_option>
3378

            
3379
    select_option => {append => 'for update'}
3380

            
3381
select method option,
3382
select method is used to check the row is already exists.
3383

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

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

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

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

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

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

            
3404
    $dbi->show_datatype($table);
3405

            
3406
Show data type of the columns of specified table.
3407

            
3408
    book
3409
    title: 5
3410
    issue_date: 91
3411

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

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

            
3416
    $dbi->show_tables;
3417

            
3418
Show tables.
3419

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

            
3422
    $dbi->show_typename($table);
3423

            
3424
Show type name of the columns of specified table.
3425

            
3426
    book
3427
    title: varchar
3428
    issue_date: date
3429

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

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

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

            
3436
Create values clause.
3437

            
3438
    (title, author) values (title = :title, age = :age);
3439

            
3440
You can use this in insert statement.
3441

            
3442
    my $insert_sql = "insert into book $values_clause";
3443

            
3444
=head2 C<where>
3445

            
3446
    my $where = $dbi->where(
3447
        clause => ['and', 'title = :title', 'author = :author'],
3448
        param => {title => 'Perl', author => 'Ken'}
3449
    );
3450

            
3451
Create a new L<DBIx::Custom::Where> object.
3452

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

            
3455
=head2 C<DBIX_CUSTOM_DEBUG>
3456

            
3457
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3458
executed SQL and bind values are printed to STDERR.
3459

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

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

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

            
3466
L<DBIx::Custom>
3467

            
3468
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3469
    default_dbi_option # will be removed 2017/1/1
3470
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3471
    data_source # will be removed at 2017/1/1
3472
    dbi_options # will be removed at 2017/1/1
3473
    filter_check # will be removed at 2017/1/1
3474
    reserved_word_quote # will be removed at 2017/1/1
3475
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3476
    
3477
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3478
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3479
    assign_param # will be removed at 2017/1/1
3480
    update_param # will be removed at 2017/1/1
3481
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3482
    create_query # will be removed at 2017/1/1
3483
    apply_filter # will be removed at 2017/1/1
3484
    select_at # will be removed at 2017/1/1
3485
    delete_at # will be removed at 2017/1/1
3486
    update_at # will be removed at 2017/1/1
3487
    insert_at # will be removed at 2017/1/1
3488
    register_tag # will be removed at 2017/1/1
3489
    default_bind_filter # will be removed at 2017/1/1
3490
    default_fetch_filter # will be removed at 2017/1/1
3491
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3492
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3493
    register_tag_processor # will be removed at 2017/1/1
3494
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3495
    
3496
    # Options
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3497
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3498
    select method relation option # will be removed at 2017/1/1
3499
    select method param option # will be removed at 2017/1/1
3500
    select method column option [COLUMN, as => ALIAS] format
3501
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3502
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3503
    
3504
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3505
    execute("select * from {= title}"); # execute method's
3506
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3507
                                        # will be removed at 2017/1/1
3508
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3509

            
3510
L<DBIx::Custom::Model>
3511

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3512
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3513
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3514
    filter # will be removed at 2017/1/1
3515
    name # will be removed at 2017/1/1
3516
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3517

            
3518
L<DBIx::Custom::Query>
3519
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3520
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3521
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3522
    table # will be removed at 2017/1/1
3523
    filters # will be removed at 2017/1/1
3524
    
3525
    # Methods
3526
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3527

            
3528
L<DBIx::Custom::QueryBuilder>
3529
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3530
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3531
    tags # will be removed at 2017/1/1
3532
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3533
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3534
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3535
    register_tag # will be removed at 2017/1/1
3536
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3537
    
3538
    # Others
3539
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3540
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3541

            
3542
L<DBIx::Custom::Result>
3543
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3544
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3545
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3546
    
3547
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3548
    end_filter # will be removed at 2017/1/1
3549
    remove_end_filter # will be removed at 2017/1/1
3550
    remove_filter # will be removed at 2017/1/1
3551
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3552

            
3553
L<DBIx::Custom::Tag>
3554

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

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

            
3559
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3560
except for attribute method.
3561
You can check all DEPRECATED functionalities by document.
3562
DEPRECATED functionality is removed after five years,
3563
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
3564
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3565

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

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

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

            
3572
C<< <kimoto.yuki at gmail.com> >>
3573

            
3574
L<http://github.com/yuki-kimoto/DBIx-Custom>
3575

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3576
=head1 AUTHOR
3577

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

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

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

            
3584
This program is free software; you can redistribute it and/or modify it
3585
under the same terms as Perl itself.
3586

            
3587
=cut