DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3578 lines | 94.167kb
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

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
4
our $VERSION = '0.2101';
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/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21

            
packaging one directory
yuki-kimoto authored on 2009-11-16
22

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
23
has [qw/connector dsn password quote user exclude_table user_table_info
24
        user_column_info/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
25
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
26
    cache_method => sub {
27
        sub {
28
            my $self = shift;
29
            
30
            $self->{_cached} ||= {};
31
            
32
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
33
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
34
            }
35
            else {
update pod
Yuki Kimoto authored on 2011-03-13
36
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
37
            }
38
        }
update pod
Yuki Kimoto authored on 2011-03-13
39
    },
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
40
    option => sub { {} },
41
    default_option => sub {
update pod
Yuki Kimoto authored on 2011-03-13
42
        {
43
            RaiseError => 1,
44
            PrintError => 0,
45
            AutoCommit => 1
46
        }
47
    },
fix tests
Yuki Kimoto authored on 2011-01-13
48
    filters => sub {
49
        {
50
            encode_utf8 => sub { encode_utf8($_[0]) },
51
            decode_utf8 => sub { decode_utf8($_[0]) }
52
        }
update pod
Yuki Kimoto authored on 2011-03-13
53
    },
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
54
    last_sql => '',
update pod
Yuki Kimoto authored on 2011-03-13
55
    models => sub { {} },
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
56
    now => sub {
57
        sub {
58
            my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
59
            $mon++;
60
            $year += 1900;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
61
            my $now = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
62
              $year, $mon, $mday, $hour, $min, $sec);
63
            return $now;
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
64
        }
65
    },
cleanup
Yuki Kimoto authored on 2011-08-13
66
    query_builder => sub {
67
        my $self = shift;
68
        my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
69
        weaken $builder->{dbi};
70
        return $builder;
71
    },
update pod
Yuki Kimoto authored on 2011-03-13
72
    result_class  => 'DBIx::Custom::Result',
73
    safety_character => '\w',
cleanup test
Yuki Kimoto authored on 2011-08-10
74
    separator => '.',
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
75
    stash => sub { {} };
cleanup
yuki-kimoto authored on 2010-10-17
76

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
77
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
78
    my $self = shift;
79
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
80
    my $data_types = '';
cleanup
Yuki Kimoto authored on 2011-10-21
81
    for my $i (-1000 .. 1000) {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
82
         my $type_info = $self->dbh->type_info($i);
83
         my $data_type = $type_info->{DATA_TYPE};
84
         my $type_name = $type_info->{TYPE_NAME};
85
         $data_types .= "$data_type ($type_name)\n"
86
           if defined $data_type;
87
    }
88
    return "Data Type maybe equal to Type Name" unless $data_types;
89
    $data_types = "Data Type (Type name)\n" . $data_types;
90
    return $data_types;
91
}
92

            
93
sub available_typename {
94
    my $self = shift;
95
    
96
    # Type Names
97
    my $type_names = {};
98
    $self->each_column(sub {
99
        my ($self, $table, $column, $column_info) = @_;
100
        $type_names->{$column_info->{TYPE_NAME}} = 1
101
          if $column_info->{TYPE_NAME};
102
    });
103
    my @output = sort keys %$type_names;
104
    unshift @output, "Type Name";
105
    return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
106
}
107

            
added helper method
yuki-kimoto authored on 2010-10-17
108
our $AUTOLOAD;
109
sub AUTOLOAD {
110
    my $self = shift;
111

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
112
    # Method name
113
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
114

            
cleanup
Yuki Kimoto authored on 2011-04-02
115
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
116
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
117
    if (my $method = $self->{_methods}->{$mname}) {
118
        return $self->$method(@_)
119
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
120
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
121
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
122
    }
123
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
124
        croak qq{Can't locate object method "$mname" via "$package" }
125
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
126
    }
added helper method
yuki-kimoto authored on 2010-10-17
127
}
128

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
129
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
130
    my ($self, $param, $opts) = @_;
131
    
132
    my $wrap = $opts->{wrap} || {};
micro optimization
Yuki Kimoto authored on 2011-11-16
133
    my ($q, $p) = split //, $self->q('');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
134
    
micro optimization
Yuki Kimoto authored on 2011-10-23
135
    # Assign clause (performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
136
    join(
137
      ', ',
138
      map {
139
          ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
140
          : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
141
          : "$q$_$p = :$_";
142
      } sort keys %$param
143
    );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
144
}
145

            
cleanup
Yuki Kimoto authored on 2011-03-21
146
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
147
    my $self = shift;
148
    my $option = pop if ref $_[-1] eq 'HASH';
149
    my $real_table = shift;
150
    my $columns = shift;
151
    my $table = $option->{alias} || $real_table;
152
    
153
    # Columns
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
154
    unless (defined $columns) {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
155
        $columns ||= $self->model($real_table)->columns;
156
    }
added helper method
yuki-kimoto authored on 2010-10-17
157
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
158
    # Separator
159
    my $separator = $self->separator;
160
    
cleanup
Yuki Kimoto authored on 2011-04-02
161
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
162
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
163
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
164
    push @column, $self->q($table) . "." . $self->q($_) .
165
      " as " . $self->q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
166
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
167
    
168
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
169
}
170

            
packaging one directory
yuki-kimoto authored on 2009-11-16
171
sub connect {
cleanup
Yuki Kimoto authored on 2011-08-16
172
    my $self = ref $_[0] ? shift : shift->new(@_);
173
    
174
    my $connector = $self->connector;
175
    
176
    if (!ref $connector && $connector) {
177
        require DBIx::Connector;
178
        
179
        my $dsn = $self->dsn;
180
        my $user = $self->user;
181
        my $password = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
182
        my $option = $self->_option;
cleanup
Yuki Kimoto authored on 2011-08-16
183
        my $connector = DBIx::Connector->new($dsn, $user, $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
184
          {%{$self->default_option} , %$option});
cleanup
Yuki Kimoto authored on 2011-08-16
185
        $self->connector($connector);
186
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
187
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
188
    # Connect
189
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
190
    
packaging one directory
yuki-kimoto authored on 2009-11-16
191
    return $self;
192
}
193

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
194
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] }
195

            
update pod
Yuki Kimoto authored on 2011-03-13
196
sub dbh {
197
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
198
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
199
    # Set
200
    if (@_) {
201
        $self->{dbh} = $_[0];
202
        
203
        return $self;
204
    }
205
    
206
    # Get
207
    else {
208
        # From Connction manager
209
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
210
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
211
              unless ref $connector && $connector->can('dbh');
212
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
213
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
214
        }
215
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
216
        # Connect
217
        $self->{dbh} ||= $self->_connect;
218
        
219
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
220
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
221
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
222
            my $quote =  $driver eq 'odbc' ? '[]'
223
                       : $driver eq 'ado' ? '[]'
224
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
225
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
226
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
227
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
228
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
229
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
230
    }
231
}
232

            
cleanup
Yuki Kimoto authored on 2011-10-21
233
sub delete {
234
    my ($self, %opt) = @_;
235
    warn "delete method where_param option is DEPRECATED!"
236
      if $opt{where_param};
237
    
cleanup
Yuki Kimoto authored on 2011-10-21
238
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
239
    croak qq{delete method where or id option must be specified } . _subname
240
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
241
    
242
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
243
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
cleanup
Yuki Kimoto authored on 2011-10-25
244
      delete $opt{id}, $opt{primary_key}, $opt{table});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
245

            
cleanup
Yuki Kimoto authored on 2011-04-02
246
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
247
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
248
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
249
    $sql .= "from " . $self->q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
250
    
251
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
252
    $opt{statement} = 'delete';
cleanup
Yuki Kimoto authored on 2011-10-25
253
    $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
254
}
255

            
cleanup
Yuki Kimoto authored on 2011-11-01
256
sub delete_all { shift->delete(@_, allow_delete_all => 1) }
packaging one directory
yuki-kimoto authored on 2009-11-16
257

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
260
sub create_model {
261
    my $self = shift;
262
    
cleanup
Yuki Kimoto authored on 2011-10-21
263
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
264
    my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
265
    $opt->{dbi} = $self;
266
    my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
267
    my $model_name  = delete $opt->{name};
268
    my $model_table = delete $opt->{table};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
269
    $model_name ||= $model_table;
270
    
cleanup
Yuki Kimoto authored on 2011-04-02
271
    # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
272
    my $model = $model_class->new($opt);
cleanup
Yuki Kimoto authored on 2011-08-13
273
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
274
    $model->name($model_name) unless $model->name;
275
    $model->table($model_table) unless $model->table;
276
    
micro optimization
Yuki Kimoto authored on 2011-07-30
277
    # Apply filter(DEPRECATED logic)
278
    if ($model->{filter}) {
279
        my $filter = ref $model->filter eq 'HASH'
280
                   ? [%{$model->filter}]
281
                   : $model->filter;
282
        $filter ||= [];
283
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
284
          if @$filter;
285
        $self->_apply_filter($model->table, @$filter);
286
    }
287
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
288
    # Set model
289
    $self->model($model->name, $model);
290
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
291
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
292
}
293

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
297
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
298
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
299
    if ($user_column_info) {
300
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
301
    }
302
    else {
303
    
304
        my $re = $self->exclude_table || $options{exclude_table};
305
        # Tables
306
        my %tables;
307
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
308

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
309
        # Iterate all tables
310
        my @tables = sort keys %tables;
311
        for (my $i = 0; $i < @tables; $i++) {
312
            my $table = $tables[$i];
313
            
314
            # Iterate all columns
315
            my $sth_columns;
316
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
317
            next if $@;
318
            while (my $column_info = $sth_columns->fetchrow_hashref) {
319
                my $column = $column_info->{COLUMN_NAME};
320
                $self->$cb($table, $column, $column_info);
321
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
322
        }
323
    }
324
}
325

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
326
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
327
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
328
    
