DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3550 lines | 92.985kb
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

            
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
4
our $VERSION = '0.1740';
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/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
267
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
268

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-10-23
676
sub _merge_id_to_param {
677
    my ($self, $id, $primary_keys, $param) = @_;
678
    
679
    # Create parameter
680
    $id = [$id] unless ref $id;
681
    
682
    return $param;
683
}
684

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1004
    my $columns = $sth->{NAME};
1005
    my $data_types = $sth->{TYPE};
1006
    
1007
    for (my $i = 0; $i < @$columns; $i++) {
1008
        my $column = $columns->[$i];
1009
        my $data_type = $data_types->[$i];
1010
        print "$column: $data_type\n";
1011
    }
1012
}
1013

            
1014
sub show_typename {
1015
    my ($self, $t) = @_;
1016
    croak "Table name must be specified" unless defined $t;
1017
    print "$t\n";
1018
    
1019
    $self->each_column(sub {
1020
        my ($self, $table, $column, $infos) = @_;
1021
        return unless $table eq $t;
1022
        my $typename = $infos->{TYPE_NAME};
1023
        print "$column: $typename\n";
1024
    });
1025
    
1026
    return $self;
1027
}
1028

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1155
sub update_or_insert {
1156
    my $self = shift;
1157

            
cleanup
Yuki Kimoto authored on 2011-10-21
1158
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1159
    my $param  = shift;
1160
    my %opt = @_;
1161
    my $id = $opt{id};
1162
    my $primary_key = $opt{primary_key};
1163
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1164
    croak "update_or_insert method need primary_key option " .
1165
          "when id is specified" . _subname
1166
      if defined $id && !defined $primary_key;
1167
    my $table  = $opt{table};
1168
    croak qq{"table" option must be specified } . _subname
1169
      unless defined $table;
1170
    my $select_option = $opt{select_option};
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
1171
    my $reuse = $opt{reuse};
1172
    $opt{select_option}->{reuse} = $opt{reuse} if $opt{reuse};
cleanup
Yuki Kimoto authored on 2011-10-21
1173
    
1174
    my $rows = $self->select(table => $table, id => $id,
1175
        primary_key => $primary_key, %$select_option)->all;
1176
    
1177
    croak "selected row count must be one or zero" . _subname
1178
      if @$rows > 1;
1179
    
1180
    my $row = $rows->[0];
1181
    my @opt = (table => $table);
1182
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1183
    push @opt, %opt;
1184
    
1185
    if ($row) {
1186
        return $self->update($param, @opt);
1187
    }
1188
    else {
1189
        return $self->insert($param, @opt);
1190
    }
1191
}
1192

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1206
sub values_clause {
1207
    my ($self, $param, $opts) = @_;
1208
    
1209
    my $wrap = $opts->{wrap} || {};
1210
    
1211
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-10-23
1212
    my $safety = $self->{safety_character} || $self->safety_character;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1213
    my $qp = $self->q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1214
    my $q = substr($qp, 0, 1) || '';
1215
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1216
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1217
    # Check unsafety keys
1218
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
1219
        for my $column (keys %$param) {
1220
            croak qq{"$column" is not safety column name } . _subname
1221
              unless $column =~ /^[$safety\.]+$/;
1222
        }
1223
    }
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1224
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1225
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1226
    '(' .
1227
    join(
1228
      ', ',
1229
      map { "$q$_$p" } sort keys %$param
1230
    ) .
1231
    ') values (' .
1232
    join(
1233
      ', ',
1234
      map {
1235
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1236
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1237
          ":$_";
1238
      } sort keys %$param
1239
    ) .
1240
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1241
}
1242

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1245
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1246
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1247
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1248
    
updated pod
Yuki Kimoto authored on 2011-06-21
1249
    # Cache
1250
    my $cache = $self->cache;
1251
    
1252
    # Query
1253
    my $query;
1254
    
1255
    # Get cached query
1256
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1257
        
updated pod
Yuki Kimoto authored on 2011-06-21
1258
        # Get query
1259
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1260
        
updated pod
Yuki Kimoto authored on 2011-06-21
1261
        # Create query
1262
        if ($q) {
1263
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1264
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1265
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1266
    }
1267
    
1268
    # Create query
1269
    unless ($query) {
1270

            
1271
        # Create query
1272
        my $builder = $self->query_builder;
1273
        $query = $builder->build_query($source);
1274

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1376
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1377
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1378
    
1379
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1380
    croak "primary_key option " .
1381
          "must be specified with id option " . _subname
1382
      unless defined $primary_keys;
1383
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1384
    
cleanup
Yuki Kimoto authored on 2011-06-08
1385
    # Create parameter
1386
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1387
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1388
        $id = [$id] unless ref $id;
1389
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1390
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1391
          unless !ref $id || ref $id eq 'ARRAY';
1392
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1393
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1394
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1395
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1396
           my $key = $primary_keys->[$i];
1397
           $key = "$table." . $key if $table;
1398
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1399
        }
