DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3594 lines | 94.957kb
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 that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4
our $VERSION = '0.2102';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
502
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
503
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
504
    my $affected;
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
505
    if (!$query->{duplicate} && $type_rule_off && !keys %$filter && !$self->{default_out_filter}
506
      && !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
micro optimization
Yuki Kimoto authored on 2011-11-16
507
    {
cleanup
Yuki Kimoto authored on 2011-11-25
508
        eval { $affected = $sth->execute(map { $params->[0]->{$_} } @{$query->{columns}}) };
micro optimization
Yuki Kimoto authored on 2011-11-16
509
    }
510
    else {
511
        # Create bind values
cleanup
Yuki Kimoto authored on 2011-11-25
512
        my ($bind, $bind_types) = $self->_create_bind_values($params->[0], $query->{columns},
micro optimization
Yuki Kimoto authored on 2011-11-16
513
          $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
514

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

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

            
545
    # Remove id from parameter
cleanup
Yuki Kimoto authored on 2011-11-25
546
    for my $column (@cleanup, @{$opt{cleanup} || []}) {
cleanup
Yuki Kimoto authored on 2011-11-25
547
        delete $_->{$column} for @$params;
cleanup
Yuki Kimoto authored on 2011-11-25
548
    }
cleanup
yuki-kimoto authored on 2010-10-17
549
    
micro optimization
Yuki Kimoto authored on 2011-10-23
550
    # Not select statement
551
    return $affected unless $sth->{NUM_OF_FIELDS};
552

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

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

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

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

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

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

            
683
    # Remove id from parameter
cleanup
Yuki Kimoto authored on 2011-11-25
684
    delete $params->[0]->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
685
    
686
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
687
    $opt{statement} = 'insert';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
688
    $opt{cleanup} = \@timestamp_cleanup;
cleanup
Yuki Kimoto authored on 2011-11-25
689
    $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
690
}
691

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
692
sub insert_timestamp {
693
    my $self = shift;
694
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
695
    warn "insert_timestamp method is DEPRECATED! use now attribute";
696
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
697
    if (@_) {
698
        $self->{insert_timestamp} = [@_];
699
        
700
        return $self;
701
    }
702
    return $self->{insert_timestamp};
703
}
704

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
705
sub include_model {
706
    my ($self, $name_space, $model_infos) = @_;
707
    
cleanup
Yuki Kimoto authored on 2011-04-02
708
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
709
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
710
    
711
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
712
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
713

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
772
sub mapper {
773
    my $self = shift;
774
    return DBIx::Custom::Mapper->new(@_);
775
}
776

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
801
sub model {
802
    my ($self, $name, $model) = @_;
803
    
cleanup
Yuki Kimoto authored on 2011-04-02
804
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
805
    if ($model) {
806
        $self->models->{$name} = $model;
807
        return $self;
808
    }
809
    
810
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
811
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
812
      unless $self->models->{$name};
813
    
cleanup
Yuki Kimoto authored on 2011-04-02
814
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
815
    return $self->models->{$name};
816
}
817

            
cleanup
Yuki Kimoto authored on 2011-03-21
818
sub mycolumn {
819
    my ($self, $table, $columns) = @_;
820
    
cleanup
Yuki Kimoto authored on 2011-04-02
821
    # Create column clause
822
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
823
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
824
    push @column, $self->q($table) . "." . $self->q($_) .
825
      " as " . $self->q($_)
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
826
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
827
    
828
    return join (', ', @column);
829
}
830

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
844
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
845
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
846
        '?'     => \&DBIx::Custom::Tag::placeholder,
847
        '='     => \&DBIx::Custom::Tag::equal,
848
        '<>'    => \&DBIx::Custom::Tag::not_equal,
849
        '>'     => \&DBIx::Custom::Tag::greater_than,
850
        '<'     => \&DBIx::Custom::Tag::lower_than,
851
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
852
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
853
        'like'  => \&DBIx::Custom::Tag::like,
854
        'in'    => \&DBIx::Custom::Tag::in,
855
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
856
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
857
    };
cleanup
Yuki Kimoto authored on 2011-11-18
858
    $self->{tag_parse} = 1 unless exists $self->{tag_parse};
859
    $self->{cache} = 0 unless exists $self->{cache};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
860
    
cleanup
Yuki Kimoto authored on 2011-08-13
861
    return $self;
862
}
863

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

            
866
sub order {
867
    my $self = shift;
868
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
869
}
870

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
871
sub q {
872
    my ($self, $value, $quotemeta) = @_;
873
    
874
    my $quote = $self->{reserved_word_quote}
875
      || $self->{quote} || $self->quote || '';
876
    return "$quote$value$quote"
877
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
878
    
879
    my $q = substr($quote, 0, 1) || '';
880
    my $p;
881
    if (defined $quote && length $quote > 1) {
882
        $p = substr($quote, 1, 1);
883
    }
884
    else { $p = $q }
885
    
886
    if ($quotemeta) {
887
        $q = quotemeta($q);
888
        $p = quotemeta($p);
889
    }
890
    
891
    return "$q$value$p";
892
}
893

            
cleanup
yuki-kimoto authored on 2010-10-17
894
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
895
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
896
    
897
    # Register filter
898
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
899
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
900
    
cleanup
Yuki Kimoto authored on 2011-04-02
901
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
902
}
packaging one directory
yuki-kimoto authored on 2009-11-16
903

            
904
sub select {
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
905
    my $self = shift;
906
    my $column = shift if @_ % 2;
907
    my %opt = @_;
908
    $opt{column} = $column if defined $column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
909

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
998
sub setup_model {
999
    my $self = shift;
1000
    
cleanup
Yuki Kimoto authored on 2011-04-02
1001
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1002
    $self->each_column(
1003
        sub {
1004
            my ($self, $table, $column, $column_info) = @_;
1005
            if (my $model = $self->models->{$table}) {
1006
                push @{$model->columns}, $column;
1007
            }
1008
        }
1009
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1010
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1011
}
1012

            
update pod
Yuki Kimoto authored on 2011-08-10
1013
sub show_datatype {
1014
    my ($self, $table) = @_;
1015
    croak "Table name must be specified" unless defined $table;
1016
    print "$table\n";
1017
    
1018
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1019
    my $sth = $result->sth;
1020

            
1021
    my $columns = $sth->{NAME};
1022
    my $data_types = $sth->{TYPE};
1023
    
1024
    for (my $i = 0; $i < @$columns; $i++) {
1025
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1026
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1027
        print "$column: $data_type\n";
1028
    }
1029
}
1030

            
1031
sub show_typename {
1032
    my ($self, $t) = @_;
1033
    croak "Table name must be specified" unless defined $t;
1034
    print "$t\n";
1035
    
1036
    $self->each_column(sub {
1037
        my ($self, $table, $column, $infos) = @_;
1038
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1039
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1040
        print "$column: $typename\n";
1041
    });
1042
    
1043
    return $self;
1044
}
1045

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1046
sub show_tables {
1047
    my $self = shift;
1048
    
1049
    my %tables;
1050
    $self->each_table(sub { $tables{$_[1]}++ });
1051
    print join("\n", sort keys %tables) . "\n";
1052
    return $self;
1053
}
1054

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1092
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1093
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1094
                }
1095
            });
