DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3535 lines | 91.653kb
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 2011-10-21
232
sub _where_clause_and_param {
233
    my ($self, $where, $param) = @_;
234
 
235
    $where ||= {};
236
    $param ||= {};
237
    my $w = {};
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
238
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
239
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
cleanup
Yuki Kimoto authored on 2011-10-21
240
        $w->{clause} = "where " . $where->[0];
241
        $w->{param} = $where->[1];
updated pod
Yuki Kimoto authored on 2011-06-21
242
    }
243
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
244
        $where = $self->_where_to_obj($where);
cleanup
Yuki Kimoto authored on 2011-10-21
245
        $w->{param} = keys %$param
246
                    ? $self->merge_param($param, $where->param)
247
                    : $where->param;
248
        $w->{clause} = $where->to_string;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
249
    }
cleanup
Yuki Kimoto authored on 2011-10-21
250
    elsif ($where) {
251
        $w->{clause} = "where $where";
252
        $w->{param} = $param;
253
    }
254
    
255
    return $w;
256
}
257

            
258
sub delete {
259
    my ($self, %opt) = @_;
260
    warn "delete method where_param option is DEPRECATED!"
261
      if $opt{where_param};
262
    
263
    # Don't allow delete all row
264
    croak qq{delete method where or id option must be specified } . _subname
265
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
266
    
267
    # Where
268
    my $where = defined $opt{id}
269
           ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
270
           : $opt{where};
271
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
272

            
cleanup
Yuki Kimoto authored on 2011-04-02
273
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
274
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
275
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
276
    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
277
    
278
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
279
    return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
280
}
281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1088
sub _create_where {
1089
    my $self = shift;
1090
    
1091
}
1092

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1096
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1097
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1098
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1099
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1100
    warn "update method where_param option is DEPRECATED!"
1101
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1102
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
1103
    my $where = $opt{where} || {};
1104
    my $where_param = $opt{where_param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1105
    
1106
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1107
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1108
        my $columns = $update_timestamp->[0];
1109
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1110
        my $value = $update_timestamp->[1];
1111
        $value = $value->() if ref $value eq 'CODE';
1112
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1113
    }
1114

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1153
sub update_timestamp {
1154
    my $self = shift;
1155
    
1156
    if (@_) {
1157
        $self->{update_timestamp} = [@_];
1158
        
1159
        return $self;
1160
    }
1161
    return $self->{update_timestamp};
1162
}
1163

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

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

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

            
1218
        # Create query
1219
        my $builder = $self->query_builder;
1220
        $query = $builder->build_query($source);
1221

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

            
1228
        # Save query to cache