cleanup test
Yuki Kimoto authored on 2011-08-16
329
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
330
    
added test
Yuki Kimoto authored on 2011-08-16
331
    # Iterate tables
332
    if ($user_table_infos) {
333
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
334
    }
335
    else {
336
        my $re = $self->exclude_table || $option{exclude};
337
        my $sth_tables = $self->dbh->table_info;
338
        while (my $table_info = $sth_tables->fetchrow_hashref) {
339
            
340
            # Table
341
            my $table = $table_info->{TABLE_NAME};
342
            next if defined $re && $table =~ /$re/;
343
            $self->$cb($table, $table_info);
344
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
345
    }
346
}
347

            
cleanup
Yuki Kimoto authored on 2011-04-02
348
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
349
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-10-20
350
    my $sql = shift;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
351

            
352
    # Options
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
353
    my $param;
354
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
355
    my %opt = @_;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
356
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
357
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
358
    my $tables = $opt{table} || [];
cleanup
Yuki Kimoto authored on 2011-04-02
359
    $tables = [$tables] unless ref $tables eq 'ARRAY';
micro optimization
Yuki Kimoto authored on 2011-10-23
360
    my $filter = ref $opt{filter} eq 'ARRAY' ?
361
      _array_to_hash($opt{filter}) : $opt{filter};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
362
    
micro optimization and
Yuki Kimoto authored on 2011-10-25
363
    # Merge second parameter
364
    my @cleanup;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
365
    my $saved_param;
micro optimization and
Yuki Kimoto authored on 2011-10-25
366
    if (ref $param eq 'ARRAY') {
367
        my $param2 = $param->[1];
368
        $param = $param->[0];
369
        for my $column (keys %$param2) {
370
            if (!exists $param->{$column}) {
371
                $param->{$column} = $param2->{$column};
372
                push @cleanup, $column;
373
            }
374
            else {
375
                delete $param->{$_} for @cleanup;
376
                @cleanup = ();
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
377
                $saved_param  = $param;
micro optimization and
Yuki Kimoto authored on 2011-10-25
378
                $param = $self->merge_param($param, $param2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
379
                delete $saved_param->{$_} for (@{$opt{cleanup} || []});
micro optimization and
Yuki Kimoto authored on 2011-10-25
380
                last;
381
            }
382
        }
383
    }
384
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
385
    # Append
386
    $sql .= $opt{append} if defined $opt{append} && !ref $sql;
387
    
388
    # Query
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
389
    my $query;
micro optimization and
Yuki Kimoto authored on 2011-10-25
390
    if (ref $sql) {
391
        $query = $sql;
392
        warn "execute method receiving query object as first parameter is DEPRECATED!" .
393
             "because this is very buggy.";
394
    }
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
395
    else {
396
        $query = $opt{reuse}->{$sql} if $opt{reuse};
micro optimization
Yuki Kimoto authored on 2011-11-16
397
        unless ($query) {
398
            my $safety = $self->{safety_character} || $self->safety_character;
399
            # Check unsafety keys
400
            unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
401
                for my $column (keys %$param) {
402
                    croak qq{"$column" is not safety column name } . _subname
403
                      unless $column =~ /^[$safety\.]+$/;
404
                }
405
            }
406
            $query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter});
407
        }
micro optimization
Yuki Kimoto authored on 2011-11-16
408
        $query->{statement} = $opt{statement} || '';
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
409
        $opt{reuse}->{$sql} = $query if $opt{reuse};
410
    }
411
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
412
    # Save query
micro optimization
Yuki Kimoto authored on 2011-10-23
413
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
414

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
415
    # Return query
cleanup
Yuki Kimoto authored on 2011-11-16
416
    if ($opt{query}) {
417
        delete $param->{$_} for (@cleanup, @{$opt{cleanup} || []});
418
        return $query;
419
    };
micro optimization
Yuki Kimoto authored on 2011-07-30
420
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
421
    # Merge query filter(DEPRECATED!)
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
422
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
423
    
cleanup
Yuki Kimoto authored on 2011-04-02
424
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
425
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
426
    my $main_table = @{$tables}[-1];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
427

            
428
    # Merge id to parameter
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
429
    if (defined $opt{id}) {
micro optimization
Yuki Kimoto authored on 2011-11-16
430
        my $statement = $query->{statement};
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
431
        warn "execute method id option is DEPRECATED!" unless $statement;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
432
        croak "execute id option must be specified with primary_key option"
433
          unless $opt{primary_key};
434
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
435
        $opt{id} = [$opt{id}] unless ref $opt{id};
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
436
        for (my $i = 0; $i < @{$opt{id}}; $i++) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
437
           my $key = $opt{primary_key}->[$i];
438
           $key = "$main_table.$key" if $statement eq 'update' ||
439
             $statement eq 'delete' || $statement eq 'select';
440
           next if exists $param->{$key};
441
           $param->{$key} = $opt{id}->[$i];
micro optimization and
Yuki Kimoto authored on 2011-10-25
442
           push @cleanup, $key;1
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
443
        }
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
444
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
445
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
446
    # Cleanup tables(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
447
    $tables = $self->_remove_duplicate_table($tables, $main_table)
448
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
449
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
450
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
451
    my $type_filters = {};
cleanup
Yuki Kimoto authored on 2011-11-16
452
    my $type_rule_off = !$self->{_type_rule_is_called} || $opt{type_rule_off};
453
    unless ($type_rule_off) {
454
        my $type_rule_off_parts = {
455
            1 => $opt{type_rule1_off},
456
            2 => $opt{type_rule2_off}
457
        };
458
        for my $i (1, 2) {
459
            unless ($type_rule_off_parts->{$i}) {
460
                $type_filters->{$i} = {};
461
                my $table_alias = $opt{table_alias} || {};
462
                for my $alias (keys %$table_alias) {
463
                    my $table = $table_alias->{$alias};
464
                    
465
                    for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
466
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
467
                    }
468
                }
cleanup
Yuki Kimoto authored on 2011-11-16
469
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
470
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
471
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
472
        }
473
    }
cleanup
Yuki Kimoto authored on 2011-04-02
474
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
475
    # Applied filter(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
476
    if ($self->{filter}{on}) {
477
        my $applied_filter = {};
cleanup
Yuki Kimoto authored on 2011-10-21
478
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
479
            $applied_filter = {
480
                %$applied_filter,
481
                %{$self->{filter}{out}->{$table} || {}}
482
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
483
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
484
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
485
    }
486
    
cleanup
Yuki Kimoto authored on 2011-04-02
487
    # Replace filter name to code
cleanup
Yuki Kimoto authored on 2011-10-21
488
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
489
        my $name = $filter->{$column};
490
        if (!defined $name) {
491
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
492
        }
cleanup
Yuki Kimoto authored on 2011-04-02
493
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
494
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
495
            unless exists $self->filters->{$name};
496
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
497
        }
498
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
499

            
cleanup
yuki-kimoto authored on 2010-10-17
500
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
501
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
502
    my $affected;
