DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3522 lines | 91.312kb
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 {
cleanup
Yuki Kimoto authored on 2011-10-21
233
    my ($self, %opt) = @_;
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-10-21
236
    my $where            = $opt{where} || {};
237
    my $where_param      = $opt{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
238
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
239
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
240
    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
241
      if defined $opt{id};
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
242
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
243
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
244
        $where_clause = "where " . $where->[0];
245
        $where_param = $where->[1];
246
    }
247
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
248
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
249
        $where_param = keys %$where_param
250
                     ? $self->merge_param($where_param, $where->param)
251
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
252
        
253
        # String where
254
        $where_clause = $where->to_string;
255
    }
256
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
257
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
258
      if $where_clause eq '' && !$opt{allow_delete_all};
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
259

            
cleanup
Yuki Kimoto authored on 2011-04-02
260
    # Delete statement
micro optimization
Yuki Kimoto authored on 2011-09-30
261
    my $sql;
262
    $sql .= "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
263
    $sql .= "$opt{prefix} " if defined $opt{prefix};
264
    $sql .= "from " . $self->_q($opt{table}) . " $where_clause ";
packaging one directory
yuki-kimoto authored on 2009-11-16
265
    
266
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
267
    return $self->execute($sql, $where_param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
268
}
269

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
274
sub create_model {
275
    my $self = shift;
276
    
cleanup
Yuki Kimoto authored on 2011-04-02
277
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
278
    my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
279
    $opt->{dbi} = $self;
280
    my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
281
    my $model_name  = delete $opt->{name};
282
    my $model_table = delete $opt->{table};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
283
    $model_name ||= $model_table;
284
    
cleanup
Yuki Kimoto authored on 2011-04-02
285
    # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
286
    my $model = $model_class->new($opt);
cleanup
Yuki Kimoto authored on 2011-08-13
287
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
288
    $model->name($model_name) unless $model->name;
289
    $model->table($model_table) unless $model->table;
290
    
micro optimization
Yuki Kimoto authored on 2011-07-30
291
    # Apply filter(DEPRECATED logic)
292
    if ($model->{filter}) {
293
        my $filter = ref $model->filter eq 'HASH'
294
                   ? [%{$model->filter}]
295
                   : $model->filter;
296
        $filter ||= [];
297
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
298
          if @$filter;
299
        $self->_apply_filter($model->table, @$filter);
300
    }
301
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
302
    # Set model
303
    $self->model($model->name, $model);
304
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
305
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
306
}
307

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
311
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
312
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
313
    if ($user_column_info) {
314
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
315
    }
316
    else {
317
    
318
        my $re = $self->exclude_table || $options{exclude_table};
319
        # Tables
320
        my %tables;
321
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
322

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
323
        # Iterate all tables
324
        my @tables = sort keys %tables;
325
        for (my $i = 0; $i < @tables; $i++) {
326
            my $table = $tables[$i];
327
            
328
            # Iterate all columns
329
            my $sth_columns;
330
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
331
            next if $@;
332
            while (my $column_info = $sth_columns->fetchrow_hashref) {
333
                my $column = $column_info->{COLUMN_NAME};
334
                $self->$cb($table, $column, $column_info);
335
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
336
        }
337
    }
338
}
339

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
340
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
341
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
342
    
cleanup test
Yuki Kimoto authored on 2011-08-16
343
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
344
    
added test
Yuki Kimoto authored on 2011-08-16
345
    # Iterate tables
346
    if ($user_table_infos) {
347
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
348
    }
349
    else {
350
        my $re = $self->exclude_table || $option{exclude};
351
        my $sth_tables = $self->dbh->table_info;
352
        while (my $table_info = $sth_tables->fetchrow_hashref) {
353
            
354
            # Table
355
            my $table = $table_info->{TABLE_NAME};
356
            next if defined $re && $table =~ /$re/;
357
            $self->$cb($table, $table_info);
358
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
359
    }
360
}
361

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
402
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
403
    
404
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
405
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
406
    
cleanup
Yuki Kimoto authored on 2011-04-02
407
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
408
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
409
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
410

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

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

            
537
        return $result;
538
    }
cleanup
Yuki Kimoto authored on 2011-04-02
539
    
540
    # Not select statement
541
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
542
}
543

            
added test
Yuki Kimoto authored on 2011-08-16
544
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
545
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
546
    
cleanup
Yuki Kimoto authored on 2011-10-21
547
    my $exclude = delete $opt{exclude};
548
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
549
    
added test
Yuki Kimoto authored on 2011-08-16
550
    my $table_info = [];
551
    $self->each_table(
552
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
553
        exclude => $exclude
554
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
555
    
cleanup test
Yuki Kimoto authored on 2011-08-16
556
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
557
}
558

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
559
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
560
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
561
    
cleanup
Yuki Kimoto authored on 2011-10-21
562
    my $exclude_table = delete $opt{exclude_table};
563
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
564
    
565
    my $column_info = [];
566
    $self->each_column(
567
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
568
        exclude_table => $exclude_table
569
    );
570
    
571
    return [
572
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
573
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
574
}
575

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
576
sub helper {
577
    my $self = shift;
578
    
579
    # Register method
580
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
581
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
582
    
583
    return $self;
584
}
585

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
619
sub update_or_insert {
620
    my $self = shift;
621

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
655
sub insert_timestamp {
656
    my $self = shift;
657
    
658
    if (@_) {
659
        $self->{insert_timestamp} = [@_];
660
        
661
        return $self;
662
    }
663
    return $self->{insert_timestamp};
664
}
665

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
666
sub include_model {
667
    my ($self, $name_space, $model_infos) = @_;
668
    
cleanup
Yuki Kimoto authored on 2011-04-02
669
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
670
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
671
    
672
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
673
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
674

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
733
sub mapper {
734
    my $self = shift;
735
    return DBIx::Custom::Mapper->new(@_);
736
}
737

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
738
sub merge_param {
739
    my ($self, @params) = @_;
740
    
cleanup
Yuki Kimoto authored on 2011-04-02
741
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
742
    my $merge = {};
743
    foreach my $param (@params) {
744
        foreach my $column (keys %$param) {
745
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
746
            
747
            if (exists $merge->{$column}) {
748
                $merge->{$column} = [$merge->{$column}]
749
                  unless ref $merge->{$column} eq 'ARRAY';
750
                push @{$merge->{$column}},
751
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
752
            }
753
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
754
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
755
            }
756
        }
757
    }
758
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
759
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
760
}
761

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
762
sub model {
763
    my ($self, $name, $model) = @_;
764
    
cleanup
Yuki Kimoto authored on 2011-04-02
765
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
766
    if ($model) {
767
        $self->models->{$name} = $model;
768
        return $self;
769
    }
770
    
771
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
772
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
773
      unless $self->models->{$name};
774
    
cleanup
Yuki Kimoto authored on 2011-04-02
775
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
776
    return $self->models->{$name};
777
}
778

            
cleanup
Yuki Kimoto authored on 2011-03-21
779
sub mycolumn {
780
    my ($self, $table, $columns) = @_;
781
    
cleanup
Yuki Kimoto authored on 2011-04-02
782
    # Create column clause
783
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
784
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
785
    push @column, $self->_q($table) . "." . $self->_q($_) .
786
      " as " . $self->_q($_)
787
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
788
    
789
    return join (', ', @column);
790
}
791

            
added dbi_options attribute
kimoto authored on 2010-12-20
792
sub new {
793
    my $self = shift->SUPER::new(@_);
794
    
cleanup
Yuki Kimoto authored on 2011-04-02
795
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
796
    my @attrs = keys %$self;
797
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
798
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
799
          unless $self->can($attr);
800
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
801

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
802
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
803
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
804
        '?'     => \&DBIx::Custom::Tag::placeholder,
805
        '='     => \&DBIx::Custom::Tag::equal,
806
        '<>'    => \&DBIx::Custom::Tag::not_equal,
807
        '>'     => \&DBIx::Custom::Tag::greater_than,
808
        '<'     => \&DBIx::Custom::Tag::lower_than,
809
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
810
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
811
        'like'  => \&DBIx::Custom::Tag::like,
812
        'in'    => \&DBIx::Custom::Tag::in,
813
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
814
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
815
    };
816
    
817
    return $self;
818
}
819

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

            
822
sub order {
823
    my $self = shift;
824
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
825
}
826

            
cleanup
yuki-kimoto authored on 2010-10-17
827
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
828
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
829
    
