DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3540 lines | 92.121kb
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 argument checking ...
Yuki Kimoto authored on 2011-10-21
4
our $VERSION = '0.1733';
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-10-21
239
    my $where            = $args{where} || {};
240
    my $allow_delete_all = $args{allow_delete_all};
241
    my $where_param      = $args{where_param} || {};
242
    my $id = $args{id};
243
    my $primary_key = $args{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
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';
cleanup
Yuki Kimoto authored on 2011-10-21
248
    my $prefix = $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
cleanup
Yuki Kimoto authored on 2011-10-21
251
    $where = $self->_id_to_param($id, $primary_key, $table)
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
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
cleanup
Yuki Kimoto authored on 2011-10-21
278
    return $self->execute($sql, $where_param, %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

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
413
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
414
    
415
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
416
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
417
    
cleanup
Yuki Kimoto authored on 2011-04-02
418
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
419
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
420
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
421

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

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

            
548
        return $result;
549
    }
cleanup
Yuki Kimoto authored on 2011-04-02
550
    
551
    # Not select statement
552
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
553
}
554

            
added test
Yuki Kimoto authored on 2011-08-16
555
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
556
    my ($self, %args) = @_;
557
    
558
    my $exclude = delete $args{exclude};
559
    croak qq/"$_" is wrong option/ for keys %args;
560
    
added test
Yuki Kimoto authored on 2011-08-16
561
    my $table_info = [];