1096
        }
1097

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

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1145
    # Created time and updated time
1146
    my @timestamp_cleanup;
1147
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1148
        my $now = $self->now;
1149
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1150
        $param->{$opt{updated_at}} = $self->now->();
1151
        push @timestamp_cleanup, $opt{updated_at};
1152
    }
1153

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

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

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

            
1180
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1181
    if (@$rows == 0) {
1182
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1183
    }
1184
    elsif (@$rows == 1) {
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
1185
        return 0 unless keys %$param;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1186
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1187
    }
1188
    else {
1189
        croak "selected row must be one " . _subname;
1190
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1191
}
1192

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1193
sub update_timestamp {
1194
    my $self = shift;
1195
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1196
    warn "update_timestamp method is DEPRECATED! use now method";
1197
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1198
    if (@_) {
1199
        $self->{update_timestamp} = [@_];
1200
        
1201
        return $self;
1202
    }
1203
    return $self->{update_timestamp};
1204
}
1205

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

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

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

            
1260
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-18
1261
        my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1262
          ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1263

            
micro optimization
Yuki Kimoto authored on 2011-11-18
1264
        my $sql = " " . $source || '';
cleanup
Yuki Kimoto authored on 2011-11-18
1265
        if ($tag_parse && ($sql =~ /\s\{/)) {
cleanup
Yuki Kimoto authored on 2011-11-18
1266
            $query = $self->query_builder->build_query($sql);
1267
        }
1268
        else {
1269
            my @columns;
cleanup
Yuki Kimoto authored on 2011-11-18
1270
            my $c = $self->{safety_character};
micro optimization
Yuki Kimoto authored on 2011-11-18
1271
            my $re = $c eq 'a-zA-Z0-9_'
1272
              ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1273
              : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
cleanup
Yuki Kimoto authored on 2011-11-16
1274
            my %duplicate;
1275
            my $duplicate;
1276
            # Parameter regex
cleanup
Yuki Kimoto authored on 2011-11-18
1277
            $sql =~ s/([0-9]):/$1\\:/g;
micro optimization
Yuki Kimoto authored on 2011-11-18
1278
            my $new_sql = '';
micro optimization
Yuki Kimoto authored on 2011-11-18
1279
            while ($sql =~ /$re/) {
cleanup
Yuki Kimoto authored on 2011-11-18
1280
                push @columns, $2;
1281
                $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
micro optimization
Yuki Kimoto authored on 2011-11-18
1282
                ($new_sql, $sql) = defined $3 ?
1283
                  ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
cleanup
Yuki Kimoto authored on 2011-11-16
1284
            }
micro optimization
Yuki Kimoto authored on 2011-11-18
1285
            $new_sql .= $sql;
1286
            $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
cleanup
Yuki Kimoto authored on 2011-11-16
1287

            
1288
            # Create query
micro optimization
Yuki Kimoto authored on 2011-11-18
1289
            $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
cleanup
Yuki Kimoto authored on 2011-11-16
1290
        }
cleanup
Yuki Kimoto authored on 2011-11-16
1291
        
updated pod
Yuki Kimoto authored on 2011-06-21
1292
        # Save query to cache
1293
        $self->cache_method->(
1294
            $self, $source,
1295
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1296
                sql     => $query->{sql}, 
1297
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1298
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1299
            }
1300
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1301
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1302

            
1303
    # Filter SQL
micro optimization
Yuki Kimoto authored on 2011-11-16
1304
    $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1305
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1306
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1307
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1308
    
updated pod
Yuki Kimoto authored on 2011-06-21
1309
    # Prepare statement handle
1310
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1311
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1312
    
1313
    if ($@) {
1314
        $self->_croak($@, qq{. Following SQL is executed.\n}
1315
                        . qq{$query->{sql}\n} . _subname);
1316
    }
1317
    
1318
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1319
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1320
    
1321
    # Set filters
cleanup
Yuki Kimoto authored on 2011-11-16
1322
    $query->{filters} = $self->{filters} || $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1323
    
1324
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1325
}
1326

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1383
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1384
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1385
    
1386
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1387
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1388
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1389
      unless defined $primary_keys;
1390
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1391
    
cleanup
Yuki Kimoto authored on 2011-06-08
1392
    # Create parameter
1393
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1394
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1395
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1396
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1397
           my $key = $primary_keys->[$i];
1398
           $key = "$table." . $key if $table;
1399
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1400
        }
1401
    }
1402
    
