DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3579 lines | 94.265kb
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
cleanup
Yuki Kimoto authored on 2011-11-18
24
        user_column_info safety_character/],
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',
cleanup test
Yuki Kimoto authored on 2011-08-10
73
    separator => '.',
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
74
    stash => sub { {} };
cleanup
yuki-kimoto authored on 2010-10-17
75

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1759
    return $tag;
1760
}
1761

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2065
=item *
2066

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

            
2069
=item *
2070

            
2071
Connection manager support
2072

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

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

            
2079
=item *
2080

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

            
2083
=item *
2084

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2306
You can set the following data.
2307

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2389
Get rows count.
2390

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

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

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

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

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

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

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

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

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

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

            
2419
Execute delete statement.
2420

            
2421
The following opitons are available.
2422

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

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

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

            
2430
=item C<id>
2431

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

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

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

            
2444
The above is same as the followin one.
2445

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

            
2448
=item C<prefix>
2449

            
2450
    prefix => 'some'
2451

            
2452
prefix before table name section.
2453

            
2454
    delete some from book
2455

            
2456
=item C<table>
2457

            
2458
    table => 'book'
2459

            
2460
Table name.
2461

            
2462
=item C<where>
2463

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

            
2466
=back
2467

            
2468
=head2 C<delete_all>
2469

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2570
=over 4
2571

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

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

            
2576
    after_build_sql => $code_ref
2577

            
2578
The following one is one example.
2579

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

            
2588
The following SQL is executed.
2589

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

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

            
2594
    append => 'order by name'
2595

            
2596
Append some statement after SQL.
2597

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

            
2600
Specify database bind data type.
2601

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

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

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

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

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

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

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

            
2634
    query => 1
2635

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2687
    type_rule_off => 1
2688

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

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

            
2693
    type_rule1_off => 1
2694

            
2695
Turn C<into1> type rule off.
2696

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

            
2699
    type_rule2_off => 1
2700

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2742
    $dbi->find_or_create;
2743

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

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

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

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

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

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

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

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

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

            
2765
    created_at => 'created_datetime'
2766

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

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

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

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

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

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

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

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

            
2795
    prefix => 'or replace'
2796

            
2797
prefix before table name section
2798

            
2799
    insert or replace into book
2800

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

            
2803
    table => 'book'
2804

            
2805
Table name.
2806

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

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

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

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

            
2815
placeholder wrapped string.
2816

            
2817
If the following statement
2818

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

            
2822
is executed, the following SQL is executed.
2823

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

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

            
2828
=over 4
2829

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2877
    my $like_value = $dbi->like_value
2878

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3055
    prefix => 'SQL_CALC_FOUND_ROWS'
3056

            
3057
Prefix of column cluase
3058

            
3059
    select SQL_CALC_FOUND_ROWS title, author from book;
3060

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3136
    $dbi->setup_model;
3137

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

            
3141
=head2 C<type_rule>
3142

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

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

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

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

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

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

            
3181
=over 4
3182

            
3183
=item 1. column name
3184

            
3185
    issue_date
3186
    issue_datetime
3187

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

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

            
3192
    book.issue_date
3193
    book.issue_datetime
3194

            
3195
=back
3196

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

            
3199
    print $dbi->available_typename;
3200

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

            
3205
    print $dbi->available_datatype;
3206

            
3207
You can also specify multiple types at once.
3208

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3258
    prefix => 'or replace'
3259

            
3260
prefix before table name section
3261

            
3262
    update or replace book
3263

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

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

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

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

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

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

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

            
3278
placeholder wrapped string.
3279

            
3280
If the following statement
3281

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

            
3285
is executed, the following SQL is executed.
3286

            
3287
    update book set price =  ? + 5;
3288

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

            
3291
    updated_at => 'updated_datetime'
3292

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

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

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

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

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

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

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

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

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

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

            
3332
=over 4
3333

            
3334
=item C<option>
3335

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

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

            
3351
=over 4
3352

            
3353
=item C<select_option>
3354

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

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

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

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

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

            
3366
    book
3367
    title: 5
3368
    issue_date: 91
3369

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

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

            
3374
    $dbi->show_tables;
3375

            
3376
Show tables.
3377

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

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

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

            
3384
    book
3385
    title: varchar
3386
    issue_date: date
3387

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

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

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

            
3394
Create values clause.
3395

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

            
3398
You can use this in insert statement.
3399

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

            
3402
=head2 C<where>
3403

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

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

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

            
3413
=head2 C<DBIX_CUSTOM_DEBUG>
3414

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

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

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

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

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

            
3426
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3427

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

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

            
3433
L<DBIx::Custom>
3434

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3579
=cut