DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3612 lines | 94.854kb
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 bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4
our $VERSION = '0.1747';
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
use DBIx::Custom::Class::Inspector;
22

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

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

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

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
130
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
131
    my ($self, $param, $opts) = @_;
132
    
133
    my $wrap = $opts->{wrap} || {};
micro optimization
Yuki Kimoto authored on 2011-10-23
134
    my $safety = $self->{safety_character} || $self->safety_character;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
135
    my $qp = $self->q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
136
    my $q = substr($qp, 0, 1) || '';
137
    my $p = substr($qp, 1, 1) || '';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
138
    
micro optimization
Yuki Kimoto authored on 2011-10-23
139
    # Check unsafety keys
140
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
141
        for my $column (keys %$param) {
142
            croak qq{"$column" is not safety column name } . _subname
143
              unless $column =~ /^[$safety\.]+$/;
144
        }
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
145
    }
146
    
micro optimization
Yuki Kimoto authored on 2011-10-23
147
    # Assign clause (performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
148
    join(
149
      ', ',
150
      map {
151
          ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
152
          : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
153
          : "$q$_$p = :$_";
154
      } sort keys %$param
155
    );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
156
}
157

            
cleanup
Yuki Kimoto authored on 2011-03-21
158
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
159
    my $self = shift;
160
    my $option = pop if ref $_[-1] eq 'HASH';
161
    my $real_table = shift;
162
    my $columns = shift;
163
    my $table = $option->{alias} || $real_table;
164
    
165
    # Columns
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
166
    unless (defined $columns) {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
167
        $columns ||= $self->model($real_table)->columns;
168
    }
added helper method
yuki-kimoto authored on 2010-10-17
169
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
170
    # Separator
171
    my $separator = $self->separator;
172
    
cleanup
Yuki Kimoto authored on 2011-04-02
173
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
174
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
175
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
176
    push @column, $self->q($table) . "." . $self->q($_) .
177
      " as " . $self->q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
178
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
179
    
180
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
181
}
182

            
packaging one directory
yuki-kimoto authored on 2009-11-16
183
sub connect {
cleanup
Yuki Kimoto authored on 2011-08-16
184
    my $self = ref $_[0] ? shift : shift->new(@_);
185
    
186
    my $connector = $self->connector;
187
    
188
    if (!ref $connector && $connector) {
189
        require DBIx::Connector;
190
        
191
        my $dsn = $self->dsn;
192
        my $user = $self->user;
193
        my $password = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
194
        my $option = $self->_option;
cleanup
Yuki Kimoto authored on 2011-08-16
195
        my $connector = DBIx::Connector->new($dsn, $user, $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
196
          {%{$self->default_option} , %$option});
cleanup
Yuki Kimoto authored on 2011-08-16
197
        $self->connector($connector);
198
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
199
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
200
    # Connect
201
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
202
    
packaging one directory
yuki-kimoto authored on 2009-11-16
203
    return $self;
204
}
205

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
245
sub delete {
246
    my ($self, %opt) = @_;
247
    warn "delete method where_param option is DEPRECATED!"
248
      if $opt{where_param};
249
    
cleanup
Yuki Kimoto authored on 2011-10-21
250
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
251
    croak qq{delete method where or id option must be specified } . _subname
252
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
253
    
254
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
255
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
cleanup
Yuki Kimoto authored on 2011-10-25
256
      delete $opt{id}, $opt{primary_key}, $opt{table});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
257

            
cleanup
Yuki Kimoto authored on 2011-04-02
258
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
259
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
260
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
261
    $sql .= "from " . $self->q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
262
    
263
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
264
    $opt{statement} = 'delete';
cleanup
Yuki Kimoto authored on 2011-10-25
265
    $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
266
}
267

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

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

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
309
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
310
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
311
    if ($user_column_info) {
312
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
313
    }
314
    else {
315
    
316
        my $re = $self->exclude_table || $options{exclude_table};
317
        # Tables
318
        my %tables;
319
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
320

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
321
        # Iterate all tables
322
        my @tables = sort keys %tables;
323
        for (my $i = 0; $i < @tables; $i++) {
324
            my $table = $tables[$i];
325
            
326
            # Iterate all columns
327
            my $sth_columns;
328
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
329
            next if $@;
330
            while (my $column_info = $sth_columns->fetchrow_hashref) {
331
                my $column = $column_info->{COLUMN_NAME};
332
                $self->$cb($table, $column, $column_info);
333
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
334
        }
335
    }
336
}
337

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
338
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
339
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
340
    
cleanup test
Yuki Kimoto authored on 2011-08-16
341
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
342
    
added test
Yuki Kimoto authored on 2011-08-16
343
    # Iterate tables
344
    if ($user_table_infos) {
345
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
346
    }
347
    else {
348
        my $re = $self->exclude_table || $option{exclude};
349
        my $sth_tables = $self->dbh->table_info;
350
        while (my $table_info = $sth_tables->fetchrow_hashref) {
351
            
352
            # Table
353
            my $table = $table_info->{TABLE_NAME};
354
            next if defined $re && $table =~ /$re/;
355
            $self->$cb($table, $table_info);
356
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
357
    }
358
}
359

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

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

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
418
    # Return query
419
    return $query if $opt{query};
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}) {
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
430
        my $statement = $query->statement;
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 = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
452
    if ($self->{_type_rule_is_called}) {
453
        unless ($opt{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};
467
                        }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
468
                    }
micro optimization
Yuki Kimoto authored on 2011-10-23
469
                    $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
470
                      if $main_table;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
471
                }
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
472
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
473
        }
474
    }
cleanup
Yuki Kimoto authored on 2011-04-02
475
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
476
    # Applied filter(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
477
    if ($self->{filter}{on}) {
478
        my $applied_filter = {};
cleanup
Yuki Kimoto authored on 2011-10-21
479
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
480
            $applied_filter = {
481
                %$applied_filter,
482
                %{$self->{filter}{out}->{$table} || {}}
483
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
484
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
485
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
486
    }
487
    
cleanup
Yuki Kimoto authored on 2011-04-02
488
    # Replace filter name to code
cleanup
Yuki Kimoto authored on 2011-10-21
489
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
490
        my $name = $filter->{$column};
491
        if (!defined $name) {
492
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
493
        }
cleanup
Yuki Kimoto authored on 2011-04-02
494
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
495
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
496
            unless exists $self->filters->{$name};
497
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
498
        }
499
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
500
    