cleanup
Yuki Kimoto authored on 2011-06-08
1403
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1404
}
1405

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1406
sub _connect {
1407
    my $self = shift;
1408
    
1409
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1410
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1411
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1412
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1413
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1414
    croak qq{"dsn" must be specified } . _subname
1415
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1416
    my $user        = $self->user;
1417
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1418
    my $option = $self->_option;
1419
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1420
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1421
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1422
    my $dbh;
1423
    eval {
1424
        $dbh = DBI->connect(
1425
            $dsn,
1426
            $user,
1427
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1428
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1429
        );
1430
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1431
    
1432
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1433
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1434
    
1435
    return $dbh;
1436
}
1437

            
cleanup
yuki-kimoto authored on 2010-10-17
1438
sub _croak {
1439
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1440
    
1441
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1442
    $append ||= "";
1443
    
1444
    # Verbose
1445
    if ($Carp::Verbose) { croak $error }
1446
    
1447
    # Not verbose
1448
    else {
1449
        
1450
        # Remove line and module infromation
1451
        my $at_pos = rindex($error, ' at ');
1452
        $error = substr($error, 0, $at_pos);
1453
        $error =~ s/\s+$//;
1454
        croak "$error$append";
1455
    }
1456
}
1457

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1460
sub _need_tables {
1461
    my ($self, $tree, $need_tables, $tables) = @_;
1462
    
cleanup
Yuki Kimoto authored on 2011-04-02
1463
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1464
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1465
        if ($tree->{$table}) {
1466
            $need_tables->{$table} = 1;
1467
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1468
        }
1469
    }
1470
}
1471

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1472
sub _option {
1473
    my $self = shift;
1474
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1475
    warn "dbi_options is DEPRECATED! use option instead\n"
1476
      if keys %{$self->dbi_options};
1477
    warn "dbi_option is DEPRECATED! use option instead\n"
1478
      if keys %{$self->dbi_option};
1479
    return $option;
1480
}
1481

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1482
sub _push_join {
1483
    my ($self, $sql, $join, $join_tables) = @_;
1484
    
cleanup
Yuki Kimoto authored on 2011-10-21
1485
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1486
    
cleanup
Yuki Kimoto authored on 2011-04-02
1487
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1488
    return unless @$join;
1489
    
cleanup
Yuki Kimoto authored on 2011-04-02
1490
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1491
    my $tree = {};
1492
    for (my $i = 0; $i < @$join; $i++) {
1493
        
cleanup
Yuki Kimoto authored on 2011-07-28
1494
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1495
        my $join_clause;;
1496
        my $option;
1497
        if (ref $join->[$i] eq 'HASH') {
1498
            $join_clause = $join->[$i]->{clause};
1499
            $option = {table => $join->[$i]->{table}};
1500
        }
1501
        else {
1502
            $join_clause = $join->[$i];
1503
            $option = {};
1504
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1505

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1553
sub _quote {
1554
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1555
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1556
}
1557

            
cleanup
Yuki Kimoto authored on 2011-04-02
1558
sub _remove_duplicate_table {
1559
    my ($self, $tables, $main_table) = @_;
1560
    
1561
    # Remove duplicate table
1562
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1563
    delete $tables{$main_table} if $main_table;
1564
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1565
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1566
    if (my $q = $self->_quote) {
1567
        $q = quotemeta($q);
1568
        $_ =~ s/[$q]//g for @$new_tables;
1569
    }
1570

            
1571
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1572
}
1573

            
cleanup
Yuki Kimoto authored on 2011-04-02
1574
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1575
    my ($self, $source) = @_;
1576
    
cleanup
Yuki Kimoto authored on 2011-04-02
1577
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1578
    my $tables = [];
cleanup
Yuki Kimoto authored on 2011-11-18
1579
    my $safety_character = $self->{safety_character};
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1580
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1581
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1582
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1583
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1584
    while ($source =~ /$table_re/g) {
1585
        push @$tables, $1;
1586
    }
1587
    
1588
    return $tables;
1589
}
1590

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1594
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1595
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1596
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1597
    my $w = {};
1598
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1599

            
cleanup
Yuki Kimoto authored on 2011-10-25
1600
    my $obj;
1601
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1602
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1603
        if (ref $where eq 'HASH') {
1604
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1605
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1606
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1607
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1608
                my $table;
1609
                my $c;
1610
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1611
                    $table = $1;
1612
                    $c = $2;
1613
                }
1614
                
1615
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1616
                $table_quote = $self->q($table) if defined $table;
1617
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1618
                $column_quote = $table_quote . '.' . $column_quote
1619
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1620
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1621
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1622

            
1623
            # Check unsafety column
cleanup
Yuki Kimoto authored on 2011-11-18
1624
            my $safety = $self->{safety_character};
cleanup
Yuki Kimoto authored on 2011-11-01
1625
            unless ($column_join =~ /^[$safety\.]+$/) {
1626
                for my $column (keys %$where) {
1627
                    croak qq{"$column" is not safety column name } . _subname
1628
                      unless $column =~ /^[$safety\.]+$/;
1629
                }
1630
            }
1631
            
cleanup
Yuki Kimoto authored on 2011-10-25
1632
            $obj = $self->where(clause => $clause, param => $where);
1633
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1634
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1635
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1636
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1637
        }
1638
        
1639
        # Check where argument
1640
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1641
            . qq{or array reference, which contains where clause and parameter}
1642
            . _subname
1643
          unless ref $obj eq 'DBIx::Custom::Where';
1644

            
1645
        $w->{param} = keys %$where_param
1646
                    ? $self->merge_param($where_param, $obj->param)
1647
                    : $obj->param;
1648
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1649
    }
1650
    elsif ($where) {
1651
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1652
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1653
    }
1654
    
1655
    return $w;
1656
}
1657

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1728
# DEPRECATED!
1729
has 'data_source';
1730
has dbi_options => sub { {} };
1731
has filter_check  => 1;
1732
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1733
has dbi_option => sub { {} };
1734
has default_dbi_option => sub {
1735
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1736
    return shift->default_option;
1737
};
1738

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1739
# DEPRECATED
1740
sub tag_parse {
1741
   my $self = shift;
1742
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1743
         "environment variable";
1744
    if (@_) {
1745
        $self->{tag_parse} = $_[0];
1746
        return $self;
1747
    }
1748
    return $self->{tag_parse};
1749
}
1750

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1751
# DEPRECATED!
1752
sub method {
1753
    warn "method is DEPRECATED! use helper instead";
1754
    return shift->helper(@_);
1755
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1756

            
1757
# DEPRECATED!
1758
sub assign_param {
1759
    my $self = shift;
1760
    warn "assing_param is DEPRECATED! use assign_clause instead";
1761
    return $self->assign_clause(@_);
1762
}
1763

            
1764
# DEPRECATED
1765
sub update_param {
1766
    my ($self, $param, $opts) = @_;
1767
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1768
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1769
    
1770
    # Create update parameter tag
1771
    my $tag = $self->assign_clause($param, $opts);
1772
    $tag = "set $tag" unless $opts->{no_set};
1773

            
1774
    return $tag;
1775
}
1776

            
updated pod
Yuki Kimoto authored on 2011-06-21
1777
# DEPRECATED!
1778
sub create_query {
1779
    warn "create_query is DEPRECATED! use query option of each method";
1780
    shift->_create_query(@_);
1781
}
1782

            
cleanup
Yuki Kimoto authored on 2011-06-13
1783
# DEPRECATED!
1784
sub apply_filter {
1785
    my $self = shift;
1786
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1787
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1788
    return $self->_apply_filter(@_);
1789
}
1790

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1797
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1798
    my $primary_keys = delete $opt{primary_key};
1799
    my $where = delete $opt{where};
1800
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1801
    
1802
    # Table
1803
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1804
      unless $opt{table};
1805
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1806
    
1807
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1808
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1809
    
cleanup
Yuki Kimoto authored on 2011-10-21
1810
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1811
}
1812

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1817
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1818
    