830
    # Register filter
831
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
832
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
833
    
cleanup
Yuki Kimoto authored on 2011-04-02
834
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
835
}
packaging one directory
yuki-kimoto authored on 2009-11-16
836

            
837
sub select {
cleanup
Yuki Kimoto authored on 2011-10-21
838
    my ($self, %opt) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
839

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
956
sub setup_model {
957
    my $self = shift;
958
    
cleanup
Yuki Kimoto authored on 2011-04-02
959
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
960
    $self->each_column(
961
        sub {
962
            my ($self, $table, $column, $column_info) = @_;
963
            if (my $model = $self->models->{$table}) {
964
                push @{$model->columns}, $column;
965
            }
966
        }
967
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
968
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
969
}
970

            
update pod
Yuki Kimoto authored on 2011-08-10
971
sub show_datatype {
972
    my ($self, $table) = @_;
973
    croak "Table name must be specified" unless defined $table;
974
    print "$table\n";
975
    
976
    my $result = $self->select(table => $table, where => "'0' <> '0'");
977
    my $sth = $result->sth;
978

            
979
    my $columns = $sth->{NAME};
980
    my $data_types = $sth->{TYPE};
981
    
982
    for (my $i = 0; $i < @$columns; $i++) {
983
        my $column = $columns->[$i];
984
        my $data_type = $data_types->[$i];
985
        print "$column: $data_type\n";
986
    }
987
}
988

            
989
sub show_typename {
990
    my ($self, $t) = @_;
991
    croak "Table name must be specified" unless defined $t;
992
    print "$t\n";
993
    
994
    $self->each_column(sub {
995
        my ($self, $table, $column, $infos) = @_;
996
        return unless $table eq $t;
997
        my $typename = $infos->{TYPE_NAME};
998
        print "$column: $typename\n";
999
    });
1000
    
1001
    return $self;
1002
}
1003

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1004
sub show_tables {
1005
    my $self = shift;
1006
    
1007
    my %tables;
1008
    $self->each_table(sub { $tables{$_[1]}++ });
1009
    print join("\n", sort keys %tables) . "\n";
1010
    return $self;
1011
}
1012

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1048
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1049
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1050
                }
1051
            });
1052
        }
1053

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1076
sub _create_where {
1077
    my $self = shift;
1078
    
1079
}
1080

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1084
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1085
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1086
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1087
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1088
    warn "update method where_param option is DEPRECATED!"
1089
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1090
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
1091
    my $where = $opt{where} || {};
1092
    my $where_param = $opt{where_param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1093
    
1094
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1095
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1096
        my $columns = $update_timestamp->[0];
1097
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1098
        my $value = $update_timestamp->[1];
1099
        $value = $value->() if ref $value eq 'CODE';
1100
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1101
    }
1102

            
cleanup
Yuki Kimoto authored on 2011-10-21
1103
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1104
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1105

            
1106
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1107
    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
1108
      if defined $opt{id};
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1109
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1110
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1111
        $where_clause = "where " . $where->[0];
1112
        $where_param = $where->[1];
1113
    }
1114
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1115
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1116
        $where_param = keys %$where_param
1117
                     ? $self->merge_param($where_param, $where->param)
1118
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1119
        
1120
        # String where
1121
        $where_clause = $where->to_string;
1122
    }
1123
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1124
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1125
      if "$where_clause" eq '' && !$opt{allow_update_all};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1126
    
cleanup
Yuki Kimoto authored on 2011-10-21
1127
    # Merge where parameter to parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1128
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1129
    
cleanup
Yuki Kimoto authored on 2011-04-02
1130
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1131
    my $sql = "update ";
1132
    $sql .= "$opt{prefix} " if defined $opt{prefix};
1133
    $sql .= $self->_q($opt{table}) . " set $assign_clause $where_clause ";
cleanup
Yuki Kimoto authored on 2011-01-27
1134
    
cleanup
yuki-kimoto authored on 2010-10-17
1135
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1136
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1137
}
1138

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1141
sub update_timestamp {
1142
    my $self = shift;
1143
    
1144
    if (@_) {
1145
        $self->{update_timestamp} = [@_];
1146
        
1147
        return $self;
1148
    }
1149
    return $self->{update_timestamp};
1150
}
1151

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1152
sub values_clause {
1153
    my ($self, $param, $opts) = @_;
1154
    
1155
    my $wrap = $opts->{wrap} || {};
1156
    
1157
    # Create insert parameter tag
1158
    my $safety = $self->safety_character;
1159
    my @columns;
1160
    my @placeholders;
1161
    foreach my $column (sort keys %$param) {
1162
        croak qq{"$column" is not safety column name } . _subname
1163
          unless $column =~ /^[$safety\.]+$/;
1164
        my $column_quote = $self->_q($column);
1165
        $column_quote =~ s/\./$self->_q(".")/e;
1166
        push @columns, $column_quote;
1167
        
1168
        my $func = $wrap->{$column} || sub { $_[0] };
1169
        push @placeholders,
1170
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1171
        : $func->(":$column");
1172
    }
1173
    
1174
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1175
           '(' . join(', ', @placeholders) . ')'
1176
}
1177

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1180
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1181
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1182
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1183
    
updated pod
Yuki Kimoto authored on 2011-06-21
1184
    # Cache
1185
    my $cache = $self->cache;
1186
    
1187
    # Query
1188
    my $query;
1189
    
1190
    # Get cached query
1191
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1192
        
updated pod
Yuki Kimoto authored on 2011-06-21
1193
        # Get query
1194
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1195
        
updated pod
Yuki Kimoto authored on 2011-06-21
1196
        # Create query
1197
        if ($q) {
1198
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1199
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1200
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1201
    }
1202
    
1203
    # Create query