micro optimization
Yuki Kimoto authored on 2011-11-16
503
    if (!$query->{duplicate} && $type_rule_off && !keys %$filter &&
504
      !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
505
    {
506
        eval { $affected = $sth->execute(map { $param->{$_} } @{$query->{columns}}) };
507
    }
508
    else {
509
        # Create bind values
510
        my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
511
          $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
512

            
513
        # Execute
514
        eval {
515
            if ($opt{bind_type} || $opt{type}) {
516
                $sth->bind_param($_ + 1, $bind->[$_],
517
                    $bind_types->[$_] ? $bind_types->[$_] : ())
518
                  for (0 .. @$bind - 1);
519
                $affected = $sth->execute;
520
            }
521
            else {
522
                $affected = $sth->execute(@$bind);
523
            }
524

            
525
            # DEBUG message
526
            if ($ENV{DBIX_CUSTOM_DEBUG}) {
527
                warn "SQL:\n" . $query->{sql} . "\n";
528
                my @output;
529
                for my $value (@$bind) {
530
                    $value = 'undef' unless defined $value;
531
                    $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
532
                      if utf8::is_utf8($value);
533
                    push @output, $value;
534
                }
535
                warn "Bind values: " . join(', ', @output) . "\n\n";
536
            }
537
        };
538
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
539
    
micro optimization
Yuki Kimoto authored on 2011-07-30
540
    $self->_croak($@, qq{. Following SQL is executed.\n}
541
      . qq{$query->{sql}\n} . _subname) if $@;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
542

            
543
    # Remove id from parameter
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
544
    delete $param->{$_} for (@cleanup, @{$opt{cleanup} || []});
cleanup
yuki-kimoto authored on 2010-10-17
545
    
micro optimization
Yuki Kimoto authored on 2011-10-23
546
    # Not select statement
547
    return $affected unless $sth->{NUM_OF_FIELDS};
548

            
549
    # Filter(DEPRECATED!)
550
    my $infilter = {};
551
    if ($self->{filter}{on}) {
552
        $infilter->{in}  = {};
553
        $infilter->{end} = {};
554
        push @$tables, $main_table if $main_table;
555
        for my $table (@$tables) {
556
            for my $way (qw/in end/) {
557
                $infilter->{$way} = {%{$infilter->{$way}},
558
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
559
            }
cleanup
Yuki Kimoto authored on 2011-01-12
560
        }
cleanup
yuki-kimoto authored on 2010-10-17
561
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
562
    
563
    # Result
micro optimization
Yuki Kimoto authored on 2011-11-16
564
    $self->result_class->new(
micro optimization
Yuki Kimoto authored on 2011-10-23
565
        sth => $sth,
566
        dbi => $self,
567
        default_filter => $self->{default_in_filter},
568
        filter => $infilter->{in} || {},
569
        end_filter => $infilter->{end} || {},
570
        type_rule => {
571
            from1 => $self->type_rule->{from1},
572
            from2 => $self->type_rule->{from2}
573
        },
574
    );
cleanup
yuki-kimoto authored on 2010-10-17
575
}
576

            
added test
Yuki Kimoto authored on 2011-08-16
577
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
578
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
579
    
cleanup
Yuki Kimoto authored on 2011-10-21
580
    my $exclude = delete $opt{exclude};
581
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
582
    
added test
Yuki Kimoto authored on 2011-08-16
583
    my $table_info = [];
584
    $self->each_table(
585
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
586
        exclude => $exclude
587
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
588
    
cleanup test
Yuki Kimoto authored on 2011-08-16
589
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
590
}
591

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
592
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
593
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
594
    
cleanup
Yuki Kimoto authored on 2011-10-21
595
    my $exclude_table = delete $opt{exclude_table};
596
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
597
    
598
    my $column_info = [];
599
    $self->each_column(
600
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
601
        exclude_table => $exclude_table
602
    );
603
    
604
    return [
605
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
606
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
607
}
608

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
609
sub helper {
610
    my $self = shift;
611
    
612
    # Register method
613
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
614
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
615
    
616
    return $self;
617
}
618

            
cleanup
yuki-kimoto authored on 2010-10-17
619
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
620
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
621
    
cleanup
Yuki Kimoto authored on 2011-10-21
622
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
623
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
624
    my %opt = @_;
micro optimization
Yuki Kimoto authored on 2011-10-23
625
    warn "insert method param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
626
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
627
    
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
628
    # Timestamp(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-10-21
629
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
630
        warn "insert timestamp option is DEPRECATED! use created_at with now attribute";
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
631
        my $columns = $insert_timestamp->[0];
632
        $columns = [$columns] unless ref $columns eq 'ARRAY';
633
        my $value = $insert_timestamp->[1];
634
        $value = $value->() if ref $value eq 'CODE';
635
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
636
    }
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
637

            
638
    # Created time and updated time
639
    my @timestamp_cleanup;
640
    if (defined $opt{created_at} || defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
641
        my $now = $self->now;
642
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
643
        if (defined $opt{created_at}) {
644
            $param->{$opt{created_at}} = $now;
645
            push @timestamp_cleanup, $opt{created_at};
646
        }
647
        if (defined $opt{updated_at}) {
648
            $param->{$opt{updated_at}} = $now;
649
            push @timestamp_cleanup, $opt{updated_at};
650
        }
651
    }
cleanup
Yuki Kimoto authored on 2011-10-21
652
    
653
    # Merge id to parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
654
    my @cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
655
    my $id_param = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
656
    if (defined $opt{id}) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
657
        croak "insert id option must be specified with primary_key option"
micro optimization
Yuki Kimoto authored on 2011-10-23
658
          unless $opt{primary_key};
659
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
660
        $opt{id} = [$opt{id}] unless ref $opt{id};
661
        for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
662
           my $key = $opt{primary_key}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
663
           next if exists $param->{$key};
micro optimization
Yuki Kimoto authored on 2011-10-23
664
           $param->{$key} = $opt{id}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
665
           push @cleanup, $key;
micro optimization
Yuki Kimoto authored on 2011-10-23
666
        }
667
    }
cleanup
Yuki Kimoto authored on 2011-10-21
668
    
cleanup
Yuki Kimoto authored on 2011-04-02
669
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
670
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
671
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
672
    $sql .= "into " . $self->q($opt{table}) . " "
cleanup
Yuki Kimoto authored on 2011-10-21
673
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
micro optimization
Yuki Kimoto authored on 2011-10-23
674

            
675
    # Remove id from parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
676
    delete $param->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
677
    
678
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
679
    $opt{statement} = 'insert';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
680
    $opt{cleanup} = \@timestamp_cleanup;
micro optimization
Yuki Kimoto authored on 2011-10-23
681
    $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
682
}
683

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
684
sub insert_timestamp {
685
    my $self = shift;
686
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
687
    warn "insert_timestamp method is DEPRECATED! use now attribute";
688
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
689
    if (@_) {
690
        $self->{insert_timestamp} = [@_];
691
        
692
        return $self;
693
    }
694
    return $self->{insert_timestamp};
695
}
696

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
697
sub include_model {
698
    my ($self, $name_space, $model_infos) = @_;
699
    
cleanup
Yuki Kimoto authored on 2011-04-02
700
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
701
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
702
    
703
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
704
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
705

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
764
sub mapper {
765
    my $self = shift;
766
    return DBIx::Custom::Mapper->new(@_);
767
}
768

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
810
sub mycolumn {
811
    my ($self, $table, $columns) = @_;
812
    
cleanup
Yuki Kimoto authored on 2011-04-02
813
    # Create column clause
814
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
815
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
816
    push @column, $self->q($table) . "." . $self->q($_) .
817
      " as " . $self->q($_)
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
818
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
819
    
820
    return join (', ', @column);
821
}
822

            
added dbi_options attribute
kimoto authored on 2010-12-20
823
sub new {
824
    my $self = shift->SUPER::new(@_);
825
    
cleanup
Yuki Kimoto authored on 2011-04-02
826
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
827
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
828
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
829
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
830
          unless $self->can($attr);
831
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
832

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
833
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
834
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
835
        '?'     => \&DBIx::Custom::Tag::placeholder,
836
        '='     => \&DBIx::Custom::Tag::equal,
837
        '<>'    => \&DBIx::Custom::Tag::not_equal,
838
        '>'     => \&DBIx::Custom::Tag::greater_than,
839
        '<'     => \&DBIx::Custom::Tag::lower_than,
840
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
841
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
842
        'like'  => \&DBIx::Custom::Tag::like,
843
        'in'    => \&DBIx::Custom::Tag::in,
844
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
845
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
846
    };
847
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
848
    # DEPRECATED!
849
    $self->{tag_parse} = 1;
850
    
cleanup
Yuki Kimoto authored on 2011-08-13
851
    return $self;
852
}
853

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

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

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
861
sub q {
862
    my ($self, $value, $quotemeta) = @_;
863
    
864
    my $quote = $self->{reserved_word_quote}
865
      || $self->{quote} || $self->quote || '';
866
    return "$quote$value$quote"
867
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
868
    
869
    my $q = substr($quote, 0, 1) || '';
870
    my $p;
871
    if (defined $quote && length $quote > 1) {
872
        $p = substr($quote, 1, 1);
873
    }
874
    else { $p = $q }
875
    
876
    if ($quotemeta) {
877
        $q = quotemeta($q);
878
        $p = quotemeta($p);
879
    }
880
    
881
    return "$q$value$p";
882
}
883

            
cleanup
yuki-kimoto authored on 2010-10-17
884
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
885
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
886
    
887
    # Register filter
888
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
889
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
890
    
cleanup
Yuki Kimoto authored on 2011-04-02
891
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
892
}
packaging one directory
yuki-kimoto authored on 2009-11-16
893

            
894
sub select {
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
895
    my $self = shift;
896
    my $column = shift if @_ % 2;
897
    my %opt = @_;
898
    $opt{column} = $column if defined $column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
899

            
cleanup
Yuki Kimoto authored on 2011-10-21
900
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
901
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
902
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
903
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
904
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
905
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select method where_param op...
Yuki Kimoto authored on 2011-10-25
906
    warn "select method where_param option is DEPRECATED!"
907
      if $opt{where_param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
908
    
cleanup
Yuki Kimoto authored on 2011-03-09
909
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
910
    if ($opt{relation}) {
911
        warn "select() relation option is DEPRECATED!";
912
        $self->_add_relation_table($tables, $opt{relation});
913
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
914
    
cleanup
Yuki Kimoto authored on 2011-04-02
915
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
916
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
917
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
918
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
919
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
920
    
cleanup
Yuki Kimoto authored on 2011-10-21
921
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
922
    if (defined $opt{column}) {
923
        my $columns
924
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
925
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
926
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
927
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
928
            }
929
            elsif (ref $column eq 'ARRAY') {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
930
                warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
931
                  "use q method to quote the value";
- select method column optio...
Yuki Kimoto authored on 2011-07-11
932
                if (@$column == 3 && $column->[1] eq 'as') {
933
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
934
                    splice @$column, 1, 1;
935
                }
936
                
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
937
                $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
938
            }
cleanup
Yuki Kimoto authored on 2011-04-02
939
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
940
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
941
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
942
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
943
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
944
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
945
    
946
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
947
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
948
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
949
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
950
        for my $table (@$tables) {
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
951
            $sql .= $self->q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
952
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
953
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
954
    }
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
955
    else { $sql .= $self->q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
956
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
957
    croak "select method table option must be specified " . _subname
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
958
      unless defined $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
959

            
cleanup
Yuki Kimoto authored on 2011-04-02
960
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
961
    unshift @$tables,
962
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
963
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
964
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
965
    my $w = $self->_where_clause_and_param($opt{where}, $where_param,
966
      delete $opt{id}, $opt{primary_key}, $tables->[-1]);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
967
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
968
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
969
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
970
    
cleanup
Yuki Kimoto authored on 2011-10-21
971
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
972
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
973
    
cleanup
Yuki Kimoto authored on 2011-03-09
974
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
975
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
976
    
cleanup
Yuki Kimoto authored on 2011-03-08
977
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
978
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
979
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
980
    
packaging one directory
yuki-kimoto authored on 2009-11-16
981
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
982
    $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2011-10-21
983
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
984
    
micro optimization
Yuki Kimoto authored on 2011-10-23
985
    $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
986
}
987

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

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

            
1011
    my $columns = $sth->{NAME};
1012
    my $data_types = $sth->{TYPE};
1013
    
1014
    for (my $i = 0; $i < @$columns; $i++) {
1015
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1016
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1017
        print "$column: $data_type\n";
1018
    }
1019
}
1020

            
1021
sub show_typename {
1022
    my ($self, $t) = @_;
1023
    croak "Table name must be specified" unless defined $t;
1024
    print "$t\n";
1025
    
1026
    $self->each_column(sub {
1027
        my ($self, $table, $column, $infos) = @_;
1028
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1029
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1030
        print "$column: $typename\n";
1031
    });
1032
    
1033
    return $self;
1034
}
1035

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

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1045
sub type_rule {
1046
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-23
1047

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1113
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1114
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1115
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1116
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1117
    warn "update method where_param option is DEPRECATED!"
1118
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1119
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1120
    
cleanup
Yuki Kimoto authored on 2011-10-21
1121
    # Don't allow update all rows
1122
    croak qq{update method where option must be specified } . _subname
1123
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1124
    
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1125
    # Timestamp(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-10-21
1126
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1127
        warn "update timestamp option is DEPRECATED! use updated_at and now method";
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1128
        my $columns = $update_timestamp->[0];
1129
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1130
        my $value = $update_timestamp->[1];
1131
        $value = $value->() if ref $value eq 'CODE';
1132
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1133
    }
1134

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1135
    # Created time and updated time
1136
    my @timestamp_cleanup;
1137
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1138
        my $now = $self->now;
1139
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1140
        $param->{$opt{updated_at}} = $self->now->();
1141
        push @timestamp_cleanup, $opt{updated_at};
1142
    }
1143

            
cleanup
Yuki Kimoto authored on 2011-10-21
1144
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1145
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1146
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1147
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
1148
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1149
      delete $opt{id}, $opt{primary_key}, $opt{table});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1150
    
