DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3577 lines | 94.232kb
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
    };
cleanup
Yuki Kimoto authored on 2011-11-18
847
    $self->{tag_parse} = 1 unless exists $self->{tag_parse};
848
    $self->{cache} = 0 unless exists $self->{cache};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
849
    
cleanup
Yuki Kimoto authored on 2011-08-13
850
    return $self;
851
}
852

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1757
    return $tag;
1758
}
1759

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2063
=item *
2064

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

            
2067
=item *
2068

            
2069
Connection manager support
2070

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

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

            
2077
=item *
2078

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

            
2081
=item *
2082

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2304
You can set the following data.
2305

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2387
Get rows count.
2388

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

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

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

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

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

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

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

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

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

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

            
2417
Execute delete statement.
2418

            
2419
The following opitons are available.
2420

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

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

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

            
2428
=item C<id>
2429

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

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

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

            
2442
The above is same as the followin one.
2443

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

            
2446
=item C<prefix>
2447

            
2448
    prefix => 'some'
2449

            
2450
prefix before table name section.
2451

            
2452
    delete some from book
2453

            
2454
=item C<table>
2455

            
2456
    table => 'book'
2457

            
2458
Table name.
2459

            
2460
=item C<where>
2461

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

            
2464
=back
2465

            
2466
=head2 C<delete_all>
2467

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2568
=over 4
2569

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

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

            
2574
    after_build_sql => $code_ref
2575

            
2576
The following one is one example.
2577

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

            
2586
The following SQL is executed.
2587

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

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

            
2592
    append => 'order by name'
2593

            
2594
Append some statement after SQL.
2595

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

            
2598
Specify database bind data type.
2599

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

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

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

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

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

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

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

            
2632
    query => 1
2633

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2685
    type_rule_off => 1
2686

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

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

            
2691
    type_rule1_off => 1
2692

            
2693
Turn C<into1> type rule off.
2694

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

            
2697
    type_rule2_off => 1
2698

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2740
    $dbi->find_or_create;
2741

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

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

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

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

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

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

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

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

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

            
2763
    created_at => 'created_datetime'
2764

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

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

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

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

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

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

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

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

            
2793
    prefix => 'or replace'
2794

            
2795
prefix before table name section
2796

            
2797
    insert or replace into book
2798

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

            
2801
    table => 'book'
2802

            
2803
Table name.
2804

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

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

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

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

            
2813
placeholder wrapped string.
2814

            
2815
If the following statement
2816

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

            
2820
is executed, the following SQL is executed.
2821

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

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

            
2826
=over 4
2827

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2875
    my $like_value = $dbi->like_value
2876

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3053
    prefix => 'SQL_CALC_FOUND_ROWS'
3054

            
3055
Prefix of column cluase
3056

            
3057
    select SQL_CALC_FOUND_ROWS title, author from book;
3058

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3134
    $dbi->setup_model;
3135

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

            
3139
=head2 C<type_rule>
3140

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

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

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

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

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

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

            
3179
=over 4
3180

            
3181
=item 1. column name
3182

            
3183
    issue_date
3184
    issue_datetime
3185

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

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

            
3190
    book.issue_date
3191
    book.issue_datetime
3192

            
3193
=back
3194

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

            
3197
    print $dbi->available_typename;
3198

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

            
3203
    print $dbi->available_datatype;
3204

            
3205
You can also specify multiple types at once.
3206

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3256
    prefix => 'or replace'
3257

            
3258
prefix before table name section
3259

            
3260
    update or replace book
3261

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

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

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

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

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

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

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

            
3276
placeholder wrapped string.
3277

            
3278
If the following statement
3279

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

            
3283
is executed, the following SQL is executed.
3284

            
3285
    update book set price =  ? + 5;
3286

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

            
3289
    updated_at => 'updated_datetime'
3290

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

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

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

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

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

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

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

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

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

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

            
3330
=over 4
3331

            
3332
=item C<option>
3333

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

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

            
3349
=over 4
3350

            
3351
=item C<select_option>
3352

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

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

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

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

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

            
3364
    book
3365
    title: 5
3366
    issue_date: 91
3367

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

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

            
3372
    $dbi->show_tables;
3373

            
3374
Show tables.
3375

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

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

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

            
3382
    book
3383
    title: varchar
3384
    issue_date: date
3385

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

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

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

            
3392
Create values clause.
3393

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

            
3396
You can use this in insert statement.
3397

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

            
3400
=head2 C<where>
3401

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

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

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

            
3411
=head2 C<DBIX_CUSTOM_DEBUG>
3412

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

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

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

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

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

            
3424
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3425

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

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

            
3431
L<DBIx::Custom>
3432

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3577
=cut