1229
        $self->cache_method->(
1230
            $self, $source,
1231
            {
1232
                sql     => $query->sql, 
1233
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1234
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1235
            }
1236
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1237
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1238

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1400
sub _need_tables {
1401
    my ($self, $tree, $need_tables, $tables) = @_;
1402
    
cleanup
Yuki Kimoto authored on 2011-04-02
1403
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1404
    foreach my $table (@$tables) {
1405
        if ($tree->{$table}) {
1406
            $need_tables->{$table} = 1;
1407
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1408
        }
1409
    }
1410
}
1411

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1412
sub _option {
1413
    my $self = shift;
1414
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1415
    warn "dbi_options is DEPRECATED! use option instead\n"
1416
      if keys %{$self->dbi_options};
1417
    warn "dbi_option is DEPRECATED! use option instead\n"
1418
      if keys %{$self->dbi_option};
1419
    return $option;
1420
}
1421

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1492
sub _quote {
1493
    my $self = shift;
1494
    
1495
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1496
         : defined $self->quote ? $self->quote
1497
         : '';
1498
}
1499

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

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

            
1532
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1533
}
1534

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1671
# DEPRECATED!
1672
has 'data_source';
1673
has dbi_options => sub { {} };
1674
has filter_check  => 1;
1675
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1676
has dbi_option => sub { {} };
1677
has default_dbi_option => sub {
1678
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1679
    return shift->default_option;
1680
};
1681

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1682
# DEPRECATED!
1683
sub method {
1684
    warn "method is DEPRECATED! use helper instead";
1685
    return shift->helper(@_);
1686
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1687

            
1688
# DEPRECATED!
1689
sub assign_param {
1690
    my $self = shift;
1691
    warn "assing_param is DEPRECATED! use assign_clause instead";
1692
    return $self->assign_clause(@_);
1693
}
1694

            
1695
# DEPRECATED
1696
sub update_param {
1697
    my ($self, $param, $opts) = @_;
1698
    
1699
    warn "update_param is DEPRECATED! use assing_clause instead.";
1700
    
1701
    # Create update parameter tag
1702
    my $tag = $self->assign_clause($param, $opts);
1703
    $tag = "set $tag" unless $opts->{no_set};
1704

            
1705
    return $tag;
1706
}
1707

            
updated pod
Yuki Kimoto authored on 2011-06-21
1708
# DEPRECATED!
1709
sub create_query {
1710
    warn "create_query is DEPRECATED! use query option of each method";
1711
    shift->_create_query(@_);
1712
}
1713

            
cleanup
Yuki Kimoto authored on 2011-06-13
1714
# DEPRECATED!
1715
sub apply_filter {
1716
    my $self = shift;
1717
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1718
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1719
    return $self->_apply_filter(@_);
1720
}
1721

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

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

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

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

            
1749
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1750
    
1751
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1752
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1753
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1754
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1755
    
1756
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1757
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1758
    
cleanup
Yuki Kimoto authored on 2011-10-21
1759
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1760
}
1761

            
cleanup
Yuki Kimoto authored on 2011-06-08
1762
# DEPRECATED!
1763
sub update_at {
1764
    my $self = shift;
1765

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

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

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

            
1820
# DEPRECATED!
1821
sub register_tag_processor {
1822
    my $self = shift;
1823
    warn "register_tag_processor is DEPRECATED!";
1824
    # Merge tag
1825
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1826
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1827
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1828
}
1829

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1854
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1855
sub default_fetch_filter {
1856
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1857

            
cleanup
Yuki Kimoto authored on 2011-06-13
1858
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1859
    
1860
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1861
        my $fname = $_[0];
1862

            
cleanup
Yuki Kimoto authored on 2011-01-12
1863
        if (@_ && !$fname) {
1864
            $self->{default_in_filter} = undef;
1865
        }
1866
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1867
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1868
              unless exists $self->filters->{$fname};
1869
        
1870
            $self->{default_in_filter} = $self->filters->{$fname};
1871
        }
1872
        
1873
        return $self;
1874
    }
1875
    
many changed
Yuki Kimoto authored on 2011-01-23
1876
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1877
}
1878

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1879
# DEPRECATED!
1880
sub insert_param {
1881
    my $self = shift;
1882
    warn "insert_param is DEPRECATED! use values_clause instead";
1883
    return $self->values_clause(@_);
1884
}
1885

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1886
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1887
sub insert_param_tag {
1888
    warn "insert_param_tag is DEPRECATED! " .
1889
         "use insert_param instead!";
1890
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1891
}
1892

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1937
=head1 NAME
1938

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1953
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1954
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1955
    
1956
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1957
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1958
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1959
    
1960
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1961
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1962

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2012
Named place holder support
2013

            
2014
=item *
2015

            
cleanup
Yuki Kimoto authored on 2011-07-29
2016
Model support
2017

            
2018
=item *
2019

            
2020
Connection manager support
2021

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

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

            
2028
=item *
2029

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

            
2032
=item *
2033

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

            
2036
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2037

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2045
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2046
L<DBIx::Custom::Result>,
2047
L<DBIx::Custom::Query>,
2048
L<DBIx::Custom::Where>,
2049
L<DBIx::Custom::Model>,
2050
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2051

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

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

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

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

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

            
2065
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2066
        "dbi:mysql:database=$database",
2067
        $user,
2068
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2069
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2070
    );
2071
    
updated pod
Yuki Kimoto authored on 2011-06-21
2072
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2073

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

            
2077
    my $dbi = DBIx::Custom->connect(
2078
      dsn => $dsn, user => $user, password => $password, connector => 1);
2079
    
2080
    my $connector = $dbi->connector; # DBIx::Connector