cleanup
Yuki Kimoto authored on 2011-04-02
501
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
502
    my ($bind, $bind_types) = $self->_create_bind_values($param, $query->columns,
503
      $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
504

            
cleanup
yuki-kimoto authored on 2010-10-17
505
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
506
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
507
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
508
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-23
509
        if ($opt{bind_type} || $opt{type}) {
510
            $sth->bind_param($_ + 1, $bind->[$_],
511
                $bind_types->[$_] ? $bind_types->[$_] : ())
512
              for (0 .. @$bind - 1);
513
            $affected = $sth->execute;
514
        }
515
        else {
516
            $affected = $sth->execute(@$bind);
517
        }
cleanup
Yuki Kimoto authored on 2011-03-21
518
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
519
    
micro optimization
Yuki Kimoto authored on 2011-07-30
520
    $self->_croak($@, qq{. Following SQL is executed.\n}
521
      . qq{$query->{sql}\n} . _subname) if $@;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
522

            
523
    # Remove id from parameter
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
524
    delete $param->{$_} for (@cleanup, @{$opt{cleanup} || []});
cleanup
yuki-kimoto authored on 2010-10-17
525
    
improved debug message
Yuki Kimoto authored on 2011-05-23
526
    # DEBUG message
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
527
    if ($ENV{DBIX_CUSTOM_DEBUG}) {
528
        warn "SQL:\n" . $query->sql . "\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
529
        my @output;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
530
        for my $value (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
531
            $value = 'undef' unless defined $value;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
532
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
improved debug message
Yuki Kimoto authored on 2011-05-23
533
              if utf8::is_utf8($value);
534
            push @output, $value;
535
        }
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
536
        warn "Bind values: " . join(', ', @output) . "\n\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
537
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
538
    
micro optimization
Yuki Kimoto authored on 2011-10-23
539
    # Not select statement
540
    return $affected unless $sth->{NUM_OF_FIELDS};
541

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

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

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

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

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

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

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

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

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

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
758
sub mapper {
759
    my $self = shift;
760
    return DBIx::Custom::Mapper->new(@_);
761
}
762

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

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

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

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

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

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

            
850
sub order {
851
    my $self = shift;
852
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
853
}
854

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

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

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
979
sub setup_model {
980
    my $self = shift;
981
    
cleanup
Yuki Kimoto authored on 2011-04-02
982
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
983
    $self->each_column(
984
        sub {
985
            my ($self, $table, $column, $column_info) = @_;
986
            if (my $model = $self->models->{$table}) {
987
                push @{$model->columns}, $column;
988
            }
989
        }
990
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
991
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
992
}
993

            
update pod
Yuki Kimoto authored on 2011-08-10
994
sub show_datatype {
995
    my ($self, $table) = @_;
996
    croak "Table name must be specified" unless defined $table;
997
    print "$table\n";
998
    
999
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1000
    my $sth = $result->sth;
1001

            
1002
    my $columns = $sth->{NAME};
1003
    my $data_types = $sth->{TYPE};
1004
    
1005
    for (my $i = 0; $i < @$columns; $i++) {
1006
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1007
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1008
        print "$column: $data_type\n";
1009
    }
1010
}
1011

            
1012
sub show_typename {
1013
    my ($self, $t) = @_;
1014
    croak "Table name must be specified" unless defined $t;
1015
    print "$t\n";
1016
    
1017
    $self->each_column(sub {
1018
        my ($self, $table, $column, $infos) = @_;
1019
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1020
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1021
        print "$column: $typename\n";
1022
    });
1023
    
1024
    return $self;
1025
}
1026

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1027
sub show_tables {
1028
    my $self = shift;
1029
    
1030
    my %tables;
1031
    $self->each_table(sub { $tables{$_[1]}++ });
1032
    print join("\n", sort keys %tables) . "\n";
1033
    return $self;
1034
}
1035

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1073
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1074
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1075
                }
1076
            });
1077
        }
1078

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

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1126
    # Created time and updated time
1127
    my @timestamp_cleanup;
1128
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1129
        my $now = $self->now;
1130
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1131
        $param->{$opt{updated_at}} = $self->now->();
1132
        push @timestamp_cleanup, $opt{updated_at};
1133
    }
1134

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

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

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

            
1161
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1162
    if (@$rows == 0) {
1163
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1164
    }
1165
    elsif (@$rows == 1) {
1166
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1167
    }
1168
    else {
1169
        croak "selected row must be one " . _subname;
1170
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1171
}
1172

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1173
sub update_timestamp {
1174
    my $self = shift;
1175
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1176
    warn "update_timestamp method is DEPRECATED! use now method";
1177
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1178
    if (@_) {
1179
        $self->{update_timestamp} = [@_];
1180
        
1181
        return $self;
1182
    }
1183
    return $self->{update_timestamp};
1184
}
1185

            
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
1186
sub use_next_version {
1187
    my $self = shift;
1188

            
1189
    my @modules = ('', qw/::Where ::Util ::Result ::Order ::NotExists ::Model ::Mapper/);
1190
    
1191
    # Replace
1192
    for my $module (@modules) {
1193
        my $old = 'DBIx::Custom' . $module;
1194
        my $new = 'DBIx::Custom::Next' . $module;
1195
        
1196
        no strict 'refs';
1197
        no warnings 'redefine';
1198
        eval "require $old";
1199
        die $@ if $@;
1200
        eval "require $new";
1201
        die $@ if $@;
1202
        for my $method (@{DBIx::Custom::Class::Inspector->methods( $old, 'full', 'public' )}) {
1203
            next unless $method =~ /^DBIx::Custom/;
1204
            undef &{"$method"};
1205
            *{"$method"} = sub { die "$method method is removed" };
1206
        }
1207
        
1208
        for my $new_method (@{DBIx::Custom::Class::Inspector->methods( $new, 'full', 'public' )}) {
1209
            next unless $new_method =~ /^DBIx::Custom/;
1210
            my $old_method = $new_method;
1211
            $old_method =~ s/::Next//;
1212
            *{"$old_method"} = \&{"$new_method"};
1213
        }
1214
    }
1215

            
1216
    # Remove
1217
    for my $module (qw/DBIx::Custom::Tag DBIx::Custom::QueryBuilder/) {
1218
        no strict 'refs';
1219
        eval "require $module";
1220
        die $@ if $@;
1221
        for my $method (@{DBIx::Custom::Class::Inspector->methods( $module, 'full', 'public' )}) {
1222
            next unless $method =~ /^DBIx::Custom/;
1223
            undef &{"$method"};
1224
            *{"$method"} = sub { die "$method method is removed" };
1225
        }
1226
    }
1227
}
1228

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1229
sub values_clause {
1230
    my ($self, $param, $opts) = @_;
1231
    
1232
    my $wrap = $opts->{wrap} || {};
1233
    
1234
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-10-23
1235
    my $safety = $self->{safety_character} || $self->safety_character;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1236
    my $qp = $self->q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1237
    my $q = substr($qp, 0, 1) || '';
1238
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1239
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1240
    # Check unsafety keys
1241
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
1242
        for my $column (keys %$param) {
1243
            croak qq{"$column" is not safety column name } . _subname
1244
              unless $column =~ /^[$safety\.]+$/;
1245
        }
1246
    }
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1247
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1248
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1249
    '(' .
1250
    join(
1251
      ', ',
1252
      map { "$q$_$p" } sort keys %$param
1253
    ) .
1254
    ') values (' .
1255
    join(
1256
      ', ',
1257
      map {
1258
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1259
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1260
          ":$_";
1261
      } sort keys %$param
1262
    ) .
1263
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1264
}
1265

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1268
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1269
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1270
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1271
    
updated pod
Yuki Kimoto authored on 2011-06-21
1272
    # Cache
1273
    my $cache = $self->cache;
1274
    
1275
    # Query
1276
    my $query;
1277
    
1278
    # Get cached query
1279
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1280
        
updated pod
Yuki Kimoto authored on 2011-06-21
1281
        # Get query
1282
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1283
        
updated pod
Yuki Kimoto authored on 2011-06-21
1284
        # Create query
1285
        if ($q) {
1286
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1287
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1288
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1289
    }
1290
    
1291
    # Create query
1292
    unless ($query) {
1293

            
1294
        # Create query
1295
        my $builder = $self->query_builder;
1296
        $query = $builder->build_query($source);
1297

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

            
1304
        # Save query to cache
1305
        $self->cache_method->(
1306
            $self, $source,
1307
            {
1308
                sql     => $query->sql, 
1309
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1310
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1311
            }
1312
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1313
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1314

            
1315
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1316
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1317
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1318
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1319
        $query->sql($sql);
1320
    }
1321
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1322
    # Save sql
1323
    $self->last_sql($query->sql);
1324
    
updated pod
Yuki Kimoto authored on 2011-06-21
1325
    # Prepare statement handle
1326
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1327
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1328
    
1329
    if ($@) {
1330
        $self->_croak($@, qq{. Following SQL is executed.\n}
1331
                        . qq{$query->{sql}\n} . _subname);
1332
    }
1333
    
1334
    # Set statement handle
1335
    $query->sth($sth);
1336
    
1337
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1338
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1339
    
1340
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1341
}
1342

            
cleanup
Yuki Kimoto authored on 2011-04-02
1343
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1344
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1345
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1346
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1347
    
