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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1463
sub _option {
1464
    my $self = shift;
1465
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1466
    warn "dbi_options is DEPRECATED! use option instead\n"
1467
      if keys %{$self->dbi_options};
1468
    warn "dbi_option is DEPRECATED! use option instead\n"
1469
      if keys %{$self->dbi_option};
1470
    return $option;
1471
}
1472

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1544
sub _quote {
1545
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1546
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1547
}
1548

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

            
1562
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1563
}
1564

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1585
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1586
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1587
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1588
    my $w = {};
1589
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1590

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

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

            
1636
        $w->{param} = keys %$where_param
1637
                    ? $self->merge_param($where_param, $obj->param)
1638
                    : $obj->param;
1639
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1640
    }
1641
    elsif ($where) {
1642
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1643
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1644
    }
1645
    
1646
    return $w;
1647
}
1648

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1719
# DEPRECATED!
1720
has 'data_source';
1721
has dbi_options => sub { {} };
1722
has filter_check  => 1;
1723
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1724
has dbi_option => sub { {} };
1725
has default_dbi_option => sub {
1726
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1727
    return shift->default_option;
1728
};
1729

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1742
# DEPRECATED!
1743
sub method {
1744
    warn "method is DEPRECATED! use helper instead";
1745
    return shift->helper(@_);
1746
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1747

            
1748
# DEPRECATED!
1749
sub assign_param {
1750
    my $self = shift;
1751
    warn "assing_param is DEPRECATED! use assign_clause instead";
1752
    return $self->assign_clause(@_);
1753
}
1754

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

            
1765
    return $tag;
1766
}
1767

            
updated pod
Yuki Kimoto authored on 2011-06-21
1768
# DEPRECATED!
1769
sub create_query {
1770
    warn "create_query is DEPRECATED! use query option of each method";
1771
    shift->_create_query(@_);
1772
}
1773

            
cleanup
Yuki Kimoto authored on 2011-06-13
1774
# DEPRECATED!
1775
sub apply_filter {
1776
    my $self = shift;
1777
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1778
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1779
    return $self->_apply_filter(@_);
1780
}
1781

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1820
# DEPRECATED!
1821
sub update_at {
1822
    my $self = shift;
1823

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1911
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1912
sub default_fetch_filter {
1913
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1914

            
cleanup
Yuki Kimoto authored on 2011-06-13
1915
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1916
    
1917
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1918
        my $fname = $_[0];
1919

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1936
# DEPRECATED!
1937
sub insert_param {
1938
    my $self = shift;
1939
    warn "insert_param is DEPRECATED! use values_clause instead";
1940
    return $self->values_clause(@_);
1941
}
1942

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1943
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1944
sub insert_param_tag {
1945
    warn "insert_param_tag is DEPRECATED! " .
1946
         "use insert_param instead!";
1947
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1948
}
1949

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1994
=head1 NAME
1995

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2069
Named place holder support
2070

            
2071
=item *
2072

            
cleanup
Yuki Kimoto authored on 2011-07-29
2073
Model support
2074

            
2075
=item *
2076

            
2077
Connection manager support
2078

            
2079
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2080

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

            
2085
=item *
2086

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

            
2089
=item *
2090

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

            
2093
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2094

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2102
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2103
L<DBIx::Custom::Result>,
2104
L<DBIx::Custom::Query>,
2105
L<DBIx::Custom::Where>,
2106
L<DBIx::Custom::Model>,
2107
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2108

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

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

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

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

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

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

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

            
2134
    my $dbi = DBIx::Custom->connect(
2135
      dsn => $dsn, user => $user, password => $password, connector => 1);
2136
    
2137
    my $connector = $dbi->connector; # DBIx::Connector
2138

            
2139
Note that L<DBIx::Connector> must be installed.
2140

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2156
    {
2157
        RaiseError => 1,
2158
        PrintError => 0,
2159
        AutoCommit => 1,
2160
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2161

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

            
2164
    my $exclude_table = $dbi->exclude_table;
2165
    $dbi = $dbi->exclude_table(qr/pg_/);
2166

            
2167
Excluded table regex.
2168
C<each_column>, C<each_table>, C<type_rule>,
2169
and C<setup_model> methods ignore matching tables.
2170

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

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

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

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

            
2180
    my $last_sql = $dbi->last_sql;
2181
    $dbi = $dbi->last_sql($last_sql);
2182

            
2183
Get last successed SQL executed by C<execute> method.
2184

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

            
2187
    my $now = $dbi->now;
2188
    $dbi = $dbi->now($now);
2189

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

            
2192
    sub {
2193
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2194
        $mon++;
2195
        $year += 1900;
2196
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2197
    }
2198

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

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

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

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

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

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

            
2213
    my $option = $dbi->option;
2214
    $dbi = $dbi->option($option);
2215

            
2216
L<DBI> option, used when C<connect> method is executed.
2217
Each value in option override the value of C<default_option>.
2218

            
cleanup
yuki-kimoto authored on 2010-10-17
2219
=head2 C<password>
2220

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2241
You can set quote pair.
2242

            
2243
    $dbi->quote('[]');
2244

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2254
    my $safety_character = $dbi->safety_character;
2255
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2256

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

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

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

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

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

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

            
2273
    my $tag_parse = $dbi->tag_parse(0);
2274
    $dbi = $dbi->tag_parse;
2275

            
2276
Enable DEPRECATED tag parsing functionality, default to 1.
2277
If you want to disable tag parsing functionality, set to 0.
2278

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

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

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

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

            
2288
    my $user_column_info = $dbi->user_column_info;
2289
    $dbi = $dbi->user_column_info($user_column_info);
2290

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

            
2293
    [
2294
        {table => 'book', column => 'title', info => {...}},
2295
        {table => 'author', column => 'name', info => {...}}
2296
    ]
2297

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

            
2300
    my $user_column_info
2301
      = $dbi->get_column_info(exclude_table => qr/^system/);
2302
    $dbi->user_column_info($user_column_info);
2303

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

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

            
2309
    my $user_table_info = $dbi->user_table_info;
2310
    $dbi = $dbi->user_table_info($user_table_info);
2311

            
2312
You can set the following data.
2313

            
2314
    [
2315
        {table => 'book', info => {...}},
2316
        {table => 'author', info => {...}}
2317
    ]
2318

            
2319
Usually, you can set return value of C<get_table_info>.
2320

            
2321
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2322
    $dbi->user_table_info($user_table_info);
2323

            
2324
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2325
to find table info.
2326

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2363
Create column clause. The follwoing column clause is created.
2364

            
2365
    book.author as "book.author",
2366
    book.title as "book.title"
2367

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

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

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

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

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

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

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

            
2395
Get rows count.
2396

            
2397
Options is same as C<select> method's ones.
2398

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2401
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2402
        table => 'book',
2403
        primary_key => 'id',
2404
        join => [
2405
            'inner join company on book.comparny_id = company.id'
2406
        ],
2407
    );
2408

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

            
2412
   $dbi->model('book')->select(...);
2413

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

            
2416
    my $dbh = $dbi->dbh;
2417

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

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

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

            
2425
Execute delete statement.
2426

            
2427
The following opitons are available.
2428

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

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

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

            
2436
=item C<id>
2437

            
2438
    id => 4
2439
    id => [4, 5]
2440

            
2441
ID corresponding to C<primary_key>.
2442
You can delete rows by C<id> and C<primary_key>.
2443

            
2444
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2445
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2446
        id => [4, 5],
2447
        table => 'book',
2448
    );
2449

            
2450
The above is same as the followin one.
2451

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

            
2454
=item C<prefix>
2455

            
2456
    prefix => 'some'
2457

            
2458
prefix before table name section.
2459

            
2460
    delete some from book
2461

            
2462
=item C<table>
2463

            
2464
    table => 'book'
2465

            
2466
Table name.
2467

            
2468
=item C<where>
2469

            
2470
Same as C<select> method's C<where> option.
2471

            
2472
=back
2473

            
2474
=head2 C<delete_all>
2475

            
2476
    $dbi->delete_all(table => $table);
2477

            
2478
Execute delete statement for all rows.
2479
Options is same as C<delete>.
2480

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

            
2483
    $dbi->each_column(
2484
        sub {
2485
            my ($dbi, $table, $column, $column_info) = @_;
2486
            
2487
            my $type = $column_info->{TYPE_NAME};
2488
            
2489
            if ($type eq 'DATE') {
2490
                # ...
2491
            }
2492
        }
2493
    );
2494

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

            
2500
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2501
infromation, you can improve the performance of C<each_column> in
2502
the following way.
2503

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

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

            
2510
    $dbi->each_table(
2511
        sub {
2512
            my ($dbi, $table, $table_info) = @_;
2513
            
2514
            my $table_name = $table_info->{TABLE_NAME};
2515
        }
2516
    );
2517

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

            
2523
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2524
infromation, you can improve the performance of C<each_table> in
2525
the following way.
2526

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

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

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

            
2538
    my $result = $dbi->execute(
2539
      "select * from book where title = :book.title and author like :book.author",
2540
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2541
    );
2542

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2557
You can specify operator with named placeholder
fixed pod
Yuki Kimoto authored on 2011-10-20
2558
by C<name{operator}> syntax.
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{=} and :author{like}
2562
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2563
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2564
    select * from where title = ? and author like ?;
2565

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

            
2570
    select * from where title = "aa\\:bb";
2571

            
cleanup
Yuki Kimoto authored on 2011-10-20
2572
B<OPTIONS>
2573

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

            
2576
=over 4
2577

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

            
2580
You can filter sql after the sql is build.
2581

            
2582
    after_build_sql => $code_ref
2583

            
2584
The following one is one example.
2585

            
2586
    $dbi->select(
2587
        table => 'book',
2588
        column => 'distinct(name)',
2589
        after_build_sql => sub {
2590
            "select count(*) from ($_[0]) as t1"
2591
        }
2592
    );
2593

            
2594
The following SQL is executed.
2595

            
2596
    select count(*) from (select distinct(name) from book) as t1;
2597

            
cleanup
Yuki Kimoto authored on 2011-10-20
2598
=item C<append>
2599

            
2600
    append => 'order by name'
2601

            
2602
Append some statement after SQL.
2603

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

            
2606
Specify database bind data type.
2607

            
2608
    bind_type => [image => DBI::SQL_BLOB]
2609
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2610

            
2611
This is used to bind parameter by C<bind_param> of statment handle.
2612

            
2613
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2614

            
update pod
Yuki Kimoto authored on 2011-03-13
2615
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2616
    
2617
    filter => {
2618
        title  => sub { uc $_[0] }
2619
        author => sub { uc $_[0] }
2620
    }
update pod
Yuki Kimoto authored on 2011-03-13
2621

            
updated pod
Yuki Kimoto authored on 2011-06-09
2622
    # Filter name
2623
    filter => {
2624
        title  => 'upper_case',
2625
        author => 'upper_case'
2626
    }
2627
        
2628
    # At once
2629
    filter => [
2630
        [qw/title author/]  => sub { uc $_[0] }
2631
    ]
2632

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

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

            
2640
    query => 1
2641

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2645
    my $sql = $query->{sql};
2646
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2647
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2648
=item C<reuse>
2649
    
2650
    reuse => $hash_ref
2651

            
2652
Reuse query object if the hash reference variable is set.
2653
    
2654
    my $queries = {};
2655
    $dbi->execute($sql, $param, reuse => $queries);
2656

            
2657
This will improved performance when you want to execute same query repeatedly
2658
because generally creating query object is slow.
2659

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2662
    primary_key => 'id'
2663
    primary_key => ['id1', 'id2']
2664

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2667
=item C<table>
2668
    
2669
    table => 'author'
2670

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2678
    # Same
2679
    $dbi->execute(
2680
      "select * from book where title = :book.title and author = :book.author",
2681
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2682

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

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

            
2687
Table alias. Key is real table name, value is alias table name.
2688
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2689
on alias table name.
2690

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

            
2693
    type_rule_off => 1
2694

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

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

            
2699
    type_rule1_off => 1
2700

            
2701
Turn C<into1> type rule off.
2702

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

            
2705
    type_rule2_off => 1
2706

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

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

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

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

            
2715
get column infomation except for one which match C<exclude_table> pattern.
2716

            
2717
    [
2718
        {table => 'book', column => 'title', info => {...}},
2719
        {table => 'author', column => 'name' info => {...}}
2720
    ]
2721

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

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

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

            
2728
    [
2729
        {table => 'book', info => {...}},
2730
        {table => 'author', info => {...}}
2731
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2732

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

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

            
2737
    $dbi->helper(
2738
        find_or_create   => sub {
2739
            my $self = shift;
2740
            
2741
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2742
        },
2743
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2744
    );
2745

            
2746
Register helper. These helper is called directly from L<DBIx::Custom> object.
2747

            
2748
    $dbi->find_or_create;
2749

            
cleanup
yuki-kimoto authored on 2010-10-17
2750
=head2 C<insert>
2751

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

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

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

            
2760
    {date => \"NOW()"}
2761

            
cleanup
Yuki Kimoto authored on 2011-10-20
2762
B<options>
2763

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

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

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

            
2771
    created_at => 'created_datetime'
2772

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2779
    id => 4
2780
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2781

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

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

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

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

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

            
2801
    prefix => 'or replace'
2802

            
2803
prefix before table name section
2804

            
2805
    insert or replace into book
2806

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

            
2809
    table => 'book'
2810

            
2811
Table name.
2812

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

            
2815
This option is same as C<update> method C<updated_at> option.
2816

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

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

            
2821
placeholder wrapped string.
2822

            
2823
If the following statement
2824

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

            
2828
is executed, the following SQL is executed.
2829

            
2830
    insert into book price values ( ? + 5 );
2831

            
update pod
Yuki Kimoto authored on 2011-03-13
2832
=back
2833

            
2834
=over 4
2835

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2843
    lib / MyModel.pm
2844
        / MyModel / book.pm
2845
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2846

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

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

            
2851
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2852
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2853
    
2854
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2855

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2860
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2861
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2862
    
2863
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2864

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2867
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2868
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2869
    
2870
    1;
2871
    
updated pod
Yuki Kimoto authored on 2011-06-21
2872
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2873

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

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

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

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

            
2883
    my $like_value = $dbi->like_value
2884

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

            
2887
    sub { "%$_[0]%" }
2888

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

            
2891
    my $mapper = $dbi->mapper(param => $param);
2892

            
2893
Create a new L<DBIx::Custom::Mapper> object.
2894

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

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

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

            
2901
    {key1 => [1, 1], key2 => 2}
2902

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

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

            
2907
    my $model = $dbi->model('book');
2908

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

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

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

            
2916
Create column clause for myself. The follwoing column clause is created.
2917

            
2918
    book.author as author,
2919
    book.title as title
2920

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

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

            
2930
Create a new L<DBIx::Custom> object.
2931

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

            
2934
    my $not_exists = $dbi->not_exists;
2935

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

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

            
2941
    my $order = $dbi->order;
2942

            
2943
Create a new L<DBIx::Custom::Order> object.
2944

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

            
2947
    my $quooted = $dbi->q("title");
2948

            
2949
Quote string by value of C<quote>.
2950

            
cleanup
yuki-kimoto authored on 2010-10-17
2951
=head2 C<register_filter>
2952

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

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

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2990
=item C<column>
2991
    
updated document
Yuki Kimoto authored on 2011-06-09
2992
    column => 'author'
2993
    column => ['author', 'title']
2994

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3003
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3004
        {book => [qw/author title/]},
3005
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3006
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3007

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

            
3010
    book.author as "book.author",
3011
    book.title as "book.title",
3012
    person.name as "person.name",
3013
    person.age as "person.age"
3014

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

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

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

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

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

            
3028
    id => 4
3029
    id => [4, 5]
3030

            
3031
ID corresponding to C<primary_key>.
3032
You can select rows by C<id> and C<primary_key>.
3033

            
3034
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3035
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3036
        id => [4, 5],
3037
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3038
    );
3039

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

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

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

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

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

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

            
3061
    prefix => 'SQL_CALC_FOUND_ROWS'
3062

            
3063
Prefix of column cluase
3064

            
3065
    select SQL_CALC_FOUND_ROWS title, author from book;
3066

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

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

            
3077
    $dbi->select(
3078
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3079
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3080
        where => {'company.name' => 'Orange'},
3081
        join => [
3082
            'left outer join company on book.company_id = company.id',
3083
            'left outer join location on company.location_id = location.id'
3084
        ]
3085
    );
3086

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3090
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3091
    from book
3092
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3093
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3094

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3095
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
3096
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3097

            
3098
    $dbi->select(
3099
        table => 'book',
3100
        column => ['company.location_id as location_id'],
3101
        where => {'company.name' => 'Orange'},
3102
        join => [
3103
            {
3104
                clause => 'left outer join location on company.location_id = location.id',
3105
                table => ['company', 'location']
3106
            }
3107
        ]
3108
    );
3109

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3114
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3115

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3136
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3137
    
update pod
Yuki Kimoto authored on 2011-03-12
3138
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3139

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

            
3142
    $dbi->setup_model;
3143

            
3144
Setup all model objects.
3145
C<columns> of model object is automatically set, parsing database information.
3146

            
3147
=head2 C<type_rule>
3148

            
3149
    $dbi->type_rule(
3150
        into1 => {
3151
            date => sub { ... },
3152
            datetime => sub { ... }
3153
        },
3154
        into2 => {
3155
            date => sub { ... },
3156
            datetime => sub { ... }
3157
        },
3158
        from1 => {
3159
            # DATE
3160
            9 => sub { ... },
3161
            # DATETIME or TIMESTAMP
3162
            11 => sub { ... },
3163
        }
3164
        from2 => {
3165
            # DATE
3166
            9 => sub { ... },
3167
            # DATETIME or TIMESTAMP
3168
            11 => sub { ... },
3169
        }
3170
    );
3171

            
3172
Filtering rule when data is send into and get from database.
3173
This has a little complex problem.
3174

            
3175
In C<into1> and C<into2> you can specify
3176
type name as same as type name defined
3177
by create table, such as C<DATETIME> or C<DATE>.
3178

            
3179
Note that type name and data type don't contain upper case.
3180
If these contain upper case charactor, you convert it to lower case.
3181

            
3182
C<into2> is executed after C<into1>.
3183

            
3184
Type rule of C<into1> and C<into2> is enabled on the following
3185
column name.
3186

            
3187
=over 4
3188

            
3189
=item 1. column name
3190

            
3191
    issue_date
3192
    issue_datetime
3193

            
3194
This need C<table> option in each method.
3195

            
3196
=item 2. table name and column name, separator is dot
3197

            
3198
    book.issue_date
3199
    book.issue_datetime
3200

            
3201
=back
3202

            
3203
You get all type name used in database by C<available_typename>.
3204

            
3205
    print $dbi->available_typename;
3206

            
3207
In C<from1> and C<from2> you specify data type, not type name.
3208
C<from2> is executed after C<from1>.
3209
You get all data type by C<available_datatype>.
3210

            
3211
    print $dbi->available_datatype;
3212

            
3213
You can also specify multiple types at once.
3214

            
3215
    $dbi->type_rule(
3216
        into1 => [
3217
            [qw/DATE DATETIME/] => sub { ... },
3218
        ],
3219
    );
3220

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

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

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

            
3227
If you want to set constant value to row data, use scalar reference
3228
as parameter value.
3229

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3241
    id => 4
3242
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3243

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3256
    $dbi->update(
3257
        {title => 'Perl', author => 'Ken'}
3258
        where => {id1 => 4, id2 => 5},
3259
        table => 'book'
3260
    );
update pod
Yuki Kimoto authored on 2011-03-13
3261

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

            
3264
    prefix => 'or replace'
3265

            
3266
prefix before table name section
3267

            
3268
    update or replace book
3269

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

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

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

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

            
3278
Same as C<select> method's C<where> option.
3279

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

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

            
3284
placeholder wrapped string.
3285

            
3286
If the following statement
3287

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

            
3291
is executed, the following SQL is executed.
3292

            
3293
    update book set price =  ? + 5;
3294

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

            
3297
    updated_at => 'updated_datetime'
3298

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3303
=back
update pod
Yuki Kimoto authored on 2011-03-13
3304

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3327
Update or insert.
3328

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3333
C<OPTIONS>
3334

            
3335
C<update_or_insert> method use all common option
3336
in C<select>, C<update>, C<delete>, and has the following new ones.
3337

            
3338
=over 4
3339

            
3340
=item C<option>
3341

            
3342
    option => {
3343
        select => {
3344
            append => '...'
3345
        },
3346
        insert => {
3347
            prefix => '...'
3348
        },
3349
        update => {
3350
            filter => {}
3351
        }
3352
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3353

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

            
3357
=over 4
3358

            
3359
=item C<select_option>
3360

            
3361
    select_option => {append => 'for update'}
3362

            
3363
select method option,
3364
select method is used to check the row is already exists.
3365

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

            
3368
    $dbi->show_datatype($table);
3369

            
3370
Show data type of the columns of specified table.
3371

            
3372
    book
3373
    title: 5
3374
    issue_date: 91
3375

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

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

            
3380
    $dbi->show_tables;
3381

            
3382
Show tables.
3383

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

            
3386
    $dbi->show_typename($table);
3387

            
3388
Show type name of the columns of specified table.
3389

            
3390
    book
3391
    title: varchar
3392
    issue_date: date
3393

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

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

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

            
3400
Create values clause.
3401

            
3402
    (title, author) values (title = :title, age = :age);
3403

            
3404
You can use this in insert statement.
3405

            
3406
    my $insert_sql = "insert into book $values_clause";
3407

            
3408
=head2 C<where>
3409

            
3410
    my $where = $dbi->where(
3411
        clause => ['and', 'title = :title', 'author = :author'],
3412
        param => {title => 'Perl', author => 'Ken'}
3413
    );
3414

            
3415
Create a new L<DBIx::Custom::Where> object.
3416

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

            
3419
=head2 C<DBIX_CUSTOM_DEBUG>
3420

            
3421
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3422
executed SQL and bind values are printed to STDERR.
3423

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

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

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

            
3430
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3431

            
3432
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3433

            
3434
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3435
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3436

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

            
3439
L<DBIx::Custom>
3440

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

            
3495
L<DBIx::Custom::Model>
3496

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3497
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3498
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3499
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3500
    filter # will be removed at 2017/1/1
3501
    name # will be removed at 2017/1/1
3502
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3503

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

            
3506
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3507
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3508
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3509
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3510
    table # will be removed at 2017/1/1
3511
    filters # will be removed at 2017/1/1
3512
    
3513
    # Methods
3514
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3515

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

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

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

            
3545
L<DBIx::Custom::Tag>
3546

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

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

            
3551
    # Other
3552
    prepend method array reference receiving
3553
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3554

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

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

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

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

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

            
3570
C<< <kimoto.yuki at gmail.com> >>
3571

            
3572
L<http://github.com/yuki-kimoto/DBIx-Custom>
3573

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3574
=head1 AUTHOR
3575

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

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

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

            
3582
This program is free software; you can redistribute it and/or modify it
3583
under the same terms as Perl itself.
3584

            
3585
=cut