2081

            
2082
Note that L<DBIx::Connector> must be installed.
2083

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2099
    {
2100
        RaiseError => 1,
2101
        PrintError => 0,
2102
        AutoCommit => 1,
2103
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2104

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

            
2107
    my $exclude_table = $dbi->exclude_table;
2108
    $dbi = $dbi->exclude_table(qr/pg_/);
2109

            
2110
Excluded table regex.
2111
C<each_column>, C<each_table>, C<type_rule>,
2112
and C<setup_model> methods ignore matching tables.
2113

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

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

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

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

            
2123
    my $last_sql = $dbi->last_sql;
2124
    $dbi = $dbi->last_sql($last_sql);
2125

            
2126
Get last successed SQL executed by C<execute> method.
2127

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

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

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

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

            
2137
    my $option = $dbi->option;
2138
    $dbi = $dbi->option($option);
2139

            
2140
L<DBI> option, used when C<connect> method is executed.
2141
Each value in option override the value of C<default_option>.
2142

            
cleanup
yuki-kimoto authored on 2010-10-17
2143
=head2 C<password>
2144

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2165
You can set quote pair.
2166

            
2167
    $dbi->quote('[]');
2168

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2178
    my $safety_character = $dbi->safety_character;
2179
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2180

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

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

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

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

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

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

            
2197
    my $tag_parse = $dbi->tag_parse(0);
2198
    $dbi = $dbi->tag_parse;
2199

            
2200
Enable DEPRECATED tag parsing functionality, default to 1.
2201
If you want to disable tag parsing functionality, set to 0.
2202

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

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

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

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

            
2212
    my $user_column_info = $dbi->user_column_info;
2213
    $dbi = $dbi->user_column_info($user_column_info);
2214

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

            
2217
    [
2218
        {table => 'book', column => 'title', info => {...}},
2219
        {table => 'author', column => 'name', info => {...}}
2220
    ]
2221

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

            
2224
    my $user_column_info
2225
      = $dbi->get_column_info(exclude_table => qr/^system/);
2226
    $dbi->user_column_info($user_column_info);
2227

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

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

            
2233
    my $user_table_info = $dbi->user_table_info;
2234
    $dbi = $dbi->user_table_info($user_table_info);
2235

            
2236
You can set the following data.
2237

            
2238
    [
2239
        {table => 'book', info => {...}},
2240
        {table => 'author', info => {...}}
2241
    ]
2242

            
2243
Usually, you can set return value of C<get_table_info>.
2244

            
2245
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2246
    $dbi->user_table_info($user_table_info);
2247

            
2248
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2249
to find table info.
2250

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2287
Create column clause. The follwoing column clause is created.
2288

            
2289
    book.author as "book.author",
2290
    book.title as "book.title"
2291

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2294
    # Separator is hyphen
2295
    $dbi->separator('-');
2296
    
2297
    book.author as "book-author",
2298
    book.title as "book-title"
2299
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2300
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2301

            
update pod
Yuki Kimoto authored on 2011-03-13
2302
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2303
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2304
        user => 'ken',
2305
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2306
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2307
    );
2308

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

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

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

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

            
2319
Get rows count.
2320

            
2321
Options is same as C<select> method's ones.
2322

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2325
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2326
        table => 'book',
2327
        primary_key => 'id',
2328
        join => [
2329
            'inner join company on book.comparny_id = company.id'
2330
        ],
2331
    );
2332

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

            
2336
   $dbi->model('book')->select(...);
2337

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

            
2340
    my $dbh = $dbi->dbh;
2341

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

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

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

            
2349
Execute delete statement.
2350

            
2351
The following opitons are available.
2352

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

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

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

            
2360
=item C<id>
2361

            
2362
    id => 4
2363
    id => [4, 5]
2364

            
2365
ID corresponding to C<primary_key>.
2366
You can delete rows by C<id> and C<primary_key>.
2367

            
2368
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2369
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2370
        id => [4, 5],
2371
        table => 'book',
2372
    );
2373

            
2374
The above is same as the followin one.
2375

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

            
2378
=item C<prefix>
2379

            
2380
    prefix => 'some'
2381

            
2382
prefix before table name section.
2383

            
2384
    delete some from book
2385

            
2386
=item C<table>
2387

            
2388
    table => 'book'