cleanup
Yuki Kimoto authored on 2011-10-21
1819
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1820
    my $primary_keys = delete $opt{primary_key};
1821
    my $where = delete $opt{where};
delete_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);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1825
    
cleanup
Yuki Kimoto authored on 2011-10-21
1826
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1827
}
1828

            
cleanup
Yuki Kimoto authored on 2011-06-08
1829
# DEPRECATED!
1830
sub update_at {
1831
    my $self = shift;
1832

            
cleanup
Yuki Kimoto authored on 2011-10-21
1833
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1834
    
cleanup
Yuki Kimoto authored on 2011-10-21
1835
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1836
    my $param;
1837
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1838
    my %opt = @_;
1839
    my $primary_keys = delete $opt{primary_key};
1840
    my $where = delete $opt{where};
1841
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1842
    $param  ||= $p;
1843
    
1844
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1845
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1846
    
cleanup
Yuki Kimoto authored on 2011-10-21
1847
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1848
}
1849

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1850
# DEPRECATED!
1851
sub insert_at {
1852
    my $self = shift;
1853
    
cleanup
Yuki Kimoto authored on 2011-10-21
1854
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1855
    
cleanup
Yuki Kimoto authored on 2011-10-21
1856
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1857
    my $param;
1858
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1859
    my %opt = @_;
1860
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1861
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1862
    my $where = delete $opt{where};
1863
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1864
    $param  ||= $p;
1865
    
1866
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1867
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1868
    $param = $self->merge_param($where_param, $param);
1869
    
cleanup
Yuki Kimoto authored on 2011-10-21
1870
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1871
}
1872

            
added warnings
Yuki Kimoto authored on 2011-06-07
1873
# DEPRECATED!
1874
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1875
    my $self = shift;
1876
    
added warnings
Yuki Kimoto authored on 2011-06-07
1877
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1878
    
1879
    # Merge tag
1880
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1881
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1882
    
1883
    return $self;
1884
}
1885

            
1886
# DEPRECATED!
1887
sub register_tag_processor {
1888
    my $self = shift;
1889
    warn "register_tag_processor is DEPRECATED!";
1890
    # Merge tag
1891
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1892
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1893
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1894
}
1895

            
cleanup
Yuki Kimoto authored on 2011-01-25
1896
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1897
sub default_bind_filter {
1898
    my $self = shift;
1899
    
cleanup
Yuki Kimoto authored on 2011-06-13
1900
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1901
    
cleanup
Yuki Kimoto authored on 2011-01-12
1902
    if (@_) {
1903
        my $fname = $_[0];
1904
        
1905
        if (@_ && !$fname) {
1906
            $self->{default_out_filter} = undef;
1907
        }
1908
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1909
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1910
              unless exists $self->filters->{$fname};
1911
        
1912
            $self->{default_out_filter} = $self->filters->{$fname};
1913
        }
1914
        return $self;
1915
    }
1916
    
1917
    return $self->{default_out_filter};
1918
}
1919

            
cleanup
Yuki Kimoto authored on 2011-01-25
1920
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1921
sub default_fetch_filter {
1922
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1923

            
cleanup
Yuki Kimoto authored on 2011-06-13
1924
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1925
    
1926
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1927
        my $fname = $_[0];
1928

            
cleanup
Yuki Kimoto authored on 2011-01-12
1929
        if (@_ && !$fname) {
1930
            $self->{default_in_filter} = undef;
1931
        }
1932
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1933
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1934
              unless exists $self->filters->{$fname};
1935
        
1936
            $self->{default_in_filter} = $self->filters->{$fname};
1937
        }
1938
        
1939
        return $self;
1940
    }
1941
    
many changed
Yuki Kimoto authored on 2011-01-23
1942
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1943
}
1944

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1945
# DEPRECATED!
1946
sub insert_param {
1947
    my $self = shift;
1948
    warn "insert_param is DEPRECATED! use values_clause instead";
1949
    return $self->values_clause(@_);
1950
}
1951

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1952
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1953
sub insert_param_tag {
1954
    warn "insert_param_tag is DEPRECATED! " .
1955
         "use insert_param instead!";
1956
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1957
}
1958

            
1959
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1960
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1961
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1962
         "use update_param instead";
1963
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1964
}
cleanup
Yuki Kimoto authored on 2011-03-08
1965
# DEPRECATED!
1966
sub _push_relation {
1967
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1968
    
1969
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1970
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1971
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1972
            my $table1 = (split (/\./, $rcolumn))[0];
1973
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1974
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1975
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1976
        }
1977
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1978
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1979
}
1980

            
1981
# DEPRECATED!
1982
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1983
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1984
    
1985
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1986
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1987
            my $table1 = (split (/\./, $rcolumn))[0];
1988
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1989
            my $table1_exists;
1990
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1991
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1992
                $table1_exists = 1 if $table eq $table1;
1993
                $table2_exists = 1 if $table eq $table2;
1994
            }
1995
            unshift @$tables, $table1 unless $table1_exists;
1996
            unshift @$tables, $table2 unless $table2_exists;
1997
        }
1998
    }
1999
}
2000

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2003
=head1 NAME
2004

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2009
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2010
    
2011
    # Connect
2012
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2013
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2014
        user => 'ken',
2015
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2016
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2017
    );
cleanup
yuki-kimoto authored on 2010-08-05
2018

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2019
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2020
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2021
    
2022
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2023
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2024
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2025
    