1204
    unless ($query) {
1205

            
1206
        # Create query
1207
        my $builder = $self->query_builder;
1208
        $query = $builder->build_query($source);
1209

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

            
1216
        # Save query to cache
1217
        $self->cache_method->(
1218
            $self, $source,
1219
            {
1220
                sql     => $query->sql, 
1221
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1222
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1223
            }
1224
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1225
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1226

            
1227
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1228
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1229
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1230
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1231
        $query->sql($sql);
1232
    }
1233
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1234
    # Save sql
1235
    $self->last_sql($query->sql);
1236
    
updated pod
Yuki Kimoto authored on 2011-06-21
1237
    # Prepare statement handle
1238
    my $sth;
1239
    eval { $sth = $self->dbh->prepare($query->{sql})};
1240
    
1241
    if ($@) {
1242
        $self->_croak($@, qq{. Following SQL is executed.\n}
1243
                        . qq{$query->{sql}\n} . _subname);
1244
    }
1245
    
1246
    # Set statement handle
1247
    $query->sth($sth);
1248
    
1249
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1250
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1251
    
1252
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1253
}
1254

            
cleanup
Yuki Kimoto authored on 2011-04-02
1255
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1256
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1257
    
cleanup
Yuki Kimoto authored on 2011-04-02
1258
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1259
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1260
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1261
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1262
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1263
        
1264
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1265
        my $value;
1266
        if(ref $params->{$column} eq 'ARRAY') {
1267
            my $i = $count->{$column} || 0;
1268
            $i += $not_exists->{$column} || 0;
1269
            my $found;
1270
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1271
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1272
                    $not_exists->{$column}++;
1273
                }
1274
                else  {
1275
                    $value = $params->{$column}->[$k];
1276
                    $found = 1;
1277
                    last
1278
                }
1279
            }
1280
            next unless $found;
1281
        }
1282
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1283
        
cleanup
Yuki Kimoto authored on 2011-01-12
1284
        # Filter
1285
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1286
        $value = $f->($value) if $f;
1287
        
1288
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1289
        foreach my $i (1 .. 2) {
1290
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1291
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1292
            $value = $tf->($value) if $tf;
1293
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1294
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1295
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1296
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1297
        
1298
        # Count up 
1299
        $count->{$column}++;
1300
    }
1301
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1302
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1303
}
1304

            
cleanup
Yuki Kimoto authored on 2011-10-21
1305
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1306
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1307
    
1308
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1309
    croak "primary_key option " .
1310
          "must be specified with id option " . _subname
1311
      unless defined $primary_keys;
1312
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1313
    
cleanup
Yuki Kimoto authored on 2011-06-08
1314
    # Create parameter
1315
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1316
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1317
        $id = [$id] unless ref $id;
1318
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1319
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1320
          unless !ref $id || ref $id eq 'ARRAY';
1321
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1322
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1323
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1324
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1325
           my $key = $primary_keys->[$i];
1326
           $key = "$table." . $key if $table;
1327
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1328
        }
1329
    }
1330
    
cleanup
Yuki Kimoto authored on 2011-06-08
1331
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1332
}
1333

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1334
sub _connect {
1335
    my $self = shift;
1336
    
1337
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1338
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1339
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1340
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1341
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1342
    croak qq{"dsn" must be specified } . _subname
1343
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1344
    my $user        = $self->user;
1345
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1346
    my $option = $self->_option;
1347
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1348
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1349
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1350
    my $dbh;
1351
    eval {
1352
        $dbh = DBI->connect(
1353
            $dsn,
1354
            $user,
1355
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1356
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1357
        );
1358
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1359
    
1360
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1361
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1362
    
1363
    return $dbh;
1364
}
1365

            
cleanup
yuki-kimoto authored on 2010-10-17
1366
sub _croak {
1367
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1368
    
1369
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1370
    $append ||= "";
1371
    
1372
    # Verbose
1373
    if ($Carp::Verbose) { croak $error }
1374
    
1375
    # Not verbose
1376
    else {
1377
        
1378
        # Remove line and module infromation
1379
        my $at_pos = rindex($error, ' at ');
1380
        $error = substr($error, 0, $at_pos);
1381
        $error =~ s/\s+$//;
1382
        croak "$error$append";
1383
    }
1384
}
1385

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1388
sub _need_tables {
1389
    my ($self, $tree, $need_tables, $tables) = @_;
1390
    
cleanup
Yuki Kimoto authored on 2011-04-02
1391
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1392
    foreach my $table (@$tables) {
1393
        if ($tree->{$table}) {
1394
            $need_tables->{$table} = 1;
1395
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1396
        }
1397
    }
1398
}
1399

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1400
sub _option {
1401
    my $self = shift;
1402
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1403
    warn "dbi_options is DEPRECATED! use option instead\n"
1404
      if keys %{$self->dbi_options};
1405
    warn "dbi_option is DEPRECATED! use option instead\n"
1406
      if keys %{$self->dbi_option};
1407
    return $option;
1408
}
1409

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1410
sub _push_join {
1411
    my ($self, $sql, $join, $join_tables) = @_;
1412
    
cleanup
Yuki Kimoto authored on 2011-04-02
1413
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1414
    return unless @$join;
1415
    
cleanup
Yuki Kimoto authored on 2011-04-02
1416
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1417
    my $tree = {};
1418
    for (my $i = 0; $i < @$join; $i++) {
1419
        
cleanup
Yuki Kimoto authored on 2011-07-28
1420
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1421
        my $join_clause;;
1422
        my $option;
1423
        if (ref $join->[$i] eq 'HASH') {
1424
            $join_clause = $join->[$i]->{clause};
1425
            $option = {table => $join->[$i]->{table}};
1426
        }
1427
        else {
1428
            $join_clause = $join->[$i];
1429
            $option = {};
1430
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1431

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1480
sub _quote {
1481
    my $self = shift;
1482
    
1483
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1484
         : defined $self->quote ? $self->quote
1485
         : '';
1486
}
1487

            
cleanup
Yuki Kimoto authored on 2011-07-29
1488
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1489
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1490
    
1491
    my $quote = $self->_quote;
1492
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1493
    my $p;
1494
    if (defined $quote && length $quote > 1) {
1495
        $p = substr($quote, 1, 1);
1496
    }
1497
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1498
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1499
    if ($quotemeta) {
1500
        $q = quotemeta($q);
1501
        $p = quotemeta($p);
1502
    }
1503
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1504
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1505
}
1506

            
cleanup
Yuki Kimoto authored on 2011-04-02
1507
sub _remove_duplicate_table {
1508
    my ($self, $tables, $main_table) = @_;
1509
    
1510
    # Remove duplicate table
1511
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1512
    delete $tables{$main_table} if $main_table;
1513
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1514
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1515
    if (my $q = $self->_quote) {
1516
        $q = quotemeta($q);
1517
        $_ =~ s/[$q]//g for @$new_tables;
1518
    }
1519

            
1520
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1521
}
1522

            
cleanup
Yuki Kimoto authored on 2011-04-02
1523
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1524
    my ($self, $source) = @_;
1525
    
cleanup
Yuki Kimoto authored on 2011-04-02
1526
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1527
    my $tables = [];
1528
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1529
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1530
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1531
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1532
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1533
    while ($source =~ /$table_re/g) {
1534
        push @$tables, $1;
1535
    }
1536
    
1537
    return $tables;
1538
}
1539

            
cleanup
Yuki Kimoto authored on 2011-04-02
1540
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1541
    my ($self, $where) = @_;
1542
    
cleanup
Yuki Kimoto authored on 2011-04-02
1543
    my $obj;
1544
    
1545
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1546
    if (ref $where eq 'HASH') {
1547
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1548
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1549
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1550
            my $table;
1551
            my $c;
1552
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1553
                $table = $1;
1554
                $c = $2;
1555
            }
1556
            
1557
            my $table_quote;
1558
            $table_quote = $self->_q($table) if defined $table;
1559
            my $column_quote = $self->_q($c);
1560
            $column_quote = $table_quote . '.' . $column_quote
1561
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1562
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1563
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1564
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1565
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1566
    
1567
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1568
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1569
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1570
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1571
    
updated pod
Yuki Kimoto authored on 2011-06-21
1572
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1573
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1574
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1575
            clause => $where->[0],
1576
            param  => $where->[1]
1577
        );
1578
    }