2389

            
2390
Table name.
2391

            
2392
=item C<where>
2393

            
2394
Same as C<select> method's C<where> option.
2395

            
2396
=back
2397

            
2398
=head2 C<delete_all>
2399

            
2400
    $dbi->delete_all(table => $table);
2401

            
2402
Execute delete statement for all rows.
2403
Options is same as C<delete>.
2404

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

            
2407
    $dbi->each_column(
2408
        sub {
2409
            my ($dbi, $table, $column, $column_info) = @_;
2410
            
2411
            my $type = $column_info->{TYPE_NAME};
2412
            
2413
            if ($type eq 'DATE') {
2414
                # ...
2415
            }
2416
        }
2417
    );
2418

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

            
2424
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2425
infromation, you can improve the performance of C<each_column> in
2426
the following way.
2427

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

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

            
2434
    $dbi->each_table(
2435
        sub {
2436
            my ($dbi, $table, $table_info) = @_;
2437
            
2438
            my $table_name = $table_info->{TABLE_NAME};
2439
        }
2440
    );
2441

            
improved pod
Yuki Kimoto authored on 2011-10-14
2442
Iterate all table informationsfrom in database.
2443
Argument is callback which is executed when one table is found.
2444
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2445
C<table information>.
2446

            
2447
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2448
infromation, you can improve the performance of C<each_table> in
2449
the following way.
2450

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2473
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2474
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2475
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2476
    select * from book where title = :title and author like :author
2477
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2478
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2479
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2480

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2484
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2485
    select * from book where :title{=} and :author{like}
2486
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2487
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2488
    select * from where title = ? and author like ?;
2489

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

            
2494
    select * from where title = "aa\\:bb";
2495

            
cleanup
Yuki Kimoto authored on 2011-10-20
2496
B<OPTIONS>
2497

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

            
2500
=over 4
2501

            
cleanup
Yuki Kimoto authored on 2011-10-20
2502
=item C<append>
2503

            
2504
    append => 'order by name'
2505

            
2506
Append some statement after SQL.
2507

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

            
2510
Specify database bind data type.
2511

            
2512
    bind_type => [image => DBI::SQL_BLOB]
2513
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2514

            
2515
This is used to bind parameter by C<bind_param> of statment handle.
2516

            
2517
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2518

            
update pod
Yuki Kimoto authored on 2011-03-13
2519
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2520
    
2521
    filter => {
2522
        title  => sub { uc $_[0] }
2523
        author => sub { uc $_[0] }
2524
    }
update pod
Yuki Kimoto authored on 2011-03-13
2525

            
updated pod
Yuki Kimoto authored on 2011-06-09
2526
    # Filter name
2527
    filter => {
2528
        title  => 'upper_case',
2529
        author => 'upper_case'
2530
    }
2531
        
2532
    # At once
2533
    filter => [
2534
        [qw/title author/]  => sub { uc $_[0] }
2535
    ]
2536

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

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

            
2544
    id => 4
2545
    id => [4, 5]
2546

            
2547
ID corresponding to C<primary_key>.
2548
You can delete rows by C<id> and C<primary_key>.
2549

            
2550
    $dbi->execute(
2551
        "select * from book where id1 = :id1 and id2 = :id2",
2552
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2553
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2554
        id => [4, 5],
2555
    );
2556

            
2557
The above is same as the followin one.
2558

            
2559
    $dbi->execute(
2560
        "select * from book where id1 = :id1 and id2 = :id2",
2561
        {id1 => 4, id2 => 5}
2562
    );
2563

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

            
2566
    query => 1
2567

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

            
2571
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2572
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2573
    my $columns = $query->columns;
2574
    
2575
If you want to execute SQL fast, you can do the following way.
2576

            
2577
    my $query;
2578
    foreach my $row (@$rows) {
2579
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2580
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2581
    }
2582

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

            
2586
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
2587
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2588
    
2589
    my $query;
2590
    my $sth;
2591
    foreach my $row (@$rows) {
2592
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2593
      $sth ||= $query->sth;
2594
      $sth->execute(map { $row->{$_} } sort keys %$row);
2595
    }
2596

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2603
    primary_key => 'id'