cleanup
Yuki Kimoto authored on 2011-04-02
1348
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1349
    my @bind;
1350
    my @types;
1351
    my %count;
1352
    my %not_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1353
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1354
        
micro optimization
Yuki Kimoto authored on 2011-10-23
1355
        # Bind value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1356
        if(ref $params->{$column} eq 'ARRAY') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1357
            my $i = $count{$column} || 0;
1358
            $i += $not_exists{$column} || 0;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1359
            my $found;
1360
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1361
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1362
                    $not_exists{$column}++;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1363
                }
1364
                else  {
micro optimization
Yuki Kimoto authored on 2011-10-23
1365
                    push @bind, $params->{$column}->[$k];
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1366
                    $found = 1;
1367
                    last
1368
                }
1369
            }
1370
            next unless $found;
1371
        }
micro optimization
Yuki Kimoto authored on 2011-10-23
1372
        else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1373
        
cleanup
Yuki Kimoto authored on 2011-01-12
1374
        # Filter
micro optimization
Yuki Kimoto authored on 2011-10-23
1375
        if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1376
            $bind[-1] = $f->($bind[-1]);
micro optimization
Yuki Kimoto authored on 2011-10-23
1377
        }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1378
        
1379
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-23
1380
        if ($self->{_type_rule_is_called}) {
1381
            my $tf1 = $self->{"_into1"}->{dot}->{$column}
1382
              || $type_filters->{1}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1383
            $bind[-1] = $tf1->($bind[-1]) if $tf1;
micro optimization
Yuki Kimoto authored on 2011-10-23
1384
            my $tf2 = $self->{"_into2"}->{dot}->{$column}
1385
              || $type_filters->{2}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1386
            $bind[-1] = $tf2->($bind[-1]) if $tf2;
micro optimization
Yuki Kimoto authored on 2011-10-23
1387
        }
micro optimization
Yuki Kimoto authored on 2011-10-22
1388
       
micro optimization
Yuki Kimoto authored on 2011-10-23
1389
        # Bind types
micro optimization
Yuki Kimoto authored on 2011-10-23
1390
        push @types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1391
        
1392
        # Count up 
micro optimization
Yuki Kimoto authored on 2011-10-23
1393
        $count{$column}++;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1394
    }
1395
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1396
    return (\@bind, \@types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1397
}
1398

            
cleanup
Yuki Kimoto authored on 2011-10-21
1399
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1400
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1401
    
1402
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1403
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1404
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1405
      unless defined $primary_keys;
1406
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1407
    
cleanup
Yuki Kimoto authored on 2011-06-08
1408
    # Create parameter
1409
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1410
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1411
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1412
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1413
           my $key = $primary_keys->[$i];
1414
           $key = "$table." . $key if $table;
1415
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1416
        }
1417
    }
1418
    