1579
    
cleanup
Yuki Kimoto authored on 2011-04-02
1580
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1581
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1582
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1583
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1584
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1585
    
cleanup
Yuki Kimoto authored on 2011-04-02
1586
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1587
}
1588

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1659
# DEPRECATED!
1660
has 'data_source';
1661
has dbi_options => sub { {} };
1662
has filter_check  => 1;
1663
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1664
has dbi_option => sub { {} };
1665
has default_dbi_option => sub {
1666
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1667
    return shift->default_option;
1668
};
1669

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1670
# DEPRECATED!
1671
sub method {
1672
    warn "method is DEPRECATED! use helper instead";
1673
    return shift->helper(@_);
1674
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1675

            
1676
# DEPRECATED!
1677
sub assign_param {
1678
    my $self = shift;
1679
    warn "assing_param is DEPRECATED! use assign_clause instead";
1680
    return $self->assign_clause(@_);
1681
}
1682

            
1683
# DEPRECATED
1684
sub update_param {
1685
    my ($self, $param, $opts) = @_;
1686
    
1687
    warn "update_param is DEPRECATED! use assing_clause instead.";
1688
    
1689
    # Create update parameter tag
1690
    my $tag = $self->assign_clause($param, $opts);
1691
    $tag = "set $tag" unless $opts->{no_set};
1692

            
1693
    return $tag;
1694
}
1695

            
updated pod
Yuki Kimoto authored on 2011-06-21
1696
# DEPRECATED!
1697
sub create_query {
1698
    warn "create_query is DEPRECATED! use query option of each method";
1699
    shift->_create_query(@_);
1700
}
1701

            
cleanup
Yuki Kimoto authored on 2011-06-13
1702
# DEPRECATED!
1703
sub apply_filter {
1704
    my $self = shift;
1705
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1706
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1707
    return $self->_apply_filter(@_);
1708
}
1709

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1710
# DEPRECATED!
1711
sub select_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1712
    my ($self, %opt) = @_;
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1713

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1716
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1717
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1718
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1719
    my $where = delete $opt{where};
1720
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1721
    
1722
    # Table
1723
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1724
      unless $opt{table};
1725
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1726
    
1727
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1728
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1729
    
cleanup
Yuki Kimoto authored on 2011-10-21
1730
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1731
}
1732

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1733
# DEPRECATED!
1734
sub delete_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1735
    my ($self, %opt) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1736

            
1737
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1738
    
1739
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1740
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1741
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1742
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1743
    
1744
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1745
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1746
    
cleanup
Yuki Kimoto authored on 2011-10-21
1747
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1748
}
1749

            
cleanup
Yuki Kimoto authored on 2011-06-08
1750
# DEPRECATED!
1751
sub update_at {
1752
    my $self = shift;
1753

            
1754
    warn "update_at is DEPRECATED! use update and id option instead";
1755
    
1756
    # Arguments
1757
    my $param;
1758
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1759
    my %opt = @_;
1760
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1761
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1762
    my $where = delete $opt{where};
1763
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1764
    $param  ||= $p;
1765
    
1766
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1767
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1768
    
cleanup
Yuki Kimoto authored on 2011-10-21
1769
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1770
}
1771

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1795
# DEPRECATED!
1796
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1797
    my $self = shift;
1798
    
added warnings
Yuki Kimoto authored on 2011-06-07
1799
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1800
    
1801
    # Merge tag
1802
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1803
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1804
    
1805
    return $self;
1806
}
1807

            
1808
# DEPRECATED!
1809
sub register_tag_processor {
1810
    my $self = shift;
1811
    warn "register_tag_processor is DEPRECATED!";
1812
    # Merge tag
1813
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1814
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1815
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1816
}
1817

            
cleanup
Yuki Kimoto authored on 2011-01-25
1818
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1819
sub default_bind_filter {
1820
    my $self = shift;
1821
    
cleanup
Yuki Kimoto authored on 2011-06-13
1822
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1823
    
cleanup
Yuki Kimoto authored on 2011-01-12
1824
    if (@_) {
1825
        my $fname = $_[0];
1826
        
1827
        if (@_ && !$fname) {
1828
            $self->{default_out_filter} = undef;
1829
        }
1830
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1831
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1832
              unless exists $self->filters->{$fname};
1833
        
1834
            $self->{default_out_filter} = $self->filters->{$fname};
1835
        }
1836
        return $self;
1837
    }
1838
    
1839
    return $self->{default_out_filter};
1840
}
1841

            
cleanup
Yuki Kimoto authored on 2011-01-25
1842
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1843
sub default_fetch_filter {
1844
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1845

            
cleanup
Yuki Kimoto authored on 2011-06-13
1846
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1847
    
1848
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1849
        my $fname = $_[0];
1850

            
cleanup
Yuki Kimoto authored on 2011-01-12
1851
        if (@_ && !$fname) {
1852
            $self->{default_in_filter} = undef;
1853
        }
1854
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1855
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1856
              unless exists $self->filters->{$fname};
1857
        
1858
            $self->{default_in_filter} = $self->filters->{$fname};
1859
        }
1860
        
1861
        return $self;
1862
    }
1863
    
many changed
Yuki Kimoto authored on 2011-01-23
1864
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1865
}
1866

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1867
# DEPRECATED!
1868
sub insert_param {
1869
    my $self = shift;
1870
    warn "insert_param is DEPRECATED! use values_clause instead";
1871
    return $self->values_clause(@_);
1872
}
1873

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1874
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1875
sub insert_param_tag {
1876
    warn "insert_param_tag is DEPRECATED! " .
1877
         "use insert_param instead!";
1878
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1879
}
1880

            
1881
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1882
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1883
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1884
         "use update_param instead";
1885
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1886
}
cleanup
Yuki Kimoto authored on 2011-03-08
1887
# DEPRECATED!
1888
sub _push_relation {
1889
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1890
    
1891
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1892
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1893
        foreach my $rcolumn (keys %$relation) {
1894
            my $table1 = (split (/\./, $rcolumn))[0];
1895
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1896
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1897
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1898
        }
1899
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1900
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1901
}
1902

            
1903
# DEPRECATED!
1904
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1905
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1906
    