2604
    primary_key => ['id1', 'id2']
2605

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

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

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

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

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

            
2616
    $dbi->select(
2617
        table => 'book',
2618
        column => 'distinct(name)',
2619
        after_build_sql => sub {
2620
            "select count(*) from ($_[0]) as t1"
2621
        }
2622
    );
2623

            
2624
The following SQL is executed.
2625

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2628
=item C<table>
2629
    
2630
    table => 'author'
2631

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2639
    # Same
2640
    $dbi->execute(
2641
      "select * from book where title = :book.title and author = :book.author",
2642
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2643

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

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

            
2648
Table alias. Key is real table name, value is alias table name.
2649
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2650
on alias table name.
2651

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

            
2654
    type_rule_off => 1
2655

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

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

            
2660
    type_rule1_off => 1
2661

            
2662
Turn C<into1> type rule off.
2663

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

            
2666
    type_rule2_off => 1
2667

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

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

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

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

            
2676
get column infomation except for one which match C<exclude_table> pattern.
2677

            
2678
    [
2679
        {table => 'book', column => 'title', info => {...}},
2680
        {table => 'author', column => 'name' info => {...}}
2681
    ]
2682

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

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

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

            
2689
    [
2690
        {table => 'book', info => {...}},
2691
        {table => 'author', info => {...}}
2692
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2693

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

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

            
2698
    $dbi->helper(
2699
        update_or_insert => sub {
2700
            my $self = shift;
2701
            
2702
            # Process
2703
        },
2704
        find_or_create   => sub {
2705
            my $self = shift;
2706
            
2707
            # Process
2708
        }
2709
    );
2710

            
2711
Register helper. These helper is called directly from L<DBIx::Custom> object.
2712

            
2713
    $dbi->update_or_insert;
2714
    $dbi->find_or_create;
2715

            
cleanup
yuki-kimoto authored on 2010-10-17
2716
=head2 C<insert>
2717

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

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

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

            
2726
    {date => \"NOW()"}
2727

            
cleanup
Yuki Kimoto authored on 2011-10-20
2728
B<options>
2729

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2737
    id => 4
2738
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2739

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2743
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2744
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2745
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2746
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2747
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2748
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2749

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

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

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

            
2759
    prefix => 'or replace'
2760

            
2761
prefix before table name section
2762

            
2763
    insert or replace into book
2764

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

            
2767
    table => 'book'
2768

            
2769
Table name.
2770

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

            
2773
    timestamp => 1
2774

            
2775
If this value is set to 1,
2776
automatically created timestamp column is set based on
2777
C<timestamp> attribute's C<insert> value.
2778

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

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

            
2783
placeholder wrapped string.
2784

            
2785
If the following statement
2786

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

            
2790
is executed, the following SQL is executed.
2791

            
2792
    insert into book price values ( ? + 5 );
2793

            
update pod
Yuki Kimoto authored on 2011-03-13
2794
=back
2795

            
2796
=over 4
2797

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2805
    lib / MyModel.pm
2806
        / MyModel / book.pm
2807
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2808

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

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

            
2813
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2814
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2815
    
2816
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2817

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2822
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2823
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2824
    
2825
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2826

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2829
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2830
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2831
    
2832
    1;
2833
    
updated pod
Yuki Kimoto authored on 2011-06-21
2834
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2835

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

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

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

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

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

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

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

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

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

            
2861
    my $like_value = $dbi->like_value
2862

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

            
2865
    sub { "%$_[0]%" }
2866

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

            
2869
    my $mapper = $dbi->mapper(param => $param);
2870

            
2871
Create a new L<DBIx::Custom::Mapper> object.
2872

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

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

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

            
2879
    {key1 => [1, 1], key2 => 2}
2880

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

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

            
2885
    my $model = $dbi->model('book');
2886

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

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

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

            
2894
Create column clause for myself. The follwoing column clause is created.
2895

            
2896
    book.author as author,
2897
    book.title as title
2898

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

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

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

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

            
2912
    my $not_exists = $dbi->not_exists;
2913

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

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

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

            
2921
Create a new L<DBIx::Custom::Order> object.
2922

            
cleanup
yuki-kimoto authored on 2010-10-17
2923
=head2 C<register_filter>
2924

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2942
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2943
        table  => 'book',
2944
        column => ['author', 'title'],
2945
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2946
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2947
    
updated document
Yuki Kimoto authored on 2011-06-09
2948
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2949

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2957
=item C<column>
2958
    
updated document
Yuki Kimoto authored on 2011-06-09
2959
    column => 'author'
2960
    column => ['author', 'title']
2961

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2970
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2971
        {book => [qw/author title/]},
2972
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2973
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2974

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

            
2977
    book.author as "book.author",
2978
    book.title as "book.title",
2979
    person.name as "person.name",
2980
    person.age as "person.age"
2981

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

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

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

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

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

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

            
2997
=item C<id>
2998

            
2999
    id => 4
3000
    id => [4, 5]
3001

            
3002
ID corresponding to C<primary_key>.
3003
You can select rows by C<id> and C<primary_key>.
3004

            
3005
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3006
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3007
        id => [4, 5],
3008
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3009
    );
3010

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3013
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3014
        where => {id1 => 4, id2 => 5},
3015
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3016
    );