cleanup
Yuki Kimoto authored on 2011-06-08
1419
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1420
}
1421

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1422
sub _connect {
1423
    my $self = shift;
1424
    
1425
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1426
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1427
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1428
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1429
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1430
    croak qq{"dsn" must be specified } . _subname
1431
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1432
    my $user        = $self->user;
1433
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1434
    my $option = $self->_option;
1435
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1436
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1437
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1438
    my $dbh;
1439
    eval {
1440
        $dbh = DBI->connect(
1441
            $dsn,
1442
            $user,
1443
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1444
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1445
        );
1446
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1447
    
1448
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1449
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1450
    
1451
    return $dbh;
1452
}
1453

            
cleanup
yuki-kimoto authored on 2010-10-17
1454
sub _croak {
1455
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1456
    
1457
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1458
    $append ||= "";
1459
    
1460
    # Verbose
1461
    if ($Carp::Verbose) { croak $error }
1462
    
1463
    # Not verbose
1464
    else {
1465
        
1466
        # Remove line and module infromation
1467
        my $at_pos = rindex($error, ' at ');
1468
        $error = substr($error, 0, $at_pos);
1469
        $error =~ s/\s+$//;
1470
        croak "$error$append";
1471
    }
1472
}
1473

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1476
sub _need_tables {
1477
    my ($self, $tree, $need_tables, $tables) = @_;
1478
    
cleanup
Yuki Kimoto authored on 2011-04-02
1479
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1480
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1481
        if ($tree->{$table}) {
1482
            $need_tables->{$table} = 1;
1483
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1484
        }
1485
    }
1486
}
1487

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1488
sub _option {
1489
    my $self = shift;
1490
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1491
    warn "dbi_options is DEPRECATED! use option instead\n"
1492
      if keys %{$self->dbi_options};
1493
    warn "dbi_option is DEPRECATED! use option instead\n"
1494
      if keys %{$self->dbi_option};
1495
    return $option;
1496
}
1497

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1498
sub _push_join {
1499
    my ($self, $sql, $join, $join_tables) = @_;
1500
    
cleanup
Yuki Kimoto authored on 2011-10-21
1501
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1502
    
cleanup
Yuki Kimoto authored on 2011-04-02
1503
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1504
    return unless @$join;
1505
    
cleanup
Yuki Kimoto authored on 2011-04-02
1506
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1507
    my $tree = {};
1508
    for (my $i = 0; $i < @$join; $i++) {
1509
        
cleanup
Yuki Kimoto authored on 2011-07-28
1510
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1511
        my $join_clause;;
1512
        my $option;
1513
        if (ref $join->[$i] eq 'HASH') {
1514
            $join_clause = $join->[$i]->{clause};
1515
            $option = {table => $join->[$i]->{table}};
1516
        }
1517
        else {
1518
            $join_clause = $join->[$i];
1519
            $option = {};
1520
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1521

            
1522
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1523
        my $table1;
1524
        my $table2;
1525
        if (my $table = $option->{table}) {
1526
            $table1 = $table->[0];
1527
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1528
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1529
        else {
1530
            my $q = $self->_quote;
1531
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1532
            $j_clause =~ s/'.+?'//g;
1533
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1534
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1535
            
1536
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1537
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1538
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1539
            for my $clause (@j_clauses) {
1540
                if ($clause =~ $join_re) {
1541
                    $table1 = $1;
1542
                    $table2 = $2;
1543
                    last;
1544
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1545
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1546
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1547
        croak qq{join clause must have two table name after "on" keyword. } .
1548
              qq{"$join_clause" is passed }  . _subname
1549
          unless defined $table1 && defined $table2;
1550
        croak qq{right side table of "$join_clause" must be unique }
1551
            . _subname
1552
          if exists $tree->{$table2};
1553
        croak qq{Same table "$table1" is specified} . _subname
1554
          if $table1 eq $table2;
1555
        $tree->{$table2}
1556
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1557
    }
1558
    
cleanup
Yuki Kimoto authored on 2011-04-02
1559
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1560
    my $need_tables = {};
1561
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1562
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1563
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1564
    
1565
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1566
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1567
}
cleanup
Yuki Kimoto authored on 2011-03-08
1568

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1569
sub _quote {
1570
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1571
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1572
}
1573

            
cleanup
Yuki Kimoto authored on 2011-04-02
1574
sub _remove_duplicate_table {
1575
    my ($self, $tables, $main_table) = @_;
1576
    
1577
    # Remove duplicate table
1578
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1579
    delete $tables{$main_table} if $main_table;
1580
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1581
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1582
    if (my $q = $self->_quote) {
1583
        $q = quotemeta($q);
1584
        $_ =~ s/[$q]//g for @$new_tables;
1585
    }
1586

            
1587
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1588
}
1589

            
cleanup
Yuki Kimoto authored on 2011-04-02
1590
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1591
    my ($self, $source) = @_;
1592
    
cleanup
Yuki Kimoto authored on 2011-04-02
1593
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1594
    my $tables = [];
1595
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1596
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1597
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1598
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1599
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1600
    while ($source =~ /$table_re/g) {
1601
        push @$tables, $1;
1602
    }
1603
    
1604
    return $tables;
1605
}
1606

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1610
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1611
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1612
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1613
    my $w = {};
1614
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1615

            
cleanup
Yuki Kimoto authored on 2011-10-25
1616
    my $obj;
1617
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1618
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1619
        if (ref $where eq 'HASH') {
1620
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1621
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1622
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1623
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1624
                my $table;
1625
                my $c;
1626
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1627
                    $table = $1;
1628
                    $c = $2;
1629
                }
1630
                
1631
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1632
                $table_quote = $self->q($table) if defined $table;
1633
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1634
                $column_quote = $table_quote . '.' . $column_quote
1635
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1636
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1637
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1638

            
1639
            # Check unsafety column
1640
            my $safety = $self->safety_character;
1641
            unless ($column_join =~ /^[$safety\.]+$/) {
1642
                for my $column (keys %$where) {
1643
                    croak qq{"$column" is not safety column name } . _subname
1644
                      unless $column =~ /^[$safety\.]+$/;
1645
                }
1646
            }
1647
            
cleanup
Yuki Kimoto authored on 2011-10-25
1648
            $obj = $self->where(clause => $clause, param => $where);
1649
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1650
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1651
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1652
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1653
        }
1654
        
1655
        # Check where argument
1656
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1657
            . qq{or array reference, which contains where clause and parameter}
1658
            . _subname
1659
          unless ref $obj eq 'DBIx::Custom::Where';
1660

            
1661
        $w->{param} = keys %$where_param
1662
                    ? $self->merge_param($where_param, $obj->param)
1663
                    : $obj->param;
1664
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1665
    }
1666
    elsif ($where) {
1667
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1668
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1669
    }
1670
    
1671
    return $w;
1672
}
1673

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

            
1677
    # Initialize filters
1678
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1679
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1680
    $self->{filter}{out} ||= {};
1681
    $self->{filter}{in} ||= {};
1682
    $self->{filter}{end} ||= {};
1683
    
1684
    # Usage
1685
    my $usage = "Usage: \$dbi->apply_filter(" .
1686
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1687
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1688
    
1689
    # Apply filter
1690
    for (my $i = 0; $i < @cinfos; $i += 2) {
1691
        
1692
        # Column
1693
        my $column = $cinfos[$i];
1694
        if (ref $column eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-10-21
1695
            for my $c (@$column) {
updated pod
Yuki Kimoto authored on 2011-06-21
1696
                push @cinfos, $c, $cinfos[$i + 1];
1697
            }
1698
            next;
1699
        }
1700
        
1701
        # Filter infomation
1702
        my $finfo = $cinfos[$i + 1] || {};
1703
        croak "$usage (table: $table) " . _subname
1704
          unless  ref $finfo eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-10-21
1705
        for my $ftype (keys %$finfo) {
updated pod
Yuki Kimoto authored on 2011-06-21
1706
            croak "$usage (table: $table) " . _subname
1707
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1708
        }
1709
        
1710
        # Set filters
cleanup
Yuki Kimoto authored on 2011-10-21
1711
        for my $way (qw/in out end/) {
updated pod
Yuki Kimoto authored on 2011-06-21
1712
        
1713
            # Filter
1714
            my $filter = $finfo->{$way};
1715
            
1716
            # Filter state
1717
            my $state = !exists $finfo->{$way} ? 'not_exists'
1718
                      : !defined $filter        ? 'not_defined'
1719
                      : ref $filter eq 'CODE'   ? 'code'
1720
                      : 'name';
1721
            
1722
            # Filter is not exists
1723
            next if $state eq 'not_exists';
1724
            
1725
            # Check filter name
1726
            croak qq{Filter "$filter" is not registered } . _subname
1727
              if  $state eq 'name'
1728
               && ! exists $self->filters->{$filter};
1729
            
1730
            # Set filter
1731
            my $f = $state eq 'not_defined' ? undef
1732
                  : $state eq 'code'        ? $filter
1733
                  : $self->filters->{$filter};
1734
            $self->{filter}{$way}{$table}{$column} = $f;
1735
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1736
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1737
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1738
        }
1739
    }
1740
    
1741
    return $self;
1742
}
1743

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1744
# DEPRECATED!
1745
has 'data_source';
1746
has dbi_options => sub { {} };
1747
has filter_check  => 1;
1748
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1749
has dbi_option => sub { {} };
1750
has default_dbi_option => sub {
1751
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1752
    return shift->default_option;
1753
};
1754

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1755
# DEPRECATED
1756
sub tag_parse {
1757
   my $self = shift;
1758
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1759
         "environment variable";
1760
    if (@_) {
1761
        $self->{tag_parse} = $_[0];
1762
        return $self;
1763
    }
1764
    return $self->{tag_parse};
1765
}
1766

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1767
# DEPRECATED!
1768
sub method {
1769
    warn "method is DEPRECATED! use helper instead";
1770
    return shift->helper(@_);
1771
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1772

            
1773
# DEPRECATED!
1774
sub assign_param {
1775
    my $self = shift;
1776
    warn "assing_param is DEPRECATED! use assign_clause instead";
1777
    return $self->assign_clause(@_);
1778
}
1779

            
1780
# DEPRECATED
1781
sub update_param {
1782
    my ($self, $param, $opts) = @_;
1783
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1784
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1785
    
1786
    # Create update parameter tag
1787
    my $tag = $self->assign_clause($param, $opts);
1788
    $tag = "set $tag" unless $opts->{no_set};
1789

            
1790
    return $tag;
1791
}
1792

            
updated pod
Yuki Kimoto authored on 2011-06-21
1793
# DEPRECATED!
1794
sub create_query {
1795
    warn "create_query is DEPRECATED! use query option of each method";
1796
    shift->_create_query(@_);
1797
}
1798

            
cleanup
Yuki Kimoto authored on 2011-06-13
1799
# DEPRECATED!
1800
sub apply_filter {
1801
    my $self = shift;
1802
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1803
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1804
    return $self->_apply_filter(@_);
1805
}
1806

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1813
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1814
    my $primary_keys = delete $opt{primary_key};
1815
    my $where = delete $opt{where};
1816
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1817
    
1818
    # Table
1819
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1820
      unless $opt{table};
1821
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1822
    
1823
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1824
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1825
    
cleanup
Yuki Kimoto authored on 2011-10-21
1826
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1827
}
1828

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1833
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1834
    
cleanup
Yuki Kimoto authored on 2011-10-21
1835
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1836
    my $primary_keys = delete $opt{primary_key};
1837
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1838
    
1839
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1840
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1841
    
cleanup
Yuki Kimoto authored on 2011-10-21
1842
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1843
}
1844

            
cleanup
Yuki Kimoto authored on 2011-06-08
1845
# DEPRECATED!
1846
sub update_at {
1847
    my $self = shift;
1848

            
cleanup
Yuki Kimoto authored on 2011-10-21
1849
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1850
    
cleanup
Yuki Kimoto authored on 2011-10-21
1851
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1852
    my $param;
1853
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1854
    my %opt = @_;
1855
    my $primary_keys = delete $opt{primary_key};
1856
    my $where = delete $opt{where};
1857
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1858
    $param  ||= $p;
1859
    
1860
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1861
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1862
    
cleanup
Yuki Kimoto authored on 2011-10-21
1863
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1864
}
1865

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1866
# DEPRECATED!
1867
sub insert_at {
1868
    my $self = shift;
1869
    
cleanup
Yuki Kimoto authored on 2011-10-21
1870
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1871
    
cleanup
Yuki Kimoto authored on 2011-10-21
1872
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1873
    my $param;
1874
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1875
    my %opt = @_;
1876
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1877
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1878
    my $where = delete $opt{where};
1879
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1880
    $param  ||= $p;
1881
    
1882
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1883
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1884
    $param = $self->merge_param($where_param, $param);
1885
    
cleanup
Yuki Kimoto authored on 2011-10-21
1886
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1887
}
1888

            
added warnings
Yuki Kimoto authored on 2011-06-07
1889
# DEPRECATED!
1890
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1891
    my $self = shift;