2026
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2027
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2028

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2033
    # Select, more complex
2034
    my $result = $dbi->select(
2035
        table  => 'book',
2036
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
2037
            {book => [qw/title author/]},
2038
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2039
        ],
2040
        where  => {'book.author' => 'Ken'},
2041
        join => ['left outer join company on book.company_id = company.id'],
2042
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2043
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2044
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2045
    # Fetch
2046
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2047
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2048
    }
2049
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2050
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2051
    while (my $row = $result->fetch_hash) {
2052
        
2053
    }
2054
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2055
    # Execute SQL with parameter.
2056
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2057
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2058
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2059
    );
2060
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2061
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2062

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2078
Named place holder support
2079

            
2080
=item *
2081

            
cleanup
Yuki Kimoto authored on 2011-07-29
2082
Model support
2083

            
2084
=item *
2085

            
2086
Connection manager support
2087

            
2088
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2089

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

            
2094
=item *
2095

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

            
2098
=item *
2099

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

            
2102
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2103

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2111
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2112
L<DBIx::Custom::Result>,
2113
L<DBIx::Custom::Query>,
2114
L<DBIx::Custom::Where>,
2115
L<DBIx::Custom::Model>,
2116
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2117

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

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

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

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

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

            
2131
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2132
        "dbi:mysql:database=$database",
2133
        $user,
2134
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2135
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2136
    );
2137
    
updated pod
Yuki Kimoto authored on 2011-06-21
2138
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2139

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

            
2143
    my $dbi = DBIx::Custom->connect(
2144
      dsn => $dsn, user => $user, password => $password, connector => 1);
2145
    
2146
    my $connector = $dbi->connector; # DBIx::Connector
2147

            
2148
Note that L<DBIx::Connector> must be installed.
2149

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2165
    {
2166
        RaiseError => 1,
2167
        PrintError => 0,
2168
        AutoCommit => 1,
2169
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2170

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

            
2173
    my $exclude_table = $dbi->exclude_table;
2174
    $dbi = $dbi->exclude_table(qr/pg_/);
2175

            
2176
Excluded table regex.
2177
C<each_column>, C<each_table>, C<type_rule>,
2178
and C<setup_model> methods ignore matching tables.
2179

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

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

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

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

            
2189
    my $last_sql = $dbi->last_sql;
2190
    $dbi = $dbi->last_sql($last_sql);
2191

            
2192
Get last successed SQL executed by C<execute> method.
2193

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

            
2196
    my $now = $dbi->now;
2197
    $dbi = $dbi->now($now);
2198

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

            
2201
    sub {
2202
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2203
        $mon++;
2204
        $year += 1900;
2205
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2206
    }
2207

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

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

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

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

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

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

            
2222
    my $option = $dbi->option;
2223
    $dbi = $dbi->option($option);
2224

            
2225
L<DBI> option, used when C<connect> method is executed.
2226
Each value in option override the value of C<default_option>.
2227

            
cleanup
yuki-kimoto authored on 2010-10-17
2228
=head2 C<password>
2229

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2250
You can set quote pair.
2251

            
2252
    $dbi->quote('[]');
2253

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2263
    my $safety_character = $dbi->safety_character;
2264
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2265

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

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

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

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

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

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

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

            
2285
Enable DEPRECATED tag parsing functionality, default to 1.
2286
If you want to disable tag parsing functionality, set to 0.
2287

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

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

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

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

            
2297
    my $user_column_info = $dbi->user_column_info;
2298
    $dbi = $dbi->user_column_info($user_column_info);
2299

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

            
2302
    [
2303
        {table => 'book', column => 'title', info => {...}},
2304
        {table => 'author', column => 'name', info => {...}}
2305
    ]
2306

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

            
2309
    my $user_column_info
2310
      = $dbi->get_column_info(exclude_table => qr/^system/);
2311
    $dbi->user_column_info($user_column_info);
2312

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

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

            
2318
    my $user_table_info = $dbi->user_table_info;
2319
    $dbi = $dbi->user_table_info($user_table_info);
2320

            
2321
You can set the following data.
2322

            
2323
    [
2324
        {table => 'book', info => {...}},
2325
        {table => 'author', info => {...}}
2326
    ]
2327

            
2328
Usually, you can set return value of C<get_table_info>.
2329

            
2330
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2331
    $dbi->user_table_info($user_table_info);
2332

            
2333
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2334
to find table info.
2335

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2372
Create column clause. The follwoing column clause is created.
2373

            
2374
    book.author as "book.author",
2375
    book.title as "book.title"
2376

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2379
    # Separator is hyphen
2380
    $dbi->separator('-');
2381
    
2382
    book.author as "book-author",
2383
    book.title as "book-title"
2384
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2385
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2386

            
update pod
Yuki Kimoto authored on 2011-03-13
2387
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2388
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2389
        user => 'ken',
2390
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2391
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2392
    );
2393

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

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

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

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

            
2404
Get rows count.
2405

            
2406
Options is same as C<select> method's ones.
2407

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2410
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2411
        table => 'book',
2412
        primary_key => 'id',
2413
        join => [
2414
            'inner join company on book.comparny_id = company.id'
2415
        ],
2416
    );
2417

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

            
2421
   $dbi->model('book')->select(...);
2422

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

            
2425
    my $dbh = $dbi->dbh;
2426

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

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

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

            
2434
Execute delete statement.
2435

            
2436
The following opitons are available.
2437

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

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

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

            
2445
=item C<id>
2446

            
2447
    id => 4
2448
    id => [4, 5]
2449

            
2450
ID corresponding to C<primary_key>.
2451
You can delete rows by C<id> and C<primary_key>.
2452

            
2453
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2454
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2455
        id => [4, 5],
2456
        table => 'book',
2457
    );
2458

            
2459
The above is same as the followin one.
2460

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

            
2463
=item C<prefix>
2464

            
2465
    prefix => 'some'
2466

            
2467
prefix before table name section.
2468

            
2469
    delete some from book
2470

            
2471
=item C<table>
2472

            
2473
    table => 'book'
2474

            
2475
Table name.
2476

            
2477
=item C<where>
2478

            
2479
Same as C<select> method's C<where> option.
2480

            
2481
=back
2482

            
2483
=head2 C<delete_all>
2484

            
2485
    $dbi->delete_all(table => $table);