3017
    
cleanup
Yuki Kimoto authored on 2011-10-20
3018
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3019

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

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

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

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

            
3032
    prefix => 'SQL_CALC_FOUND_ROWS'
3033

            
3034
Prefix of column cluase
3035

            
3036
    select SQL_CALC_FOUND_ROWS title, author from book;
3037

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

            
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
Join clause. If column cluase or where clause contain table name like "company.name",
3046
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3047

            
3048
    $dbi->select(
3049
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3050
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3051
        where => {'company.name' => 'Orange'},
3052
        join => [
3053
            'left outer join company on book.company_id = company.id',
3054
            'left outer join location on company.location_id = location.id'
3055
        ]
3056
    );
3057

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3061
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3062
    from book
3063
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3064
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3065

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3066
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
3067
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3068

            
3069
    $dbi->select(
3070
        table => 'book',
3071
        column => ['company.location_id as location_id'],
3072
        where => {'company.name' => 'Orange'},
3073
        join => [
3074
            {
3075
                clause => 'left outer join location on company.location_id = location.id',
3076
                table => ['company', 'location']
3077
            }
3078
        ]
3079
    );
3080

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3085
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3086

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3113
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3114
    
update pod
Yuki Kimoto authored on 2011-03-12
3115
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3116

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

            
3119
    $dbi->setup_model;
3120

            
3121
Setup all model objects.
3122
C<columns> of model object is automatically set, parsing database information.
3123

            
3124
=head2 C<type_rule>
3125

            
3126
    $dbi->type_rule(
3127
        into1 => {
3128
            date => sub { ... },
3129
            datetime => sub { ... }
3130
        },
3131
        into2 => {
3132
            date => sub { ... },
3133
            datetime => sub { ... }
3134
        },
3135
        from1 => {
3136
            # DATE
3137
            9 => sub { ... },
3138
            # DATETIME or TIMESTAMP
3139
            11 => sub { ... },
3140
        }
3141
        from2 => {
3142
            # DATE
3143
            9 => sub { ... },
3144
            # DATETIME or TIMESTAMP
3145
            11 => sub { ... },
3146
        }
3147
    );
3148

            
3149
Filtering rule when data is send into and get from database.
3150
This has a little complex problem.
3151

            
3152
In C<into1> and C<into2> you can specify
3153
type name as same as type name defined
3154
by create table, such as C<DATETIME> or C<DATE>.
3155

            
3156
Note that type name and data type don't contain upper case.
3157
If these contain upper case charactor, you convert it to lower case.
3158

            
3159
C<into2> is executed after C<into1>.
3160

            
3161
Type rule of C<into1> and C<into2> is enabled on the following
3162
column name.
3163

            
3164
=over 4
3165

            
3166
=item 1. column name
3167

            
3168
    issue_date
3169
    issue_datetime
3170

            
3171
This need C<table> option in each method.
3172

            
3173
=item 2. table name and column name, separator is dot
3174

            
3175
    book.issue_date
3176
    book.issue_datetime
3177

            
3178
=back
3179

            
3180
You get all type name used in database by C<available_typename>.
3181

            
3182
    print $dbi->available_typename;