1892
    
added warnings
Yuki Kimoto authored on 2011-06-07
1893
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1894
    
1895
    # Merge tag
1896
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1897
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1898
    
1899
    return $self;
1900
}
1901

            
1902
# DEPRECATED!
1903
sub register_tag_processor {
1904
    my $self = shift;
1905
    warn "register_tag_processor is DEPRECATED!";
1906
    # Merge tag
1907
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1908
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1909
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1910
}
1911

            
cleanup
Yuki Kimoto authored on 2011-01-25
1912
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1913
sub default_bind_filter {
1914
    my $self = shift;
1915
    
cleanup
Yuki Kimoto authored on 2011-06-13
1916
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1917
    
cleanup
Yuki Kimoto authored on 2011-01-12
1918
    if (@_) {
1919
        my $fname = $_[0];
1920
        
1921
        if (@_ && !$fname) {
1922
            $self->{default_out_filter} = undef;
1923
        }
1924
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1925
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1926
              unless exists $self->filters->{$fname};
1927
        
1928
            $self->{default_out_filter} = $self->filters->{$fname};
1929
        }
1930
        return $self;
1931
    }
1932
    
1933
    return $self->{default_out_filter};
1934
}
1935

            
cleanup
Yuki Kimoto authored on 2011-01-25
1936
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1937
sub default_fetch_filter {
1938
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1939

            
cleanup
Yuki Kimoto authored on 2011-06-13
1940
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1941
    
1942
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1943
        my $fname = $_[0];
1944

            
cleanup
Yuki Kimoto authored on 2011-01-12
1945
        if (@_ && !$fname) {
1946
            $self->{default_in_filter} = undef;
1947
        }
1948
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1949
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1950
              unless exists $self->filters->{$fname};
1951
        
1952
            $self->{default_in_filter} = $self->filters->{$fname};
1953
        }
1954
        
1955
        return $self;
1956
    }
1957
    
many changed
Yuki Kimoto authored on 2011-01-23
1958
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1959
}
1960

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1961
# DEPRECATED!
1962
sub insert_param {
1963
    my $self = shift;
1964
    warn "insert_param is DEPRECATED! use values_clause instead";
1965
    return $self->values_clause(@_);
1966
}
1967

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1968
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1969
sub insert_param_tag {
1970
    warn "insert_param_tag is DEPRECATED! " .
1971
         "use insert_param instead!";
1972
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1973
}
1974

            
1975
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1976
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1977
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1978
         "use update_param instead";
1979
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1980
}
cleanup
Yuki Kimoto authored on 2011-03-08
1981
# DEPRECATED!
1982
sub _push_relation {
1983
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1984
    
1985
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1986
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1987
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1988
            my $table1 = (split (/\./, $rcolumn))[0];
1989
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1990
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1991
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1992
        }
1993
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1994
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1995
}
1996

            
1997
# DEPRECATED!
1998
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1999
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
2000
    
2001
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
2002
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
2003
            my $table1 = (split (/\./, $rcolumn))[0];
2004
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2005
            my $table1_exists;
2006
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
2007
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
2008
                $table1_exists = 1 if $table eq $table1;
2009
                $table2_exists = 1 if $table eq $table2;
2010
            }
2011
            unshift @$tables, $table1 unless $table1_exists;
2012
            unshift @$tables, $table2 unless $table2_exists;
2013
        }
2014
    }
2015
}
2016

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2019
=head1 NAME
2020

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2025
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2026
    
2027
    # Connect
2028
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2029
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2030
        user => 'ken',
2031
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2032
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2033
    );
cleanup
yuki-kimoto authored on 2010-08-05
2034

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2035
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2036
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2037
    
2038
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2039
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2040
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2041
    
2042
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2043
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2044

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2049
    # Select, more complex
2050
    my $result = $dbi->select(
2051
        table  => 'book',
2052
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
2053
            {book => [qw/title author/]},
2054
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2055
        ],
2056
        where  => {'book.author' => 'Ken'},
2057
        join => ['left outer join company on book.company_id = company.id'],
2058
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2059
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2060
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2061
    # Fetch
2062
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2063
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2064
    }
2065
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2066
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2067
    while (my $row = $result->fetch_hash) {
2068
        
2069
    }
2070
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2071
    # Execute SQL with parameter.
2072
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2073
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2074
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2075
    );
2076
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2077
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2078

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2094
Named place holder support
2095

            
2096
=item *
2097

            
cleanup
Yuki Kimoto authored on 2011-07-29
2098
Model support
2099

            
2100
=item *
2101

            
2102
Connection manager support
2103

            
2104
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2105

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

            
2110
=item *
2111

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

            
2114
=item *
2115

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

            
2118
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2119

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2127
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2128
L<DBIx::Custom::Result>,
2129
L<DBIx::Custom::Query>,
2130
L<DBIx::Custom::Where>,
2131
L<DBIx::Custom::Model>,
2132
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2133

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

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

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

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

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

            
2147
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2148
        "dbi:mysql:database=$database",
2149
        $user,
2150
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2151
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2152
    );
2153
    
updated pod
Yuki Kimoto authored on 2011-06-21
2154
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2155

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

            
2159
    my $dbi = DBIx::Custom->connect(
2160
      dsn => $dsn, user => $user, password => $password, connector => 1);
2161
    
2162
    my $connector = $dbi->connector; # DBIx::Connector
2163

            
2164
Note that L<DBIx::Connector> must be installed.
2165

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2181
    {
2182
        RaiseError => 1,
2183
        PrintError => 0,
2184
        AutoCommit => 1,
2185
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2186

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

            
2189
    my $exclude_table = $dbi->exclude_table;
2190
    $dbi = $dbi->exclude_table(qr/pg_/);
2191

            
2192
Excluded table regex.
2193
C<each_column>, C<each_table>, C<type_rule>,
2194
and C<setup_model> methods ignore matching tables.
2195

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

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

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

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

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

            
2208
Get last successed SQL executed by C<execute> method.
2209

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

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

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

            
2217
    sub {
2218
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2219
        $mon++;
2220
        $year += 1900;
2221
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2222
    }
2223

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

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

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

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

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

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

            
2238
    my $option = $dbi->option;
2239
    $dbi = $dbi->option($option);
2240

            
2241
L<DBI> option, used when C<connect> method is executed.
2242
Each value in option override the value of C<default_option>.
2243

            
cleanup
yuki-kimoto authored on 2010-10-17
2244
=head2 C<password>
2245

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2266
You can set quote pair.
2267

            
2268
    $dbi->quote('[]');
2269

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2279
    my $safety_character = $dbi->safety_character;
2280
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2281

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

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

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

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

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

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

            
2298
    my $tag_parse = $dbi->tag_parse(0);
2299
    $dbi = $dbi->tag_parse;
2300

            
2301
Enable DEPRECATED tag parsing functionality, default to 1.
2302
If you want to disable tag parsing functionality, set to 0.
2303

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

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

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

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

            
2313
    my $user_column_info = $dbi->user_column_info;
2314
    $dbi = $dbi->user_column_info($user_column_info);
2315

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

            
2318
    [
2319
        {table => 'book', column => 'title', info => {...}},
2320
        {table => 'author', column => 'name', info => {...}}
2321
    ]
2322

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

            
2325
    my $user_column_info
2326
      = $dbi->get_column_info(exclude_table => qr/^system/);
2327
    $dbi->user_column_info($user_column_info);
2328

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

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

            
2334
    my $user_table_info = $dbi->user_table_info;
2335
    $dbi = $dbi->user_table_info($user_table_info);
2336

            
2337
You can set the following data.
2338

            
2339
    [
2340
        {table => 'book', info => {...}},
2341
        {table => 'author', info => {...}}
2342
    ]
2343

            
2344
Usually, you can set return value of C<get_table_info>.
2345

            
2346
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2347
    $dbi->user_table_info($user_table_info);
2348

            
2349
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2350
to find table info.
2351

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2388
Create column clause. The follwoing column clause is created.
2389

            
2390
    book.author as "book.author",
2391
    book.title as "book.title"
2392

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2395
    # Separator is hyphen
2396
    $dbi->separator('-');
2397
    
2398
    book.author as "book-author",
2399
    book.title as "book-title"
2400
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2401
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2402

            
update pod
Yuki Kimoto authored on 2011-03-13
2403
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2404
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2405
        user => 'ken',
2406
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2407
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2408
    );