2486

            
2487
Execute delete statement for all rows.
2488
Options is same as C<delete>.
2489

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

            
2492
    $dbi->each_column(
2493
        sub {
2494
            my ($dbi, $table, $column, $column_info) = @_;
2495
            
2496
            my $type = $column_info->{TYPE_NAME};
2497
            
2498
            if ($type eq 'DATE') {
2499
                # ...
2500
            }
2501
        }
2502
    );
2503

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

            
2509
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2510
infromation, you can improve the performance of C<each_column> in
2511
the following way.
2512

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

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

            
2519
    $dbi->each_table(
2520
        sub {
2521
            my ($dbi, $table, $table_info) = @_;
2522
            
2523
            my $table_name = $table_info->{TABLE_NAME};
2524
        }
2525
    );
2526

            
improved pod
Yuki Kimoto authored on 2011-10-14
2527
Iterate all table informationsfrom in database.
2528
Argument is callback which is executed when one table is found.
2529
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2530
C<table information>.
2531

            
2532
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2533
infromation, you can improve the performance of C<each_table> in
2534
the following way.
2535

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

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

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

            
2547
    my $result = $dbi->execute(
2548
      "select * from book where title = :book.title and author like :book.author",
2549
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2550
    );
2551

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2558
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2559
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2560
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2561
    select * from book where title = :title and author like :author
2562
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2563
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2564
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2565

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2569
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2570
    select * from book where :title{=} and :author{like}
2571
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2572
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2573
    select * from where title = ? and author like ?;
2574

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

            
2579
    select * from where title = "aa\\:bb";
2580

            
cleanup
Yuki Kimoto authored on 2011-10-20
2581
B<OPTIONS>
2582

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

            
2585
=over 4
2586

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

            
2589
You can filter sql after the sql is build.
2590

            
2591
    after_build_sql => $code_ref
2592

            
2593
The following one is one example.
2594

            
2595
    $dbi->select(
2596
        table => 'book',
2597
        column => 'distinct(name)',
2598
        after_build_sql => sub {
2599
            "select count(*) from ($_[0]) as t1"
2600
        }
2601
    );
2602

            
2603
The following SQL is executed.
2604

            
2605
    select count(*) from (select distinct(name) from book) as t1;
2606

            
cleanup
Yuki Kimoto authored on 2011-10-20
2607
=item C<append>
2608

            
2609
    append => 'order by name'
2610

            
2611
Append some statement after SQL.
2612

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

            
2615
Specify database bind data type.
2616

            
2617
    bind_type => [image => DBI::SQL_BLOB]
2618
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2619

            
2620
This is used to bind parameter by C<bind_param> of statment handle.
2621

            
2622
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2623

            
update pod
Yuki Kimoto authored on 2011-03-13
2624
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2625
    
2626
    filter => {
2627
        title  => sub { uc $_[0] }
2628
        author => sub { uc $_[0] }
2629
    }
update pod
Yuki Kimoto authored on 2011-03-13
2630

            
updated pod
Yuki Kimoto authored on 2011-06-09
2631
    # Filter name
2632
    filter => {
2633
        title  => 'upper_case',
2634
        author => 'upper_case'
2635
    }
2636
        
2637
    # At once
2638
    filter => [
2639
        [qw/title author/]  => sub { uc $_[0] }
2640
    ]
2641

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

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

            
2649
    query => 1
2650

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2654
    my $sql = $query->{sql};
2655
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2656
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2657
=item C<reuse>
2658
    
2659
    reuse => $hash_ref
2660

            
2661
Reuse query object if the hash reference variable is set.
2662
    
2663
    my $queries = {};
2664
    $dbi->execute($sql, $param, reuse => $queries);
2665

            
2666
This will improved performance when you want to execute same query repeatedly
2667
because generally creating query object is slow.
2668

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2671
    primary_key => 'id'
2672
    primary_key => ['id1', 'id2']
2673

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2676
=item C<table>
2677
    
2678
    table => 'author'
2679

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2687
    # Same