562
    $self->each_table(
563
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
564
        exclude => $exclude
565
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
566
    
cleanup test
Yuki Kimoto authored on 2011-08-16
567
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
568
}
569

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
570
sub get_column_info {
571
    my ($self, %args) = @_;
572
    
573
    my $exclude_table = delete $args{exclude_table};
574
    croak qq/"$_" is wrong option/ for keys %args;
575
    
576
    my $column_info = [];
577
    $self->each_column(
578
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
579
        exclude_table => $exclude_table
580
    );
581
    
582
    return [
583
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
584
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
585
}
586

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
587
sub helper {
588
    my $self = shift;
589
    
590
    # Register method
591
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
592
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
593
    
594
    return $self;
595
}
596

            
cleanup
yuki-kimoto authored on 2010-10-17
597
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
598
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
599
    
cleanup
yuki-kimoto authored on 2010-10-17
600
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
601
    my $param = @_ % 2 ? shift : undef;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
602
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
603
    warn "insert method param option is DEPRECATED" if $args{param};
604
    $param ||= delete $args{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
605
    
606
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
607
    if ($args{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
608
        my $columns = $insert_timestamp->[0];
609
        $columns = [$columns] unless ref $columns eq 'ARRAY';
610
        my $value = $insert_timestamp->[1];
611
        $value = $value->() if ref $value eq 'CODE';
612
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
613
    }
cleanup
Yuki Kimoto authored on 2011-10-21
614
    
615
    # Merge id to parameter
616
    $param = $self->merge_param(
617
        $self->_id_to_param($args{id}, $args{primary_key}), $param)
618
      if defined $args{id};
619
    
cleanup
Yuki Kimoto authored on 2011-04-02
620
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
621
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
622
    $sql .= "$args{prefix} " if defined $args{prefix};
623
    $sql .= "into " . $self->_q($args{table}) . " "
624
      . $self->values_clause($param, {wrap => $args{wrap}}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
625
    
626
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
627
    return $self->execute($sql, $param, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
628
}
629

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
630
sub update_or_insert {
631
    my $self = shift;
632

            
633
    # Arguments
634
    my $param  = shift;
635
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
636
    my $id = $args{id};
637
    my $primary_key = $args{primary_key};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
638
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
639
    croak "update_or_insert method need primary_key option " .
640
          "when id is specified" . _subname
641
      if defined $id && !defined $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
642
    my $table  = $args{table};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
643
    croak qq{"table" option must be specified } . _subname
644
      unless defined $table;
cleanup
Yuki Kimoto authored on 2011-10-21
645
    my $select_option = $args{select_option};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
646
    
647
    my $rows = $self->select(table => $table, id => $id,
648
        primary_key => $primary_key, %$select_option)->all;
649
    
650
    croak "selected row count must be one or zero" . _subname
651
      if @$rows > 1;
652
    
653
    my $row = $rows->[0];
654
    my @options = (table => $table);
655
    push @options, id => $id, primary_key => $primary_key if defined $id;
656
    push @options, %args;
657
    
658
    if ($row) {
659
        return $self->update($param, @options);
660
    }
661
    else {
662
        return $self->insert($param, @options);
663
    }
664
}
665

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
666
sub insert_timestamp {
667
    my $self = shift;
668
    
669
    if (@_) {
670
        $self->{insert_timestamp} = [@_];
671
        
672
        return $self;
673
    }
674
    return $self->{insert_timestamp};
675
}
676

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
677
sub include_model {
678
    my ($self, $name_space, $model_infos) = @_;
679
    
cleanup
Yuki Kimoto authored on 2011-04-02
680
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
681
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
682
    
683
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
684
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
685

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
686
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
687
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
688
          if $name_space =~ /[^\w:]/;
689
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
690
        croak qq{Name space module "$name_space.pm" is needed. $@ }
691
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
692
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
693
        
694
        # Search model modules
695
        my $path = $INC{"$name_space.pm"};
696
        $path =~ s/\.pm$//;
697
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
698
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
        $model_infos = [];
700
        while (my $module = readdir $dh) {
701
            push @$model_infos, $module
702
              if $module =~ s/\.pm$//;
703
        }
704
        close $dh;
705
    }
706
    
cleanup
Yuki Kimoto authored on 2011-04-02
707
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
708
    foreach my $model_info (@$model_infos) {
709
        
cleanup
Yuki Kimoto authored on 2011-04-02
710
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
711
        my $model_class;
712
        my $model_name;
713
        my $model_table;
714
        if (ref $model_info eq 'HASH') {
715
            $model_class = $model_info->{class};
716
            $model_name  = $model_info->{name};
717
            $model_table = $model_info->{table};
718
            
719
            $model_name  ||= $model_class;
720
            $model_table ||= $model_name;
721
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
722
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
723
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
724
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
725
          if $mclass =~ /[^\w:]/;
726
        unless ($mclass->can('isa')) {
727
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
728
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
729
        }
730
        
cleanup
Yuki Kimoto authored on 2011-04-02
731
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
732
        my $args = {};
733
        $args->{model_class} = $mclass if $mclass;
734
        $args->{name}        = $model_name if $model_name;
735
        $args->{table}       = $model_table if $model_table;
736
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
737
    }
738
    
739
    return $self;
740
}
741

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
744
sub mapper {
745
    my $self = shift;
746
    return DBIx::Custom::Mapper->new(@_);
747
}
748

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
749
sub merge_param {
750
    my ($self, @params) = @_;
751
    
cleanup
Yuki Kimoto authored on 2011-04-02
752
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
753
    my $merge = {};
754
    foreach my $param (@params) {
755
        foreach my $column (keys %$param) {
756
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
757
            
758
            if (exists $merge->{$column}) {
759
                $merge->{$column} = [$merge->{$column}]
760
                  unless ref $merge->{$column} eq 'ARRAY';
761
                push @{$merge->{$column}},
762
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
763
            }
764
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
765
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
766
            }
767
        }
768
    }
769
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
770
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
771
}
772

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
773
sub model {
774
    my ($self, $name, $model) = @_;
775
    
cleanup
Yuki Kimoto authored on 2011-04-02
776
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
777
    if ($model) {
778
        $self->models->{$name} = $model;
779
        return $self;
780
    }
781
    
782
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
783
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
784
      unless $self->models->{$name};
785
    
cleanup
Yuki Kimoto authored on 2011-04-02
786
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
787
    return $self->models->{$name};
788
}
789

            
cleanup
Yuki Kimoto authored on 2011-03-21
790
sub mycolumn {
791
    my ($self, $table, $columns) = @_;
792
    
cleanup
Yuki Kimoto authored on 2011-04-02
793
    # Create column clause
794
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
795
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
796
    push @column, $self->_q($table) . "." . $self->_q($_) .
797
      " as " . $self->_q($_)
798
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
799
    
800
    return join (', ', @column);
801
}
802

            
added dbi_options attribute
kimoto authored on 2010-12-20
803
sub new {
804
    my $self = shift->SUPER::new(@_);
805
    
cleanup
Yuki Kimoto authored on 2011-04-02
806
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
807
    my @attrs = keys %$self;
808
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
809
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
810
          unless $self->can($attr);
811
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
812

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
813
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
814
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
815
        '?'     => \&DBIx::Custom::Tag::placeholder,
816
        '='     => \&DBIx::Custom::Tag::equal,
817
        '<>'    => \&DBIx::Custom::Tag::not_equal,
818
        '>'     => \&DBIx::Custom::Tag::greater_than,
819
        '<'     => \&DBIx::Custom::Tag::lower_than,
820
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
821
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
822
        'like'  => \&DBIx::Custom::Tag::like,
823
        'in'    => \&DBIx::Custom::Tag::in,
824
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
825
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
826
    };
827
    
828
    return $self;
829
}
830

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

            
833
sub order {
834
    my $self = shift;
835
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
836
}
837

            
cleanup
yuki-kimoto authored on 2010-10-17
838
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
839
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
840
    
841
    # Register filter
842
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
843
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
844
    
cleanup
Yuki Kimoto authored on 2011-04-02
845
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
846
}
packaging one directory
yuki-kimoto authored on 2009-11-16
847

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
851
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
852
    my $table = $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
853
    my $tables = ref $table eq 'ARRAY' ? $table
854
               : defined $table ? [$table]
855
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
856
    $args{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
857
    my $columns   = $args{column};
858
    my $where     = $args{where} || {};
859
    my $join      = $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
860
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
861
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
862
    my $relation = $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
863
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
864
      if $relation;
cleanup
Yuki Kimoto authored on 2011-10-21
865
    my $param = $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
866
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
867
      if keys %$param;
cleanup
Yuki Kimoto authored on 2011-10-21
868
    my $where_param = $args{where_param} || $param || {};
869
    my $id = $args{id};
870
    my $primary_key = $args{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
871
    croak "update method primary_key option " .
872
          "must be specified when id is specified " . _subname
873
      if defined $id && !defined $primary_key;
874
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
875
    my $prefix = $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
876
    
cleanup
Yuki Kimoto authored on 2011-03-09
877
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
878
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
879
    
cleanup
Yuki Kimoto authored on 2011-04-02
880
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
881
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
882
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
883
    # Prefix
micro optimization
Yuki Kimoto authored on 2011-09-30
884
    $sql .= "$prefix " if defined $prefix;
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
885
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
886
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
887
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
888
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
889
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
890
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
891
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
892
            }
893
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
894
                if (@$column == 3 && $column->[1] eq 'as') {
895
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
896
                    splice @$column, 1, 1;
897
                }
898
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
899
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
900
            }
cleanup
Yuki Kimoto authored on 2011-04-02
901
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
902
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
903
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
904
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
905
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
906
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
907
    
908
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
909
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-03-30
910
    if ($relation) {
911
        my $found = {};
912
        foreach my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
913
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
914
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
915
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
916
    }
cleanup
Yuki Kimoto authored on 2011-03-30
917
    else {
918
        my $main_table = $tables->[-1] || '';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
919
        $sql .= $self->_q($main_table) . ' ';
cleanup
Yuki Kimoto authored on 2011-03-30
920
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
921
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-04-25
922
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
923
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
924

            
cleanup
Yuki Kimoto authored on 2011-04-02
925
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
926
    unshift @$tables,
927
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
928
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
929
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
930
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-21
931
    $where = $self->_id_to_param($id, $primary_key, $tables->[-1])
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
932
      if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
933
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
934
        $where_clause = "where " . $where->[0];
935
        $where_param = $where->[1];
936
    }
937
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
938
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
939
        $where_param = keys %$where_param
940
                     ? $self->merge_param($where_param, $where->param)
941
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
942
        
943
        # String where
944
        $where_clause = $where->to_string;
945
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
946
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
947
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
948
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
949
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
950
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
951
    # Push join
micro optimization
Yuki Kimoto authored on 2011-09-30
952
    $self->_push_join(\$sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
953
    
cleanup
Yuki Kimoto authored on 2011-03-09
954
    # Add where clause
micro optimization
Yuki Kimoto authored on 2011-09-30
955
    $sql .= "$where_clause ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
956
    
cleanup
Yuki Kimoto authored on 2011-03-08
957
    # Relation(DEPRECATED!);
micro optimization
Yuki Kimoto authored on 2011-09-30
958
    $self->_push_relation(\$sql, $tables, $relation, $where_clause eq '' ? 1 : 0)
959
      if $relation;
cleanup
Yuki Kimoto authored on 2011-03-08
960
    
packaging one directory
yuki-kimoto authored on 2009-11-16
961
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
962
    my $result = $self->execute($sql, $where_param, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
963
    
964
    return $result;
965
}
966

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
967
sub setup_model {
968
    my $self = shift;
969
    
cleanup
Yuki Kimoto authored on 2011-04-02
970
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
971
    $self->each_column(
972
        sub {
973
            my ($self, $table, $column, $column_info) = @_;
974
            if (my $model = $self->models->{$table}) {
975
                push @{$model->columns}, $column;
976
            }
977
        }
978
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
979
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
980
}
981

            
update pod
Yuki Kimoto authored on 2011-08-10
982
sub show_datatype {
983
    my ($self, $table) = @_;
984
    croak "Table name must be specified" unless defined $table;
985
    print "$table\n";
986
    
987
    my $result = $self->select(table => $table, where => "'0' <> '0'");
988
    my $sth = $result->sth;
989

            
990
    my $columns = $sth->{NAME};
991
    my $data_types = $sth->{TYPE};
992
    
993
    for (my $i = 0; $i < @$columns; $i++) {
994
        my $column = $columns->[$i];
995
        my $data_type = $data_types->[$i];
996
        print "$column: $data_type\n";
997
    }
998
}
999

            
1000
sub show_typename {
1001
    my ($self, $t) = @_;
1002
    croak "Table name must be specified" unless defined $t;
1003
    print "$t\n";
1004
    
1005
    $self->each_column(sub {
1006
        my ($self, $table, $column, $infos) = @_;
1007
        return unless $table eq $t;
1008
        my $typename = $infos->{TYPE_NAME};
1009
        print "$column: $typename\n";
1010
    });
1011
    
1012
    return $self;
1013
}
1014

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1015
sub show_tables {
1016
    my $self = shift;
1017
    
1018
    my %tables;
1019
    $self->each_table(sub { $tables{$_[1]}++ });
1020
    print join("\n", sort keys %tables) . "\n";
1021
    return $self;
1022
}
1023

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1024
sub type_rule {
1025
    my $self = shift;
1026
    
1027
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1028
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1029
        
1030
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1031
        foreach my $i (1 .. 2) {
1032
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1033
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1034
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1035
            $self->{type_rule} = $type_rule;
1036
            $self->{"_$into"} = {};
1037
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1038
                croak qq{type name of $into section must be lower case}
1039
                  if $type_name =~ /[A-Z]/;
1040
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1041
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1042
            $self->each_column(sub {
1043
                my ($dbi, $table, $column, $column_info) = @_;
1044
                
1045
                my $type_name = lc $column_info->{TYPE_NAME};
1046
                if ($type_rule->{$into} &&
1047
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1048
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1049
                    return unless exists $type_rule->{$into}->{$type_name};
1050
                    if  (defined $filter && ref $filter ne 'CODE') 
1051
                    {
1052
                        my $fname = $filter;
1053
                        croak qq{Filter "$fname" is not registered" } . _subname
1054
                          unless exists $self->filters->{$fname};
1055
                        
1056
                        $filter = $self->filters->{$fname};
1057
                    }
1058

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1059
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1060
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1061
                }
1062
            });
1063
        }
1064

            
1065
        # From
1066
        foreach my $i (1 .. 2) {
1067
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1068
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1069
                croak qq{data type of from$i section must be lower case or number}
1070
                  if $data_type =~ /[A-Z]/;
1071
                my $fname = $type_rule->{"from$i"}{$data_type};
1072
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1073
                    croak qq{Filter "$fname" is not registered" } . _subname
1074
                      unless exists $self->filters->{$fname};
1075
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1076
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1077
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1078
            }
1079
        }
1080
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1081
        return $self;
1082
    }
1083
    
1084
    return $self->{type_rule} || {};
1085
}
1086

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1090
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1091
    my $param;
1092
    $param = shift if @_ % 2;
1093
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1094
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1095
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1096
      unless $table;
cleanup
Yuki Kimoto authored on 2011-10-21
1097
    my $p = $args{param} || {};
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1098
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-10-21
1099
    my $where = $args{where} || {};
1100
    my $where_param = $args{where_param} || {};
1101
    my $allow_update_all = $args{allow_update_all};
1102
    my $id = $args{id};
1103
    my $primary_key = $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1104
    croak "update method primary_key option " .
1105
          "must be specified when id is specified " . _subname
1106
      if defined $id && !defined $primary_key;
1107
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1108
    my $prefix = $args{prefix};
1109
    my $wrap = $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1110
    my $timestamp = $args{timestamp};
1111
    
1112
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1113
    if ($timestamp && (my $update_timestamp = $self->update_timestamp)) {
1114
        my $columns = $update_timestamp->[0];
1115
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1116
        my $value = $update_timestamp->[1];
1117
        $value = $value->() if ref $value eq 'CODE';
1118
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1119
    }
1120

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

            
1124
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1125
    $where = $self->_id_to_param($id, $primary_key, $table)
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1126
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1127
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1128
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1129
        $where_clause = "where " . $where->[0];
1130
        $where_param = $where->[1];
1131
    }
1132
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1133
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1134
        $where_param = keys %$where_param
1135
                     ? $self->merge_param($where_param, $where->param)
1136
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1137
        
1138
        # String where
1139
        $where_clause = $where->to_string;
1140
    }
1141
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1142
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1143
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1144
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1145
    # Merge param
1146
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1147
    
cleanup
Yuki Kimoto authored on 2011-04-02
1148
    # Update statement
micro optimization
Yuki Kimoto authored on 2011-09-30
1149
    my $sql;
1150
    $sql .= "update ";
1151
    $sql .= "$prefix " if defined $prefix;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1152
    $sql .= $self->_q($table) . " set $assign_clause $where_clause ";
cleanup
Yuki Kimoto authored on 2011-01-27
1153
    
cleanup
yuki-kimoto authored on 2010-10-17
1154
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1155
    return $self->execute($sql, $param, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1156
}
1157

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1160
sub update_timestamp {
1161
    my $self = shift;
1162
    
1163
    if (@_) {
1164
        $self->{update_timestamp} = [@_];
1165
        
1166
        return $self;
1167
    }
1168
    return $self->{update_timestamp};
1169
}
1170

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1171
sub values_clause {
1172
    my ($self, $param, $opts) = @_;
1173
    
1174
    my $wrap = $opts->{wrap} || {};
1175
    
1176
    # Create insert parameter tag
1177
    my $safety = $self->safety_character;
1178
    my @columns;
1179
    my @placeholders;
1180
    foreach my $column (sort keys %$param) {
1181
        croak qq{"$column" is not safety column name } . _subname
1182
          unless $column =~ /^[$safety\.]+$/;
1183
        my $column_quote = $self->_q($column);
1184
        $column_quote =~ s/\./$self->_q(".")/e;
1185
        push @columns, $column_quote;
1186
        
1187
        my $func = $wrap->{$column} || sub { $_[0] };
1188
        push @placeholders,
1189
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1190
        : $func->(":$column");
1191
    }
1192
    
1193
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1194
           '(' . join(', ', @placeholders) . ')'
1195
}
1196

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1199
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1200
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1201
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1202
    
updated pod
Yuki Kimoto authored on 2011-06-21
1203
    # Cache
1204
    my $cache = $self->cache;
1205
    
1206
    # Query
1207
    my $query;
1208
    
1209
    # Get cached query
1210
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1211
        
updated pod
Yuki Kimoto authored on 2011-06-21
1212
        # Get query
1213
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1214
        
updated pod
Yuki Kimoto authored on 2011-06-21
1215
        # Create query
1216
        if ($q) {
1217
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1218
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1219
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1220
    }
1221
    
1222
    # Create query
1223
    unless ($query) {
1224

            
1225
        # Create query
1226
        my $builder = $self->query_builder;
1227
        $query = $builder->build_query($source);
1228

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

            
1235
        # Save query to cache
1236
        $self->cache_method->(
1237
            $self, $source,
1238
            {
1239
                sql     => $query->sql, 
1240
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1241
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1242
            }
1243
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1244
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1245

            
1246
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1247
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1248
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1249
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1250
        $query->sql($sql);
1251
    }
1252
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1253
    # Save sql
1254
    $self->last_sql($query->sql);
1255
    
updated pod
Yuki Kimoto authored on 2011-06-21
1256
    # Prepare statement handle
1257
    my $sth;
1258
    eval { $sth = $self->dbh->prepare($query->{sql})};
1259
    
1260
    if ($@) {
1261
        $self->_croak($@, qq{. Following SQL is executed.\n}
1262
                        . qq{$query->{sql}\n} . _subname);
1263
    }
1264
    
1265
    # Set statement handle
1266
    $query->sth($sth);
1267
    
1268
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1269
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1270
    
1271
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1272
}
1273

            
cleanup
Yuki Kimoto authored on 2011-04-02
1274
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1275
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1276
    
cleanup
Yuki Kimoto authored on 2011-04-02
1277
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1278
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1279
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1280
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1281
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1282
        
1283
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1284
        my $value;
1285
        if(ref $params->{$column} eq 'ARRAY') {
1286
            my $i = $count->{$column} || 0;
1287
            $i += $not_exists->{$column} || 0;
1288
            my $found;
1289
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1290
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1291
                    $not_exists->{$column}++;
1292
                }
1293
                else  {
1294
                    $value = $params->{$column}->[$k];
1295
                    $found = 1;
1296
                    last
1297
                }
1298
            }
