DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3575 lines | 94.087kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
4
our $VERSION = '0.2101';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1250
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-16
1251
        if (exists $ENV{DBIX_CUSTOM_TAG_PARSE} && !$ENV{DBIX_CUSTOM_TAG_PARSE}) {
1252
            $source ||= '';
1253
            my $columns = [];
1254
            my $c = $self->{safety_character} || $self->safety_character;
1255
            my %duplicate;
1256
            my $duplicate;
1257
            # Parameter regex
1258
            $source =~ s/([0-9]):/$1\\:/g;
1259
            while ($source =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) {
1260
                push @$columns, $2;
1261
                $duplicate = 1 if ++$duplicate{$columns->[-1]} > 1;
1262
                $source = defined $3 ? "$1$2 $3 ?$4" : "$1?$4";
1263
            }
1264
            $source =~ s/\\:/:/g if index($source, "\\:") != -1;
1265

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1552
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1553
}
1554

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1755
    return $tag;
1756
}
1757

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1810
# DEPRECATED!
1811
sub update_at {
1812
    my $self = shift;
1813

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1984
=head1 NAME
1985

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
2051
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- 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
Create C<where> clause flexibly
- 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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2059
Named place holder support
2060

            
2061
=item *
2062

            
cleanup
Yuki Kimoto authored on 2011-07-29
2063
Model support
2064

            
2065
=item *
2066

            
2067
Connection manager support
2068

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

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

            
2075
=item *
2076

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

            
2079
=item *
2080

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

            
2083
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2084

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

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

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

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

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

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

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

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

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

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

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

            
2124
    my $dbi = DBIx::Custom->connect(
2125
      dsn => $dsn, user => $user, password => $password, connector => 1);
2126
    
2127
    my $connector = $dbi->connector; # DBIx::Connector
2128

            
2129
Note that L<DBIx::Connector> must be installed.
2130

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

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

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

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

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

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

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

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

            
2154
    my $exclude_table = $dbi->exclude_table;
2155
    $dbi = $dbi->exclude_table(qr/pg_/);
2156

            
2157
Excluded table regex.
2158
C<each_column>, C<each_table>, C<type_rule>,
2159
and C<setup_model> methods ignore matching tables.
2160

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

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

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

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

            
2170
    my $last_sql = $dbi->last_sql;
2171
    $dbi = $dbi->last_sql($last_sql);
2172

            
2173
Get last successed SQL executed by C<execute> method.
2174

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

            
2177
    my $now = $dbi->now;
2178
    $dbi = $dbi->now($now);
2179

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

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

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

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

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

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

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

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

            
2203
    my $option = $dbi->option;
2204
    $dbi = $dbi->option($option);
2205

            
2206
L<DBI> option, used when C<connect> method is executed.
2207
Each value in option override the value of C<default_option>.
2208

            
cleanup
yuki-kimoto authored on 2010-10-17
2209
=head2 C<password>
2210

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2231
You can set quote pair.
2232

            
2233
    $dbi->quote('[]');
2234

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2244
    my $safety_character = $dbi->safety_character;
2245
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2246

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

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

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

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

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

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

            
2263
    my $tag_parse = $dbi->tag_parse(0);
2264
    $dbi = $dbi->tag_parse;
2265

            
2266
Enable DEPRECATED tag parsing functionality, default to 1.
2267
If you want to disable tag parsing functionality, set to 0.
2268

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

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

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

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

            
2278
    my $user_column_info = $dbi->user_column_info;
2279
    $dbi = $dbi->user_column_info($user_column_info);
2280

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

            
2283
    [
2284
        {table => 'book', column => 'title', info => {...}},
2285
        {table => 'author', column => 'name', info => {...}}
2286
    ]
2287

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

            
2290
    my $user_column_info
2291
      = $dbi->get_column_info(exclude_table => qr/^system/);
2292
    $dbi->user_column_info($user_column_info);
2293

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

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

            
2299
    my $user_table_info = $dbi->user_table_info;
2300
    $dbi = $dbi->user_table_info($user_table_info);
2301

            
2302
You can set the following data.
2303

            
2304
    [
2305
        {table => 'book', info => {...}},
2306
        {table => 'author', info => {...}}
2307
    ]
2308

            
2309
Usually, you can set return value of C<get_table_info>.
2310

            
2311
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2312
    $dbi->user_table_info($user_table_info);
2313

            
2314
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2315
to find table info.
2316

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2353
Create column clause. The follwoing column clause is created.
2354

            
2355
    book.author as "book.author",
2356
    book.title as "book.title"
2357

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

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

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

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

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

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

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

            
2385
Get rows count.
2386

            
2387
Options is same as C<select> method's ones.
2388

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

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

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

            
2402
   $dbi->model('book')->select(...);
2403

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

            
2406
    my $dbh = $dbi->dbh;
2407

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

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

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

            
2415
Execute delete statement.
2416

            
2417
The following opitons are available.
2418

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

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

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

            
2426
=item C<id>
2427

            
2428
    id => 4
2429
    id => [4, 5]
2430

            
2431
ID corresponding to C<primary_key>.
2432
You can delete rows by C<id> and C<primary_key>.
2433

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

            
2440
The above is same as the followin one.
2441

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

            
2444
=item C<prefix>
2445

            
2446
    prefix => 'some'
2447

            
2448
prefix before table name section.
2449

            
2450
    delete some from book
2451

            
2452
=item C<table>
2453

            
2454
    table => 'book'
2455

            
2456
Table name.
2457

            
2458
=item C<where>
2459

            
2460
Same as C<select> method's C<where> option.
2461

            
2462
=back
2463

            
2464
=head2 C<delete_all>
2465

            
2466
    $dbi->delete_all(table => $table);
2467

            
2468
Execute delete statement for all rows.
2469
Options is same as C<delete>.
2470

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

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

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

            
2490
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2491
infromation, you can improve the performance of C<each_column> in
2492
the following way.
2493

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

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

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

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

            
2513
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2514
infromation, you can improve the performance of C<each_table> in
2515
the following way.
2516

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

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

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

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

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

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

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

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

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

            
2560
    select * from where title = "aa\\:bb";
2561

            
cleanup
Yuki Kimoto authored on 2011-10-20
2562
B<OPTIONS>
2563

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

            
2566
=over 4
2567

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

            
2570
You can filter sql after the sql is build.
2571

            
2572
    after_build_sql => $code_ref
2573

            
2574
The following one is one example.
2575

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

            
2584
The following SQL is executed.
2585

            
2586
    select count(*) from (select distinct(name) from book) as t1;
2587

            
cleanup
Yuki Kimoto authored on 2011-10-20
2588
=item C<append>
2589

            
2590
    append => 'order by name'
2591

            
2592
Append some statement after SQL.
2593

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

            
2596
Specify database bind data type.
2597

            
2598
    bind_type => [image => DBI::SQL_BLOB]
2599
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2600

            
2601
This is used to bind parameter by C<bind_param> of statment handle.
2602

            
2603
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2604

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

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

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

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

            
2630
    query => 1
2631

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

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

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

            
2647
This will improved performance when you want to execute same query repeatedly
2648
because generally creating query object is slow.
2649

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2652
    primary_key => 'id'
2653
    primary_key => ['id1', 'id2']
2654

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2657
=item C<table>
2658
    
2659
    table => 'author'
2660

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

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

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

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

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

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

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

            
2683
    type_rule_off => 1
2684

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

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

            
2689
    type_rule1_off => 1
2690

            
2691
Turn C<into1> type rule off.
2692

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

            
2695
    type_rule2_off => 1
2696

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

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

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

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

            
2705
get column infomation except for one which match C<exclude_table> pattern.
2706

            
2707
    [
2708
        {table => 'book', column => 'title', info => {...}},
2709
        {table => 'author', column => 'name' info => {...}}
2710
    ]
2711

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

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

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

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

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

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

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

            
2736
Register helper. These helper is called directly from L<DBIx::Custom> object.
2737

            
2738
    $dbi->find_or_create;
2739

            
cleanup
yuki-kimoto authored on 2010-10-17
2740
=head2 C<insert>
2741

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

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

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

            
2750
    {date => \"NOW()"}
2751

            
cleanup
Yuki Kimoto authored on 2011-10-20
2752
B<options>
2753

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

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

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

            
2761
    created_at => 'created_datetime'
2762

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2769
    id => 4
2770
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2771

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

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

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

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

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

            
2791
    prefix => 'or replace'
2792

            
2793
prefix before table name section
2794

            
2795
    insert or replace into book
2796

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

            
2799
    table => 'book'
2800

            
2801
Table name.
2802

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

            
2805
This option is same as C<update> method C<updated_at> option.
2806

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

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

            
2811
placeholder wrapped string.
2812

            
2813
If the following statement
2814

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

            
2818
is executed, the following SQL is executed.
2819

            
2820
    insert into book price values ( ? + 5 );
2821

            
update pod
Yuki Kimoto authored on 2011-03-13
2822
=back
2823

            
2824
=over 4
2825

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2873
    my $like_value = $dbi->like_value
2874

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

            
2877
    sub { "%$_[0]%" }
2878

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

            
2881
    my $mapper = $dbi->mapper(param => $param);
2882

            
2883
Create a new L<DBIx::Custom::Mapper> object.
2884

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

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

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

            
2891
    {key1 => [1, 1], key2 => 2}
2892

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

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

            
2897
    my $model = $dbi->model('book');
2898

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

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

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

            
2906
Create column clause for myself. The follwoing column clause is created.
2907

            
2908
    book.author as author,
2909
    book.title as title
2910

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

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

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

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

            
2924
    my $not_exists = $dbi->not_exists;
2925

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

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

            
2931
    my $order = $dbi->order;
2932

            
2933
Create a new L<DBIx::Custom::Order> object.
2934

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

            
2937
    my $quooted = $dbi->q("title");
2938

            
2939
Quote string by value of C<quote>.
2940

            
cleanup
yuki-kimoto authored on 2010-10-17
2941
=head2 C<register_filter>
2942

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3000
    book.author as "book.author",
3001
    book.title as "book.title",
3002
    person.name as "person.name",
3003
    person.age as "person.age"
3004

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

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

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

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

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

            
3018
    id => 4
3019
    id => [4, 5]
3020

            
3021
ID corresponding to C<primary_key>.
3022
You can select rows by C<id> and C<primary_key>.
3023

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

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

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

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

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

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

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

            
3051
    prefix => 'SQL_CALC_FOUND_ROWS'
3052

            
3053
Prefix of column cluase
3054

            
3055
    select SQL_CALC_FOUND_ROWS title, author from book;
3056

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

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

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

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

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

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3085
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
3086
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3087

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3104
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3105

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

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

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

            
3132
    $dbi->setup_model;
3133

            
3134
Setup all model objects.
3135
C<columns> of model object is automatically set, parsing database information.
3136

            
3137
=head2 C<type_rule>
3138

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

            
3162
Filtering rule when data is send into and get from database.
3163
This has a little complex problem.
3164

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

            
3169
Note that type name and data type don't contain upper case.
3170
If these contain upper case charactor, you convert it to lower case.
3171

            
3172
C<into2> is executed after C<into1>.
3173

            
3174
Type rule of C<into1> and C<into2> is enabled on the following
3175
column name.
3176

            
3177
=over 4
3178

            
3179
=item 1. column name
3180

            
3181
    issue_date
3182
    issue_datetime
3183

            
3184
This need C<table> option in each method.
3185

            
3186
=item 2. table name and column name, separator is dot
3187

            
3188
    book.issue_date
3189
    book.issue_datetime
3190

            
3191
=back
3192

            
3193
You get all type name used in database by C<available_typename>.
3194

            
3195
    print $dbi->available_typename;
3196

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

            
3201
    print $dbi->available_datatype;
3202

            
3203
You can also specify multiple types at once.
3204

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

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

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

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

            
3217
If you want to set constant value to row data, use scalar reference
3218
as parameter value.
3219

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3231
    id => 4
3232
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3233

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

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

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

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

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

            
3254
    prefix => 'or replace'
3255

            
3256
prefix before table name section
3257

            
3258
    update or replace book
3259

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

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

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

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

            
3268
Same as C<select> method's C<where> option.
3269

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

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

            
3274
placeholder wrapped string.
3275

            
3276
If the following statement
3277

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

            
3281
is executed, the following SQL is executed.
3282

            
3283
    update book set price =  ? + 5;
3284

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

            
3287
    updated_at => 'updated_datetime'
3288

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3293
=back
update pod
Yuki Kimoto authored on 2011-03-13
3294

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3317
Update or insert.
3318

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3323
C<OPTIONS>
3324

            
3325
C<update_or_insert> method use all common option
3326
in C<select>, C<update>, C<delete>, and has the following new ones.
3327

            
3328
=over 4
3329

            
3330
=item C<option>
3331

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

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

            
3347
=over 4
3348

            
3349
=item C<select_option>
3350

            
3351
    select_option => {append => 'for update'}
3352

            
3353
select method option,
3354
select method is used to check the row is already exists.
3355

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

            
3358
    $dbi->show_datatype($table);
3359

            
3360
Show data type of the columns of specified table.
3361

            
3362
    book
3363
    title: 5
3364
    issue_date: 91
3365

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

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

            
3370
    $dbi->show_tables;
3371

            
3372
Show tables.
3373

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

            
3376
    $dbi->show_typename($table);
3377

            
3378
Show type name of the columns of specified table.
3379

            
3380
    book
3381
    title: varchar
3382
    issue_date: date
3383

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

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

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

            
3390
Create values clause.
3391

            
3392
    (title, author) values (title = :title, age = :age);
3393

            
3394
You can use this in insert statement.
3395

            
3396
    my $insert_sql = "insert into book $values_clause";
3397

            
3398
=head2 C<where>
3399

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

            
3405
Create a new L<DBIx::Custom::Where> object.
3406

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

            
3409
=head2 C<DBIX_CUSTOM_DEBUG>
3410

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

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

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

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

            
3420
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3421

            
3422
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3423

            
3424
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3425
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3426

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

            
3429
L<DBIx::Custom>
3430

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

            
3485
L<DBIx::Custom::Model>
3486

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

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

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

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

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

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

            
3535
L<DBIx::Custom::Tag>
3536

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

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

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

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

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

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

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

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

            
3560
C<< <kimoto.yuki at gmail.com> >>
3561

            
3562
L<http://github.com/yuki-kimoto/DBIx-Custom>
3563

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3564
=head1 AUTHOR
3565

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

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

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

            
3572
This program is free software; you can redistribute it and/or modify it
3573
under the same terms as Perl itself.
3574

            
3575
=cut