1907
    if (keys %{$relation || {}}) {
1908
        foreach my $rcolumn (keys %$relation) {
1909
            my $table1 = (split (/\./, $rcolumn))[0];
1910
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1911
            my $table1_exists;
1912
            my $table2_exists;
1913
            foreach my $table (@$tables) {
1914
                $table1_exists = 1 if $table eq $table1;
1915
                $table2_exists = 1 if $table eq $table2;
1916
            }
1917
            unshift @$tables, $table1 unless $table1_exists;
1918
            unshift @$tables, $table2 unless $table2_exists;
1919
        }
1920
    }
1921
}
1922

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1925
=head1 NAME
1926

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1931
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1932
    
1933
    # Connect
1934
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1935
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1936
        user => 'ken',
1937
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1938
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1939
    );
cleanup
yuki-kimoto authored on 2010-08-05
1940

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1941
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1942
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1943
    
1944
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1945
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1946
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1947
    
1948
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1949
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1950

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1955
    # Select, more complex
1956
    my $result = $dbi->select(
1957
        table  => 'book',
1958
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1959
            {book => [qw/title author/]},
1960
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1961
        ],
1962
        where  => {'book.author' => 'Ken'},
1963
        join => ['left outer join company on book.company_id = company.id'],
1964
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1965
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1966
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1967
    # Fetch
1968
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1969
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1970
    }
1971
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1972
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1973
    while (my $row = $result->fetch_hash) {
1974
        
1975
    }
1976
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1977
    # Execute SQL with parameter.
1978
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1979
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1980
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1981
    );
1982
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1983
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1984

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2000
Named place holder support
2001

            
2002
=item *
2003

            
cleanup
Yuki Kimoto authored on 2011-07-29
2004
Model support
2005

            
2006
=item *
2007

            
2008
Connection manager support
2009

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

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

            
2016
=item *
2017

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

            
2020
=item *
2021

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

            
2024
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2025

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2033
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2034
L<DBIx::Custom::Result>,
2035
L<DBIx::Custom::Query>,
2036
L<DBIx::Custom::Where>,
2037
L<DBIx::Custom::Model>,
2038
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2039

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

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

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

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

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

            
2053
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2054
        "dbi:mysql:database=$database",
2055
        $user,
2056
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2057
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2058
    );
2059
    
updated pod
Yuki Kimoto authored on 2011-06-21
2060
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2061

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

            
2065
    my $dbi = DBIx::Custom->connect(
2066
      dsn => $dsn, user => $user, password => $password, connector => 1);
2067
    
2068
    my $connector = $dbi->connector; # DBIx::Connector
2069

            
2070
Note that L<DBIx::Connector> must be installed.
2071

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2087
    {
2088
        RaiseError => 1,
2089
        PrintError => 0,
2090
        AutoCommit => 1,
2091
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2092

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

            
2095
    my $exclude_table = $dbi->exclude_table;
2096
    $dbi = $dbi->exclude_table(qr/pg_/);
2097

            
2098
Excluded table regex.
2099
C<each_column>, C<each_table>, C<type_rule>,
2100
and C<setup_model> methods ignore matching tables.
2101

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

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

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

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

            
2111
    my $last_sql = $dbi->last_sql;
2112
    $dbi = $dbi->last_sql($last_sql);
2113

            
2114
Get last successed SQL executed by C<execute> method.
2115

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

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

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

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

            
2125
    my $option = $dbi->option;
2126
    $dbi = $dbi->option($option);
2127

            
2128
L<DBI> option, used when C<connect> method is executed.
2129
Each value in option override the value of C<default_option>.
2130

            
cleanup
yuki-kimoto authored on 2010-10-17
2131
=head2 C<password>
2132

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

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

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

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

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

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

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

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

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

            
2155
    $dbi->quote('[]');
2156

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2166
    my $safety_character = $dbi->safety_character;
2167
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2168

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

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

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

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

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

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

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

            
2188
Enable DEPRECATED tag parsing functionality, default to 1.
2189
If you want to disable tag parsing functionality, set to 0.
2190

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

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

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

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

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

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

            
2205
    [
2206
        {table => 'book', column => 'title', info => {...}},
2207
        {table => 'author', column => 'name', info => {...}}
2208
    ]
2209

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

            
2212
    my $user_column_info
2213
      = $dbi->get_column_info(exclude_table => qr/^system/);
2214
    $dbi->user_column_info($user_column_info);
2215

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

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

            
2221
    my $user_table_info = $dbi->user_table_info;
2222
    $dbi = $dbi->user_table_info($user_table_info);
2223

            
2224
You can set the following data.
2225

            
2226
    [
2227
        {table => 'book', info => {...}},
2228
        {table => 'author', info => {...}}
2229
    ]
2230

            
2231
Usually, you can set return value of C<get_table_info>.
2232

            
2233
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2234
    $dbi->user_table_info($user_table_info);
2235

            
2236
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2237
to find table info.
2238

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2275
Create column clause. The follwoing column clause is created.
2276

            
2277
    book.author as "book.author",
2278
    book.title as "book.title"
2279

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2282
    # Separator is hyphen
2283
    $dbi->separator('-');
2284
    
2285
    book.author as "book-author",
2286
    book.title as "book-title"
2287
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2288
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2289

            
update pod
Yuki Kimoto authored on 2011-03-13
2290
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2291
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2292
        user => 'ken',
2293
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2294
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2295
    );
2296

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

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

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

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

            
2307
Get rows count.
2308

            
2309
Options is same as C<select> method's ones.
2310

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2313
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2314
        table => 'book',
2315
        primary_key => 'id',
2316
        join => [
2317
            'inner join company on book.comparny_id = company.id'
2318
        ],
2319
    );
2320

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

            
2324
   $dbi->model('book')->select(...);
2325

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

            
2328
    my $dbh = $dbi->dbh;
2329

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

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

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

            
2337
Execute delete statement.
2338

            
2339
The following opitons are available.
2340

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

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

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

            
2348
=item C<id>
2349

            
2350
    id => 4
2351
    id => [4, 5]
2352

            
2353
ID corresponding to C<primary_key>.
2354
You can delete rows by C<id> and C<primary_key>.
2355

            
2356
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2357
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2358
        id => [4, 5],
2359
        table => 'book',
2360
    );
2361

            
2362
The above is same as the followin one.
2363

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

            
2366
=item C<prefix>
2367

            
2368
    prefix => 'some'
2369

            
2370
prefix before table name section.
2371

            
2372
    delete some from book
2373

            
2374
=item C<table>
2375

            
2376
    table => 'book'
2377

            
2378
Table name.
2379

            
2380
=item C<where>
2381

            
2382
Same as C<select> method's C<where> option.
2383

            
2384
=back
2385

            
2386
=head2 C<delete_all>
2387

            
2388
    $dbi->delete_all(table => $table);