cleanup
Yuki Kimoto authored on 2011-04-02
1151
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1152
    my $sql = "update ";
1153
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1154
    $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1155
    
cleanup
yuki-kimoto authored on 2010-10-17
1156
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
1157
    $opt{statement} = 'update';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1158
    $opt{cleanup} = \@timestamp_cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
1159
    $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1160
}
1161

            
cleanup
Yuki Kimoto authored on 2011-11-01
1162
sub update_all { shift->update(@_, allow_update_all => 1) };
cleanup
yuki-kimoto authored on 2010-10-17
1163

            
cleanup
Yuki Kimoto authored on 2011-10-21
1164
sub update_or_insert {
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
1165
    my ($self, $param, %opt) = @_;
1166
    croak "update_or_insert method need primary_key and id option "
1167
      unless defined $opt{id} && defined $opt{primary_key};
1168
    my $statement_opt = $opt{option} || {};
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1169

            
1170
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1171
    if (@$rows == 0) {
1172
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1173
    }
1174
    elsif (@$rows == 1) {
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
1175
        return 0 unless keys %$param;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1176
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1177
    }
1178
    else {
1179
        croak "selected row must be one " . _subname;
1180
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1181
}
1182

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1183
sub update_timestamp {
1184
    my $self = shift;
1185
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1186
    warn "update_timestamp method is DEPRECATED! use now method";
1187
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1188
    if (@_) {
1189
        $self->{update_timestamp} = [@_];
1190
        
1191
        return $self;
1192
    }
1193
    return $self->{update_timestamp};
1194
}
1195

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1196
sub values_clause {
1197
    my ($self, $param, $opts) = @_;
1198
    
1199
    my $wrap = $opts->{wrap} || {};
1200
    
1201
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-11-16
1202
    my ($q, $p) = split //, $self->q('');
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1203
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1204
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1205
    '(' .
1206
    join(
1207
      ', ',
1208
      map { "$q$_$p" } sort keys %$param
1209
    ) .
1210
    ') values (' .
1211
    join(
1212
      ', ',
1213
      map {
1214
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1215
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1216
          ":$_";
1217
      } sort keys %$param
1218
    ) .
1219
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1220
}
1221

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

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

            
1250
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-18
1251
        my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1252
          ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1253

            
1254
        my $sql = $source || '';
1255
        if ($tag_parse && ($sql =~ /\s\{/ || $sql =~ /^\{/)) {
1256
            $query = $self->query_builder->build_query($sql);
1257
        }
1258
        else {
1259
            my @columns;
cleanup
Yuki Kimoto authored on 2011-11-16
1260
            my $c = $self->{safety_character} || $self->safety_character;
1261
            my %duplicate;
1262
            my $duplicate;
1263
            # Parameter regex
cleanup
Yuki Kimoto authored on 2011-11-18
1264
            $sql =~ s/([0-9]):/$1\\:/g;
1265
            while ($sql =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) {
1266
                push @columns, $2;
1267
                $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1268
                $sql = defined $3 ? "$1$2 $3 ?$4" : "$1?$4";
cleanup
Yuki Kimoto authored on 2011-11-16
1269
            }
cleanup
Yuki Kimoto authored on 2011-11-18
1270
            $sql =~ s/\\:/:/g if index($sql, "\\:") != -1;
cleanup
Yuki Kimoto authored on 2011-11-16
1271

            
1272
            # Create query
cleanup
Yuki Kimoto authored on 2011-11-18
1273
            $query = {sql => $sql, columns => \@columns, duplicate => $duplicate};
cleanup
Yuki Kimoto authored on 2011-11-16
1274
        }
cleanup
Yuki Kimoto authored on 2011-11-16
1275
        
updated pod
Yuki Kimoto authored on 2011-06-21
1276
        # Save query to cache
1277
        $self->cache_method->(
1278
            $self, $source,
1279
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1280
                sql     => $query->{sql}, 
1281
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1282
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1283
            }
1284
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1285
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1286

            
1287
    # Filter SQL
micro optimization
Yuki Kimoto authored on 2011-11-16
1288
    $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1289
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1290
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1291
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1292
    
updated pod
Yuki Kimoto authored on 2011-06-21
1293
    # Prepare statement handle
1294
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1295
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1296
    
1297
    if ($@) {
1298
        $self->_croak($@, qq{. Following SQL is executed.\n}
1299
                        . qq{$query->{sql}\n} . _subname);
1300
    }
1301
    
1302
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1303
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1304
    
1305
    # Set filters
cleanup
Yuki Kimoto authored on 2011-11-16
1306
    $query->{filters} = $self->{filters} || $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1307
    
1308
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1309
}
1310

            
cleanup
Yuki Kimoto authored on 2011-04-02
1311
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1312
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1313
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1314
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1315
    
cleanup
Yuki Kimoto authored on 2011-04-02
1316
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1317
    my @bind;
1318
    my @types;
1319
    my %count;
1320
    my %not_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1321
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1322
        
micro optimization
Yuki Kimoto authored on 2011-10-23
1323
        # Bind value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1324
        if(ref $params->{$column} eq 'ARRAY') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1325
            my $i = $count{$column} || 0;
1326
            $i += $not_exists{$column} || 0;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1327
            my $found;
1328
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1329
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1330
                    $not_exists{$column}++;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1331
                }
1332
                else  {
micro optimization
Yuki Kimoto authored on 2011-10-23
1333
                    push @bind, $params->{$column}->[$k];
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1334
                    $found = 1;
1335
                    last
1336
                }
1337
            }
1338
            next unless $found;
1339
        }
micro optimization
Yuki Kimoto authored on 2011-10-23
1340
        else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1341
        
cleanup
Yuki Kimoto authored on 2011-01-12
1342
        # Filter
micro optimization
Yuki Kimoto authored on 2011-10-23
1343
        if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1344
            $bind[-1] = $f->($bind[-1]);
micro optimization
Yuki Kimoto authored on 2011-10-23
1345
        }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1346
        
1347
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-23
1348
        if ($self->{_type_rule_is_called}) {
1349
            my $tf1 = $self->{"_into1"}->{dot}->{$column}
1350
              || $type_filters->{1}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1351
            $bind[-1] = $tf1->($bind[-1]) if $tf1;
micro optimization
Yuki Kimoto authored on 2011-10-23
1352
            my $tf2 = $self->{"_into2"}->{dot}->{$column}
1353
              || $type_filters->{2}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1354
            $bind[-1] = $tf2->($bind[-1]) if $tf2;
micro optimization
Yuki Kimoto authored on 2011-10-23
1355
        }
micro optimization
Yuki Kimoto authored on 2011-10-22
1356
       
micro optimization
Yuki Kimoto authored on 2011-10-23
1357
        # Bind types
micro optimization
Yuki Kimoto authored on 2011-10-23
1358
        push @types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1359
        
1360
        # Count up 
micro optimization
Yuki Kimoto authored on 2011-10-23
1361
        $count{$column}++;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1362
    }
1363
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1364
    return (\@bind, \@types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1365
}
1366

            
cleanup
Yuki Kimoto authored on 2011-10-21
1367
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1368
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1369
    
1370
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1371
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1372
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1373
      unless defined $primary_keys;
1374
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1375
    
cleanup
Yuki Kimoto authored on 2011-06-08
1376
    # Create parameter
1377
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1378
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1379
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1380
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1381
           my $key = $primary_keys->[$i];
1382
           $key = "$table." . $key if $table;
1383
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1384
        }
1385
    }