1299
            next unless $found;
1300
        }
1301
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1302
        
cleanup
Yuki Kimoto authored on 2011-01-12
1303
        # Filter
1304
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1305
        $value = $f->($value) if $f;
1306
        
1307
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1308
        foreach my $i (1 .. 2) {
1309
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1310
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1311
            $value = $tf->($value) if $tf;
1312
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1313
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1314
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1315
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1316
        
1317
        # Count up 
1318
        $count->{$column}++;
1319
    }
1320
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1321
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1322
}
1323

            
cleanup
Yuki Kimoto authored on 2011-10-21
1324
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1325
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1326
    
1327
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1328
    croak "primary_key option " .
1329
          "must be specified with id option " . _subname
1330
      unless defined $primary_keys;
1331
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1332
    
cleanup
Yuki Kimoto authored on 2011-06-08
1333
    # Create parameter
1334
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1335
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1336
        $id = [$id] unless ref $id;
1337
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1338
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1339
          unless !ref $id || ref $id eq 'ARRAY';
1340
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1341
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1342
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1343
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1344
           my $key = $primary_keys->[$i];
1345
           $key = "$table." . $key if $table;
1346
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1347
        }
1348
    }
1349
    
cleanup
Yuki Kimoto authored on 2011-06-08
1350
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1351
}
1352

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1353
sub _connect {
1354
    my $self = shift;
1355
    
1356
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1357
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1358
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1359
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1360
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1361
    croak qq{"dsn" must be specified } . _subname
1362
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1363
    my $user        = $self->user;
1364
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1365
    my $option = $self->_option;
1366
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1367
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1368
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1369
    my $dbh;
1370
    eval {
1371
        $dbh = DBI->connect(
1372
            $dsn,
1373
            $user,
1374
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1375
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1376
        );
1377
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1378
    
1379
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1380
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1381
    
1382
    return $dbh;
1383
}
1384

            
cleanup
yuki-kimoto authored on 2010-10-17
1385
sub _croak {
1386
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1387
    
1388
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1389
    $append ||= "";
1390
    
1391
    # Verbose
1392
    if ($Carp::Verbose) { croak $error }
1393
    
1394
    # Not verbose
1395
    else {
1396
        
1397
        # Remove line and module infromation
1398
        my $at_pos = rindex($error, ' at ');
1399
        $error = substr($error, 0, $at_pos);
1400
        $error =~ s/\s+$//;
1401
        croak "$error$append";
1402
    }
1403
}
1404

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1407
sub _need_tables {
1408
    my ($self, $tree, $need_tables, $tables) = @_;
1409
    
cleanup
Yuki Kimoto authored on 2011-04-02
1410
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1411
    foreach my $table (@$tables) {
1412
        if ($tree->{$table}) {
1413
            $need_tables->{$table} = 1;
1414
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1415
        }
1416
    }
1417
}
1418

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1419
sub _option {
1420
    my $self = shift;
1421
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1422
    warn "dbi_options is DEPRECATED! use option instead\n"
1423
      if keys %{$self->dbi_options};
1424
    warn "dbi_option is DEPRECATED! use option instead\n"
1425
      if keys %{$self->dbi_option};
1426
    return $option;
1427
}
1428

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1429
sub _push_join {
1430
    my ($self, $sql, $join, $join_tables) = @_;
1431
    
cleanup
Yuki Kimoto authored on 2011-04-02
1432
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1433
    return unless @$join;
1434
    
cleanup
Yuki Kimoto authored on 2011-04-02
1435
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1436
    my $tree = {};
1437
    for (my $i = 0; $i < @$join; $i++) {
1438
        
cleanup
Yuki Kimoto authored on 2011-07-28
1439
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1440
        my $join_clause;;
1441
        my $option;
1442
        if (ref $join->[$i] eq 'HASH') {
1443
            $join_clause = $join->[$i]->{clause};
1444
            $option = {table => $join->[$i]->{table}};
1445
        }
1446
        else {
1447
            $join_clause = $join->[$i];
1448
            $option = {};
1449
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1450

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1499
sub _quote {
1500
    my $self = shift;
1501
    
1502
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1503
         : defined $self->quote ? $self->quote
1504
         : '';
1505
}
1506

            
cleanup
Yuki Kimoto authored on 2011-07-29
1507
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1508
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1509
    
1510
    my $quote = $self->_quote;
1511
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1512
    my $p;
1513
    if (defined $quote && length $quote > 1) {
1514
        $p = substr($quote, 1, 1);
1515
    }
1516
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1517
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1518
    if ($quotemeta) {
1519
        $q = quotemeta($q);
1520
        $p = quotemeta($p);
1521
    }
1522
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1523
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1524
}
1525

            
cleanup
Yuki Kimoto authored on 2011-04-02
1526
sub _remove_duplicate_table {
1527
    my ($self, $tables, $main_table) = @_;
1528
    
1529
    # Remove duplicate table
1530
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1531
    delete $tables{$main_table} if $main_table;
1532
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1533
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1534
    if (my $q = $self->_quote) {
1535
        $q = quotemeta($q);
1536
        $_ =~ s/[$q]//g for @$new_tables;
1537
    }
1538

            
1539
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1540
}
1541

            
cleanup
Yuki Kimoto authored on 2011-04-02
1542
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1543
    my ($self, $source) = @_;
1544
    
cleanup
Yuki Kimoto authored on 2011-04-02
1545
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1546
    my $tables = [];
1547
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1548
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1549
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1550
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1551
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1552
    while ($source =~ /$table_re/g) {
1553
        push @$tables, $1;
1554
    }
1555
    
1556
    return $tables;
1557
}
1558

            
cleanup
Yuki Kimoto authored on 2011-04-02
1559
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1560
    my ($self, $where) = @_;
1561
    
cleanup
Yuki Kimoto authored on 2011-04-02
1562
    my $obj;
1563
    
1564
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1565
    if (ref $where eq 'HASH') {
1566
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1567
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1568
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1569
            my $table;
1570
            my $c;
1571
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1572
                $table = $1;
1573
                $c = $2;
1574
            }
1575
            
1576
            my $table_quote;
1577
            $table_quote = $self->_q($table) if defined $table;
1578
            my $column_quote = $self->_q($c);
1579
            $column_quote = $table_quote . '.' . $column_quote
1580
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1581
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1582
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1583
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1584
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1585
    
1586
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1587
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1588
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1589
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1590
    
updated pod
Yuki Kimoto authored on 2011-06-21
1591
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1592
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1593
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1594
            clause => $where->[0],
1595
            param  => $where->[1]
1596
        );
1597
    }