1400
    }
1401
    
cleanup
Yuki Kimoto authored on 2011-06-08
1402
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1403
}
1404

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-25
1599
    my $obj;
1600
    
cleanup
Yuki Kimoto authored on 2011-10-21
1601
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1602
        $w->{clause} = "where " . $where->[0];
1603
        $w->{param} = $where->[1];
1604
    }
1605
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1606

            
1607
        # Hash
1608
        if (ref $where eq 'HASH') {
1609
            my $clause = ['and'];
1610
            my $q = $self->_quote;
1611
            for my $column (keys %$where) {
1612
                my $table;
1613
                my $c;
1614
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1615
                    $table = $1;
1616
                    $c = $2;
1617
                }
1618
                
1619
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1620
                $table_quote = $self->q($table) if defined $table;
1621
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1622
                $column_quote = $table_quote . '.' . $column_quote
1623
                  if defined $table_quote;
1624
                push @$clause, "$column_quote = :$column" for keys %$where;
1625
            }
1626
            $obj = $self->where(clause => $clause, param => $where);
1627
        }
1628
        
1629
        # DBIx::Custom::Where object
1630
        elsif (ref $where eq 'DBIx::Custom::Where') {
1631
            $obj = $where;
1632
        }
1633
        
1634
        # Array
1635
        elsif (ref $where eq 'ARRAY') {
1636
            $obj = $self->where(
1637
                clause => $where->[0],
1638
                param  => $where->[1]
1639
            );
1640
        }
1641
        
1642
        # Check where argument
1643
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1644
            . qq{or array reference, which contains where clause and parameter}
1645
            . _subname
1646
          unless ref $obj eq 'DBIx::Custom::Where';
1647

            
1648

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

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

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

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

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

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

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

            
1766
    return $tag;