2688
    $dbi->execute(
2689
      "select * from book where title = :book.title and author = :book.author",
2690
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2691

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

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

            
2696
Table alias. Key is real table name, value is alias table name.
2697
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2698
on alias table name.
2699

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

            
2702
    type_rule_off => 1
2703

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

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

            
2708
    type_rule1_off => 1
2709

            
2710
Turn C<into1> type rule off.
2711

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

            
2714
    type_rule2_off => 1
2715

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

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

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

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

            
2724
get column infomation except for one which match C<exclude_table> pattern.
2725

            
2726
    [
2727
        {table => 'book', column => 'title', info => {...}},
2728
        {table => 'author', column => 'name' info => {...}}
2729
    ]
2730

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

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

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

            
2737
    [
2738
        {table => 'book', info => {...}},
2739
        {table => 'author', info => {...}}
2740
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2741

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

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

            
2746
    $dbi->helper(
2747
        find_or_create   => sub {
2748
            my $self = shift;
2749
            
2750
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2751
        },
2752
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2753
    );
2754

            
2755
Register helper. These helper is called directly from L<DBIx::Custom> object.
2756

            
2757
    $dbi->find_or_create;
2758

            
cleanup
yuki-kimoto authored on 2010-10-17
2759
=head2 C<insert>
2760

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

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

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

            
2769
    {date => \"NOW()"}
2770

            
cleanup
Yuki Kimoto authored on 2011-10-20
2771
B<options>
2772

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

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

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

            
2780
    created_at => 'created_datetime'
2781

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2788
    id => 4
2789
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2790

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2794
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2795
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2796
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2797
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2798
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2799
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2800

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

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

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

            
2810
    prefix => 'or replace'
2811

            
2812
prefix before table name section
2813

            
2814
    insert or replace into book
2815

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

            
2818
    table => 'book'
2819

            
2820
Table name.
2821

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

            
2824
This option is same as C<update> method C<updated_at> option.
2825

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

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

            
2830
placeholder wrapped string.
2831

            
2832
If the following statement
2833

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

            
2837
is executed, the following SQL is executed.
2838

            
2839
    insert into book price values ( ? + 5 );
2840

            
update pod
Yuki Kimoto authored on 2011-03-13
2841
=back
2842

            
2843
=over 4
2844

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2852
    lib / MyModel.pm
2853
        / MyModel / book.pm
2854
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2855

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

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

            
2860
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2861
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2862
    
2863
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2864

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2869
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2870
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2871
    
2872
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2873

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2876
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2877
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2878
    
2879
    1;
2880
    
updated pod
Yuki Kimoto authored on 2011-06-21
2881
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2882

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

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

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

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

            
2892
    my $like_value = $dbi->like_value
2893

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

            
2896
    sub { "%$_[0]%" }
2897

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

            
2900
    my $mapper = $dbi->mapper(param => $param);
2901

            
2902
Create a new L<DBIx::Custom::Mapper> object.
2903

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

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

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

            
2910
    {key1 => [1, 1], key2 => 2}
2911

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

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

            
2916
    my $model = $dbi->model('book');
2917

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

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

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

            
2925
Create column clause for myself. The follwoing column clause is created.
2926

            
2927
    book.author as author,
2928
    book.title as title
2929

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

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

            
2939
Create a new L<DBIx::Custom> object.
2940

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

            
2943
    my $not_exists = $dbi->not_exists;
2944

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

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

            
2950
    my $order = $dbi->order;
2951

            
2952
Create a new L<DBIx::Custom::Order> object.
2953

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

            
2956
    my $quooted = $dbi->q("title");
2957

            
2958
Quote string by value of C<quote>.
2959

            
cleanup
yuki-kimoto authored on 2010-10-17
2960
=head2 C<register_filter>
2961

            
update pod
Yuki Kimoto authored on 2011-03-13
2962
    $dbi->register_filter(
2963
        # Time::Piece object to database DATE format
2964
        tp_to_date => sub {
2965
            my $tp = shift;
2966
            return $tp->strftime('%Y-%m-%d');
2967
        },
2968
        # database DATE format to Time::Piece object
2969
        date_to_tp => sub {
2970
           my $date = shift;
2971
           return Time::Piece->strptime($date, '%Y-%m-%d');
2972
        }
2973
    );
cleanup
yuki-kimoto authored on 2010-10-17
2974
    
update pod
Yuki Kimoto authored on 2011-03-13
2975
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2976

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2979
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2980
        column => ['author', 'title'],
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
2981
        table  => 'book',
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2982
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2983
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2984
    
updated document
Yuki Kimoto authored on 2011-06-09
2985
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2986

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2999
=item C<column>
3000
    
updated document
Yuki Kimoto authored on 2011-06-09
3001
    column => 'author'
3002
    column => ['author', 'title']
3003

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3012
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3013
        {book => [qw/author title/]},
3014
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3015
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3016

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

            
3019
    book.author as "book.author",
3020
    book.title as "book.title",
3021
    person.name as "person.name",
3022
    person.age as "person.age"
3023

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

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

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

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

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

            
3037
    id => 4
3038
    id => [4, 5]
3039

            
3040
ID corresponding to C<primary_key>.
3041
You can select rows by C<id> and C<primary_key>.
3042

            
3043
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3044
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3045
        id => [4, 5],
3046
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3047
    );
3048

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3051
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3052
        where => {id1 => 4, id2 => 5},
3053
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3054
    );
3055
    
cleanup
Yuki Kimoto authored on 2011-10-20
3056
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3057

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

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

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

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

            
3070
    prefix => 'SQL_CALC_FOUND_ROWS'
3071

            
3072
Prefix of column cluase
3073

            
3074
    select SQL_CALC_FOUND_ROWS title, author from book;
3075

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

            
3078
    join => [
3079
        'left outer join company on book.company_id = company_id',
3080
        'left outer join location on company.location_id = location.id'
3081
    ]
3082
        
3083
Join clause. If column cluase or where clause contain table name like "company.name",
3084
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3085

            
3086
    $dbi->select(
3087
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3088
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3089
        where => {'company.name' => 'Orange'},
3090
        join => [
3091
            'left outer join company on book.company_id = company.id',
3092
            'left outer join location on company.location_id = location.id'
3093
        ]
3094
    );
3095

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3099
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3100
    from book
3101
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3102
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3103

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3104
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
3105
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3106

            
3107
    $dbi->select(
3108
        table => 'book',
3109
        column => ['company.location_id as location_id'],
3110
        where => {'company.name' => 'Orange'},
3111
        join => [
3112
            {
3113
                clause => 'left outer join location on company.location_id = location.id',
3114
                table => ['company', 'location']
3115
            }
3116
        ]
3117
    );
3118

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3123
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3124

            
updated document
Yuki Kimoto authored on 2011-06-09
3125
=item C<where>
3126
    
3127
    # Hash refrence
3128
    where => {author => 'Ken', 'title' => 'Perl'}
3129
    
3130
    # DBIx::Custom::Where object
3131
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3132
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3133
        param  => {author => 'Ken', title => '%Perl%'}
3134
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3135
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3136
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3137
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3138
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3139
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3140
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3141
    
3142
    # String
3143
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3144

            
cleanup
Yuki Kimoto authored on 2011-10-20
3145
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3146
    
update pod
Yuki Kimoto authored on 2011-03-12
3147
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3148

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

            
3151
    $dbi->setup_model;
3152

            
3153
Setup all model objects.
3154
C<columns> of model object is automatically set, parsing database information.
3155

            
3156
=head2 C<type_rule>
3157

            
3158
    $dbi->type_rule(
3159
        into1 => {
3160
            date => sub { ... },
3161
            datetime => sub { ... }
3162
        },
3163
        into2 => {
3164
            date => sub { ... },
3165
            datetime => sub { ... }
3166
        },
3167
        from1 => {
3168
            # DATE
3169
            9 => sub { ... },
3170
            # DATETIME or TIMESTAMP
3171
            11 => sub { ... },
3172
        }
3173
        from2 => {
3174
            # DATE
3175
            9 => sub { ... },
3176
            # DATETIME or TIMESTAMP
3177
            11 => sub { ... },
3178
        }
3179
    );
3180

            
3181
Filtering rule when data is send into and get from database.
3182
This has a little complex problem.
3183

            
3184
In C<into1> and C<into2> you can specify
3185
type name as same as type name defined
3186
by create table, such as C<DATETIME> or C<DATE>.
3187

            
3188
Note that type name and data type don't contain upper case.
3189
If these contain upper case charactor, you convert it to lower case.
3190

            
3191
C<into2> is executed after C<into1>.
3192

            
3193
Type rule of C<into1> and C<into2> is enabled on the following
3194
column name.
3195

            
3196
=over 4
3197

            
3198
=item 1. column name
3199

            
3200
    issue_date