2389

            
2390
Execute delete statement for all rows.
2391
Options is same as C<delete>.
2392

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

            
2395
    $dbi->each_column(
2396
        sub {
2397
            my ($dbi, $table, $column, $column_info) = @_;
2398
            
2399
            my $type = $column_info->{TYPE_NAME};
2400
            
2401
            if ($type eq 'DATE') {
2402
                # ...
2403
            }
2404
        }
2405
    );
2406

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

            
2412
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2413
infromation, you can improve the performance of C<each_column> in
2414
the following way.
2415

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

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

            
2422
    $dbi->each_table(
2423
        sub {
2424
            my ($dbi, $table, $table_info) = @_;
2425
            
2426
            my $table_name = $table_info->{TABLE_NAME};
2427
        }
2428
    );
2429

            
improved pod
Yuki Kimoto authored on 2011-10-14
2430
Iterate all table informationsfrom in database.
2431
Argument is callback which is executed when one table is found.
2432
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2433
C<table information>.
2434

            
2435
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2436
infromation, you can improve the performance of C<each_table> in
2437
the following way.
2438

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

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

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

            
2450
    my $result = $dbi->execute(
2451
      "select * from book where title = :book.title and author like :book.author",
2452
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2453
    );
2454

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2461
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2462
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2463
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2464
    select * from book where title = :title and author like :author
2465
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2466
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2467
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2468

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2472
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2473
    select * from book where :title{=} and :author{like}
2474
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2475
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2476
    select * from where title = ? and author like ?;
2477

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

            
2482
    select * from where title = "aa\\:bb";
2483

            
cleanup
Yuki Kimoto authored on 2011-10-20
2484
B<OPTIONS>
2485

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

            
2488
=over 4
2489

            
cleanup
Yuki Kimoto authored on 2011-10-20
2490
=item C<append>
2491

            
2492
    append => 'order by name'
2493

            
2494
Append some statement after SQL.
2495

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

            
2498
Specify database bind data type.
2499

            
2500
    bind_type => [image => DBI::SQL_BLOB]
2501
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2502

            
2503
This is used to bind parameter by C<bind_param> of statment handle.
2504

            
2505
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2506

            
update pod
Yuki Kimoto authored on 2011-03-13
2507
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2508
    
2509
    filter => {
2510
        title  => sub { uc $_[0] }
2511
        author => sub { uc $_[0] }
2512
    }
update pod
Yuki Kimoto authored on 2011-03-13
2513

            
updated pod
Yuki Kimoto authored on 2011-06-09
2514
    # Filter name
2515
    filter => {
2516
        title  => 'upper_case',
2517
        author => 'upper_case'
2518
    }
2519
        
2520
    # At once
2521
    filter => [
2522
        [qw/title author/]  => sub { uc $_[0] }
2523
    ]
2524

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

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

            
2532
    id => 4
2533
    id => [4, 5]
2534

            
2535
ID corresponding to C<primary_key>.
2536
You can delete rows by C<id> and C<primary_key>.
2537

            
2538
    $dbi->execute(
2539
        "select * from book where id1 = :id1 and id2 = :id2",
2540
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2541
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2542
        id => [4, 5],
2543
    );
2544

            
2545
The above is same as the followin one.
2546

            
2547
    $dbi->execute(
2548
        "select * from book where id1 = :id1 and id2 = :id2",
2549
        {id1 => 4, id2 => 5}
2550
    );
2551

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

            
2554
    query => 1
2555

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

            
2559
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2560
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2561
    my $columns = $query->columns;
2562
    
2563
If you want to execute SQL fast, you can do the following way.
2564

            
2565
    my $query;
2566
    foreach my $row (@$rows) {
2567
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2568
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2569
    }
2570

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

            
2574
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
2575
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2576
    
2577
    my $query;
2578
    my $sth;
2579
    foreach my $row (@$rows) {
2580
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2581
      $sth ||= $query->sth;
2582
      $sth->execute(map { $row->{$_} } sort keys %$row);
2583
    }
2584

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2591
    primary_key => 'id'
2592
    primary_key => ['id1', 'id2']
2593

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

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

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

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

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

            
2604
    $dbi->select(
2605
        table => 'book',
2606
        column => 'distinct(name)',
2607
        after_build_sql => sub {
2608
            "select count(*) from ($_[0]) as t1"
2609
        }
2610
    );
2611

            
2612
The following SQL is executed.
2613

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2616
=item C<table>
2617
    
2618
    table => 'author'
2619

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2627
    # Same
2628
    $dbi->execute(
2629
      "select * from book where title = :book.title and author = :book.author",
2630
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2631

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

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

            
2636
Table alias. Key is real table name, value is alias table name.
2637
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2638
on alias table name.
2639

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

            
2642
    type_rule_off => 1
2643

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

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

            
2648
    type_rule1_off => 1
2649

            
2650
Turn C<into1> type rule off.
2651

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

            
2654
    type_rule2_off => 1
2655

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

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

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

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

            
2664
get column infomation except for one which match C<exclude_table> pattern.
2665

            
2666
    [
2667
        {table => 'book', column => 'title', info => {...}},
2668
        {table => 'author', column => 'name' info => {...}}
2669
    ]
2670

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

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

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

            
2677
    [
2678
        {table => 'book', info => {...}},
2679
        {table => 'author', info => {...}}
2680
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2681

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

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

            
2686
    $dbi->helper(
2687
        update_or_insert => sub {
2688
            my $self = shift;
2689
            
2690
            # Process
2691
        },
2692
        find_or_create   => sub {
2693
            my $self = shift;
2694
            
2695
            # Process
2696
        }
2697
    );
2698

            
2699
Register helper. These helper is called directly from L<DBIx::Custom> object.
2700

            
2701
    $dbi->update_or_insert;
2702
    $dbi->find_or_create;
2703

            
cleanup
yuki-kimoto authored on 2010-10-17
2704
=head2 C<insert>
2705

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

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

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

            
2714
    {date => \"NOW()"}
2715

            
cleanup
Yuki Kimoto authored on 2011-10-20
2716
B<options>
2717

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2725
    id => 4
2726
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2727

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2731
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2732
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2733
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2734
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2735
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2736
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2737

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

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

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

            
2747
    prefix => 'or replace'
2748

            
2749
prefix before table name section
2750

            
2751
    insert or replace into book
2752

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

            
2755
    table => 'book'
2756

            
2757
Table name.
2758

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

            
2761
    timestamp => 1
2762

            
2763
If this value is set to 1,
2764
automatically created timestamp column is set based on
2765
C<timestamp> attribute's C<insert> value.
2766

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

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

            
2771
placeholder wrapped string.
2772

            
2773
If the following statement
2774

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

            
2778
is executed, the following SQL is executed.
2779

            
2780
    insert into book price values ( ? + 5 );
2781

            
update pod
Yuki Kimoto authored on 2011-03-13
2782
=back
2783

            
2784
=over 4
2785

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2793
    lib / MyModel.pm
2794
        / MyModel / book.pm
2795
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2796

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

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

            
2801
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2802
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2803
    
2804
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2805

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2810
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2811
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2812
    
2813
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2814

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2817
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2818
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2819
    
2820
    1;
2821
    
updated pod
Yuki Kimoto authored on 2011-06-21
2822
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2823

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

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

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

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

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

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

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

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

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

            
2849
    my $like_value = $dbi->like_value
2850

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

            
2853
    sub { "%$_[0]%" }
2854

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

            
2857
    my $mapper = $dbi->mapper(param => $param);
2858

            
2859
Create a new L<DBIx::Custom::Mapper> object.
2860

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

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

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

            
2867
    {key1 => [1, 1], key2 => 2}
2868

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

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

            
2873
    my $model = $dbi->model('book');
2874

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

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

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

            
2882
Create column clause for myself. The follwoing column clause is created.
2883

            
2884
    book.author as author,
2885
    book.title as title
2886

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

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

            
2896
Create a new L<DBIx::Custom> object.
2897

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

            
2900
    my $not_exists = $dbi->not_exists;
2901

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

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

            
2907
    my $order = $dbi->order;
2908

            
2909
Create a new L<DBIx::Custom::Order> object.
2910

            
cleanup
yuki-kimoto authored on 2010-10-17
2911
=head2 C<register_filter>
2912

            
update pod
Yuki Kimoto authored on 2011-03-13
2913
    $dbi->register_filter(
2914
        # Time::Piece object to database DATE format
2915
        tp_to_date => sub {
2916
            my $tp = shift;
2917
            return $tp->strftime('%Y-%m-%d');
2918
        },
2919
        # database DATE format to Time::Piece object
2920
        date_to_tp => sub {
2921
           my $date = shift;
2922
           return Time::Piece->strptime($date, '%Y-%m-%d');
2923
        }
2924
    );
cleanup
yuki-kimoto authored on 2010-10-17
2925
    
update pod
Yuki Kimoto authored on 2011-03-13
2926
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2927

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2930
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2931
        table  => 'book',
2932
        column => ['author', 'title'],
2933
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2934
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2935
    
updated document
Yuki Kimoto authored on 2011-06-09
2936
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2937

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2945
=item C<column>
2946
    
updated document
Yuki Kimoto authored on 2011-06-09
2947
    column => 'author'
2948
    column => ['author', 'title']
2949

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2958
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2959
        {book => [qw/author title/]},
2960
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2961
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2962

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

            
2965
    book.author as "book.author",
2966
    book.title as "book.title",
2967
    person.name as "person.name",
2968
    person.age as "person.age"
2969

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

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

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

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

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

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

            
2985
=item C<id>
2986

            
2987
    id => 4
2988
    id => [4, 5]
2989

            
2990
ID corresponding to C<primary_key>.
2991
You can select rows by C<id> and C<primary_key>.
2992

            
2993
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2994
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2995
        id => [4, 5],
2996
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2997
    );
2998

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3001
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3002
        where => {id1 => 4, id2 => 5},
3003
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3004
    );