2409

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

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

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

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

            
2420
Get rows count.
2421

            
2422
Options is same as C<select> method's ones.
2423

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2426
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2427
        table => 'book',
2428
        primary_key => 'id',
2429
        join => [
2430
            'inner join company on book.comparny_id = company.id'
2431
        ],
2432
    );
2433

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

            
2437
   $dbi->model('book')->select(...);
2438

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

            
2441
    my $dbh = $dbi->dbh;
2442

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

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

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

            
2450
Execute delete statement.
2451

            
2452
The following opitons are available.
2453

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

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

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

            
2461
=item C<id>
2462

            
2463
    id => 4
2464
    id => [4, 5]
2465

            
2466
ID corresponding to C<primary_key>.
2467
You can delete rows by C<id> and C<primary_key>.
2468

            
2469
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2470
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2471
        id => [4, 5],
2472
        table => 'book',
2473
    );
2474

            
2475
The above is same as the followin one.
2476

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

            
2479
=item C<prefix>
2480

            
2481
    prefix => 'some'
2482

            
2483
prefix before table name section.
2484

            
2485
    delete some from book
2486

            
2487
=item C<table>
2488

            
2489
    table => 'book'
2490

            
2491
Table name.
2492

            
2493
=item C<where>
2494

            
2495
Same as C<select> method's C<where> option.
2496

            
2497
=back
2498

            
2499
=head2 C<delete_all>
2500

            
2501
    $dbi->delete_all(table => $table);
2502

            
2503
Execute delete statement for all rows.
2504
Options is same as C<delete>.
2505

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

            
2508
    $dbi->each_column(
2509
        sub {
2510
            my ($dbi, $table, $column, $column_info) = @_;
2511
            
2512
            my $type = $column_info->{TYPE_NAME};
2513
            
2514
            if ($type eq 'DATE') {
2515
                # ...
2516
            }
2517
        }
2518
    );
2519

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

            
2525
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2526
infromation, you can improve the performance of C<each_column> in
2527
the following way.
2528

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

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

            
2535
    $dbi->each_table(
2536
        sub {
2537
            my ($dbi, $table, $table_info) = @_;
2538
            
2539
            my $table_name = $table_info->{TABLE_NAME};
2540
        }
2541
    );
2542

            
improved pod
Yuki Kimoto authored on 2011-10-14
2543
Iterate all table informationsfrom in database.
2544
Argument is callback which is executed when one table is found.
2545
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2546
C<table information>.
2547

            
2548
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2549
infromation, you can improve the performance of C<each_table> in
2550
the following way.
2551

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

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

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

            
2563
    my $result = $dbi->execute(
2564
      "select * from book where title = :book.title and author like :book.author",
2565
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2566
    );
2567

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2574
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2575
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2576
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2577
    select * from book where title = :title and author like :author
2578
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2579
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2580
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2581

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2585
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2586
    select * from book where :title{=} and :author{like}
2587
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2588
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2589
    select * from where title = ? and author like ?;
2590

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

            
2595
    select * from where title = "aa\\:bb";
2596

            
cleanup
Yuki Kimoto authored on 2011-10-20
2597
B<OPTIONS>
2598

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

            
2601
=over 4
2602

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

            
2605
You can filter sql after the sql is build.
2606

            
2607
    after_build_sql => $code_ref
2608

            
2609
The following one is one example.
2610

            
2611
    $dbi->select(
2612
        table => 'book',
2613
        column => 'distinct(name)',
2614
        after_build_sql => sub {
2615
            "select count(*) from ($_[0]) as t1"
2616
        }
2617
    );
2618

            
2619
The following SQL is executed.
2620

            
2621
    select count(*) from (select distinct(name) from book) as t1;
2622

            
cleanup
Yuki Kimoto authored on 2011-10-20
2623
=item C<append>
2624

            
2625
    append => 'order by name'
2626

            
2627
Append some statement after SQL.
2628

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

            
2631
Specify database bind data type.
2632

            
2633
    bind_type => [image => DBI::SQL_BLOB]
2634
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2635

            
2636
This is used to bind parameter by C<bind_param> of statment handle.
2637

            
2638
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2639

            
update pod
Yuki Kimoto authored on 2011-03-13
2640
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2641
    
2642
    filter => {
2643
        title  => sub { uc $_[0] }
2644
        author => sub { uc $_[0] }
2645
    }
update pod
Yuki Kimoto authored on 2011-03-13
2646

            
updated pod
Yuki Kimoto authored on 2011-06-09
2647
    # Filter name
2648
    filter => {
2649
        title  => 'upper_case',
2650
        author => 'upper_case'
2651
    }
2652
        
2653
    # At once
2654
    filter => [
2655
        [qw/title author/]  => sub { uc $_[0] }
2656
    ]
2657

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

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

            
2665
    query => 1
2666

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2670
    my $sql = $query->{sql};
2671
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2672
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2673
=item C<reuse>
2674
    
2675
    reuse => $hash_ref
2676

            
2677
Reuse query object if the hash reference variable is set.
2678
    
2679
    my $queries = {};
2680
    $dbi->execute($sql, $param, reuse => $queries);
2681

            
2682
This will improved performance when you want to execute same query repeatedly
2683
because generally creating query object is slow.
2684

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2687
    primary_key => 'id'
2688
    primary_key => ['id1', 'id2']
2689

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2692
=item C<table>
2693
    
2694
    table => 'author'
2695

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2703
    # Same