1598
    
cleanup
Yuki Kimoto authored on 2011-04-02
1599
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1600
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1601
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1602
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1603
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1604
    
cleanup
Yuki Kimoto authored on 2011-04-02
1605
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1606
}
1607

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

            
1611
    # Initialize filters
1612
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1613
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1614
    $self->{filter}{out} ||= {};
1615
    $self->{filter}{in} ||= {};
1616
    $self->{filter}{end} ||= {};
1617
    
1618
    # Usage
1619
    my $usage = "Usage: \$dbi->apply_filter(" .
1620
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1621
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1622
    
1623
    # Apply filter
1624
    for (my $i = 0; $i < @cinfos; $i += 2) {
1625
        
1626
        # Column
1627
        my $column = $cinfos[$i];
1628
        if (ref $column eq 'ARRAY') {
1629
            foreach my $c (@$column) {
1630
                push @cinfos, $c, $cinfos[$i + 1];
1631
            }
1632
            next;
1633
        }
1634
        
1635
        # Filter infomation
1636
        my $finfo = $cinfos[$i + 1] || {};
1637
        croak "$usage (table: $table) " . _subname
1638
          unless  ref $finfo eq 'HASH';
1639
        foreach my $ftype (keys %$finfo) {
1640
            croak "$usage (table: $table) " . _subname
1641
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1642
        }
1643
        
1644
        # Set filters
1645
        foreach my $way (qw/in out end/) {
1646
        
1647
            # Filter
1648
            my $filter = $finfo->{$way};
1649
            
1650
            # Filter state
1651
            my $state = !exists $finfo->{$way} ? 'not_exists'
1652
                      : !defined $filter        ? 'not_defined'
1653
                      : ref $filter eq 'CODE'   ? 'code'
1654
                      : 'name';
1655
            
1656
            # Filter is not exists
1657
            next if $state eq 'not_exists';
1658
            
1659
            # Check filter name
1660
            croak qq{Filter "$filter" is not registered } . _subname
1661
              if  $state eq 'name'
1662
               && ! exists $self->filters->{$filter};
1663
            
1664
            # Set filter
1665
            my $f = $state eq 'not_defined' ? undef
1666
                  : $state eq 'code'        ? $filter
1667
                  : $self->filters->{$filter};
1668
            $self->{filter}{$way}{$table}{$column} = $f;
1669
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1670
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1671
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1672
        }
1673
    }
1674
    
1675
    return $self;