1386
    
cleanup
Yuki Kimoto authored on 2011-06-08
1387
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1388
}
1389

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1390
sub _connect {
1391
    my $self = shift;
1392
    
1393
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1394
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1395
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1396
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1397
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1398
    croak qq{"dsn" must be specified } . _subname
1399
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1400
    my $user        = $self->user;
1401
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1402
    my $option = $self->_option;
1403
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1404
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1405
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1406
    my $dbh;
1407
    eval {
1408
        $dbh = DBI->connect(
1409
            $dsn,
1410
            $user,
1411
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1412
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1413
        );
1414
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1415
    
1416
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1417
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1418
    
1419
    return $dbh;
1420
}
1421

            
cleanup
yuki-kimoto authored on 2010-10-17
1422
sub _croak {
1423
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1424
    
1425
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1426
    $append ||= "";
1427
    
1428
    # Verbose
1429
    if ($Carp::Verbose) { croak $error }
1430
    
1431
    # Not verbose
1432
    else {
1433
        
1434
        # Remove line and module infromation
1435
        my $at_pos = rindex($error, ' at ');
1436
        $error = substr($error, 0, $at_pos);
1437
        $error =~ s/\s+$//;
1438
        croak "$error$append";
1439
    }
1440
}
1441

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1444
sub _need_tables {
1445
    my ($self, $tree, $need_tables, $tables) = @_;
1446
    
cleanup
Yuki Kimoto authored on 2011-04-02
1447
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1448
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1449
        if ($tree->{$table}) {
1450
            $need_tables->{$table} = 1;
1451
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1452
        }
1453
    }
1454
}
1455

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1456
sub _option {
1457
    my $self = shift;
1458
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1459
    warn "dbi_options is DEPRECATED! use option instead\n"
1460
      if keys %{$self->dbi_options};
1461
    warn "dbi_option is DEPRECATED! use option instead\n"
1462
      if keys %{$self->dbi_option};
1463
    return $option;
1464
}
1465

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1466
sub _push_join {
1467
    my ($self, $sql, $join, $join_tables) = @_;
1468
    
cleanup
Yuki Kimoto authored on 2011-10-21
1469
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1470
    
cleanup
Yuki Kimoto authored on 2011-04-02
1471
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1472
    return unless @$join;
1473
    
cleanup
Yuki Kimoto authored on 2011-04-02
1474
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1475
    my $tree = {};
1476
    for (my $i = 0; $i < @$join; $i++) {
1477
        
cleanup
Yuki Kimoto authored on 2011-07-28
1478
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1479
        my $join_clause;;
1480
        my $option;
1481
        if (ref $join->[$i] eq 'HASH') {
1482
            $join_clause = $join->[$i]->{clause};
1483
            $option = {table => $join->[$i]->{table}};
1484
        }
1485
        else {
1486
            $join_clause = $join->[$i];
1487
            $option = {};
1488
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1489

            
1490
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1491
        my $table1;
1492
        my $table2;
1493
        if (my $table = $option->{table}) {
1494
            $table1 = $table->[0];
1495
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1496
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1497
        else {
1498
            my $q = $self->_quote;
1499
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1500
            $j_clause =~ s/'.+?'//g;
1501
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1502
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1503
            
1504
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1505
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1506
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1507
            for my $clause (@j_clauses) {
1508
                if ($clause =~ $join_re) {
1509
                    $table1 = $1;
1510
                    $table2 = $2;
1511
                    last;
1512
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1513
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1514
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1515
        croak qq{join clause must have two table name after "on" keyword. } .
1516
              qq{"$join_clause" is passed }  . _subname
1517
          unless defined $table1 && defined $table2;
1518
        croak qq{right side table of "$join_clause" must be unique }
1519
            . _subname
1520
          if exists $tree->{$table2};
1521
        croak qq{Same table "$table1" is specified} . _subname
1522
          if $table1 eq $table2;
1523
        $tree->{$table2}
1524
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1525
    }
1526
    
cleanup
Yuki Kimoto authored on 2011-04-02
1527
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1528
    my $need_tables = {};
1529
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1530
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1531
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1532
    
1533
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1534
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1535
}
cleanup
Yuki Kimoto authored on 2011-03-08
1536

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1537
sub _quote {
1538
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1539
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1540
}
1541

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

            
1555
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1556
}
1557

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1575
sub _where_clause_and_param {
cleanup
Yuki Kimoto authored on 2011-10-25
1576
    my ($self, $where, $where_param, $id, $primary_key, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-25
1577

            
cleanup
Yuki Kimoto authored on 2011-10-21
1578
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1579
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1580
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1581
    my $w = {};
1582
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1583

            
cleanup
Yuki Kimoto authored on 2011-10-25
1584
    my $obj;
1585
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1586
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1587
        if (ref $where eq 'HASH') {
1588
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1589
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1590
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1591
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1592
                my $table;
1593
                my $c;
1594
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1595
                    $table = $1;
1596
                    $c = $2;
1597
                }
1598
                
1599
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1600
                $table_quote = $self->q($table) if defined $table;
1601
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1602
                $column_quote = $table_quote . '.' . $column_quote
1603
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1604
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1605
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1606

            
1607
            # Check unsafety column
1608
            my $safety = $self->safety_character;
1609
            unless ($column_join =~ /^[$safety\.]+$/) {
1610
                for my $column (keys %$where) {
1611
                    croak qq{"$column" is not safety column name } . _subname
1612
                      unless $column =~ /^[$safety\.]+$/;
1613
                }
1614
            }
1615
            
cleanup
Yuki Kimoto authored on 2011-10-25
1616
            $obj = $self->where(clause => $clause, param => $where);
1617
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1618
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1619
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1620
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1621
        }
1622
        
1623
        # Check where argument
1624
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1625
            . qq{or array reference, which contains where clause and parameter}
1626
            . _subname
1627
          unless ref $obj eq 'DBIx::Custom::Where';
1628

            
1629
        $w->{param} = keys %$where_param
1630
                    ? $self->merge_param($where_param, $obj->param)
1631
                    : $obj->param;
1632
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1633
    }
1634
    elsif ($where) {
1635
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1636
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1637
    }
1638
    
1639
    return $w;
1640
}
1641

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1712
# DEPRECATED!
1713
has 'data_source';
1714
has dbi_options => sub { {} };
1715
has filter_check  => 1;
1716
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1717
has dbi_option => sub { {} };
1718
has default_dbi_option => sub {
1719
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1720
    return shift->default_option;
1721
};
1722

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1723
# DEPRECATED
1724
sub tag_parse {
1725
   my $self = shift;
1726
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1727
         "environment variable";
1728
    if (@_) {
1729
        $self->{tag_parse} = $_[0];
1730
        return $self;
1731
    }
1732
    return $self->{tag_parse};
1733
}
1734

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1735
# DEPRECATED!
1736
sub method {
1737
    warn "method is DEPRECATED! use helper instead";
1738
    return shift->helper(@_);
1739
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1740

            
1741
# DEPRECATED!
1742
sub assign_param {
1743
    my $self = shift;
1744
    warn "assing_param is DEPRECATED! use assign_clause instead";
1745
    return $self->assign_clause(@_);
1746
}
1747

            
1748
# DEPRECATED
1749
sub update_param {
1750
    my ($self, $param, $opts) = @_;
1751
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1752
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1753
    
1754
    # Create update parameter tag
1755
    my $tag = $self->assign_clause($param, $opts);
1756
    $tag = "set $tag" unless $opts->{no_set};
1757

            
1758
    return $tag;
1759
}
1760

            
updated pod
Yuki Kimoto authored on 2011-06-21
1761
# DEPRECATED!
1762
sub create_query {
1763
    warn "create_query is DEPRECATED! use query option of each method";
1764
    shift->_create_query(@_);
1765
}
1766

            
cleanup
Yuki Kimoto authored on 2011-06-13
1767
# DEPRECATED!
1768
sub apply_filter {
1769
    my $self = shift;
1770
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1771
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1772
    return $self->_apply_filter(@_);
1773
}
1774

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1779
    warn "select_at is DEPRECATED! use select method id option instead";
updated pod
Yuki Kimoto authored on 2011-06-08
1780

            
cleanup
Yuki Kimoto authored on 2011-10-21
1781
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1782
    my $primary_keys = delete $opt{primary_key};
1783
    my $where = delete $opt{where};
1784
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1785
    
1786
    # Table
1787
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1788
      unless $opt{table};
1789
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1790
    
1791
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1792
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1793
    
cleanup
Yuki Kimoto authored on 2011-10-21
1794
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1795
}
1796

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1801
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1802
    
cleanup
Yuki Kimoto authored on 2011-10-21
1803
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1804
    my $primary_keys = delete $opt{primary_key};
1805
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1806
    
1807
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1808
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1809
    
cleanup
Yuki Kimoto authored on 2011-10-21
1810
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1811
}
1812

            
cleanup
Yuki Kimoto authored on 2011-06-08
1813
# DEPRECATED!
1814
sub update_at {
1815
    my $self = shift;
1816

            
cleanup
Yuki Kimoto authored on 2011-10-21
1817
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1818
    
cleanup
Yuki Kimoto authored on 2011-10-21
1819
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1820
    my $param;
1821
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1822
    my %opt = @_;
1823
    my $primary_keys = delete $opt{primary_key};
1824
    my $where = delete $opt{where};
1825
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1826
    $param  ||= $p;
1827
    
1828
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1829
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1830
    
cleanup
Yuki Kimoto authored on 2011-10-21
1831
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1832
}
1833

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1834
# DEPRECATED!
1835
sub insert_at {
1836
    my $self = shift;
1837
    
cleanup
Yuki Kimoto authored on 2011-10-21
1838
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1839
    
cleanup
Yuki Kimoto authored on 2011-10-21
1840
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1841
    my $param;
1842
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1843
    my %opt = @_;
1844
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1845
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1846
    my $where = delete $opt{where};
1847
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1848
    $param  ||= $p;
1849
    
1850
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1851
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1852
    $param = $self->merge_param($where_param, $param);
1853
    
cleanup
Yuki Kimoto authored on 2011-10-21
1854
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1855
}
1856

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1904
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1905
sub default_fetch_filter {
1906
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1907

            
cleanup
Yuki Kimoto authored on 2011-06-13
1908
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1909
    
1910
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1911
        my $fname = $_[0];
1912

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1929
# DEPRECATED!
1930
sub insert_param {
1931
    my $self = shift;
1932
    warn "insert_param is DEPRECATED! use values_clause instead";
1933
    return $self->values_clause(@_);
1934
}
1935

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1987
=head1 NAME
1988

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1989
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1990

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2062
Named place holder support
2063

            
2064
=item *
2065

            
cleanup
Yuki Kimoto authored on 2011-07-29
2066
Model support
2067

            
2068
=item *
2069

            
2070
Connection manager support
2071

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

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

            
2078
=item *
2079

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

            
2082
=item *
2083

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

            
2086
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2087

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2095
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2096
L<DBIx::Custom::Result>,
2097
L<DBIx::Custom::Query>,
2098
L<DBIx::Custom::Where>,
2099
L<DBIx::Custom::Model>,
2100
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2101

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

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

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

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

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

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

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

            
2127
    my $dbi = DBIx::Custom->connect(
2128
      dsn => $dsn, user => $user, password => $password, connector => 1);
2129
    
2130
    my $connector = $dbi->connector; # DBIx::Connector
2131

            
2132
Note that L<DBIx::Connector> must be installed.
2133

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2149
    {
2150
        RaiseError => 1,
2151
        PrintError => 0,
2152
        AutoCommit => 1,
2153
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2154

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

            
2157
    my $exclude_table = $dbi->exclude_table;
2158
    $dbi = $dbi->exclude_table(qr/pg_/);
2159

            
2160
Excluded table regex.
2161
C<each_column>, C<each_table>, C<type_rule>,
2162
and C<setup_model> methods ignore matching tables.
2163

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

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

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

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

            
2173
    my $last_sql = $dbi->last_sql;
2174
    $dbi = $dbi->last_sql($last_sql);
2175

            
2176
Get last successed SQL executed by C<execute> method.
2177

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2178
=head2 C<now>
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2179

            
2180
    my $now = $dbi->now;
2181
    $dbi = $dbi->now($now);
2182

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2183
Code reference which return current time, default to the following code reference.
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2184

            
2185
    sub {
2186
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2187
        $mon++;
2188
        $year += 1900;
2189
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2190
    }
2191

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2192
This return the time like C<2011-10-14 05:05:27>.
2193

            
2194
This is used by C<insert> method's C<created_at> option and C<updated_at> option,
2195
and C<update> method's C<updated_at> option.
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2196

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

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

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

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

            
2206
    my $option = $dbi->option;
2207
    $dbi = $dbi->option($option);
2208

            
2209
L<DBI> option, used when C<connect> method is executed.
2210
Each value in option override the value of C<default_option>.
2211

            
cleanup
yuki-kimoto authored on 2010-10-17
2212
=head2 C<password>
2213

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2234
You can set quote pair.
2235

            
2236
    $dbi->quote('[]');
2237

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2247
    my $safety_character = $dbi->safety_character;
2248
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2249

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

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

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

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

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

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

            
2266
    my $tag_parse = $dbi->tag_parse(0);
2267
    $dbi = $dbi->tag_parse;
2268

            
2269
Enable DEPRECATED tag parsing functionality, default to 1.
2270
If you want to disable tag parsing functionality, set to 0.
2271

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

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

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

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

            
2281
    my $user_column_info = $dbi->user_column_info;
2282
    $dbi = $dbi->user_column_info($user_column_info);
2283

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

            
2286
    [
2287
        {table => 'book', column => 'title', info => {...}},
2288
        {table => 'author', column => 'name', info => {...}}
2289
    ]
2290

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

            
2293
    my $user_column_info
2294
      = $dbi->get_column_info(exclude_table => qr/^system/);
2295
    $dbi->user_column_info($user_column_info);
2296

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

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

            
2302
    my $user_table_info = $dbi->user_table_info;
2303
    $dbi = $dbi->user_table_info($user_table_info);
2304

            
2305
You can set the following data.
2306

            
2307
    [
2308
        {table => 'book', info => {...}},
2309
        {table => 'author', info => {...}}
2310
    ]
2311

            
2312
Usually, you can set return value of C<get_table_info>.
2313

            
2314
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2315
    $dbi->user_table_info($user_table_info);
2316

            
2317
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2318
to find table info.
2319

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2356
Create column clause. The follwoing column clause is created.
2357

            
2358
    book.author as "book.author",
2359
    book.title as "book.title"
2360

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2363
    # Separator is hyphen
2364
    $dbi->separator('-');
2365
    
2366
    book.author as "book-author",
2367
    book.title as "book-title"
2368
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2369
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2370

            
update pod
Yuki Kimoto authored on 2011-03-13
2371
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2372
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2373
        user => 'ken',
2374
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2375
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2376
    );
2377

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

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

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

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

            
2388
Get rows count.
2389

            
2390
Options is same as C<select> method's ones.
2391

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2394
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2395
        table => 'book',
2396
        primary_key => 'id',
2397
        join => [
2398
            'inner join company on book.comparny_id = company.id'
2399
        ],
2400
    );
2401

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

            
2405
   $dbi->model('book')->select(...);
2406

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

            
2409
    my $dbh = $dbi->dbh;
2410

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

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

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

            
2418
Execute delete statement.
2419

            
2420
The following opitons are available.
2421

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

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

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

            
2429
=item C<id>
2430

            
2431
    id => 4
2432
    id => [4, 5]
2433

            
2434
ID corresponding to C<primary_key>.
2435
You can delete rows by C<id> and C<primary_key>.
2436

            
2437
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2438
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2439
        id => [4, 5],
2440
        table => 'book',
2441
    );
2442

            
2443
The above is same as the followin one.
2444

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

            
2447
=item C<prefix>
2448

            
2449
    prefix => 'some'
2450

            
2451
prefix before table name section.
2452

            
2453
    delete some from book
2454

            
2455
=item C<table>
2456

            
2457
    table => 'book'
2458

            
2459
Table name.
2460

            
2461
=item C<where>
2462

            
2463
Same as C<select> method's C<where> option.
2464

            
2465
=back
2466

            
2467
=head2 C<delete_all>
2468

            
2469
    $dbi->delete_all(table => $table);
2470

            
2471
Execute delete statement for all rows.
2472
Options is same as C<delete>.
2473

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

            
2476
    $dbi->each_column(
2477
        sub {
2478
            my ($dbi, $table, $column, $column_info) = @_;
2479
            
2480
            my $type = $column_info->{TYPE_NAME};
2481
            
2482
            if ($type eq 'DATE') {
2483
                # ...
2484
            }
2485
        }
2486
    );
2487

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

            
2493
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2494
infromation, you can improve the performance of C<each_column> in
2495
the following way.
2496

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

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

            
2503
    $dbi->each_table(
2504
        sub {
2505
            my ($dbi, $table, $table_info) = @_;
2506
            
2507
            my $table_name = $table_info->{TABLE_NAME};
2508
        }
2509
    );
2510

            
improved pod
Yuki Kimoto authored on 2011-10-14
2511
Iterate all table informationsfrom in database.
2512
Argument is callback which is executed when one table is found.
2513
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2514
C<table information>.
2515

            
2516
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2517
infromation, you can improve the performance of C<each_table> in
2518
the following way.
2519

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

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

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

            
2531
    my $result = $dbi->execute(
2532
      "select * from book where title = :book.title and author like :book.author",
2533
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2534
    );
2535

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2542
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2543
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2544
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2545
    select * from book where title = :title and author like :author
2546
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2547
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2548
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2549

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2553
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2554
    select * from book where :title{=} and :author{like}
2555
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2556
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2557
    select * from where title = ? and author like ?;
2558

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

            
2563
    select * from where title = "aa\\:bb";
2564

            
cleanup
Yuki Kimoto authored on 2011-10-20
2565
B<OPTIONS>
2566

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

            
2569
=over 4
2570

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2571
=item C<after_build_sql> 
2572

            
2573
You can filter sql after the sql is build.
2574

            
2575
    after_build_sql => $code_ref
2576

            
2577
The following one is one example.
2578

            
2579
    $dbi->select(
2580
        table => 'book',
2581
        column => 'distinct(name)',
2582
        after_build_sql => sub {
2583
            "select count(*) from ($_[0]) as t1"
2584
        }
2585
    );
2586

            
2587
The following SQL is executed.
2588

            
2589
    select count(*) from (select distinct(name) from book) as t1;
2590

            
cleanup
Yuki Kimoto authored on 2011-10-20
2591
=item C<append>
2592

            
2593
    append => 'order by name'
2594

            
2595
Append some statement after SQL.
2596

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

            
2599
Specify database bind data type.
2600

            
2601
    bind_type => [image => DBI::SQL_BLOB]
2602
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2603

            
2604
This is used to bind parameter by C<bind_param> of statment handle.
2605

            
2606
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2607

            
update pod
Yuki Kimoto authored on 2011-03-13
2608
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2609
    
2610
    filter => {
2611
        title  => sub { uc $_[0] }
2612
        author => sub { uc $_[0] }
2613
    }
update pod
Yuki Kimoto authored on 2011-03-13
2614

            
updated pod
Yuki Kimoto authored on 2011-06-09
2615
    # Filter name
2616
    filter => {
2617
        title  => 'upper_case',
2618
        author => 'upper_case'
2619
    }
2620
        
2621
    # At once
2622
    filter => [
2623
        [qw/title author/]  => sub { uc $_[0] }
2624
    ]
2625

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

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

            
2633
    query => 1
2634

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2635
C<execute> method return hash reference which contain SQL and column
2636
infromation
updated pod
Yuki Kimoto authored on 2011-06-21
2637

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2638
    my $sql = $query->{sql};
2639
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2640
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2641
=item C<reuse>
2642
    
2643
    reuse => $hash_ref
2644

            
2645
Reuse query object if the hash reference variable is set.
2646
    
2647
    my $queries = {};
2648
    $dbi->execute($sql, $param, reuse => $queries);
2649

            
2650
This will improved performance when you want to execute same query repeatedly
2651
because generally creating query object is slow.
2652

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2655
    primary_key => 'id'
2656
    primary_key => ['id1', 'id2']
2657

            
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
2658
Priamry key. This is used for C<id> option.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2659

            
updated pod
Yuki Kimoto authored on 2011-06-09
2660
=item C<table>
2661
    
2662
    table => 'author'
2663

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2671
    # Same
2672
    $dbi->execute(
2673
      "select * from book where title = :book.title and author = :book.author",
2674
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2675

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

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

            
2680
Table alias. Key is real table name, value is alias table name.
2681
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2682
on alias table name.
2683

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

            
2686
    type_rule_off => 1
2687

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

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

            
2692
    type_rule1_off => 1
2693

            
2694
Turn C<into1> type rule off.
2695

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

            
2698
    type_rule2_off => 1
2699

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

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

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

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

            
2708
get column infomation except for one which match C<exclude_table> pattern.
2709

            
2710
    [
2711
        {table => 'book', column => 'title', info => {...}},
2712
        {table => 'author', column => 'name' info => {...}}
2713
    ]
2714

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

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

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

            
2721
    [
2722
        {table => 'book', info => {...}},
2723
        {table => 'author', info => {...}}
2724
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2725

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

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

            
2730
    $dbi->helper(
2731
        find_or_create   => sub {
2732
            my $self = shift;
2733
            
2734
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2735
        },
2736
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2737
    );
2738

            
2739
Register helper. These helper is called directly from L<DBIx::Custom> object.
2740

            
2741
    $dbi->find_or_create;
2742

            
cleanup
yuki-kimoto authored on 2010-10-17
2743
=head2 C<insert>
2744

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

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

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

            
2753
    {date => \"NOW()"}
2754

            
cleanup
Yuki Kimoto authored on 2011-10-20
2755
B<options>
2756

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2762
=item C<created_at>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2763

            
2764
    created_at => 'created_datetime'
2765

            
2766
Created timestamp column name. time when row is created is set to the column.
2767
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by
2768
C<now> attribute.
2769

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2772
    id => 4
2773
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2774

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2778
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2779
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2780
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2781
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2782
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2783
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2784

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

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

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

            
2794
    prefix => 'or replace'
2795

            
2796
prefix before table name section
2797

            
2798
    insert or replace into book
2799

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

            
2802
    table => 'book'
2803

            
2804
Table name.
2805

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2806
=item C<updated_at>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2807

            
2808
This option is same as C<update> method C<updated_at> option.
2809

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

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

            
2814
placeholder wrapped string.
2815

            
2816
If the following statement
2817

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

            
2821
is executed, the following SQL is executed.
2822

            
2823
    insert into book price values ( ? + 5 );
2824

            
update pod
Yuki Kimoto authored on 2011-03-13
2825
=back
2826

            
2827
=over 4
2828

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2836
    lib / MyModel.pm
2837
        / MyModel / book.pm
2838
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2839

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

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

            
2844
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2845
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2846
    
2847
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2848

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2853
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2854
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2855
    
2856
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2857

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2860
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2861
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2862
    
2863
    1;
2864
    
updated pod
Yuki Kimoto authored on 2011-06-21
2865
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2866

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

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

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

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

            
2876
    my $like_value = $dbi->like_value
2877

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

            
2880
    sub { "%$_[0]%" }
2881

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

            
2884
    my $mapper = $dbi->mapper(param => $param);
2885

            
2886
Create a new L<DBIx::Custom::Mapper> object.
2887

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

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

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

            
2894
    {key1 => [1, 1], key2 => 2}
2895

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

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

            
2900
    my $model = $dbi->model('book');
2901

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

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

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

            
2909
Create column clause for myself. The follwoing column clause is created.
2910

            
2911
    book.author as author,
2912
    book.title as title
2913

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

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

            
2923
Create a new L<DBIx::Custom> object.
2924

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

            
2927
    my $not_exists = $dbi->not_exists;
2928

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

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

            
2934
    my $order = $dbi->order;
2935

            
2936
Create a new L<DBIx::Custom::Order> object.
2937

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2938
=head2 C<q>
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
2939

            
2940
    my $quooted = $dbi->q("title");
2941

            
2942
Quote string by value of C<quote>.
2943

            
cleanup
yuki-kimoto authored on 2010-10-17
2944
=head2 C<register_filter>
2945

            
update pod
Yuki Kimoto authored on 2011-03-13
2946
    $dbi->register_filter(
2947
        # Time::Piece object to database DATE format
2948
        tp_to_date => sub {
2949
            my $tp = shift;
2950
            return $tp->strftime('%Y-%m-%d');
2951
        },
2952
        # database DATE format to Time::Piece object
2953
        date_to_tp => sub {
2954
           my $date = shift;
2955
           return Time::Piece->strptime($date, '%Y-%m-%d');
2956
        }
2957
    );
cleanup
yuki-kimoto authored on 2010-10-17
2958
    
update pod
Yuki Kimoto authored on 2011-03-13
2959
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2960

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2963
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2964
        column => ['author', 'title'],
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
2965
        table  => 'book',
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2966
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2967
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2968
    
updated document
Yuki Kimoto authored on 2011-06-09
2969
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2970

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
2971
You can pass odd number arguments. first argument is C<column>.
2972
This is EXPERIMENTAL.
2973

            
2974
    my $result = $dbi->select(['author', 'title'], table => 'book');
2975

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2983
=item C<column>
2984
    
updated document
Yuki Kimoto authored on 2011-06-09
2985
    column => 'author'
2986
    column => ['author', 'title']
2987

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2996
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2997
        {book => [qw/author title/]},
2998
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2999
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3000

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

            
3003
    book.author as "book.author",
3004
    book.title as "book.title",
3005
    person.name as "person.name",
3006
    person.age as "person.age"
3007

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3019
=item C<id>
3020

            
3021
    id => 4
3022
    id => [4, 5]
3023

            
3024
ID corresponding to C<primary_key>.
3025
You can select rows by C<id> and C<primary_key>.
3026

            
3027
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3028
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3029
        id => [4, 5],
3030
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3031
    );
3032

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3035
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3036
        where => {id1 => 4, id2 => 5},
3037
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3038
    );
3039
    
cleanup
Yuki Kimoto authored on 2011-10-20
3040
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3041

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

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

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

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

            
3054
    prefix => 'SQL_CALC_FOUND_ROWS'
3055

            
3056
Prefix of column cluase
3057

            
3058
    select SQL_CALC_FOUND_ROWS title, author from book;
3059

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

            
3062
    join => [
3063
        'left outer join company on book.company_id = company_id',
3064
        'left outer join location on company.location_id = location.id'
3065
    ]
3066
        
3067
Join clause. If column cluase or where clause contain table name like "company.name",
3068
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3069

            
3070
    $dbi->select(
3071
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3072
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3073
        where => {'company.name' => 'Orange'},
3074
        join => [
3075
            'left outer join company on book.company_id = company.id',
3076
            'left outer join location on company.location_id = location.id'
3077
        ]
3078
    );
3079

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3083
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3084
    from book
3085
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3086
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3087

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3088
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
3089
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3090

            
3091
    $dbi->select(
3092
        table => 'book',
3093
        column => ['company.location_id as location_id'],
3094
        where => {'company.name' => 'Orange'},
3095
        join => [
3096
            {
3097
                clause => 'left outer join location on company.location_id = location.id',
3098
                table => ['company', 'location']
3099
            }
3100
        ]
3101
    );
3102

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3107
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3108

            
updated document
Yuki Kimoto authored on 2011-06-09
3109
=item C<where>
3110
    
3111
    # Hash refrence
3112
    where => {author => 'Ken', 'title' => 'Perl'}
3113
    
3114
    # DBIx::Custom::Where object
3115
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3116
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3117
        param  => {author => 'Ken', title => '%Perl%'}
3118
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3119
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3120
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3121
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3122
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3123
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3124
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3125
    
3126
    # String
3127
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3128

            
cleanup
Yuki Kimoto authored on 2011-10-20
3129
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3130
    
update pod
Yuki Kimoto authored on 2011-03-12
3131
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3132

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

            
3135
    $dbi->setup_model;
3136

            
3137
Setup all model objects.
3138
C<columns> of model object is automatically set, parsing database information.
3139

            
3140
=head2 C<type_rule>
3141

            
3142
    $dbi->type_rule(
3143
        into1 => {
3144
            date => sub { ... },
3145
            datetime => sub { ... }
3146
        },
3147
        into2 => {
3148
            date => sub { ... },
3149
            datetime => sub { ... }
3150
        },
3151
        from1 => {
3152
            # DATE
3153
            9 => sub { ... },
3154
            # DATETIME or TIMESTAMP
3155
            11 => sub { ... },
3156
        }
3157
        from2 => {
3158
            # DATE
3159
            9 => sub { ... },
3160
            # DATETIME or TIMESTAMP
3161
            11 => sub { ... },
3162
        }
3163
    );
3164

            
3165
Filtering rule when data is send into and get from database.
3166
This has a little complex problem.
3167

            
3168
In C<into1> and C<into2> you can specify
3169
type name as same as type name defined
3170
by create table, such as C<DATETIME> or C<DATE>.
3171

            
3172
Note that type name and data type don't contain upper case.
3173
If these contain upper case charactor, you convert it to lower case.
3174

            
3175
C<into2> is executed after C<into1>.
3176

            
3177
Type rule of C<into1> and C<into2> is enabled on the following
3178
column name.
3179

            
3180
=over 4
3181

            
3182
=item 1. column name
3183

            
3184
    issue_date
3185
    issue_datetime
3186

            
3187
This need C<table> option in each method.
3188

            
3189
=item 2. table name and column name, separator is dot
3190

            
3191
    book.issue_date
3192
    book.issue_datetime
3193

            
3194
=back
3195

            
3196
You get all type name used in database by C<available_typename>.
3197

            
3198
    print $dbi->available_typename;
3199

            
3200
In C<from1> and C<from2> you specify data type, not type name.
3201
C<from2> is executed after C<from1>.
3202
You get all data type by C<available_datatype>.
3203

            
3204
    print $dbi->available_datatype;
3205

            
3206
You can also specify multiple types at once.
3207

            
3208
    $dbi->type_rule(
3209
        into1 => [
3210
            [qw/DATE DATETIME/] => sub { ... },
3211
        ],
3212
    );
3213

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

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

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

            
3220
If you want to set constant value to row data, use scalar reference
3221
as parameter value.
3222

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3234
    id => 4
3235
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3236

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3240
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3241
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3242
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3243
        id => [4, 5],
3244
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3245
    );