2704
    $dbi->execute(
2705
      "select * from book where title = :book.title and author = :book.author",
2706
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2707

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

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

            
2712
Table alias. Key is real table name, value is alias table name.
2713
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2714
on alias table name.
2715

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

            
2718
    type_rule_off => 1
2719

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

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

            
2724
    type_rule1_off => 1
2725

            
2726
Turn C<into1> type rule off.
2727

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

            
2730
    type_rule2_off => 1
2731

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

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

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

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

            
2740
get column infomation except for one which match C<exclude_table> pattern.
2741

            
2742
    [
2743
        {table => 'book', column => 'title', info => {...}},
2744
        {table => 'author', column => 'name' info => {...}}
2745
    ]
2746

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

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

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

            
2753
    [
2754
        {table => 'book', info => {...}},
2755
        {table => 'author', info => {...}}
2756
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2757

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

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

            
2762
    $dbi->helper(
2763
        find_or_create   => sub {
2764
            my $self = shift;
2765
            
2766
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2767
        },
2768
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2769
    );
2770

            
2771
Register helper. These helper is called directly from L<DBIx::Custom> object.
2772

            
2773
    $dbi->find_or_create;
2774

            
cleanup
yuki-kimoto authored on 2010-10-17
2775
=head2 C<insert>
2776

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

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

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

            
2785
    {date => \"NOW()"}
2786

            
cleanup
Yuki Kimoto authored on 2011-10-20
2787
B<options>
2788

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

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

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

            
2796
    created_at => 'created_datetime'
2797

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2804
    id => 4
2805
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2806

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2810
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2811
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2812
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2813
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2814
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2815
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2816

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

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

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

            
2826
    prefix => 'or replace'
2827

            
2828
prefix before table name section
2829

            
2830
    insert or replace into book
2831

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

            
2834
    table => 'book'
2835

            
2836
Table name.
2837

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

            
2840
This option is same as C<update> method C<updated_at> option.
2841

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

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

            
2846
placeholder wrapped string.
2847

            
2848
If the following statement
2849

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

            
2853
is executed, the following SQL is executed.
2854

            
2855
    insert into book price values ( ? + 5 );
2856

            
update pod
Yuki Kimoto authored on 2011-03-13
2857
=back
2858

            
2859
=over 4
2860

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2868
    lib / MyModel.pm
2869
        / MyModel / book.pm
2870
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2871

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

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

            
2876
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2877
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2878
    
2879
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2880

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2885
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2886
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2887
    
2888
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2889

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2892
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2893
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2894
    
2895
    1;
2896
    
updated pod
Yuki Kimoto authored on 2011-06-21
2897
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2898

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

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

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

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

            
2908
    my $like_value = $dbi->like_value
2909

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

            
2912
    sub { "%$_[0]%" }
2913

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

            
2916
    my $mapper = $dbi->mapper(param => $param);
2917

            
2918
Create a new L<DBIx::Custom::Mapper> object.
2919

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

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

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

            
2926
    {key1 => [1, 1], key2 => 2}
2927

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

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

            
2932
    my $model = $dbi->model('book');
2933

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

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

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

            
2941
Create column clause for myself. The follwoing column clause is created.
2942

            
2943
    book.author as author,
2944
    book.title as title
2945

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

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

            
2955
Create a new L<DBIx::Custom> object.
2956

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

            
2959
    my $not_exists = $dbi->not_exists;
2960

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

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

            
2966
    my $order = $dbi->order;
2967

            
2968
Create a new L<DBIx::Custom::Order> object.
2969

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

            
2972
    my $quooted = $dbi->q("title");
2973

            
2974
Quote string by value of C<quote>.
2975

            
cleanup
yuki-kimoto authored on 2010-10-17
2976
=head2 C<register_filter>
2977

            
update pod
Yuki Kimoto authored on 2011-03-13
2978
    $dbi->register_filter(
2979
        # Time::Piece object to database DATE format
2980
        tp_to_date => sub {
2981
            my $tp = shift;
2982
            return $tp->strftime('%Y-%m-%d');
2983
        },
2984
        # database DATE format to Time::Piece object
2985
        date_to_tp => sub {
2986
           my $date = shift;
2987
           return Time::Piece->strptime($date, '%Y-%m-%d');
2988
        }
2989
    );
cleanup
yuki-kimoto authored on 2010-10-17
2990
    
update pod
Yuki Kimoto authored on 2011-03-13
2991
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2992

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2995
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2996
        table  => 'book',
2997
        column => ['author', 'title'],
2998
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2999
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3000
    
updated document
Yuki Kimoto authored on 2011-06-09
3001
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3002

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3010
=item C<column>
3011
    
updated document
Yuki Kimoto authored on 2011-06-09
3012
    column => 'author'
3013
    column => ['author', 'title']
3014

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3023
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3024
        {book => [qw/author title/]},
3025
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3026
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3027

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

            
3030
    book.author as "book.author",
3031
    book.title as "book.title",
3032
    person.name as "person.name",
3033
    person.age as "person.age"
3034

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

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

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

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

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

            
3048
    id => 4
3049
    id => [4, 5]
3050

            
3051
ID corresponding to C<primary_key>.
3052
You can select rows by C<id> and C<primary_key>.
3053

            
3054
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3055
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3056
        id => [4, 5],
3057
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3058
    );
3059

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3062
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3063
        where => {id1 => 4, id2 => 5},
3064
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3065
    );
3066
    
cleanup
Yuki Kimoto authored on 2011-10-20
3067
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3068

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

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

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

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

            
3081
    prefix => 'SQL_CALC_FOUND_ROWS'
3082

            
3083
Prefix of column cluase
3084

            
3085
    select SQL_CALC_FOUND_ROWS title, author from book;
3086

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

            
3089
    join => [
3090
        'left outer join company on book.company_id = company_id',
3091
        'left outer join location on company.location_id = location.id'
3092
    ]
3093
        
3094
Join clause. If column cluase or where clause contain table name like "company.name",
3095
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3096

            
3097
    $dbi->select(
3098
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3099
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3100
        where => {'company.name' => 'Orange'},
3101
        join => [
3102
            'left outer join company on book.company_id = company.id',
3103
            'left outer join location on company.location_id = location.id'
3104
        ]
3105
    );
3106

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3110
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3111
    from book
3112
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3113
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3114

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3115
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
3116
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3117

            
3118
    $dbi->select(
3119
        table => 'book',
3120
        column => ['company.location_id as location_id'],
3121
        where => {'company.name' => 'Orange'},
3122
        join => [
3123
            {
3124
                clause => 'left outer join location on company.location_id = location.id',
3125
                table => ['company', 'location']
3126
            }
3127
        ]
3128
    );
3129

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3134
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3135

            
updated document
Yuki Kimoto authored on 2011-06-09
3136
=item C<where>
3137
    
3138
    # Hash refrence
3139
    where => {author => 'Ken', 'title' => 'Perl'}
3140
    
3141
    # DBIx::Custom::Where object
3142
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3143
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3144
        param  => {author => 'Ken', title => '%Perl%'}
3145
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3146
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3147
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3148
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3149
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3150
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3151
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3152
    
3153
    # String
3154
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3155

            
cleanup
Yuki Kimoto authored on 2011-10-20
3156
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3157
    
update pod
Yuki Kimoto authored on 2011-03-12
3158
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3159

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

            
3162
    $dbi->setup_model;
3163

            
3164
Setup all model objects.
3165
C<columns> of model object is automatically set, parsing database information.
3166

            
3167
=head2 C<type_rule>
3168

            
3169
    $dbi->type_rule(
3170
        into1 => {
3171
            date => sub { ... },
3172
            datetime => sub { ... }
3173
        },
3174
        into2 => {
3175
            date => sub { ... },
3176
            datetime => sub { ... }
3177
        },
3178
        from1 => {
3179
            # DATE
3180
            9 => sub { ... },
3181
            # DATETIME or TIMESTAMP
3182
            11 => sub { ... },
3183
        }
3184
        from2 => {
3185
            # DATE
3186
            9 => sub { ... },
3187
            # DATETIME or TIMESTAMP
3188
            11 => sub { ... },
3189
        }
3190
    );
3191

            
3192
Filtering rule when data is send into and get from database.
3193
This has a little complex problem.
3194

            
3195
In C<into1> and C<into2> you can specify
3196
type name as same as type name defined
3197
by create table, such as C<DATETIME> or C<DATE>.
3198

            
3199
Note that type name and data type don't contain upper case.
3200
If these contain upper case charactor, you convert it to lower case.
3201

            
3202
C<into2> is executed after C<into1>.
3203

            
3204
Type rule of C<into1> and C<into2> is enabled on the following
3205
column name.
3206

            
3207
=over 4
3208

            
3209
=item 1. column name
3210

            
3211
    issue_date
3212
    issue_datetime
3213

            
3214
This need C<table> option in each method.
3215

            
3216
=item 2. table name and column name, separator is dot
3217

            
3218
    book.issue_date
3219
    book.issue_datetime
3220

            
3221
=back
3222

            
3223
You get all type name used in database by C<available_typename>.
3224

            
3225
    print $dbi->available_typename;