1676
}
1677

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1678
# DEPRECATED!
1679
has 'data_source';
1680
has dbi_options => sub { {} };
1681
has filter_check  => 1;
1682
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1683
has dbi_option => sub { {} };
1684
has default_dbi_option => sub {
1685
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1686
    return shift->default_option;
1687
};
1688

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1689
# DEPRECATED!
1690
sub method {
1691
    warn "method is DEPRECATED! use helper instead";
1692
    return shift->helper(@_);
1693
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1694

            
1695
# DEPRECATED!
1696
sub assign_param {
1697
    my $self = shift;
1698
    warn "assing_param is DEPRECATED! use assign_clause instead";
1699
    return $self->assign_clause(@_);
1700
}
1701

            
1702
# DEPRECATED
1703
sub update_param {
1704
    my ($self, $param, $opts) = @_;
1705
    
1706
    warn "update_param is DEPRECATED! use assing_clause instead.";
1707
    
1708
    # Create update parameter tag
1709
    my $tag = $self->assign_clause($param, $opts);
1710
    $tag = "set $tag" unless $opts->{no_set};
1711

            
1712
    return $tag;
1713
}
1714

            
updated pod
Yuki Kimoto authored on 2011-06-21
1715
# DEPRECATED!
1716
sub create_query {
1717
    warn "create_query is DEPRECATED! use query option of each method";
1718
    shift->_create_query(@_);
1719
}
1720

            
cleanup
Yuki Kimoto authored on 2011-06-13
1721
# DEPRECATED!
1722
sub apply_filter {
1723
    my $self = shift;
1724
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1725
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1726
    return $self->_apply_filter(@_);
1727
}
1728

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1729
# DEPRECATED!
1730
sub select_at {
1731
    my ($self, %args) = @_;
1732

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1735
    # Arguments
1736
    my $primary_keys = delete $args{primary_key};
1737
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1738
    my $where = delete $args{where};
1739
    my $param = delete $args{param};
1740
    
1741
    # Table
1742
    croak qq{"table" option must be specified } . _subname
1743
      unless $args{table};
1744
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1745
    
1746
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1747
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1748
    
1749
    return $self->select(where => $where_param, %args);
1750
}
1751

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1752
# DEPRECATED!
1753
sub delete_at {
1754
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1755

            
1756
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1757
    
1758
    # Arguments
1759
    my $primary_keys = delete $args{primary_key};
1760
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1761
    my $where = delete $args{where};
1762
    
1763
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1764
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1765
    
1766
    return $self->delete(where => $where_param, %args);
1767
}
1768

            
cleanup
Yuki Kimoto authored on 2011-06-08
1769
# DEPRECATED!
1770
sub update_at {
1771
    my $self = shift;
1772

            
1773
    warn "update_at is DEPRECATED! use update and id option instead";
1774
    
1775
    # Arguments
1776
    my $param;
1777
    $param = shift if @_ % 2;
1778
    my %args = @_;
1779
    my $primary_keys = delete $args{primary_key};
1780
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1781
    my $where = delete $args{where};
1782
    my $p = delete $args{param} || {};
1783
    $param  ||= $p;
1784
    
1785
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1786
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1787
    
1788
    return $self->update(where => $where_param, param => $param, %args);
1789
}
1790

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1791
# DEPRECATED!
1792
sub insert_at {
1793
    my $self = shift;
1794
    
1795
    warn "insert_at is DEPRECATED! use insert and id option instead";
1796
    
1797
    # Arguments
1798
    my $param;
1799
    $param = shift if @_ % 2;
1800
    my %args = @_;
1801
    my $primary_key = delete $args{primary_key};
1802
    $primary_key = [$primary_key] unless ref $primary_key;
1803
    my $where = delete $args{where};
1804
    my $p = delete $args{param} || {};
1805
    $param  ||= $p;
1806
    
1807
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1808
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1809
    $param = $self->merge_param($where_param, $param);
1810
    
1811
    return $self->insert(param => $param, %args);
1812
}
1813

            
added warnings
Yuki Kimoto authored on 2011-06-07
1814
# DEPRECATED!
1815
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1816
    my $self = shift;
1817
    
added warnings
Yuki Kimoto authored on 2011-06-07
1818
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1819
    
1820
    # Merge tag
1821
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1822
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1823
    
1824
    return $self;
1825
}
1826

            
1827
# DEPRECATED!
1828
sub register_tag_processor {
1829
    my $self = shift;
1830
    warn "register_tag_processor is DEPRECATED!";
1831
    # Merge tag
1832
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1833
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1834
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1835
}
1836

            
cleanup
Yuki Kimoto authored on 2011-01-25
1837
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1838
sub default_bind_filter {
1839
    my $self = shift;
1840
    
cleanup
Yuki Kimoto authored on 2011-06-13
1841
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1842
    
cleanup
Yuki Kimoto authored on 2011-01-12
1843
    if (@_) {
1844
        my $fname = $_[0];
1845
        
1846
        if (@_ && !$fname) {
1847
            $self->{default_out_filter} = undef;
1848
        }
1849
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1850
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1851
              unless exists $self->filters->{$fname};
1852
        
1853
            $self->{default_out_filter} = $self->filters->{$fname};
1854
        }
1855
        return $self;
1856
    }
1857
    
1858
    return $self->{default_out_filter};
1859
}
1860

            
cleanup
Yuki Kimoto authored on 2011-01-25
1861
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1862
sub default_fetch_filter {
1863
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1864

            
cleanup
Yuki Kimoto authored on 2011-06-13
1865
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1866
    
1867
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1868
        my $fname = $_[0];
1869

            
cleanup
Yuki Kimoto authored on 2011-01-12
1870
        if (@_ && !$fname) {
1871
            $self->{default_in_filter} = undef;
1872
        }
1873
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1874
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1875
              unless exists $self->filters->{$fname};
1876
        
1877
            $self->{default_in_filter} = $self->filters->{$fname};
1878
        }
1879
        
1880
        return $self;
1881
    }
1882
    
many changed
Yuki Kimoto authored on 2011-01-23
1883
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1884
}
1885

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1886
# DEPRECATED!
1887
sub insert_param {
1888
    my $self = shift;
1889
    warn "insert_param is DEPRECATED! use values_clause instead";
1890
    return $self->values_clause(@_);
1891
}
1892

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1893
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1894
sub insert_param_tag {
1895
    warn "insert_param_tag is DEPRECATED! " .
1896
         "use insert_param instead!";
1897
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1898
}
1899

            
1900
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1901
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1902
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1903
         "use update_param instead";
1904
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1905
}
cleanup
Yuki Kimoto authored on 2011-03-08
1906
# DEPRECATED!
1907
sub _push_relation {
1908
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1909
    
1910
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1911
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1912
        foreach my $rcolumn (keys %$relation) {
1913
            my $table1 = (split (/\./, $rcolumn))[0];
1914
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1915
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1916
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1917
        }
1918
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1919
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1920
}
1921

            
1922
# DEPRECATED!
1923
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1924
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1925
    
1926
    if (keys %{$relation || {}}) {
1927
        foreach my $rcolumn (keys %$relation) {
1928
            my $table1 = (split (/\./, $rcolumn))[0];
1929
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1930
            my $table1_exists;
1931
            my $table2_exists;
1932
            foreach my $table (@$tables) {
1933
                $table1_exists = 1 if $table eq $table1;
1934
                $table2_exists = 1 if $table eq $table2;
1935
            }
1936
            unshift @$tables, $table1 unless $table1_exists;
1937
            unshift @$tables, $table2 unless $table2_exists;
1938
        }
1939
    }
1940
}
1941

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1944
=head1 NAME
1945

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1950
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1951
    
1952
    # Connect
1953
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1954
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1955
        user => 'ken',
1956
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1957
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1958
    );
cleanup
yuki-kimoto authored on 2010-08-05
1959

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1960
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1961
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1962
    
1963
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1964
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1965
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1966
    
1967
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1968
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1969

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1974
    # Select, more complex
1975
    my $result = $dbi->select(
1976
        table  => 'book',
1977
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1978
            {book => [qw/title author/]},
1979
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1980
        ],
1981
        where  => {'book.author' => 'Ken'},
1982
        join => ['left outer join company on book.company_id = company.id'],
1983
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1984
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1985
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1986
    # Fetch
1987
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1988
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1989
    }
1990
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1991
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1992
    while (my $row = $result->fetch_hash) {
1993
        
1994
    }
1995
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1996
    # Execute SQL with parameter.
1997
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1998
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1999
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2000
    );
2001
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2002
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2003

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2019
Named place holder support
2020

            
2021
=item *
2022

            
cleanup
Yuki Kimoto authored on 2011-07-29
2023
Model support
2024

            
2025
=item *
2026

            
2027
Connection manager support
2028

            
2029
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2030

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

            
2035
=item *
2036

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

            
2039
=item *
2040

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

            
2043
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2044

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2052
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2053
L<DBIx::Custom::Result>,
2054
L<DBIx::Custom::Query>,
2055
L<DBIx::Custom::Where>,
2056
L<DBIx::Custom::Model>,
2057
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2058

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

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

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

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

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

            
2072
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2073
        "dbi:mysql:database=$database",
2074
        $user,
2075
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2076
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2077
    );
2078
    
updated pod
Yuki Kimoto authored on 2011-06-21
2079
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2080

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

            
2084
    my $dbi = DBIx::Custom->connect(
2085
      dsn => $dsn, user => $user, password => $password, connector => 1);
2086
    
2087
    my $connector = $dbi->connector; # DBIx::Connector