update pod
Yuki Kimoto authored on 2011-03-13
3246

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3249
    $dbi->update(
3250
        {title => 'Perl', author => 'Ken'}
3251
        where => {id1 => 4, id2 => 5},
3252
        table => 'book'
3253
    );
update pod
Yuki Kimoto authored on 2011-03-13
3254

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

            
3257
    prefix => 'or replace'
3258

            
3259
prefix before table name section
3260

            
3261
    update or replace book
3262

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

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

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

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

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

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

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

            
3277
placeholder wrapped string.
3278

            
3279
If the following statement
3280

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

            
3284
is executed, the following SQL is executed.
3285

            
3286
    update book set price =  ? + 5;
3287

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3288
=item C<updated_at>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3289

            
3290
    updated_at => 'updated_datetime'
3291

            
3292
Updated timestamp column name. time when row is updated is set to the column.
3293
default time format is C<YYYY-mm-dd HH:MM:SS>, which can be changed by
3294
C<now> attribute.
3295

            
updated pod
Yuki Kimoto authored on 2011-06-08
3296
=back
update pod
Yuki Kimoto authored on 2011-03-13
3297

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3305
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3306
    
3307
    # ID
3308
    $dbi->update_or_insert(
3309
        {title => 'Perl'},
3310
        table => 'book',
3311
        id => 1,
3312
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3313
        option => {
3314
            select => {
3315
                 append => 'for update'
3316
            }
3317
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3318
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3319

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3320
Update or insert.
3321

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3322
C<update_or_insert> method execute C<select> method first to find row.
3323
If the row is exists, C<update> is executed.
3324
If not, C<insert> is executed.
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3325

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3326
C<OPTIONS>
3327

            
3328
C<update_or_insert> method use all common option
3329
in C<select>, C<update>, C<delete>, and has the following new ones.
3330

            
3331
=over 4
3332

            
3333
=item C<option>
3334

            
3335
    option => {
3336
        select => {
3337
            append => '...'
3338
        },
3339
        insert => {
3340
            prefix => '...'
3341
        },
3342
        update => {
3343
            filter => {}
3344
        }
3345
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3346

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3347
If you want to pass option to each method,
3348
you can use C<option> option.
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3349

            
3350
=over 4
3351

            
3352
=item C<select_option>
3353

            
3354
    select_option => {append => 'for update'}
3355

            
3356
select method option,
3357
select method is used to check the row is already exists.
3358

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

            
3361
    $dbi->show_datatype($table);
3362

            
3363
Show data type of the columns of specified table.
3364

            
3365
    book
3366
    title: 5
3367
    issue_date: 91
3368

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

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

            
3373
    $dbi->show_tables;
3374

            
3375
Show tables.
3376

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

            
3379
    $dbi->show_typename($table);
3380

            
3381
Show type name of the columns of specified table.
3382

            
3383
    book
3384
    title: varchar
3385
    issue_date: date
3386

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

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

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

            
3393
Create values clause.
3394

            
3395
    (title, author) values (title = :title, age = :age);
3396

            
3397
You can use this in insert statement.
3398

            
3399
    my $insert_sql = "insert into book $values_clause";
3400

            
3401
=head2 C<where>
3402

            
3403
    my $where = $dbi->where(
3404
        clause => ['and', 'title = :title', 'author = :author'],
3405
        param => {title => 'Perl', author => 'Ken'}
3406
    );
3407

            
3408
Create a new L<DBIx::Custom::Where> object.
3409

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

            
3412
=head2 C<DBIX_CUSTOM_DEBUG>
3413

            
3414
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3415
executed SQL and bind values are printed to STDERR.
3416

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

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3421
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3422

            
3423
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3424

            
3425
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3426

            
3427
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3428
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3429

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

            
3432
L<DBIx::Custom>
3433

            
3434
    # Attribute methods
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3435
    tag_parse # will be removed 2017/1/1
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3436
    default_dbi_option # will be removed 2017/1/1
3437
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3438
    data_source # will be removed at 2017/1/1
3439
    dbi_options # will be removed at 2017/1/1
3440
    filter_check # will be removed at 2017/1/1
3441
    reserved_word_quote # will be removed at 2017/1/1
3442
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3443
    
3444
    # Methods
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3445
    update_timestamp # will be removed at 2017/1/1
3446
    insert_timestamp # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3447
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3448
    assign_param # will be removed at 2017/1/1
3449
    update_param # will be removed at 2017/1/1
3450
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3451
    create_query # will be removed at 2017/1/1
3452
    apply_filter # will be removed at 2017/1/1
3453
    select_at # will be removed at 2017/1/1
3454
    delete_at # will be removed at 2017/1/1
3455
    update_at # will be removed at 2017/1/1
3456
    insert_at # will be removed at 2017/1/1
3457
    register_tag # will be removed at 2017/1/1
3458
    default_bind_filter # will be removed at 2017/1/1
3459
    default_fetch_filter # will be removed at 2017/1/1
3460
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3461
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3462
    register_tag_processor # will be removed at 2017/1/1
3463
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3464
    
3465
    # Options
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
3466
    select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
3467
    execute method id option # will be removed 2017/1/1
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3468
    update timestamp option # will be removed 2017/1/1
3469
    insert timestamp option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3470
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3471
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3472
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3473
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3474
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3475
    select method relation option # will be removed at 2017/1/1
3476
    select method column option [COLUMN, as => ALIAS] format
3477
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3478
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479
    
3480
    # Others
micro optimization and
Yuki Kimoto authored on 2011-10-25
3481
    execute($query, ...) # execute method receiving query object.
3482
                         # this is removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2011-07-28
3483
    execute("select * from {= title}"); # execute method's
3484
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3485
                                        # will be removed at 2017/1/1
3486
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487

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

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3490
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3491
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3492
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3493
    filter # will be removed at 2017/1/1
3494
    name # will be removed at 2017/1/1
3495
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3496

            
3497
L<DBIx::Custom::Query>
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
3498

            
3499
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3500
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3501
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3502
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3503
    table # will be removed at 2017/1/1
3504
    filters # will be removed at 2017/1/1
3505
    
3506
    # Methods
3507
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3508

            
3509
L<DBIx::Custom::QueryBuilder>
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3510

            
3511
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3512
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3513
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3514
    tags # will be removed at 2017/1/1
3515
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3516
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3517
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3518
    register_tag # will be removed at 2017/1/1
3519
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3520
    
3521
    # Others
3522
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3523
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3524

            
3525
L<DBIx::Custom::Result>
3526
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3527
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3528
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3529
    
3530
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3531
    filter_on # will be removed at 2017/1/1
3532
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3533
    end_filter # will be removed at 2017/1/1
3534
    remove_end_filter # will be removed at 2017/1/1
3535
    remove_filter # will be removed at 2017/1/1
3536
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3537

            
3538
L<DBIx::Custom::Tag>
3539

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

            
micro optimization
Yuki Kimoto authored on 2011-11-07
3542
L<DBIx::Custom::Order>
3543

            
3544
    # Other
3545
    prepend method array reference receiving
3546
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3547

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

            
3550
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3551
except for attribute method.
3552
You can check all DEPRECATED functionalities by document.
3553
DEPRECATED functionality is removed after five years,
3554
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
3555
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3556

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

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

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

            
3563
C<< <kimoto.yuki at gmail.com> >>
3564

            
3565
L<http://github.com/yuki-kimoto/DBIx-Custom>
3566

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3567
=head1 AUTHOR
3568

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

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

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

            
3575
This program is free software; you can redistribute it and/or modify it
3576
under the same terms as Perl itself.
3577

            
3578
=cut