3005
    
cleanup
Yuki Kimoto authored on 2011-10-20
3006
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3007

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

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

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

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

            
3020
    prefix => 'SQL_CALC_FOUND_ROWS'
3021

            
3022
Prefix of column cluase
3023

            
3024
    select SQL_CALC_FOUND_ROWS title, author from book;
3025

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

            
3028
    join => [
3029
        'left outer join company on book.company_id = company_id',
3030
        'left outer join location on company.location_id = location.id'
3031
    ]
3032
        
3033
Join clause. If column cluase or where clause contain table name like "company.name",
3034
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3035

            
3036
    $dbi->select(
3037
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3038
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3039
        where => {'company.name' => 'Orange'},
3040
        join => [
3041
            'left outer join company on book.company_id = company.id',
3042
            'left outer join location on company.location_id = location.id'
3043
        ]
3044
    );
3045

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3049
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3050
    from book
3051
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3052
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3053

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3054
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
3055
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3056

            
3057
    $dbi->select(
3058
        table => 'book',
3059
        column => ['company.location_id as location_id'],
3060
        where => {'company.name' => 'Orange'},
3061
        join => [
3062
            {
3063
                clause => 'left outer join location on company.location_id = location.id',
3064
                table => ['company', 'location']
3065
            }
3066
        ]
3067
    );
3068

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3073
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3074

            
updated document
Yuki Kimoto authored on 2011-06-09
3075
=item C<where>
3076
    
3077
    # Hash refrence
3078
    where => {author => 'Ken', 'title' => 'Perl'}
3079
    
3080
    # DBIx::Custom::Where object
3081
    where => $dbi->where(
3082
        clause => ['and', 'author = :author', 'title like :title'],
3083
        param  => {author => 'Ken', title => '%Perl%'}
3084
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3085
    
3086
    # Array reference 1 (array reference, hash referenc). same as above
3087
    where => [
3088
        ['and', 'author = :author', 'title like :title'],
3089
        {author => 'Ken', title => '%Perl%'}
3090
    ];    
3091
    
3092
    # Array reference 2 (String, hash reference)
3093
    where => [
3094
        'title like :title',
3095
        {title => '%Perl%'}
3096
    ]
3097
    
3098
    # String
3099
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3100

            
cleanup
Yuki Kimoto authored on 2011-10-20
3101
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3102
    
update pod
Yuki Kimoto authored on 2011-03-12
3103
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3104

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

            
3107
    $dbi->setup_model;
3108

            
3109
Setup all model objects.
3110
C<columns> of model object is automatically set, parsing database information.
3111

            
3112
=head2 C<type_rule>
3113

            
3114
    $dbi->type_rule(
3115
        into1 => {
3116
            date => sub { ... },
3117
            datetime => sub { ... }
3118
        },
3119
        into2 => {
3120
            date => sub { ... },
3121
            datetime => sub { ... }
3122
        },
3123
        from1 => {
3124
            # DATE
3125
            9 => sub { ... },
3126
            # DATETIME or TIMESTAMP
3127
            11 => sub { ... },
3128
        }
3129
        from2 => {
3130
            # DATE
3131
            9 => sub { ... },
3132
            # DATETIME or TIMESTAMP
3133
            11 => sub { ... },
3134
        }
3135
    );
3136

            
3137
Filtering rule when data is send into and get from database.
3138
This has a little complex problem.
3139

            
3140
In C<into1> and C<into2> you can specify
3141
type name as same as type name defined
3142
by create table, such as C<DATETIME> or C<DATE>.
3143

            
3144
Note that type name and data type don't contain upper case.
3145
If these contain upper case charactor, you convert it to lower case.
3146

            
3147
C<into2> is executed after C<into1>.
3148

            
3149
Type rule of C<into1> and C<into2> is enabled on the following
3150
column name.
3151

            
3152
=over 4
3153

            
3154
=item 1. column name
3155

            
3156
    issue_date
3157
    issue_datetime
3158

            
3159
This need C<table> option in each method.
3160

            
3161
=item 2. table name and column name, separator is dot
3162

            
3163
    book.issue_date
3164
    book.issue_datetime
3165

            
3166
=back
3167

            
3168
You get all type name used in database by C<available_typename>.
3169

            
3170
    print $dbi->available_typename;
3171

            
3172
In C<from1> and C<from2> you specify data type, not type name.
3173
C<from2> is executed after C<from1>.
3174
You get all data type by C<available_datatype>.
3175

            
3176
    print $dbi->available_datatype;
3177

            
3178
You can also specify multiple types at once.
3179

            
3180
    $dbi->type_rule(
3181
        into1 => [
3182
            [qw/DATE DATETIME/] => sub { ... },
3183
        ],
3184
    );
3185

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

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

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

            
3192
If you want to set constant value to row data, use scalar reference
3193
as parameter value.
3194

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3206
    id => 4
3207
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3208

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3212
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3213
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3214
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3215
        id => [4, 5],
3216
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3217
    );