3201
    issue_datetime
3202

            
3203
This need C<table> option in each method.
3204

            
3205
=item 2. table name and column name, separator is dot
3206

            
3207
    book.issue_date
3208
    book.issue_datetime
3209

            
3210
=back
3211

            
3212
You get all type name used in database by C<available_typename>.
3213

            
3214
    print $dbi->available_typename;
3215

            
3216
In C<from1> and C<from2> you specify data type, not type name.
3217
C<from2> is executed after C<from1>.
3218
You get all data type by C<available_datatype>.
3219

            
3220
    print $dbi->available_datatype;
3221

            
3222
You can also specify multiple types at once.
3223

            
3224
    $dbi->type_rule(
3225
        into1 => [
3226
            [qw/DATE DATETIME/] => sub { ... },
3227
        ],
3228
    );
3229

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

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

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

            
3236
If you want to set constant value to row data, use scalar reference
3237
as parameter value.
3238

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3250
    id => 4
3251
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3252

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3256
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3257
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3258
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3259
        id => [4, 5],
3260
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3261
    );
update pod
Yuki Kimoto authored on 2011-03-13
3262

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3265
    $dbi->update(
3266
        {title => 'Perl', author => 'Ken'}
3267
        where => {id1 => 4, id2 => 5},
3268
        table => 'book'
3269
    );
update pod
Yuki Kimoto authored on 2011-03-13
3270

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

            
3273
    prefix => 'or replace'
3274

            
3275
prefix before table name section
3276

            
3277
    update or replace book
3278

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

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

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

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

            
3287
Same as C<select> method's C<where> option.
3288

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

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

            
3293
placeholder wrapped string.
3294

            
3295
If the following statement
3296

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

            
3300
is executed, the following SQL is executed.
3301

            
3302
    update book set price =  ? + 5;
3303

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

            
3306
    updated_at => 'updated_datetime'
3307

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3312
=back
update pod
Yuki Kimoto authored on 2011-03-13
3313

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3321
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3322
    
3323
    # ID
3324
    $dbi->update_or_insert(
3325
        {title => 'Perl'},
3326
        table => 'book',
3327
        id => 1,
3328
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3329
        option => {
3330
            select => {
3331
                 append => 'for update'
3332
            }
3333
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3334
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3335

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3336
Update or insert.
3337

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3342
C<OPTIONS>
3343

            
3344
C<update_or_insert> method use all common option
3345
in C<select>, C<update>, C<delete>, and has the following new ones.
3346

            
3347
=over 4
3348

            
3349
=item C<option>
3350

            
3351
    option => {
3352
        select => {
3353
            append => '...'
3354
        },
3355
        insert => {
3356
            prefix => '...'
3357
        },
3358
        update => {
3359
            filter => {}
3360
        }
3361
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3362

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

            
3366
=over 4
3367

            
3368
=item C<select_option>
3369

            
3370
    select_option => {append => 'for update'}
3371

            
3372
select method option,
3373
select method is used to check the row is already exists.
3374

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

            
3377
    $dbi->show_datatype($table);
3378

            
3379
Show data type of the columns of specified table.
3380

            
3381
    book
3382
    title: 5
3383
    issue_date: 91
3384

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

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

            
3389
    $dbi->show_tables;
3390

            
3391
Show tables.
3392

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

            
3395
    $dbi->show_typename($table);
3396

            
3397
Show type name of the columns of specified table.
3398

            
3399
    book
3400
    title: varchar
3401
    issue_date: date
3402

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

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

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

            
3409
Create values clause.
3410

            
3411
    (title, author) values (title = :title, age = :age);
3412

            
3413
You can use this in insert statement.
3414

            
3415
    my $insert_sql = "insert into book $values_clause";
3416

            
3417
=head2 C<where>
3418

            
3419
    my $where = $dbi->where(
3420
        clause => ['and', 'title = :title', 'author = :author'],
3421
        param => {title => 'Perl', author => 'Ken'}
3422
    );
3423

            
3424
Create a new L<DBIx::Custom::Where> object.
3425

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

            
3428
=head2 C<DBIX_CUSTOM_DEBUG>
3429

            
3430
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3431
executed SQL and bind values are printed to STDERR.
3432

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

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

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

            
3439
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3440

            
3441
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3442

            
3443
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3444
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3445

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

            
3448
L<DBIx::Custom>
3449

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

            
3504
L<DBIx::Custom::Model>
3505

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3506
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3507
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3508
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3509
    filter # will be removed at 2017/1/1
3510
    name # will be removed at 2017/1/1
3511
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3512

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

            
3515
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3516
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3517
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3518
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3519
    table # will be removed at 2017/1/1
3520
    filters # will be removed at 2017/1/1
3521
    
3522
    # Methods
3523
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3524

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

            
3527
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3528
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3529
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3530
    tags # will be removed at 2017/1/1
3531
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3532
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3533
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3534
    register_tag # will be removed at 2017/1/1
3535
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3536
    
3537
    # Others
3538
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3539
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3540

            
3541
L<DBIx::Custom::Result>
3542
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3543
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3544
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3545
    
3546
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3547
    filter_on # will be removed at 2017/1/1
3548
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3549
    end_filter # will be removed at 2017/1/1
3550
    remove_end_filter # will be removed at 2017/1/1
3551
    remove_filter # will be removed at 2017/1/1
3552
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3553

            
3554
L<DBIx::Custom::Tag>
3555

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

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

            
3560
    # Other
3561
    prepend method array reference receiving
3562
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3563

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

            
3566
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3567
except for attribute method.
3568
You can check all DEPRECATED functionalities by document.
3569
DEPRECATED functionality is removed after five years,
3570
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
3571
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3572

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

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

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

            
3579
C<< <kimoto.yuki at gmail.com> >>
3580

            
3581
L<http://github.com/yuki-kimoto/DBIx-Custom>
3582

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3583
=head1 AUTHOR
3584

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

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

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

            
3591
This program is free software; you can redistribute it and/or modify it
3592
under the same terms as Perl itself.
3593

            
3594
=cut