2088

            
2089
Note that L<DBIx::Connector> must be installed.
2090

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2106
    {
2107
        RaiseError => 1,
2108
        PrintError => 0,
2109
        AutoCommit => 1,
2110
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2111

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

            
2114
    my $exclude_table = $dbi->exclude_table;
2115
    $dbi = $dbi->exclude_table(qr/pg_/);
2116

            
2117
Excluded table regex.
2118
C<each_column>, C<each_table>, C<type_rule>,
2119
and C<setup_model> methods ignore matching tables.
2120

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

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

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

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

            
2130
    my $last_sql = $dbi->last_sql;
2131
    $dbi = $dbi->last_sql($last_sql);
2132

            
2133
Get last successed SQL executed by C<execute> method.
2134

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

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

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

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

            
2144
    my $option = $dbi->option;
2145
    $dbi = $dbi->option($option);
2146

            
2147
L<DBI> option, used when C<connect> method is executed.
2148
Each value in option override the value of C<default_option>.
2149

            
cleanup
yuki-kimoto authored on 2010-10-17
2150
=head2 C<password>
2151

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

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

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

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

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

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

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

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

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

            
2174
    $dbi->quote('[]');
2175

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2185
    my $safety_character = $dbi->safety_character;
2186
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2187

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

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

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

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

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

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

            
2204
    my $tag_parse = $dbi->tag_parse(0);
2205
    $dbi = $dbi->tag_parse;
2206

            
2207
Enable DEPRECATED tag parsing functionality, default to 1.
2208
If you want to disable tag parsing functionality, set to 0.
2209

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

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

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

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

            
2219
    my $user_column_info = $dbi->user_column_info;
2220
    $dbi = $dbi->user_column_info($user_column_info);
2221

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

            
2224
    [
2225
        {table => 'book', column => 'title', info => {...}},
2226
        {table => 'author', column => 'name', info => {...}}
2227
    ]
2228

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

            
2231
    my $user_column_info
2232
      = $dbi->get_column_info(exclude_table => qr/^system/);
2233
    $dbi->user_column_info($user_column_info);
2234

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

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

            
2240
    my $user_table_info = $dbi->user_table_info;
2241
    $dbi = $dbi->user_table_info($user_table_info);
2242

            
2243
You can set the following data.
2244

            
2245
    [
2246
        {table => 'book', info => {...}},
2247
        {table => 'author', info => {...}}
2248
    ]
2249

            
2250
Usually, you can set return value of C<get_table_info>.
2251

            
2252
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2253
    $dbi->user_table_info($user_table_info);
2254

            
2255
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2256
to find table info.
2257

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2294
Create column clause. The follwoing column clause is created.
2295

            
2296
    book.author as "book.author",
2297
    book.title as "book.title"
2298

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2301
    # Separator is hyphen
2302
    $dbi->separator('-');
2303
    
2304
    book.author as "book-author",
2305
    book.title as "book-title"
2306
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2307
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2308

            
update pod
Yuki Kimoto authored on 2011-03-13
2309
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2310
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2311
        user => 'ken',
2312
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2313
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2314
    );
2315

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

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

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

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

            
2326
Get rows count.
2327

            
2328
Options is same as C<select> method's ones.
2329

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2332
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2333
        table => 'book',
2334
        primary_key => 'id',
2335
        join => [
2336
            'inner join company on book.comparny_id = company.id'
2337
        ],
2338
    );
2339

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

            
2343
   $dbi->model('book')->select(...);
2344

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

            
2347
    my $dbh = $dbi->dbh;
2348

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

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

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

            
2356
Execute delete statement.
2357

            
2358
The following opitons are available.
2359

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

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

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

            
2367
=item C<id>
2368

            
2369
    id => 4
2370
    id => [4, 5]
2371

            
2372
ID corresponding to C<primary_key>.
2373
You can delete rows by C<id> and C<primary_key>.
2374

            
2375
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2376
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2377
        id => [4, 5],
2378
        table => 'book',
2379
    );
2380

            
2381
The above is same as the followin one.
2382

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

            
2385
=item C<prefix>
2386

            
2387
    prefix => 'some'
2388

            
2389
prefix before table name section.
2390

            
2391
    delete some from book
2392

            
2393
=item C<table>
2394

            
2395
    table => 'book'
2396

            
2397
Table name.
2398

            
2399
=item C<where>
2400

            
2401
Same as C<select> method's C<where> option.
2402

            
2403
=back
2404

            
2405
=head2 C<delete_all>
2406

            
2407
    $dbi->delete_all(table => $table);
2408

            
2409
Execute delete statement for all rows.
2410
Options is same as C<delete>.
2411

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

            
2414
    $dbi->each_column(
2415
        sub {
2416
            my ($dbi, $table, $column, $column_info) = @_;
2417
            
2418
            my $type = $column_info->{TYPE_NAME};
2419
            
2420
            if ($type eq 'DATE') {
2421
                # ...
2422
            }
2423
        }
2424
    );
2425

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

            
2431
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2432
infromation, you can improve the performance of C<each_column> in
2433
the following way.
2434

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

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

            
2441
    $dbi->each_table(
2442
        sub {
2443
            my ($dbi, $table, $table_info) = @_;
2444
            
2445
            my $table_name = $table_info->{TABLE_NAME};
2446
        }
2447
    );
2448

            
improved pod
Yuki Kimoto authored on 2011-10-14
2449
Iterate all table informationsfrom in database.
2450
Argument is callback which is executed when one table is found.
2451
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2452
C<table information>.
2453

            
2454
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2455
infromation, you can improve the performance of C<each_table> in
2456
the following way.
2457

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

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

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

            
2469
    my $result = $dbi->execute(
2470
      "select * from book where title = :book.title and author like :book.author",
2471
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2472
    );
2473

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2480
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2481
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2482
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2483
    select * from book where title = :title and author like :author
2484
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2485
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2486
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2487

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2491
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2492
    select * from book where :title{=} and :author{like}
2493
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2494
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2495
    select * from where title = ? and author like ?;
2496

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

            
2501
    select * from where title = "aa\\:bb";
2502

            
cleanup
Yuki Kimoto authored on 2011-10-20
2503
B<OPTIONS>
2504

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

            
2507
=over 4
2508

            
cleanup
Yuki Kimoto authored on 2011-10-20
2509
=item C<append>
2510

            
2511
    append => 'order by name'
2512

            
2513
Append some statement after SQL.
2514

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

            
2517
Specify database bind data type.
2518

            
2519
    bind_type => [image => DBI::SQL_BLOB]
2520
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2521

            
2522
This is used to bind parameter by C<bind_param> of statment handle.
2523

            
2524
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2525

            
update pod
Yuki Kimoto authored on 2011-03-13
2526
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2527
    
2528
    filter => {
2529
        title  => sub { uc $_[0] }
2530
        author => sub { uc $_[0] }
2531
    }
update pod
Yuki Kimoto authored on 2011-03-13
2532

            
updated pod
Yuki Kimoto authored on 2011-06-09
2533
    # Filter name
2534
    filter => {
2535
        title  => 'upper_case',
2536
        author => 'upper_case'
2537
    }
2538
        
2539
    # At once
2540
    filter => [
2541
        [qw/title author/]  => sub { uc $_[0] }
2542
    ]
2543

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

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

            
2551
    id => 4
2552
    id => [4, 5]
2553

            
2554
ID corresponding to C<primary_key>.
2555
You can delete rows by C<id> and C<primary_key>.
2556

            
2557
    $dbi->execute(
2558
        "select * from book where id1 = :id1 and id2 = :id2",
2559
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2560
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2561
        id => [4, 5],
2562
    );
2563

            
2564
The above is same as the followin one.
2565

            
2566
    $dbi->execute(
2567
        "select * from book where id1 = :id1 and id2 = :id2",
2568
        {id1 => 4, id2 => 5}
2569
    );
2570

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

            
2573
    query => 1
2574

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

            
2578
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2579
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2580
    my $columns = $query->columns;
2581
    
2582
If you want to execute SQL fast, you can do the following way.
2583

            
2584
    my $query;
2585
    foreach my $row (@$rows) {
2586
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2587
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2588
    }
2589

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

            
2593
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
2594
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2595
    
2596
    my $query;
2597
    my $sth;
2598
    foreach my $row (@$rows) {
2599
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2600
      $sth ||= $query->sth;
2601
      $sth->execute(map { $row->{$_} } sort keys %$row);
2602
    }
2603

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2610
    primary_key => 'id'
2611
    primary_key => ['id1', 'id2']
2612

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

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

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

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

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

            
2623
    $dbi->select(
2624
        table => 'book',
2625
        column => 'distinct(name)',
2626
        after_build_sql => sub {
2627
            "select count(*) from ($_[0]) as t1"
2628
        }
2629
    );
2630

            
2631
The following SQL is executed.
2632

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2635
=item C<table>
2636
    
2637
    table => 'author'
2638

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2646
    # Same