3226

            
3227
In C<from1> and C<from2> you specify data type, not type name.
3228
C<from2> is executed after C<from1>.
3229
You get all data type by C<available_datatype>.
3230

            
3231
    print $dbi->available_datatype;
3232

            
3233
You can also specify multiple types at once.
3234

            
3235
    $dbi->type_rule(
3236
        into1 => [
3237
            [qw/DATE DATETIME/] => sub { ... },
3238
        ],
3239
    );
3240

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

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

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

            
3247
If you want to set constant value to row data, use scalar reference
3248
as parameter value.
3249

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3261
    id => 4
3262
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3263

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3267
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3268
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3269
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3270
        id => [4, 5],
3271
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3272
    );
update pod
Yuki Kimoto authored on 2011-03-13
3273

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3276
    $dbi->update(
3277
        {title => 'Perl', author => 'Ken'}
3278
        where => {id1 => 4, id2 => 5},
3279
        table => 'book'
3280
    );
update pod
Yuki Kimoto authored on 2011-03-13
3281

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

            
3284
    prefix => 'or replace'
3285

            
3286
prefix before table name section
3287

            
3288
    update or replace book
3289

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

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

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

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

            
3298
Same as C<select> method's C<where> option.
3299

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

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

            
3304
placeholder wrapped string.
3305

            
3306
If the following statement
3307

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

            
3311
is executed, the following SQL is executed.
3312

            
3313
    update book set price =  ? + 5;
3314

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

            
3317
    updated_at => 'updated_datetime'
3318

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3323
=back
update pod
Yuki Kimoto authored on 2011-03-13
3324

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3332
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3333
    
3334
    # ID
3335
    $dbi->update_or_insert(
3336
        {title => 'Perl'},
3337
        table => 'book',
3338
        id => 1,
3339
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3340
        option => {
3341
            select => {
3342
                 append => 'for update'
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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3347
Update or insert.
3348

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3353
C<OPTIONS>
3354

            
3355
C<update_or_insert> method use all common option
3356
in C<select>, C<update>, C<delete>, and has the following new ones.
3357

            
3358
=over 4
3359

            
3360
=item C<option>
3361

            
3362
    option => {
3363
        select => {
3364
            append => '...'
3365
        },
3366
        insert => {
3367
            prefix => '...'
3368
        },
3369
        update => {
3370
            filter => {}
3371
        }
3372
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3373

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

            
3377
=over 4
3378

            
3379
=item C<select_option>
3380

            
3381
    select_option => {append => 'for update'}
3382

            
3383
select method option,
3384
select method is used to check the row is already exists.
3385

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

            
3388
    $dbi->show_datatype($table);
3389

            
3390
Show data type of the columns of specified table.
3391

            
3392
    book
3393
    title: 5
3394
    issue_date: 91
3395

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

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

            
3400
    $dbi->show_tables;
3401

            
3402
Show tables.
3403

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

            
3406
    $dbi->show_typename($table);
3407

            
3408
Show type name of the columns of specified table.
3409

            
3410
    book
3411
    title: varchar
3412
    issue_date: date
3413

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

            
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
3416
=head2 C<use_next_version EXPERIMENTAL>
3417

            
3418
    DBIx::Custom->use_next_version;
3419

            
3420
Upgrade next major version L<DBIx::Custom>.
3421
You can't use DEPRECATED method no more and method performance is improved.
3422

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

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

            
3427
Create values clause.
3428

            
3429
    (title, author) values (title = :title, age = :age);
3430

            
3431
You can use this in insert statement.
3432

            
3433
    my $insert_sql = "insert into book $values_clause";
3434

            
3435
=head2 C<where>
3436

            
3437
    my $where = $dbi->where(
3438
        clause => ['and', 'title = :title', 'author = :author'],
3439
        param => {title => 'Perl', author => 'Ken'}
3440
    );
3441

            
3442
Create a new L<DBIx::Custom::Where> object.
3443

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

            
3446
=head2 C<DBIX_CUSTOM_DEBUG>
3447

            
3448
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3449
executed SQL and bind values are printed to STDERR.
3450

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

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

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

            
3457
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3458

            
3459
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3460

            
3461
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3462
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3463

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

            
3466
L<DBIx::Custom>
3467

            
3468
    # Attribute methods
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3469
    tag_parse # will be removed 2017/1/1
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3470
    default_dbi_option # will be removed 2017/1/1
3471
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3472
    data_source # will be removed at 2017/1/1
3473
    dbi_options # will be removed at 2017/1/1
3474
    filter_check # will be removed at 2017/1/1
3475
    reserved_word_quote # will be removed at 2017/1/1
3476
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3477
    
3478
    # Methods
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3479
    update_timestamp # will be removed at 2017/1/1
3480
    insert_timestamp # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3481
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3482
    assign_param # will be removed at 2017/1/1
3483
    update_param # will be removed at 2017/1/1
3484
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3485
    create_query # will be removed at 2017/1/1
3486
    apply_filter # will be removed at 2017/1/1
3487
    select_at # will be removed at 2017/1/1
3488
    delete_at # will be removed at 2017/1/1
3489
    update_at # will be removed at 2017/1/1
3490
    insert_at # will be removed at 2017/1/1
3491
    register_tag # will be removed at 2017/1/1
3492
    default_bind_filter # will be removed at 2017/1/1
3493
    default_fetch_filter # will be removed at 2017/1/1
3494
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3495
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3496
    register_tag_processor # will be removed at 2017/1/1
3497
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3498
    
3499
    # Options
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
3500
    select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
3501
    execute method id option # will be removed 2017/1/1
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3502
    update timestamp option # will be removed 2017/1/1
3503
    insert timestamp option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3504
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3505
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3506
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3507
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3508
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3509
    select method relation option # will be removed at 2017/1/1
3510
    select method column option [COLUMN, as => ALIAS] format
3511
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3512
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3513
    
3514
    # Others
micro optimization and
Yuki Kimoto authored on 2011-10-25
3515
    execute($query, ...) # execute method receiving query object.
3516
                         # this is removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2011-07-28
3517
    execute("select * from {= title}"); # execute method's
3518
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3519
                                        # will be removed at 2017/1/1
3520
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3521

            
3522
L<DBIx::Custom::Model>
3523

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3524
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3525
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3526
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3527
    filter # will be removed at 2017/1/1
3528
    name # will be removed at 2017/1/1
3529
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3530

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

            
3533
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3534
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3535
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3536
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3537
    table # will be removed at 2017/1/1
3538
    filters # will be removed at 2017/1/1
3539
    
3540
    # Methods
3541
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3542

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

            
3545
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3546
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3547
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3548
    tags # will be removed at 2017/1/1
3549
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3550
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3551
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3552
    register_tag # will be removed at 2017/1/1
3553
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3554
    
3555
    # Others
3556
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3557
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3558

            
3559
L<DBIx::Custom::Result>
3560
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3561
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3562
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3563
    
3564
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3565
    filter_on # will be removed at 2017/1/1
3566
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3567
    end_filter # will be removed at 2017/1/1
3568
    remove_end_filter # will be removed at 2017/1/1
3569
    remove_filter # will be removed at 2017/1/1
3570
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3571

            
3572
L<DBIx::Custom::Tag>
3573

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

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

            
3578
    # Other
3579
    prepend method array reference receiving
3580
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3581

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

            
3584
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3585
except for attribute method.
3586
You can check all DEPRECATED functionalities by document.
3587
DEPRECATED functionality is removed after five years,
3588
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
3589
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3590

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

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

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

            
3597
C<< <kimoto.yuki at gmail.com> >>
3598

            
3599
L<http://github.com/yuki-kimoto/DBIx-Custom>
3600

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3601
=head1 AUTHOR
3602

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

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

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

            
3609
This program is free software; you can redistribute it and/or modify it
3610
under the same terms as Perl itself.
3611

            
3612
=cut