3183

            
3184
In C<from1> and C<from2> you specify data type, not type name.
3185
C<from2> is executed after C<from1>.
3186
You get all data type by C<available_datatype>.
3187

            
3188
    print $dbi->available_datatype;
3189

            
3190
You can also specify multiple types at once.
3191

            
3192
    $dbi->type_rule(
3193
        into1 => [
3194
            [qw/DATE DATETIME/] => sub { ... },
3195
        ],
3196
    );
3197

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

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

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

            
3204
If you want to set constant value to row data, use scalar reference
3205
as parameter value.
3206

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3218
    id => 4
3219
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3220

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3224
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3225
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3226
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3227
        id => [4, 5],
3228
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3229
    );
update pod
Yuki Kimoto authored on 2011-03-13
3230

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3233
    $dbi->update(
3234
        {title => 'Perl', author => 'Ken'}
3235
        where => {id1 => 4, id2 => 5},
3236
        table => 'book'
3237
    );
update pod
Yuki Kimoto authored on 2011-03-13
3238

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

            
3241
    prefix => 'or replace'
3242

            
3243
prefix before table name section
3244

            
3245
    update or replace book
3246

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

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

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

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

            
3255
    timestamp => 1
3256

            
3257
If this value is set to 1,
3258
automatically updated timestamp column is set based on
3259
C<timestamp> attribute's C<update> value.
3260

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

            
3263
Same as C<select> method's C<where> option.
3264

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

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

            
3269
placeholder wrapped string.
3270

            
3271
If the following statement
3272

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

            
3276
is executed, the following SQL is executed.
3277

            
3278
    update book set price =  ? + 5;
3279

            
updated pod
Yuki Kimoto authored on 2011-06-08
3280
=back
update pod
Yuki Kimoto authored on 2011-03-13
3281

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

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

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

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

            
3310
In both examples, the following SQL is executed.
3311

            
3312
    # In case insert
3313
    insert into book (id, title) values (?, ?)
3314
    
3315
    # In case update
3316
    update book set (id = ?, title = ?) where book.id = ?
3317

            
3318
The following opitons are available adding to C<update> option.
3319

            
3320
=over 4
3321

            
3322
=item C<select_option>
3323

            
3324
    select_option => {append => 'for update'}
3325

            
3326
select method option,
3327
select method is used to check the row is already exists.
3328

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

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

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

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

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

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

            
3349
    $dbi->show_datatype($table);
3350

            
3351
Show data type of the columns of specified table.
3352

            
3353
    book
3354
    title: 5
3355
    issue_date: 91
3356

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

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

            
3361
    $dbi->show_tables;
3362

            
3363
Show tables.
3364

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

            
3367
    $dbi->show_typename($table);
3368

            
3369
Show type name of the columns of specified table.
3370

            
3371
    book
3372
    title: varchar
3373
    issue_date: date
3374

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

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

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

            
3381
Create values clause.
3382

            
3383
    (title, author) values (title = :title, age = :age);
3384

            
3385
You can use this in insert statement.
3386

            
3387
    my $insert_sql = "insert into book $values_clause";
3388

            
3389
=head2 C<where>
3390

            
3391
    my $where = $dbi->where(
3392
        clause => ['and', 'title = :title', 'author = :author'],
3393
        param => {title => 'Perl', author => 'Ken'}
3394
    );
3395

            
3396
Create a new L<DBIx::Custom::Where> object.
3397

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

            
3400
=head2 C<DBIX_CUSTOM_DEBUG>
3401

            
3402
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3403
executed SQL and bind values are printed to STDERR.
3404

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

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

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

            
3411
L<DBIx::Custom>
3412

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

            
3458
L<DBIx::Custom::Model>
3459

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

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

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

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

            
3501
L<DBIx::Custom::Tag>
3502

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

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

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

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

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

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

            
3520
C<< <kimoto.yuki at gmail.com> >>
3521

            
3522
L<http://github.com/yuki-kimoto/DBIx-Custom>
3523

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3524
=head1 AUTHOR
3525

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

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

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

            
3532
This program is free software; you can redistribute it and/or modify it
3533
under the same terms as Perl itself.
3534

            
3535
=cut