2647
    $dbi->execute(
2648
      "select * from book where title = :book.title and author = :book.author",
2649
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2650

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2653
    table_alias => {user => 'worker'}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2654

            
2655
Table alias. Key is real table name, value is alias table name.
2656
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2657
on alias table name.
2658

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

            
2661
    type_rule_off => 1
2662

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

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

            
2667
    type_rule1_off => 1
2668

            
2669
Turn C<into1> type rule off.
2670

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

            
2673
    type_rule2_off => 1
2674

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

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

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

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

            
2683
get column infomation except for one which match C<exclude_table> pattern.
2684

            
2685
    [
2686
        {table => 'book', column => 'title', info => {...}},
2687
        {table => 'author', column => 'name' info => {...}}
2688
    ]
2689

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

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

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

            
2696
    [
2697
        {table => 'book', info => {...}},
2698
        {table => 'author', info => {...}}
2699
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2700

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

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

            
2705
    $dbi->helper(
2706
        update_or_insert => sub {
2707
            my $self = shift;
2708
            
2709
            # Process
2710
        },
2711
        find_or_create   => sub {
2712
            my $self = shift;
2713
            
2714
            # Process
2715
        }
2716
    );
2717

            
2718
Register helper. These helper is called directly from L<DBIx::Custom> object.
2719

            
2720
    $dbi->update_or_insert;
2721
    $dbi->find_or_create;
2722

            
cleanup
yuki-kimoto authored on 2010-10-17
2723
=head2 C<insert>
2724

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

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

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

            
2733
    {date => \"NOW()"}
2734

            
cleanup
Yuki Kimoto authored on 2011-10-20
2735
B<options>
2736

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2744
    id => 4
2745
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2746

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2750
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2751
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2752
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2753
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2754
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2755
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2756

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

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

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

            
2766
    prefix => 'or replace'
2767

            
2768
prefix before table name section
2769

            
2770
    insert or replace into book
2771

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

            
2774
    table => 'book'
2775

            
2776
Table name.
2777

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

            
2780
    timestamp => 1
2781

            
2782
If this value is set to 1,
2783
automatically created timestamp column is set based on
2784
C<timestamp> attribute's C<insert> value.
2785

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

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

            
2790
placeholder wrapped string.
2791

            
2792
If the following statement
2793

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

            
2797
is executed, the following SQL is executed.
2798

            
2799
    insert into book price values ( ? + 5 );
2800

            
update pod
Yuki Kimoto authored on 2011-03-13
2801
=back
2802

            
2803
=over 4
2804

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2812
    lib / MyModel.pm
2813
        / MyModel / book.pm
2814
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2815

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

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

            
2820
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2821
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2822
    
2823
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2824

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2829
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2830
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2831
    
2832
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2833

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2836
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2837
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2838
    
2839
    1;
2840
    
updated pod
Yuki Kimoto authored on 2011-06-21
2841
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2842

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

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

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

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

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

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

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

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

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

            
2868
    my $like_value = $dbi->like_value
2869

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

            
2872
    sub { "%$_[0]%" }
2873

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

            
2876
    my $mapper = $dbi->mapper(param => $param);
2877

            
2878
Create a new L<DBIx::Custom::Mapper> object.
2879

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

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

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

            
2886
    {key1 => [1, 1], key2 => 2}
2887

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

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

            
2892
    my $model = $dbi->model('book');
2893

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

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

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

            
2901
Create column clause for myself. The follwoing column clause is created.
2902

            
2903
    book.author as author,
2904
    book.title as title
2905

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

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

            
2915
Create a new L<DBIx::Custom> object.
2916

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

            
2919
    my $not_exists = $dbi->not_exists;
2920

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

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

            
2926
    my $order = $dbi->order;
2927

            
2928
Create a new L<DBIx::Custom::Order> object.
2929

            
cleanup
yuki-kimoto authored on 2010-10-17
2930
=head2 C<register_filter>
2931

            
update pod
Yuki Kimoto authored on 2011-03-13
2932
    $dbi->register_filter(
2933
        # Time::Piece object to database DATE format
2934
        tp_to_date => sub {
2935
            my $tp = shift;
2936
            return $tp->strftime('%Y-%m-%d');
2937
        },
2938
        # database DATE format to Time::Piece object
2939
        date_to_tp => sub {
2940
           my $date = shift;
2941
           return Time::Piece->strptime($date, '%Y-%m-%d');
2942
        }
2943
    );
cleanup
yuki-kimoto authored on 2010-10-17
2944
    
update pod
Yuki Kimoto authored on 2011-03-13
2945
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2946

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2949
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2950
        table  => 'book',
2951
        column => ['author', 'title'],
2952
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2953
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2954
    
updated document
Yuki Kimoto authored on 2011-06-09
2955
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2956

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2964
=item C<column>
2965
    
updated document
Yuki Kimoto authored on 2011-06-09
2966
    column => 'author'
2967
    column => ['author', 'title']
2968

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2977
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2978
        {book => [qw/author title/]},
2979
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2980
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2981

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

            
2984
    book.author as "book.author",
2985
    book.title as "book.title",
2986
    person.name as "person.name",
2987
    person.age as "person.age"
2988

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

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

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

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

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

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

            
3004
=item C<id>
3005

            
3006
    id => 4
3007
    id => [4, 5]
3008

            
3009
ID corresponding to C<primary_key>.
3010
You can select rows by C<id> and C<primary_key>.
3011

            
3012
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3013
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3014
        id => [4, 5],
3015
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3016
    );
3017

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3020
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3021
        where => {id1 => 4, id2 => 5},
3022
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3023
    );
3024
    
cleanup
Yuki Kimoto authored on 2011-10-20
3025
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3026

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

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

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

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

            
3039
    prefix => 'SQL_CALC_FOUND_ROWS'
3040

            
3041
Prefix of column cluase
3042

            
3043
    select SQL_CALC_FOUND_ROWS title, author from book;
3044

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

            
3047
    join => [
3048
        'left outer join company on book.company_id = company_id',
3049
        'left outer join location on company.location_id = location.id'
3050
    ]
3051
        
3052
Join clause. If column cluase or where clause contain table name like "company.name",
3053
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3054

            
3055
    $dbi->select(
3056
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3057
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3058
        where => {'company.name' => 'Orange'},
3059
        join => [
3060
            'left outer join company on book.company_id = company.id',
3061
            'left outer join location on company.location_id = location.id'
3062
        ]
3063
    );
3064

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3068
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3069
    from book
3070
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3071
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3072

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3073
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
3074
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3075

            
3076
    $dbi->select(
3077
        table => 'book',
3078
        column => ['company.location_id as location_id'],
3079
        where => {'company.name' => 'Orange'},
3080
        join => [
3081
            {
3082
                clause => 'left outer join location on company.location_id = location.id',
3083
                table => ['company', 'location']
3084
            }
3085
        ]
3086
    );
3087

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3092
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3093

            
updated document
Yuki Kimoto authored on 2011-06-09
3094
=item C<where>
3095
    
3096
    # Hash refrence
3097
    where => {author => 'Ken', 'title' => 'Perl'}
3098
    
3099
    # DBIx::Custom::Where object