1767
}
1768

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1823
# DEPRECATED!
1824
sub update_at {
1825
    my $self = shift;
1826

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1915
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1916
sub default_fetch_filter {
1917
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1918

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1998
=head1 NAME
1999

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2061
=over 4
- 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
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- 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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2073
Named place holder support
2074

            
2075
=item *
2076

            
cleanup
Yuki Kimoto authored on 2011-07-29
2077
Model support
2078

            
2079
=item *
2080

            
2081
Connection manager support
2082

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

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

            
2089
=item *
2090

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

            
2093
=item *
2094

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

            
2097
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2098

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

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

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

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

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

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

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

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

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

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

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

            
2138
    my $dbi = DBIx::Custom->connect(
2139
      dsn => $dsn, user => $user, password => $password, connector => 1);
2140
    
2141
    my $connector = $dbi->connector; # DBIx::Connector
2142

            
2143
Note that L<DBIx::Connector> must be installed.
2144

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

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

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

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

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

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

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

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

            
2168
    my $exclude_table = $dbi->exclude_table;
2169
    $dbi = $dbi->exclude_table(qr/pg_/);
2170

            
2171
Excluded table regex.
2172
C<each_column>, C<each_table>, C<type_rule>,
2173
and C<setup_model> methods ignore matching tables.
2174

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

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

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

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

            
2184
    my $last_sql = $dbi->last_sql;
2185
    $dbi = $dbi->last_sql($last_sql);
2186

            
2187
Get last successed SQL executed by C<execute> method.
2188

            
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2189
=head2 C<now EXPERIMENTAL>
2190

            
2191
    my $now = $dbi->now;
2192
    $dbi = $dbi->now($now);
2193

            
2194
Code reference which return time now, default to the following code reference.
2195

            
2196
    sub {
2197
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2198
        $mon++;
2199
        $year += 1900;
2200
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2201
    }
2202

            
2203
This return the time like "2011-10-14 05:05:27".
2204

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2313
You can set the following data.
2314

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2396
Get rows count.
2397

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

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

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

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

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

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

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

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

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

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

            
2426
Execute delete statement.
2427

            
2428
The following opitons are available.
2429

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

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

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

            
2437
=item C<id>
2438

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

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

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

            
2451
The above is same as the followin one.
2452

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

            
2455
=item C<prefix>
2456

            
2457
    prefix => 'some'
2458

            
2459
prefix before table name section.
2460

            
2461
    delete some from book
2462

            
2463
=item C<table>
2464

            
2465
    table => 'book'
2466

            
2467
Table name.
2468

            
2469
=item C<where>
2470

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

            
2473
=back
2474

            
2475
=head2 C<delete_all>
2476

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2561
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2562
    select * from book where :title{=} and :author{like}
2563
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2564
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2565
    select * from where title = ? and author like ?;
2566

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

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

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

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

            
2577
=over 4
2578

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

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

            
2583
    after_build_sql => $code_ref
2584

            
2585
The following one is one example.
2586

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

            
2595
The following SQL is executed.
2596

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

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

            
2601
    append => 'order by name'
2602

            
2603
Append some statement after SQL.
2604

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

            
2607
Specify database bind data type.
2608

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

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

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

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

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

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

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

            
2641
    query => 1
2642

            
2643
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
micro optimization and
Yuki Kimoto authored on 2011-10-25
2644
You can check SQL, column, or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2645

            
2646
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2647
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2648
    my $columns = $query->columns;
2649
    
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2650
=item C<primary_key>
2651

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2681
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2682
    
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2683
    reuse => $hash_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2684

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2685
Reuse query object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2686
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2687
    my $queries = {};
2688
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2689

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2690
This will improved performance when you want to execute same query repeatedly
2691
because generally creating query object is slow.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2692

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

            
2695
    type_rule_off => 1
2696

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

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

            
2701
    type_rule1_off => 1
2702

            
2703
Turn C<into1> type rule off.
2704

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

            
2707
    type_rule2_off => 1
2708

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

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

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

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

            
2717
get column infomation except for one which match C<exclude_table> pattern.
2718

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

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

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

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

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

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

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

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

            
2748
Register helper. These helper is called directly from L<DBIx::Custom> object.
2749

            
2750
    $dbi->find_or_create;
2751

            
cleanup
yuki-kimoto authored on 2010-10-17
2752
=head2 C<insert>
2753

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

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

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

            
2762
    {date => \"NOW()"}
2763

            
cleanup
Yuki Kimoto authored on 2011-10-20
2764
B<options>
2765

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2771
=item C<created_at EXPERIMETNAL>
2772

            
2773
    created_at => 'created_datetime'
2774

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

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

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

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

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

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

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

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

            
2803
    prefix => 'or replace'
2804

            
2805
prefix before table name section
2806

            
2807
    insert or replace into book
2808

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

            
2811
    table => 'book'
2812

            
2813
Table name.
2814

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2815
=item C<updated_at EXPERIMENTAL>
2816

            
2817
This option is same as C<update> method C<updated_at> option.
2818

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

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

            
2823
placeholder wrapped string.
2824

            
2825
If the following statement
2826

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

            
2830
is executed, the following SQL is executed.
2831

            
2832
    insert into book price values ( ? + 5 );
2833

            
update pod
Yuki Kimoto authored on 2011-03-13
2834
=back
2835

            
2836
=over 4
2837

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2885
    my $like_value = $dbi->like_value
2886

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

            
2889
    sub { "%$_[0]%" }
2890

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

            
2893
    my $mapper = $dbi->mapper(param => $param);
2894

            
2895
Create a new L<DBIx::Custom::Mapper> object.
2896

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

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

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

            
2903
    {key1 => [1, 1], key2 => 2}
2904

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

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

            
2909
    my $model = $dbi->model('book');
2910

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

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

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

            
2918
Create column clause for myself. The follwoing column clause is created.
2919

            
2920
    book.author as author,
2921
    book.title as title
2922

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

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

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

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

            
2936
    my $not_exists = $dbi->not_exists;
2937

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

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

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

            
2945
Create a new L<DBIx::Custom::Order> object.
2946

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
2947
=head2 C<q EXPERIMENTAL>
2948

            
2949
    my $quooted = $dbi->q("title");
2950

            
2951
Quote string by value of C<quote>.
2952

            
cleanup
yuki-kimoto authored on 2010-10-17
2953
=head2 C<register_filter>
2954

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

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

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

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

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

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

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

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

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

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

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

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

            
3007
    book.author as "book.author",
3008
    book.title as "book.title",
3009
    person.name as "person.name",
3010
    person.age as "person.age"
3011

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

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

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

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

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

            
3025
    id => 4
3026
    id => [4, 5]
3027

            
3028
ID corresponding to C<primary_key>.
3029
You can select rows by C<id> and C<primary_key>.
3030

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

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

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

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

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

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

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

            
3058
    prefix => 'SQL_CALC_FOUND_ROWS'
3059

            
3060
Prefix of column cluase
3061

            
3062
    select SQL_CALC_FOUND_ROWS title, author from book;
3063

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

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

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

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

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

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3092
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
3093
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3094

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3111
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3112

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

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

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

            
3145
    $dbi->setup_model;
3146

            
3147
Setup all model objects.
3148
C<columns> of model object is automatically set, parsing database information.
3149

            
3150
=head2 C<type_rule>
3151

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

            
3175
Filtering rule when data is send into and get from database.
3176
This has a little complex problem.
3177

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

            
3182
Note that type name and data type don't contain upper case.
3183
If these contain upper case charactor, you convert it to lower case.
3184

            
3185
C<into2> is executed after C<into1>.
3186

            
3187
Type rule of C<into1> and C<into2> is enabled on the following
3188
column name.
3189

            
3190
=over 4
3191

            
3192
=item 1. column name
3193

            
3194
    issue_date
3195
    issue_datetime
3196

            
3197
This need C<table> option in each method.
3198

            
3199
=item 2. table name and column name, separator is dot
3200

            
3201
    book.issue_date
3202
    book.issue_datetime
3203

            
3204
=back
3205

            
3206
You get all type name used in database by C<available_typename>.
3207

            
3208
    print $dbi->available_typename;
3209

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

            
3214
    print $dbi->available_datatype;
3215

            
3216
You can also specify multiple types at once.
3217

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

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

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

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

            
3230
If you want to set constant value to row data, use scalar reference
3231
as parameter value.
3232

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3244
    id => 4
3245
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3246

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

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

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

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

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

            
3267
    prefix => 'or replace'
3268

            
3269
prefix before table name section
3270

            
3271
    update or replace book
3272

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

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

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

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

            
3281
Same as C<select> method's C<where> option.
3282

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

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

            
3287
placeholder wrapped string.
3288

            
3289
If the following statement
3290

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

            
3294
is executed, the following SQL is executed.
3295

            
3296
    update book set price =  ? + 5;
3297

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3298
=item C<updated_at EXPERIMETNAL>
3299

            
3300
    updated_at => 'updated_datetime'
3301

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3306
=back
update pod
Yuki Kimoto authored on 2011-03-13
3307

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3315
=head2 C<update_or_insert EXPERIMENTAL>
3316
    
3317
    # Where
3318
    $dbi->update_or_insert(
3319
        {id => 1, title => 'Perl'},
3320
        table => 'book',
3321
        where => {id => 1},
3322
        select_option => {append => 'for update'}
3323
    );
3324
    
3325
    # ID
3326
    $dbi->update_or_insert(
3327
        {title => 'Perl'},
3328
        table => 'book',
3329
        id => 1,
3330
        primary_key => 'id',
3331
        select_option => {append => 'for update'}
3332
    );
3333
    
3334
Update or insert.
3335

            
3336
In both examples, the following SQL is executed.
3337

            
3338
    # In case insert
3339
    insert into book (id, title) values (?, ?)
3340
    
3341
    # In case update
3342
    update book set (id = ?, title = ?) where book.id = ?
3343

            
3344
The following opitons are available adding to C<update> option.
3345

            
3346
=over 4
3347

            
3348
=item C<select_option>
3349

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

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

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

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

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

            
3361
    book
3362
    title: 5
3363
    issue_date: 91
3364

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

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

            
3369
    $dbi->show_tables;
3370

            
3371
Show tables.
3372

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

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

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

            
3379
    book
3380
    title: varchar
3381
    issue_date: date
3382

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

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

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

            
3389
Create values clause.
3390

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

            
3393
You can use this in insert statement.
3394

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

            
3397
=head2 C<where>
3398

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

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

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

            
3408
=head2 C<DBIX_CUSTOM_DEBUG>
3409

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

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

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

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

            
3419
L<DBIx::Custom>
3420

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

            
3473
L<DBIx::Custom::Model>
3474

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3475
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3476
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3477
    filter # will be removed at 2017/1/1
3478
    name # will be removed at 2017/1/1
3479
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3480

            
3481
L<DBIx::Custom::Query>
3482
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3483
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3484
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3485
    table # will be removed at 2017/1/1
3486
    filters # will be removed at 2017/1/1
3487
    
3488
    # Methods
3489
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3490

            
3491
L<DBIx::Custom::QueryBuilder>
3492
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3493
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3494
    tags # will be removed at 2017/1/1
3495
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3496
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3497
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3498
    register_tag # will be removed at 2017/1/1
3499
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3500
    
3501
    # Others
3502
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3503
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3504

            
3505
L<DBIx::Custom::Result>
3506
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3507
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3508
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3509
    
3510
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3511
    end_filter # will be removed at 2017/1/1
3512
    remove_end_filter # will be removed at 2017/1/1
3513
    remove_filter # will be removed at 2017/1/1
3514
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3515

            
3516
L<DBIx::Custom::Tag>
3517

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

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

            
3522
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3523
except for attribute method.
3524
You can check all DEPRECATED functionalities by document.
3525
DEPRECATED functionality is removed after five years,
3526
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
3527
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3528

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

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

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

            
3535
C<< <kimoto.yuki at gmail.com> >>
3536

            
3537
L<http://github.com/yuki-kimoto/DBIx-Custom>
3538

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3539
=head1 AUTHOR
3540

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

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

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

            
3547
This program is free software; you can redistribute it and/or modify it
3548
under the same terms as Perl itself.
3549

            
3550
=cut