update pod
Yuki Kimoto authored on 2011-03-13
3218

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3221
    $dbi->update(
3222
        {title => 'Perl', author => 'Ken'}
3223
        where => {id1 => 4, id2 => 5},
3224
        table => 'book'
3225
    );
update pod
Yuki Kimoto authored on 2011-03-13
3226

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

            
3229
    prefix => 'or replace'
3230

            
3231
prefix before table name section
3232

            
3233
    update or replace book
3234

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

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

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

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

            
3243
    timestamp => 1
3244

            
3245
If this value is set to 1,
3246
automatically updated timestamp column is set based on
3247
C<timestamp> attribute's C<update> value.
3248

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

            
3251
Same as C<select> method's C<where> option.
3252

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

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

            
3257
placeholder wrapped string.
3258

            
3259
If the following statement
3260

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

            
3264
is executed, the following SQL is executed.
3265

            
3266
    update book set price =  ? + 5;
3267

            
updated pod
Yuki Kimoto authored on 2011-06-08
3268
=back
update pod
Yuki Kimoto authored on 2011-03-13
3269

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3277
=head2 C<update_or_insert EXPERIMENTAL>
3278
    
3279
    # Where
3280
    $dbi->update_or_insert(
3281
        {id => 1, title => 'Perl'},
3282
        table => 'book',
3283
        where => {id => 1},
3284
        select_option => {append => 'for update'}
3285
    );
3286
    
3287
    # ID
3288
    $dbi->update_or_insert(
3289
        {title => 'Perl'},
3290
        table => 'book',
3291
        id => 1,
3292
        primary_key => 'id',
3293
        select_option => {append => 'for update'}
3294
    );
3295
    
3296
Update or insert.
3297

            
3298
In both examples, the following SQL is executed.
3299

            
3300
    # In case insert
3301
    insert into book (id, title) values (?, ?)
3302
    
3303
    # In case update
3304
    update book set (id = ?, title = ?) where book.id = ?
3305

            
3306
The following opitons are available adding to C<update> option.
3307

            
3308
=over 4
3309

            
3310
=item C<select_option>
3311

            
3312
    select_option => {append => 'for update'}
3313

            
3314
select method option,
3315
select method is used to check the row is already exists.
3316

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

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

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

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

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

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

            
3337
    $dbi->show_datatype($table);
3338

            
3339
Show data type of the columns of specified table.
3340

            
3341
    book
3342
    title: 5
3343
    issue_date: 91
3344

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

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

            
3349
    $dbi->show_tables;
3350

            
3351
Show tables.
3352

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

            
3355
    $dbi->show_typename($table);
3356

            
3357
Show type name of the columns of specified table.
3358

            
3359
    book
3360
    title: varchar
3361
    issue_date: date
3362

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

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

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

            
3369
Create values clause.
3370

            
3371
    (title, author) values (title = :title, age = :age);
3372

            
3373
You can use this in insert statement.
3374

            
3375
    my $insert_sql = "insert into book $values_clause";
3376

            
3377
=head2 C<where>
3378

            
3379
    my $where = $dbi->where(
3380
        clause => ['and', 'title = :title', 'author = :author'],
3381
        param => {title => 'Perl', author => 'Ken'}
3382
    );
3383

            
3384
Create a new L<DBIx::Custom::Where> object.
3385

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

            
3388
=head2 C<DBIX_CUSTOM_DEBUG>
3389

            
3390
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3391
executed SQL and bind values are printed to STDERR.
3392

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

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

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

            
3399
L<DBIx::Custom>
3400

            
3401
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3402
    default_dbi_option # will be removed 2017/1/1
3403
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3404
    data_source # will be removed at 2017/1/1
3405
    dbi_options # will be removed at 2017/1/1
3406
    filter_check # will be removed at 2017/1/1
3407
    reserved_word_quote # will be removed at 2017/1/1
3408
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3409
    
3410
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3411
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3412
    assign_param # will be removed at 2017/1/1
3413
    update_param # will be removed at 2017/1/1
3414
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3415
    create_query # will be removed at 2017/1/1
3416
    apply_filter # will be removed at 2017/1/1
3417
    select_at # will be removed at 2017/1/1
3418
    delete_at # will be removed at 2017/1/1
3419
    update_at # will be removed at 2017/1/1
3420
    insert_at # will be removed at 2017/1/1
3421
    register_tag # will be removed at 2017/1/1
3422
    default_bind_filter # will be removed at 2017/1/1
3423
    default_fetch_filter # will be removed at 2017/1/1
3424
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3425
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3426
    register_tag_processor # will be removed at 2017/1/1
3427
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3428
    
3429
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3430
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3431
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3432
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3433
    select method relation option # will be removed at 2017/1/1
3434
    select method param option # will be removed at 2017/1/1
3435
    select method column option [COLUMN, as => ALIAS] format
3436
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3437
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3438
    
3439
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3440
    execute("select * from {= title}"); # execute method's
3441
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3442
                                        # will be removed at 2017/1/1
3443
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3444

            
3445
L<DBIx::Custom::Model>
3446

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3447
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3448
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3449
    filter # will be removed at 2017/1/1
3450
    name # will be removed at 2017/1/1
3451
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3452

            
3453
L<DBIx::Custom::Query>
3454
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3455
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3456
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3457
    table # will be removed at 2017/1/1
3458
    filters # will be removed at 2017/1/1
3459
    
3460
    # Methods
3461
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3462

            
3463
L<DBIx::Custom::QueryBuilder>
3464
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3465
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3466
    tags # will be removed at 2017/1/1
3467
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3468
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3469
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3470
    register_tag # will be removed at 2017/1/1
3471
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3472
    
3473
    # Others
3474
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3475
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3476

            
3477
L<DBIx::Custom::Result>
3478
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3479
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3480
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3481
    
3482
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3483
    end_filter # will be removed at 2017/1/1
3484
    remove_end_filter # will be removed at 2017/1/1
3485
    remove_filter # will be removed at 2017/1/1
3486
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487

            
3488
L<DBIx::Custom::Tag>
3489

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

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

            
3494
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3495
except for attribute method.
3496
You can check all DEPRECATED functionalities by document.
3497
DEPRECATED functionality is removed after five years,
3498
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
3499
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3500

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

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

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

            
3507
C<< <kimoto.yuki at gmail.com> >>
3508

            
3509
L<http://github.com/yuki-kimoto/DBIx-Custom>
3510

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3511
=head1 AUTHOR
3512

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

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

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

            
3519
This program is free software; you can redistribute it and/or modify it
3520
under the same terms as Perl itself.
3521

            
3522
=cut