3100
    where => $dbi->where(
3101
        clause => ['and', 'author = :author', 'title like :title'],
3102
        param  => {author => 'Ken', title => '%Perl%'}
3103
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3104
    
3105
    # Array reference 1 (array reference, hash referenc). same as above
3106
    where => [
3107
        ['and', 'author = :author', 'title like :title'],
3108
        {author => 'Ken', title => '%Perl%'}
3109
    ];    
3110
    
3111
    # Array reference 2 (String, hash reference)
3112
    where => [
3113
        'title like :title',
3114
        {title => '%Perl%'}
3115
    ]
3116
    
3117
    # String
3118
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3119

            
cleanup
Yuki Kimoto authored on 2011-10-20
3120
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3121
    
update pod
Yuki Kimoto authored on 2011-03-12
3122
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3123

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

            
3126
    $dbi->setup_model;
3127

            
3128
Setup all model objects.
3129
C<columns> of model object is automatically set, parsing database information.
3130

            
3131
=head2 C<type_rule>
3132

            
3133
    $dbi->type_rule(
3134
        into1 => {
3135
            date => sub { ... },
3136
            datetime => sub { ... }
3137
        },
3138
        into2 => {
3139
            date => sub { ... },
3140
            datetime => sub { ... }
3141
        },
3142
        from1 => {
3143
            # DATE
3144
            9 => sub { ... },
3145
            # DATETIME or TIMESTAMP
3146
            11 => sub { ... },
3147
        }
3148
        from2 => {
3149
            # DATE
3150
            9 => sub { ... },
3151
            # DATETIME or TIMESTAMP
3152
            11 => sub { ... },
3153
        }
3154
    );
3155

            
3156
Filtering rule when data is send into and get from database.
3157
This has a little complex problem.
3158

            
3159
In C<into1> and C<into2> you can specify
3160
type name as same as type name defined
3161
by create table, such as C<DATETIME> or C<DATE>.
3162

            
3163
Note that type name and data type don't contain upper case.
3164
If these contain upper case charactor, you convert it to lower case.
3165

            
3166
C<into2> is executed after C<into1>.
3167

            
3168
Type rule of C<into1> and C<into2> is enabled on the following
3169
column name.
3170

            
3171
=over 4
3172

            
3173
=item 1. column name
3174

            
3175
    issue_date
3176
    issue_datetime
3177

            
3178
This need C<table> option in each method.
3179

            
3180
=item 2. table name and column name, separator is dot
3181

            
3182
    book.issue_date
3183
    book.issue_datetime
3184

            
3185
=back
3186

            
3187
You get all type name used in database by C<available_typename>.
3188

            
3189
    print $dbi->available_typename;
3190

            
3191
In C<from1> and C<from2> you specify data type, not type name.
3192
C<from2> is executed after C<from1>.
3193
You get all data type by C<available_datatype>.
3194

            
3195
    print $dbi->available_datatype;
3196

            
3197
You can also specify multiple types at once.
3198

            
3199
    $dbi->type_rule(
3200
        into1 => [
3201
            [qw/DATE DATETIME/] => sub { ... },
3202
        ],
3203
    );
3204

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

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

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

            
3211
If you want to set constant value to row data, use scalar reference
3212
as parameter value.
3213

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3225
    id => 4
3226
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3227

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3231
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3232
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3233
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3234
        id => [4, 5],
3235
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3236
    );
update pod
Yuki Kimoto authored on 2011-03-13
3237

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3240
    $dbi->update(
3241
        {title => 'Perl', author => 'Ken'}
3242
        where => {id1 => 4, id2 => 5},
3243
        table => 'book'
3244
    );
update pod
Yuki Kimoto authored on 2011-03-13
3245

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

            
3248
    prefix => 'or replace'
3249

            
3250
prefix before table name section
3251

            
3252
    update or replace book
3253

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

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

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

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

            
3262
    timestamp => 1
3263

            
3264
If this value is set to 1,
3265
automatically updated timestamp column is set based on
3266
C<timestamp> attribute's C<update> value.
3267

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

            
3270
Same as C<select> method's C<where> option.
3271

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

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

            
3276
placeholder wrapped string.
3277

            
3278
If the following statement
3279

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

            
3283
is executed, the following SQL is executed.
3284

            
3285
    update book set price =  ? + 5;
3286

            
updated pod
Yuki Kimoto authored on 2011-06-08
3287
=back
update pod
Yuki Kimoto authored on 2011-03-13
3288

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3296
=head2 C<update_or_insert EXPERIMENTAL>
3297
    
3298
    # Where
3299
    $dbi->update_or_insert(
3300
        {id => 1, title => 'Perl'},
3301
        table => 'book',
3302
        where => {id => 1},
3303
        select_option => {append => 'for update'}
3304
    );
3305
    
3306
    # ID
3307
    $dbi->update_or_insert(
3308
        {title => 'Perl'},
3309
        table => 'book',
3310
        id => 1,
3311
        primary_key => 'id',
3312
        select_option => {append => 'for update'}
3313
    );
3314
    
3315
Update or insert.
3316

            
3317
In both examples, the following SQL is executed.
3318

            
3319
    # In case insert
3320
    insert into book (id, title) values (?, ?)
3321
    
3322
    # In case update
3323
    update book set (id = ?, title = ?) where book.id = ?
3324

            
3325
The following opitons are available adding to C<update> option.
3326

            
3327
=over 4
3328

            
3329
=item C<select_option>
3330

            
3331
    select_option => {append => 'for update'}
3332

            
3333
select method option,
3334
select method is used to check the row is already exists.
3335

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

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

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

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

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

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

            
3356
    $dbi->show_datatype($table);
3357

            
3358
Show data type of the columns of specified table.
3359

            
3360
    book
3361
    title: 5
3362
    issue_date: 91
3363

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

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

            
3368
    $dbi->show_tables;
3369

            
3370
Show tables.
3371

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

            
3374
    $dbi->show_typename($table);
3375

            
3376
Show type name of the columns of specified table.
3377

            
3378
    book
3379
    title: varchar
3380
    issue_date: date
3381

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

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

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

            
3388
Create values clause.
3389

            
3390
    (title, author) values (title = :title, age = :age);
3391

            
3392
You can use this in insert statement.
3393

            
3394
    my $insert_sql = "insert into book $values_clause";
3395

            
3396
=head2 C<where>
3397

            
3398
    my $where = $dbi->where(
3399
        clause => ['and', 'title = :title', 'author = :author'],
3400
        param => {title => 'Perl', author => 'Ken'}
3401
    );
3402

            
3403
Create a new L<DBIx::Custom::Where> object.
3404

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

            
3407
=head2 C<DBIX_CUSTOM_DEBUG>
3408

            
3409
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3410
executed SQL and bind values are printed to STDERR.
3411

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

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

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

            
3418
L<DBIx::Custom>
3419

            
3420
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3421
    default_dbi_option # will be removed 2017/1/1
3422
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3423
    data_source # will be removed at 2017/1/1
3424
    dbi_options # will be removed at 2017/1/1
3425
    filter_check # will be removed at 2017/1/1
3426
    reserved_word_quote # will be removed at 2017/1/1
3427
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3428
    
3429
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3430
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3431
    assign_param # will be removed at 2017/1/1
3432
    update_param # will be removed at 2017/1/1
3433
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3434
    create_query # will be removed at 2017/1/1
3435
    apply_filter # will be removed at 2017/1/1
3436
    select_at # will be removed at 2017/1/1
3437
    delete_at # will be removed at 2017/1/1
3438
    update_at # will be removed at 2017/1/1
3439
    insert_at # will be removed at 2017/1/1
3440
    register_tag # will be removed at 2017/1/1
3441
    default_bind_filter # will be removed at 2017/1/1
3442
    default_fetch_filter # will be removed at 2017/1/1
3443
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3444
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3445
    register_tag_processor # will be removed at 2017/1/1
3446
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3447
    
3448
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3449
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3450
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3451
    select method relation option # will be removed at 2017/1/1
3452
    select method param option # will be removed at 2017/1/1
3453
    select method column option [COLUMN, as => ALIAS] format
3454
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3455
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3456
    
3457
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3458
    execute("select * from {= title}"); # execute method's
3459
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3460
                                        # will be removed at 2017/1/1
3461
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3462

            
3463
L<DBIx::Custom::Model>
3464

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3465
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3466
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3467
    filter # will be removed at 2017/1/1
3468
    name # will be removed at 2017/1/1
3469
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3470

            
3471
L<DBIx::Custom::Query>
3472
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3473
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3474
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3475
    table # will be removed at 2017/1/1
3476
    filters # will be removed at 2017/1/1
3477
    
3478
    # Methods
3479
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3480

            
3481
L<DBIx::Custom::QueryBuilder>
3482
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3483
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3484
    tags # will be removed at 2017/1/1
3485
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3486
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3487
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3488
    register_tag # will be removed at 2017/1/1
3489
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3490
    
3491
    # Others
3492
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3493
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3494

            
3495
L<DBIx::Custom::Result>
3496
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3497
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3498
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3499
    
3500
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3501
    end_filter # will be removed at 2017/1/1
3502
    remove_end_filter # will be removed at 2017/1/1
3503
    remove_filter # will be removed at 2017/1/1
3504
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3505

            
3506
L<DBIx::Custom::Tag>
3507

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

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

            
3512
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3513
except for attribute method.
3514
You can check all DEPRECATED functionalities by document.
3515
DEPRECATED functionality is removed after five years,
3516
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
3517
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3518

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

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

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

            
3525
C<< <kimoto.yuki at gmail.com> >>
3526

            
3527
L<http://github.com/yuki-kimoto/DBIx-Custom>
3528

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3529
=head1 AUTHOR
3530

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

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

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

            
3537
This program is free software; you can redistribute it and/or modify it
3538
under the same terms as Perl itself.
3539

            
3540
=cut