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

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4
our $VERSION = '0.2106';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
502
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
503
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
504
    my $affected;
improved bulk_insert perform...
Yuki Kimoto authored on 2011-11-29
505
    if ((!$query->{duplicate} || $opt{bulk_insert}) && $type_rule_off
506
      && !keys %$filter && !$self->{default_out_filter}
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
507
      && !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
micro optimization
Yuki Kimoto authored on 2011-11-16
508
    {
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
509
        eval {
improved bulk_insert perform...
Yuki Kimoto authored on 2011-11-29
510
            if ($opt{bulk_insert}) {
511
                my %count;
512
                my $param = $params->[0];
513
                $affected = $sth->execute(map { $param->{$_}->[++$count{$_} - 1] }
514
                  @{$query->{columns}});
515
            }
516
            else {
517
                for my $param (@$params) {
518
                    $affected = $sth->execute(map { $param->{$_} }
519
                      @{$query->{columns}});
520
                }
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
521
            }
522
        };
micro optimization
Yuki Kimoto authored on 2011-11-16
523
    }
524
    else {
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
525
        for my $param (@$params) {
526
            # Create bind values
527
            my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
528
              $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
micro optimization
Yuki Kimoto authored on 2011-11-16
529

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
530
            # Execute
531
            eval {
532
                if ($opt{bind_type} || $opt{type}) {
533
                    $sth->bind_param($_ + 1, $bind->[$_],
534
                        $bind_types->[$_] ? $bind_types->[$_] : ())
535
                      for (0 .. @$bind - 1);
536
                    $affected = $sth->execute;
537
                }
538
                else {
539
                    $affected = $sth->execute(@$bind);
540
                }
micro optimization
Yuki Kimoto authored on 2011-11-16
541

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
542
                # DEBUG message
543
                if ($ENV{DBIX_CUSTOM_DEBUG}) {
544
                    warn "SQL:\n" . $query->{sql} . "\n";
545
                    my @output;
546
                    for my $value (@$bind) {
547
                        $value = 'undef' unless defined $value;
548
                        $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
549
                          if utf8::is_utf8($value);
550
                        push @output, $value;
551
                    }
552
                    warn "Bind values: " . join(', ', @output) . "\n\n";
micro optimization
Yuki Kimoto authored on 2011-11-16
553
                }
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
554
            };
555
        }
micro optimization
Yuki Kimoto authored on 2011-11-16
556
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
557
    
micro optimization
Yuki Kimoto authored on 2011-07-30
558
    $self->_croak($@, qq{. Following SQL is executed.\n}
559
      . qq{$query->{sql}\n} . _subname) if $@;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
560

            
561
    # Remove id from parameter
cleanup
Yuki Kimoto authored on 2011-11-25
562
    for my $column (@cleanup, @{$opt{cleanup} || []}) {
cleanup
Yuki Kimoto authored on 2011-11-25
563
        delete $_->{$column} for @$params;
cleanup
Yuki Kimoto authored on 2011-11-25
564
    }
cleanup
yuki-kimoto authored on 2010-10-17
565
    
micro optimization
Yuki Kimoto authored on 2011-10-23
566
    # Not select statement
567
    return $affected unless $sth->{NUM_OF_FIELDS};
568

            
569
    # Filter(DEPRECATED!)
570
    my $infilter = {};
571
    if ($self->{filter}{on}) {
572
        $infilter->{in}  = {};
573
        $infilter->{end} = {};
574
        push @$tables, $main_table if $main_table;
575
        for my $table (@$tables) {
576
            for my $way (qw/in end/) {
577
                $infilter->{$way} = {%{$infilter->{$way}},
578
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
579
            }
cleanup
Yuki Kimoto authored on 2011-01-12
580
        }
cleanup
yuki-kimoto authored on 2010-10-17
581
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
582
    
583
    # Result
micro optimization
Yuki Kimoto authored on 2011-11-16
584
    $self->result_class->new(
micro optimization
Yuki Kimoto authored on 2011-10-23
585
        sth => $sth,
586
        dbi => $self,
587
        default_filter => $self->{default_in_filter},
588
        filter => $infilter->{in} || {},
589
        end_filter => $infilter->{end} || {},
590
        type_rule => {
591
            from1 => $self->type_rule->{from1},
592
            from2 => $self->type_rule->{from2}
593
        },
594
    );
cleanup
yuki-kimoto authored on 2010-10-17
595
}
596

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
612
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
613
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
614
    
cleanup
Yuki Kimoto authored on 2011-10-21
615
    my $exclude_table = delete $opt{exclude_table};
616
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
617
    
618
    my $column_info = [];
619
    $self->each_column(
620
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
621
        exclude_table => $exclude_table
622
    );
623
    
624
    return [
625
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
626
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
627
}
628

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
629
sub helper {
630
    my $self = shift;
631
    
632
    # Register method
633
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
634
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
635
    
636
    return $self;
637
}
638

            
cleanup
yuki-kimoto authored on 2010-10-17
639
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
640
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
641
    
cleanup
Yuki Kimoto authored on 2011-10-21
642
    # Options
cleanup
Yuki Kimoto authored on 2011-11-25
643
    my $params = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
644
    my %opt = @_;
micro optimization
Yuki Kimoto authored on 2011-10-23
645
    warn "insert method param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-11-25
646
    $params ||= delete $opt{param} || {};
647
    
648
    my $multi;
649
    if (ref $params eq 'ARRAY') { $multi = 1 }
650
    else { $params = [$params] }
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
651
    
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
652
    # Timestamp(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-11-25
653
    if (!$multi && $opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
654
        warn "insert timestamp option is DEPRECATED! use created_at with now attribute";
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
655
        my $columns = $insert_timestamp->[0];
656
        $columns = [$columns] unless ref $columns eq 'ARRAY';
657
        my $value = $insert_timestamp->[1];
658
        $value = $value->() if ref $value eq 'CODE';
cleanup
Yuki Kimoto authored on 2011-11-25
659
        $params->[0]->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
660
    }
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
661

            
662
    # Created time and updated time
663
    my @timestamp_cleanup;
664
    if (defined $opt{created_at} || defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
665
        my $now = $self->now;
666
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
667
        if (defined $opt{created_at}) {
cleanup
Yuki Kimoto authored on 2011-11-25
668
            $_->{$opt{created_at}} = $now for @$params;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
669
            push @timestamp_cleanup, $opt{created_at};
670
        }
671
        if (defined $opt{updated_at}) {
cleanup
Yuki Kimoto authored on 2011-11-25
672
            $_->{$opt{updated_at}} = $now for @$params;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
673
            push @timestamp_cleanup, $opt{updated_at};
674
        }
675
    }
cleanup
Yuki Kimoto authored on 2011-10-21
676
    
677
    # Merge id to parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
678
    my @cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
679
    my $id_param = {};
cleanup
Yuki Kimoto authored on 2011-11-25
680
    if (defined $opt{id} && !$multi) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
681
        croak "insert id option must be specified with primary_key option"
micro optimization
Yuki Kimoto authored on 2011-10-23
682
          unless $opt{primary_key};
683
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
684
        $opt{id} = [$opt{id}] unless ref $opt{id};
685
        for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
686
           my $key = $opt{primary_key}->[$i];
cleanup
Yuki Kimoto authored on 2011-11-25
687
           next if exists $params->[0]->{$key};
688
           $params->[0]->{$key} = $opt{id}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
689
           push @cleanup, $key;
micro optimization
Yuki Kimoto authored on 2011-10-23
690
        }
691
    }
cleanup
Yuki Kimoto authored on 2011-10-21
692
    
cleanup
Yuki Kimoto authored on 2011-04-02
693
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
694
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
695
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
696
    $sql .= "into " . $self->q($opt{table}) . " ";
697
    if ($opt{bulk_insert}) {
698
        $sql .= $self->_multi_values_clause($params, {wrap => $opt{wrap}}) . " ";
699
        my $new_param = {};
700
        $new_param->{$_} = [] for keys %{$params->[0]};
701
        for my $param (@$params) {
702
            push @{$new_param->{$_}}, $param->{$_} for keys %$param;
703
        }
704
        $params = [$new_param];
705
    }
706
    else {
707
        $sql .= $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " ";
708
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
709

            
710
    # Remove id from parameter
cleanup
Yuki Kimoto authored on 2011-11-25
711
    delete $params->[0]->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
712
    
713
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
714
    $opt{statement} = 'insert';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
715
    $opt{cleanup} = \@timestamp_cleanup;
cleanup
Yuki Kimoto authored on 2011-11-25
716
    $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
717
}
718

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
719
sub insert_timestamp {
720
    my $self = shift;
721
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
722
    warn "insert_timestamp method is DEPRECATED! use now attribute";
723
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
724
    if (@_) {
725
        $self->{insert_timestamp} = [@_];
726
        
727
        return $self;
728
    }
729
    return $self->{insert_timestamp};
730
}
731

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
732
sub include_model {
733
    my ($self, $name_space, $model_infos) = @_;
734
    
cleanup
Yuki Kimoto authored on 2011-04-02
735
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
736
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
737
    
738
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
739
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
740

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
741
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
742
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
743
          if $name_space =~ /[^\w:]/;
744
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
745
        croak qq{Name space module "$name_space.pm" is needed. $@ }
746
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
747
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
748
        
749
        # Search model modules
750
        my $path = $INC{"$name_space.pm"};
751
        $path =~ s/\.pm$//;
752
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
753
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
754
        $model_infos = [];
755
        while (my $module = readdir $dh) {
756
            push @$model_infos, $module
757
              if $module =~ s/\.pm$//;
758
        }
759
        close $dh;
760
    }
761
    
cleanup
Yuki Kimoto authored on 2011-04-02
762
    # Include models
cleanup
Yuki Kimoto authored on 2011-10-21
763
    for my $model_info (@$model_infos) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
764
        
cleanup
Yuki Kimoto authored on 2011-04-02
765
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
766
        my $model_class;
767
        my $model_name;
768
        my $model_table;
769
        if (ref $model_info eq 'HASH') {
770
            $model_class = $model_info->{class};
771
            $model_name  = $model_info->{name};
772
            $model_table = $model_info->{table};
773
            
774
            $model_name  ||= $model_class;
775
            $model_table ||= $model_name;
776
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
777
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
778
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
779
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
          if $mclass =~ /[^\w:]/;
781
        unless ($mclass->can('isa')) {
782
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
783
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
784
        }
785
        
cleanup
Yuki Kimoto authored on 2011-04-02
786
        # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
787
        my $opt = {};
788
        $opt->{model_class} = $mclass if $mclass;
789
        $opt->{name}        = $model_name if $model_name;
790
        $opt->{table}       = $model_table if $model_table;
791
        $self->create_model($opt);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
792
    }
793
    
794
    return $self;
795
}
796

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
799
sub mapper {
800
    my $self = shift;
801
    return DBIx::Custom::Mapper->new(@_);
802
}
803

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
804
sub merge_param {
805
    my ($self, @params) = @_;
806
    
cleanup
Yuki Kimoto authored on 2011-04-02
807
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
808
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
809
    for my $param (@params) {
810
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
811
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
812
            
813
            if (exists $merge->{$column}) {
814
                $merge->{$column} = [$merge->{$column}]
815
                  unless ref $merge->{$column} eq 'ARRAY';
816
                push @{$merge->{$column}},
817
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
818
            }
819
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
820
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
821
            }
822
        }
823
    }
824
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
825
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
826
}
827

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
828
sub model {
829
    my ($self, $name, $model) = @_;
830
    
cleanup
Yuki Kimoto authored on 2011-04-02
831
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
832
    if ($model) {
833
        $self->models->{$name} = $model;
834
        return $self;
835
    }
836
    
837
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
838
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
839
      unless $self->models->{$name};
840
    
cleanup
Yuki Kimoto authored on 2011-04-02
841
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
842
    return $self->models->{$name};
843
}
844

            
cleanup
Yuki Kimoto authored on 2011-03-21
845
sub mycolumn {
846
    my ($self, $table, $columns) = @_;
847
    
cleanup
Yuki Kimoto authored on 2011-04-02
848
    # Create column clause
849
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
850
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
851
    push @column, $self->q($table) . "." . $self->q($_) .
852
      " as " . $self->q($_)
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
853
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
854
    
855
    return join (', ', @column);
856
}
857

            
added dbi_options attribute
kimoto authored on 2010-12-20
858
sub new {
859
    my $self = shift->SUPER::new(@_);
860
    
cleanup
Yuki Kimoto authored on 2011-04-02
861
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
862
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
863
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
864
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
865
          unless $self->can($attr);
866
    }
cleanup
Yuki Kimoto authored on 2011-11-18
867
    
868
    $self->{safety_character} = 'a-zA-Z0-9_'
869
      unless exists $self->{safety_character};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
870

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
871
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
872
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
873
        '?'     => \&DBIx::Custom::Tag::placeholder,
874
        '='     => \&DBIx::Custom::Tag::equal,
875
        '<>'    => \&DBIx::Custom::Tag::not_equal,
876
        '>'     => \&DBIx::Custom::Tag::greater_than,
877
        '<'     => \&DBIx::Custom::Tag::lower_than,
878
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
879
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
880
        'like'  => \&DBIx::Custom::Tag::like,
881
        'in'    => \&DBIx::Custom::Tag::in,
882
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
883
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
884
    };
cleanup
Yuki Kimoto authored on 2011-11-18
885
    $self->{tag_parse} = 1 unless exists $self->{tag_parse};
886
    $self->{cache} = 0 unless exists $self->{cache};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
887
    
cleanup
Yuki Kimoto authored on 2011-08-13
888
    return $self;
889
}
890

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

            
893
sub order {
894
    my $self = shift;
895
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
896
}
897

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
898
sub q {
899
    my ($self, $value, $quotemeta) = @_;
900
    
901
    my $quote = $self->{reserved_word_quote}
902
      || $self->{quote} || $self->quote || '';
903
    return "$quote$value$quote"
904
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
905
    
906
    my $q = substr($quote, 0, 1) || '';
907
    my $p;
908
    if (defined $quote && length $quote > 1) {
909
        $p = substr($quote, 1, 1);
910
    }
911
    else { $p = $q }
912
    
913
    if ($quotemeta) {
914
        $q = quotemeta($q);
915
        $p = quotemeta($p);
916
    }
917
    
918
    return "$q$value$p";
919
}
920

            
cleanup
yuki-kimoto authored on 2010-10-17
921
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
922
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
923
    
924
    # Register filter
925
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
926
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
927
    
cleanup
Yuki Kimoto authored on 2011-04-02
928
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
929
}
packaging one directory
yuki-kimoto authored on 2009-11-16
930

            
931
sub select {
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
932
    my $self = shift;
933
    my $column = shift if @_ % 2;
934
    my %opt = @_;
935
    $opt{column} = $column if defined $column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
936

            
cleanup
Yuki Kimoto authored on 2011-10-21
937
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
938
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
939
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
940
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
941
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
942
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select method where_param op...
Yuki Kimoto authored on 2011-10-25
943
    warn "select method where_param option is DEPRECATED!"
944
      if $opt{where_param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
945
    
cleanup
Yuki Kimoto authored on 2011-03-09
946
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
947
    if ($opt{relation}) {
948
        warn "select() relation option is DEPRECATED!";
949
        $self->_add_relation_table($tables, $opt{relation});
950
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
951
    
cleanup
Yuki Kimoto authored on 2011-04-02
952
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
953
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
954
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
955
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
956
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
957
    
cleanup
Yuki Kimoto authored on 2011-10-21
958
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
959
    if (defined $opt{column}) {
960
        my $columns
961
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
962
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
963
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
964
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
965
            }
966
            elsif (ref $column eq 'ARRAY') {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
967
                warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
968
                  "use q method to quote the value";
- select method column optio...
Yuki Kimoto authored on 2011-07-11
969
                if (@$column == 3 && $column->[1] eq 'as') {
970
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
971
                    splice @$column, 1, 1;
972
                }
973
                
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
974
                $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
975
            }
cleanup
Yuki Kimoto authored on 2011-04-02
976
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
977
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
978
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
979
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
980
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
981
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
982
    
983
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
984
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
985
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
986
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
987
        for my $table (@$tables) {
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
988
            $sql .= $self->q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
989
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
990
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
991
    }
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
992
    else { $sql .= $self->q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
993
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
994
    croak "select method table option must be specified " . _subname
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
995
      unless defined $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
996

            
cleanup
Yuki Kimoto authored on 2011-04-02
997
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
998
    unshift @$tables,
999
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1000
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1001
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
1002
    my $w = $self->_where_clause_and_param($opt{where}, $where_param,
1003
      delete $opt{id}, $opt{primary_key}, $tables->[-1]);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1004
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1005
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
1006
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1007
    
cleanup
Yuki Kimoto authored on 2011-10-21
1008
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
1009
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1010
    
cleanup
Yuki Kimoto authored on 2011-03-09
1011
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
1012
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1013
    
cleanup
Yuki Kimoto authored on 2011-03-08
1014
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
1015
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
1016
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
1017
    
packaging one directory
yuki-kimoto authored on 2009-11-16
1018
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
1019
    $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2011-10-21
1020
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
1021
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1022
    $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
1023
}
1024

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1025
sub setup_model {
1026
    my $self = shift;
1027
    
cleanup
Yuki Kimoto authored on 2011-04-02
1028
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1029
    $self->each_column(
1030
        sub {
1031
            my ($self, $table, $column, $column_info) = @_;
1032
            if (my $model = $self->models->{$table}) {
1033
                push @{$model->columns}, $column;
1034
            }
1035
        }
1036
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1037
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1038
}
1039

            
update pod
Yuki Kimoto authored on 2011-08-10
1040
sub show_datatype {
1041
    my ($self, $table) = @_;
1042
    croak "Table name must be specified" unless defined $table;
1043
    print "$table\n";
1044
    
1045
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1046
    my $sth = $result->sth;
1047

            
1048
    my $columns = $sth->{NAME};
1049
    my $data_types = $sth->{TYPE};
1050
    
1051
    for (my $i = 0; $i < @$columns; $i++) {
1052
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1053
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1054
        print "$column: $data_type\n";
1055
    }
1056
}
1057

            
1058
sub show_typename {
1059
    my ($self, $t) = @_;
1060
    croak "Table name must be specified" unless defined $t;
1061
    print "$t\n";
1062
    
1063
    $self->each_column(sub {
1064
        my ($self, $table, $column, $infos) = @_;
1065
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1066
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1067
        print "$column: $typename\n";
1068
    });
1069
    
1070
    return $self;
1071
}
1072

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1073
sub show_tables {
1074
    my $self = shift;
1075
    
1076
    my %tables;
1077
    $self->each_table(sub { $tables{$_[1]}++ });
1078
    print join("\n", sort keys %tables) . "\n";
1079
    return $self;
1080
}
1081

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

            
1085
    $self->{_type_rule_is_called} = 1;
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1086
    
1087
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1088
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1089
        
1090
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
1091
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1092
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1093
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1094
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1095
            $self->{type_rule} = $type_rule;
1096
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
1097
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1098
                croak qq{type name of $into section must be lower case}
1099
                  if $type_name =~ /[A-Z]/;
1100
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1101
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1102
            $self->each_column(sub {
1103
                my ($dbi, $table, $column, $column_info) = @_;
1104
                
1105
                my $type_name = lc $column_info->{TYPE_NAME};
1106
                if ($type_rule->{$into} &&
1107
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1108
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1109
                    return unless exists $type_rule->{$into}->{$type_name};
1110
                    if  (defined $filter && ref $filter ne 'CODE') 
1111
                    {
1112
                        my $fname = $filter;
1113
                        croak qq{Filter "$fname" is not registered" } . _subname
1114
                          unless exists $self->filters->{$fname};
1115
                        
1116
                        $filter = $self->filters->{$fname};
1117
                    }
1118

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1119
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1120
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1121
                }
1122
            });
1123
        }
1124

            
1125
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
1126
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1127
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
1128
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1129
                croak qq{data type of from$i section must be lower case or number}
1130
                  if $data_type =~ /[A-Z]/;
1131
                my $fname = $type_rule->{"from$i"}{$data_type};
1132
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1133
                    croak qq{Filter "$fname" is not registered" } . _subname
1134
                      unless exists $self->filters->{$fname};
1135
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1136
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1137
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1138
            }
1139
        }
1140
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1141
        return $self;
1142
    }
1143
    
1144
    return $self->{type_rule} || {};
1145
}
1146

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1150
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1151
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1152
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1153
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1154
    warn "update method where_param option is DEPRECATED!"
1155
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1156
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1157
    
cleanup
Yuki Kimoto authored on 2011-10-21
1158
    # Don't allow update all rows
1159
    croak qq{update method where option must be specified } . _subname
1160
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1161
    
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1162
    # Timestamp(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-10-21
1163
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1164
        warn "update timestamp option is DEPRECATED! use updated_at and now method";
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1165
        my $columns = $update_timestamp->[0];
1166
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1167
        my $value = $update_timestamp->[1];
1168
        $value = $value->() if ref $value eq 'CODE';
1169
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1170
    }
1171

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1172
    # Created time and updated time
1173
    my @timestamp_cleanup;
1174
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1175
        my $now = $self->now;
1176
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1177
        $param->{$opt{updated_at}} = $self->now->();
1178
        push @timestamp_cleanup, $opt{updated_at};
1179
    }
1180

            
cleanup
Yuki Kimoto authored on 2011-10-21
1181
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1182
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1183
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1184
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
1185
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1186
      delete $opt{id}, $opt{primary_key}, $opt{table});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1187
    
cleanup
Yuki Kimoto authored on 2011-04-02
1188
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1189
    my $sql = "update ";
1190
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1191
    $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1192
    
cleanup
yuki-kimoto authored on 2010-10-17
1193
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
1194
    $opt{statement} = 'update';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1195
    $opt{cleanup} = \@timestamp_cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
1196
    $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1197
}
1198

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

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

            
1207
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1208
    if (@$rows == 0) {
1209
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1210
    }
1211
    elsif (@$rows == 1) {
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
1212
        return 0 unless keys %$param;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1213
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1214
    }
1215
    else {
1216
        croak "selected row must be one " . _subname;
1217
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1218
}
1219

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1220
sub update_timestamp {
1221
    my $self = shift;
1222
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1223
    warn "update_timestamp method is DEPRECATED! use now method";
1224
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1225
    if (@_) {
1226
        $self->{update_timestamp} = [@_];
1227
        
1228
        return $self;
1229
    }
1230
    return $self->{update_timestamp};
1231
}
1232

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1233
sub values_clause {
1234
    my ($self, $param, $opts) = @_;
1235
    
1236
    my $wrap = $opts->{wrap} || {};
1237
    
1238
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-11-16
1239
    my ($q, $p) = split //, $self->q('');
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1240
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1241
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1242
    '(' .
1243
    join(
1244
      ', ',
1245
      map { "$q$_$p" } sort keys %$param
1246
    ) .
1247
    ') values (' .
1248
    join(
1249
      ', ',
1250
      map {
1251
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1252
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1253
          ":$_";
1254
      } sort keys %$param
1255
    ) .
1256
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1257
}
1258

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1259
sub _multi_values_clause {
1260
    my ($self, $params, $opts) = @_;
1261
    
1262
    my $wrap = $opts->{wrap} || {};
1263
    
1264
    # Create insert parameter tag
1265
    my ($q, $p) = split //, $self->q('');
1266
    
1267
    # Multi values clause
1268
    my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1269
    
1270
    for (1 .. @$params) {
1271
        $clause .= '(' . join(', ', 
1272
          map {
1273
              ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1274
              $wrap->{$_} ? $wrap->{$_}->(":$_") :
1275
              ":$_";
1276
          } sort keys %{$params->[0]}
1277
        ) . '), '
1278
    }
1279
    $clause =~ s/, $//;
1280
    return $clause;
1281
}
1282

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1285
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1286
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1287
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1288
    
updated pod
Yuki Kimoto authored on 2011-06-21
1289
    # Cache
cleanup
Yuki Kimoto authored on 2011-11-18
1290
    my $cache = $self->{cache};
updated pod
Yuki Kimoto authored on 2011-06-21
1291
    
1292
    # Query
1293
    my $query;
1294
    
1295
    # Get cached query
1296
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1297
        
updated pod
Yuki Kimoto authored on 2011-06-21
1298
        # Get query
1299
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1300
        
updated pod
Yuki Kimoto authored on 2011-06-21
1301
        # Create query
1302
        if ($q) {
1303
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1304
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1305
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1306
    }
1307
    
1308
    # Create query
1309
    unless ($query) {
1310

            
1311
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-18
1312
        my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1313
          ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1314

            
micro optimization
Yuki Kimoto authored on 2011-11-18
1315
        my $sql = " " . $source || '';
cleanup
Yuki Kimoto authored on 2011-11-18
1316
        if ($tag_parse && ($sql =~ /\s\{/)) {
cleanup
Yuki Kimoto authored on 2011-11-18
1317
            $query = $self->query_builder->build_query($sql);
1318
        }
1319
        else {
1320
            my @columns;
cleanup
Yuki Kimoto authored on 2011-11-18
1321
            my $c = $self->{safety_character};
micro optimization
Yuki Kimoto authored on 2011-11-18
1322
            my $re = $c eq 'a-zA-Z0-9_'
1323
              ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1324
              : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
cleanup
Yuki Kimoto authored on 2011-11-16
1325
            my %duplicate;
1326
            my $duplicate;
1327
            # Parameter regex
cleanup
Yuki Kimoto authored on 2011-11-18
1328
            $sql =~ s/([0-9]):/$1\\:/g;
micro optimization
Yuki Kimoto authored on 2011-11-18
1329
            my $new_sql = '';
micro optimization
Yuki Kimoto authored on 2011-11-18
1330
            while ($sql =~ /$re/) {
cleanup
Yuki Kimoto authored on 2011-11-18
1331
                push @columns, $2;
1332
                $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
micro optimization
Yuki Kimoto authored on 2011-11-18
1333
                ($new_sql, $sql) = defined $3 ?
1334
                  ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
cleanup
Yuki Kimoto authored on 2011-11-16
1335
            }
micro optimization
Yuki Kimoto authored on 2011-11-18
1336
            $new_sql .= $sql;
1337
            $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
cleanup
Yuki Kimoto authored on 2011-11-16
1338

            
1339
            # Create query
micro optimization
Yuki Kimoto authored on 2011-11-18
1340
            $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
cleanup
Yuki Kimoto authored on 2011-11-16
1341
        }
cleanup
Yuki Kimoto authored on 2011-11-16
1342
        
updated pod
Yuki Kimoto authored on 2011-06-21
1343
        # Save query to cache
1344
        $self->cache_method->(
1345
            $self, $source,
1346
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1347
                sql     => $query->{sql}, 
1348
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1349
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1350
            }
1351
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1352
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1353

            
1354
    # Filter SQL
micro optimization
Yuki Kimoto authored on 2011-11-16
1355
    $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1356
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1357
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1358
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1359
    
updated pod
Yuki Kimoto authored on 2011-06-21
1360
    # Prepare statement handle
1361
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1362
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1363
    
1364
    if ($@) {
1365
        $self->_croak($@, qq{. Following SQL is executed.\n}
1366
                        . qq{$query->{sql}\n} . _subname);
1367
    }
1368
    
1369
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1370
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1371
    
1372
    # Set filters
cleanup
Yuki Kimoto authored on 2011-11-16
1373
    $query->{filters} = $self->{filters} || $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1374
    
1375
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1376
}
1377

            
cleanup
Yuki Kimoto authored on 2011-04-02
1378
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1379
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1380
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1381
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1382
    
cleanup
Yuki Kimoto authored on 2011-04-02
1383
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1384
    my @bind;
1385
    my @types;
1386
    my %count;
1387
    my %not_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1388
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1389
        
micro optimization
Yuki Kimoto authored on 2011-10-23
1390
        # Bind value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1391
        if(ref $params->{$column} eq 'ARRAY') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1392
            my $i = $count{$column} || 0;
1393
            $i += $not_exists{$column} || 0;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1394
            my $found;
1395
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1396
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1397
                    $not_exists{$column}++;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1398
                }
1399
                else  {
micro optimization
Yuki Kimoto authored on 2011-10-23
1400
                    push @bind, $params->{$column}->[$k];
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1401
                    $found = 1;
1402
                    last
1403
                }
1404
            }
1405
            next unless $found;
1406
        }
micro optimization
Yuki Kimoto authored on 2011-10-23
1407
        else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1408
        
cleanup
Yuki Kimoto authored on 2011-01-12
1409
        # Filter
micro optimization
Yuki Kimoto authored on 2011-10-23
1410
        if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1411
            $bind[-1] = $f->($bind[-1]);
micro optimization
Yuki Kimoto authored on 2011-10-23
1412
        }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1413
        
1414
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-23
1415
        if ($self->{_type_rule_is_called}) {
1416
            my $tf1 = $self->{"_into1"}->{dot}->{$column}
1417
              || $type_filters->{1}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1418
            $bind[-1] = $tf1->($bind[-1]) if $tf1;
micro optimization
Yuki Kimoto authored on 2011-10-23
1419
            my $tf2 = $self->{"_into2"}->{dot}->{$column}
1420
              || $type_filters->{2}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1421
            $bind[-1] = $tf2->($bind[-1]) if $tf2;
micro optimization
Yuki Kimoto authored on 2011-10-23
1422
        }
micro optimization
Yuki Kimoto authored on 2011-10-22
1423
       
micro optimization
Yuki Kimoto authored on 2011-10-23
1424
        # Bind types
micro optimization
Yuki Kimoto authored on 2011-10-23
1425
        push @types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1426
        
1427
        # Count up 
micro optimization
Yuki Kimoto authored on 2011-10-23
1428
        $count{$column}++;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1429
    }
1430
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1431
    return (\@bind, \@types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1432
}
1433

            
cleanup
Yuki Kimoto authored on 2011-10-21
1434
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1435
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1436
    
1437
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1438
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1439
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1440
      unless defined $primary_keys;
1441
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1442
    
cleanup
Yuki Kimoto authored on 2011-06-08
1443
    # Create parameter
1444
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1445
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1446
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1447
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1448
           my $key = $primary_keys->[$i];
1449
           $key = "$table." . $key if $table;
1450
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1451
        }
1452
    }
1453
    
cleanup
Yuki Kimoto authored on 2011-06-08
1454
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1455
}
1456

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1457
sub _connect {
1458
    my $self = shift;
1459
    
1460
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1461
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1462
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1463
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1464
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1465
    croak qq{"dsn" must be specified } . _subname
1466
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1467
    my $user        = $self->user;
1468
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1469
    my $option = $self->_option;
1470
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1471
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1472
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1473
    my $dbh;
1474
    eval {
1475
        $dbh = DBI->connect(
1476
            $dsn,
1477
            $user,
1478
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1479
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1480
        );
1481
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1482
    
1483
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1484
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1485
    
1486
    return $dbh;
1487
}
1488

            
cleanup
yuki-kimoto authored on 2010-10-17
1489
sub _croak {
1490
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1491
    
1492
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1493
    $append ||= "";
1494
    
1495
    # Verbose
1496
    if ($Carp::Verbose) { croak $error }
1497
    
1498
    # Not verbose
1499
    else {
1500
        
1501
        # Remove line and module infromation
1502
        my $at_pos = rindex($error, ' at ');
1503
        $error = substr($error, 0, $at_pos);
1504
        $error =~ s/\s+$//;
1505
        croak "$error$append";
1506
    }
1507
}
1508

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1511
sub _need_tables {
1512
    my ($self, $tree, $need_tables, $tables) = @_;
1513
    
cleanup
Yuki Kimoto authored on 2011-04-02
1514
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1515
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1516
        if ($tree->{$table}) {
1517
            $need_tables->{$table} = 1;
1518
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1519
        }
1520
    }
1521
}
1522

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1523
sub _option {
1524
    my $self = shift;
1525
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1526
    warn "dbi_options is DEPRECATED! use option instead\n"
1527
      if keys %{$self->dbi_options};
1528
    warn "dbi_option is DEPRECATED! use option instead\n"
1529
      if keys %{$self->dbi_option};
1530
    return $option;
1531
}
1532

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1533
sub _push_join {
1534
    my ($self, $sql, $join, $join_tables) = @_;
1535
    
cleanup
Yuki Kimoto authored on 2011-10-21
1536
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1537
    
cleanup
Yuki Kimoto authored on 2011-04-02
1538
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1539
    return unless @$join;
1540
    
cleanup
Yuki Kimoto authored on 2011-04-02
1541
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1542
    my $tree = {};
1543
    for (my $i = 0; $i < @$join; $i++) {
1544
        
cleanup
Yuki Kimoto authored on 2011-07-28
1545
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1546
        my $join_clause;;
1547
        my $option;
1548
        if (ref $join->[$i] eq 'HASH') {
1549
            $join_clause = $join->[$i]->{clause};
1550
            $option = {table => $join->[$i]->{table}};
1551
        }
1552
        else {
1553
            $join_clause = $join->[$i];
1554
            $option = {};
1555
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1556

            
1557
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1558
        my $table1;
1559
        my $table2;
1560
        if (my $table = $option->{table}) {
1561
            $table1 = $table->[0];
1562
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1563
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1564
        else {
1565
            my $q = $self->_quote;
1566
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1567
            $j_clause =~ s/'.+?'//g;
1568
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1569
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1570
            
1571
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-11-18
1572
            my $c = $self->{safety_character};
1573
            my $join_re = qr/([$c]+)\.[$c]+[^$c].*?([$c]+)\.[$c]+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1574
            for my $clause (@j_clauses) {
1575
                if ($clause =~ $join_re) {
1576
                    $table1 = $1;
1577
                    $table2 = $2;
1578
                    last;
1579
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1580
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1581
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1582
        croak qq{join clause must have two table name after "on" keyword. } .
1583
              qq{"$join_clause" is passed }  . _subname
1584
          unless defined $table1 && defined $table2;
1585
        croak qq{right side table of "$join_clause" must be unique }
1586
            . _subname
1587
          if exists $tree->{$table2};
1588
        croak qq{Same table "$table1" is specified} . _subname
1589
          if $table1 eq $table2;
1590
        $tree->{$table2}
1591
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1592
    }
1593
    
cleanup
Yuki Kimoto authored on 2011-04-02
1594
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1595
    my $need_tables = {};
1596
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1597
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1598
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1599
    
1600
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1601
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1602
}
cleanup
Yuki Kimoto authored on 2011-03-08
1603

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1604
sub _quote {
1605
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1606
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1607
}
1608

            
cleanup
Yuki Kimoto authored on 2011-04-02
1609
sub _remove_duplicate_table {
1610
    my ($self, $tables, $main_table) = @_;
1611
    
1612
    # Remove duplicate table
1613
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1614
    delete $tables{$main_table} if $main_table;
1615
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1616
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1617
    if (my $q = $self->_quote) {
1618
        $q = quotemeta($q);
1619
        $_ =~ s/[$q]//g for @$new_tables;
1620
    }
1621

            
1622
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1623
}
1624

            
cleanup
Yuki Kimoto authored on 2011-04-02
1625
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1626
    my ($self, $source) = @_;
1627
    
cleanup
Yuki Kimoto authored on 2011-04-02
1628
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1629
    my $tables = [];
cleanup
Yuki Kimoto authored on 2011-11-18
1630
    my $safety_character = $self->{safety_character};
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1631
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1632
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1633
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1634
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1635
    while ($source =~ /$table_re/g) {
1636
        push @$tables, $1;
1637
    }
1638
    
1639
    return $tables;
1640
}
1641

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1645
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1646
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1647
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1648
    my $w = {};
1649
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1650

            
cleanup
Yuki Kimoto authored on 2011-10-25
1651
    my $obj;
1652
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1653
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1654
        if (ref $where eq 'HASH') {
1655
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1656
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1657
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1658
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1659
                my $table;
1660
                my $c;
1661
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1662
                    $table = $1;
1663
                    $c = $2;
1664
                }
1665
                
1666
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1667
                $table_quote = $self->q($table) if defined $table;
1668
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1669
                $column_quote = $table_quote . '.' . $column_quote
1670
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1671
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1672
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1673

            
1674
            # Check unsafety column
cleanup
Yuki Kimoto authored on 2011-11-18
1675
            my $safety = $self->{safety_character};
cleanup
Yuki Kimoto authored on 2011-11-01
1676
            unless ($column_join =~ /^[$safety\.]+$/) {
1677
                for my $column (keys %$where) {
1678
                    croak qq{"$column" is not safety column name } . _subname
1679
                      unless $column =~ /^[$safety\.]+$/;
1680
                }
1681
            }
1682
            
cleanup
Yuki Kimoto authored on 2011-10-25
1683
            $obj = $self->where(clause => $clause, param => $where);
1684
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1685
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1686
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1687
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1688
        }
1689
        
1690
        # Check where argument
1691
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1692
            . qq{or array reference, which contains where clause and parameter}
1693
            . _subname
1694
          unless ref $obj eq 'DBIx::Custom::Where';
1695

            
1696
        $w->{param} = keys %$where_param
1697
                    ? $self->merge_param($where_param, $obj->param)
1698
                    : $obj->param;
1699
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1700
    }
1701
    elsif ($where) {
1702
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1703
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1704
    }
1705
    
1706
    return $w;
1707
}
1708

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

            
1712
    # Initialize filters
1713
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1714
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1715
    $self->{filter}{out} ||= {};
1716
    $self->{filter}{in} ||= {};
1717
    $self->{filter}{end} ||= {};
1718
    
1719
    # Usage
1720
    my $usage = "Usage: \$dbi->apply_filter(" .
1721
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1722
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1723
    
1724
    # Apply filter
1725
    for (my $i = 0; $i < @cinfos; $i += 2) {
1726
        
1727
        # Column
1728
        my $column = $cinfos[$i];
1729
        if (ref $column eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-10-21
1730
            for my $c (@$column) {
updated pod
Yuki Kimoto authored on 2011-06-21
1731
                push @cinfos, $c, $cinfos[$i + 1];
1732
            }
1733
            next;
1734
        }
1735
        
1736
        # Filter infomation
1737
        my $finfo = $cinfos[$i + 1] || {};
1738
        croak "$usage (table: $table) " . _subname
1739
          unless  ref $finfo eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-10-21
1740
        for my $ftype (keys %$finfo) {
updated pod
Yuki Kimoto authored on 2011-06-21
1741
            croak "$usage (table: $table) " . _subname
1742
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1743
        }
1744
        
1745
        # Set filters
cleanup
Yuki Kimoto authored on 2011-10-21
1746
        for my $way (qw/in out end/) {
updated pod
Yuki Kimoto authored on 2011-06-21
1747
        
1748
            # Filter
1749
            my $filter = $finfo->{$way};
1750
            
1751
            # Filter state
1752
            my $state = !exists $finfo->{$way} ? 'not_exists'
1753
                      : !defined $filter        ? 'not_defined'
1754
                      : ref $filter eq 'CODE'   ? 'code'
1755
                      : 'name';
1756
            
1757
            # Filter is not exists
1758
            next if $state eq 'not_exists';
1759
            
1760
            # Check filter name
1761
            croak qq{Filter "$filter" is not registered } . _subname
1762
              if  $state eq 'name'
1763
               && ! exists $self->filters->{$filter};
1764
            
1765
            # Set filter
1766
            my $f = $state eq 'not_defined' ? undef
1767
                  : $state eq 'code'        ? $filter
1768
                  : $self->filters->{$filter};
1769
            $self->{filter}{$way}{$table}{$column} = $f;
1770
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1771
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1772
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1773
        }
1774
    }
1775
    
1776
    return $self;
1777
}
1778

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1779
# DEPRECATED!
1780
has 'data_source';
1781
has dbi_options => sub { {} };
1782
has filter_check  => 1;
1783
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1784
has dbi_option => sub { {} };
1785
has default_dbi_option => sub {
1786
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1787
    return shift->default_option;
1788
};
1789

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1790
# DEPRECATED
1791
sub tag_parse {
1792
   my $self = shift;
1793
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1794
         "environment variable";
1795
    if (@_) {
1796
        $self->{tag_parse} = $_[0];
1797
        return $self;
1798
    }
1799
    return $self->{tag_parse};
1800
}
1801

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1802
# DEPRECATED!
1803
sub method {
1804
    warn "method is DEPRECATED! use helper instead";
1805
    return shift->helper(@_);
1806
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1807

            
1808
# DEPRECATED!
1809
sub assign_param {
1810
    my $self = shift;
1811
    warn "assing_param is DEPRECATED! use assign_clause instead";
1812
    return $self->assign_clause(@_);
1813
}
1814

            
1815
# DEPRECATED
1816
sub update_param {
1817
    my ($self, $param, $opts) = @_;
1818
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1819
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1820
    
1821
    # Create update parameter tag
1822
    my $tag = $self->assign_clause($param, $opts);
1823
    $tag = "set $tag" unless $opts->{no_set};
1824

            
1825
    return $tag;
1826
}
1827

            
updated pod
Yuki Kimoto authored on 2011-06-21
1828
# DEPRECATED!
1829
sub create_query {
1830
    warn "create_query is DEPRECATED! use query option of each method";
1831
    shift->_create_query(@_);
1832
}
1833

            
cleanup
Yuki Kimoto authored on 2011-06-13
1834
# DEPRECATED!
1835
sub apply_filter {
1836
    my $self = shift;
1837
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1838
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1839
    return $self->_apply_filter(@_);
1840
}
1841

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1848
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1849
    my $primary_keys = delete $opt{primary_key};
1850
    my $where = delete $opt{where};
1851
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1852
    
1853
    # Table
1854
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1855
      unless $opt{table};
1856
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1857
    
1858
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1859
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1860
    
cleanup
Yuki Kimoto authored on 2011-10-21
1861
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1862
}
1863

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1868
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1869
    
cleanup
Yuki Kimoto authored on 2011-10-21
1870
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1871
    my $primary_keys = delete $opt{primary_key};
1872
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1873
    
1874
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1875
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1876
    
cleanup
Yuki Kimoto authored on 2011-10-21
1877
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1878
}
1879

            
cleanup
Yuki Kimoto authored on 2011-06-08
1880
# DEPRECATED!
1881
sub update_at {
1882
    my $self = shift;
1883

            
cleanup
Yuki Kimoto authored on 2011-10-21
1884
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1885
    
cleanup
Yuki Kimoto authored on 2011-10-21
1886
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1887
    my $param;
1888
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1889
    my %opt = @_;
1890
    my $primary_keys = delete $opt{primary_key};
1891
    my $where = delete $opt{where};
1892
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1893
    $param  ||= $p;
1894
    
1895
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1896
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1897
    
cleanup
Yuki Kimoto authored on 2011-10-21
1898
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1899
}
1900

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1901
# DEPRECATED!
1902
sub insert_at {
1903
    my $self = shift;
1904
    
cleanup
Yuki Kimoto authored on 2011-10-21
1905
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1906
    
cleanup
Yuki Kimoto authored on 2011-10-21
1907
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1908
    my $param;
1909
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1910
    my %opt = @_;
1911
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1912
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1913
    my $where = delete $opt{where};
1914
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1915
    $param  ||= $p;
1916
    
1917
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1918
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1919
    $param = $self->merge_param($where_param, $param);
1920
    
cleanup
Yuki Kimoto authored on 2011-10-21
1921
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1922
}
1923

            
added warnings
Yuki Kimoto authored on 2011-06-07
1924
# DEPRECATED!
1925
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1926
    my $self = shift;
1927
    
added warnings
Yuki Kimoto authored on 2011-06-07
1928
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1929
    
1930
    # Merge tag
1931
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1932
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1933
    
1934
    return $self;
1935
}
1936

            
1937
# DEPRECATED!
1938
sub register_tag_processor {
1939
    my $self = shift;
1940
    warn "register_tag_processor is DEPRECATED!";
1941
    # Merge tag
1942
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1943
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1944
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1945
}
1946

            
cleanup
Yuki Kimoto authored on 2011-01-25
1947
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1948
sub default_bind_filter {
1949
    my $self = shift;
1950
    
cleanup
Yuki Kimoto authored on 2011-06-13
1951
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1952
    
cleanup
Yuki Kimoto authored on 2011-01-12
1953
    if (@_) {
1954
        my $fname = $_[0];
1955
        
1956
        if (@_ && !$fname) {
1957
            $self->{default_out_filter} = undef;
1958
        }
1959
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1960
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1961
              unless exists $self->filters->{$fname};
1962
        
1963
            $self->{default_out_filter} = $self->filters->{$fname};
1964
        }
1965
        return $self;
1966
    }
1967
    
1968
    return $self->{default_out_filter};
1969
}
1970

            
cleanup
Yuki Kimoto authored on 2011-01-25
1971
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1972
sub default_fetch_filter {
1973
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1974

            
cleanup
Yuki Kimoto authored on 2011-06-13
1975
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1976
    
1977
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1978
        my $fname = $_[0];
1979

            
cleanup
Yuki Kimoto authored on 2011-01-12
1980
        if (@_ && !$fname) {
1981
            $self->{default_in_filter} = undef;
1982
        }
1983
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1984
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1985
              unless exists $self->filters->{$fname};
1986
        
1987
            $self->{default_in_filter} = $self->filters->{$fname};
1988
        }
1989
        
1990
        return $self;
1991
    }
1992
    
many changed
Yuki Kimoto authored on 2011-01-23
1993
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1994
}
1995

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1996
# DEPRECATED!
1997
sub insert_param {
1998
    my $self = shift;
1999
    warn "insert_param is DEPRECATED! use values_clause instead";
2000
    return $self->values_clause(@_);
2001
}
2002

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2003
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2004
sub insert_param_tag {
2005
    warn "insert_param_tag is DEPRECATED! " .
2006
         "use insert_param instead!";
2007
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2008
}
2009

            
2010
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2011
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
2012
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2013
         "use update_param instead";
2014
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2015
}
cleanup
Yuki Kimoto authored on 2011-03-08
2016
# DEPRECATED!
2017
sub _push_relation {
2018
    my ($self, $sql, $tables, $relation, $need_where) = @_;
2019
    
2020
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
2021
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
2022
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
2023
            my $table1 = (split (/\./, $rcolumn))[0];
2024
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2025
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
2026
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2027
        }
2028
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
2029
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2030
}
2031

            
2032
# DEPRECATED!
2033
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
2034
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
2035
    
2036
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
2037
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
2038
            my $table1 = (split (/\./, $rcolumn))[0];
2039
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2040
            my $table1_exists;
2041
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
2042
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
2043
                $table1_exists = 1 if $table eq $table1;
2044
                $table2_exists = 1 if $table eq $table2;
2045
            }
2046
            unshift @$tables, $table1 unless $table1_exists;
2047
            unshift @$tables, $table2 unless $table2_exists;
2048
        }
2049
    }
2050
}
2051

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2054
=head1 NAME
2055

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2060
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2061
    
2062
    # Connect
2063
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2064
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2065
        user => 'ken',
2066
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2067
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2068
    );
cleanup
yuki-kimoto authored on 2010-08-05
2069

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2070
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2071
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2072
    
2073
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2074
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2075
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2076
    
2077
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2078
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2079

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2084
    # Select, more complex
2085
    my $result = $dbi->select(
2086
        table  => 'book',
2087
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
2088
            {book => [qw/title author/]},
2089
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2090
        ],
2091
        where  => {'book.author' => 'Ken'},
2092
        join => ['left outer join company on book.company_id = company.id'],
2093
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2094
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2095
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2096
    # Fetch
2097
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2098
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2099
    }
2100
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2101
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2102
    while (my $row = $result->fetch_hash) {
2103
        
2104
    }
2105
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2106
    # Execute SQL with parameter.
2107
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2108
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2109
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2110
    );
2111
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2112
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2113

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2129
Named place holder support
2130

            
2131
=item *
2132

            
cleanup
Yuki Kimoto authored on 2011-07-29
2133
Model support
2134

            
2135
=item *
2136

            
2137
Connection manager support
2138

            
2139
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2140

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

            
2145
=item *
2146

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

            
2149
=item *
2150

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

            
2153
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2154

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2162
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2163
L<DBIx::Custom::Result>,
2164
L<DBIx::Custom::Query>,
2165
L<DBIx::Custom::Where>,
2166
L<DBIx::Custom::Model>,
2167
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2168

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

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

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

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

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

            
2182
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2183
        "dbi:mysql:database=$database",
2184
        $user,
2185
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2186
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2187
    );
2188
    
updated pod
Yuki Kimoto authored on 2011-06-21
2189
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2190

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

            
2194
    my $dbi = DBIx::Custom->connect(
2195
      dsn => $dsn, user => $user, password => $password, connector => 1);
2196
    
2197
    my $connector = $dbi->connector; # DBIx::Connector
2198

            
2199
Note that L<DBIx::Connector> must be installed.
2200

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2216
    {
2217
        RaiseError => 1,
2218
        PrintError => 0,
2219
        AutoCommit => 1,
2220
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2221

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

            
2224
    my $exclude_table = $dbi->exclude_table;
2225
    $dbi = $dbi->exclude_table(qr/pg_/);
2226

            
2227
Excluded table regex.
2228
C<each_column>, C<each_table>, C<type_rule>,
2229
and C<setup_model> methods ignore matching tables.
2230

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

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

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

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

            
2240
    my $last_sql = $dbi->last_sql;
2241
    $dbi = $dbi->last_sql($last_sql);
2242

            
2243
Get last successed SQL executed by C<execute> method.
2244

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

            
2247
    my $now = $dbi->now;
2248
    $dbi = $dbi->now($now);
2249

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

            
2252
    sub {
2253
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2254
        $mon++;
2255
        $year += 1900;
2256
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2257
    }
2258

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

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

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

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

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

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

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

            
2276
L<DBI> option, used when C<connect> method is executed.
2277
Each value in option override the value of C<default_option>.
2278

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2301
You can set quote pair.
2302

            
2303
    $dbi->quote('[]');
2304

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2314
    my $safety_character = $dbi->safety_character;
2315
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2316

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

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

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

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

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

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

            
2333
    my $tag_parse = $dbi->tag_parse(0);
2334
    $dbi = $dbi->tag_parse;
2335

            
2336
Enable DEPRECATED tag parsing functionality, default to 1.
2337
If you want to disable tag parsing functionality, set to 0.
2338

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

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

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

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

            
2348
    my $user_column_info = $dbi->user_column_info;
2349
    $dbi = $dbi->user_column_info($user_column_info);
2350

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

            
2353
    [
2354
        {table => 'book', column => 'title', info => {...}},
2355
        {table => 'author', column => 'name', info => {...}}
2356
    ]
2357

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

            
2360
    my $user_column_info
2361
      = $dbi->get_column_info(exclude_table => qr/^system/);
2362
    $dbi->user_column_info($user_column_info);
2363

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

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

            
2369
    my $user_table_info = $dbi->user_table_info;
2370
    $dbi = $dbi->user_table_info($user_table_info);
2371

            
2372
You can set the following data.
2373

            
2374
    [
2375
        {table => 'book', info => {...}},
2376
        {table => 'author', info => {...}}
2377
    ]
2378

            
2379
Usually, you can set return value of C<get_table_info>.
2380

            
2381
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2382
    $dbi->user_table_info($user_table_info);
2383

            
2384
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2385
to find table info.
2386

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2423
Create column clause. The follwoing column clause is created.
2424

            
2425
    book.author as "book.author",
2426
    book.title as "book.title"
2427

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2430
    # Separator is hyphen
2431
    $dbi->separator('-');
2432
    
2433
    book.author as "book-author",
2434
    book.title as "book-title"
2435
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2436
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2437

            
update pod
Yuki Kimoto authored on 2011-03-13
2438
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2439
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2440
        user => 'ken',
2441
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2442
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2443
    );
2444

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

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

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

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

            
2455
Get rows count.
2456

            
2457
Options is same as C<select> method's ones.
2458

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2461
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2462
        table => 'book',
2463
        primary_key => 'id',
2464
        join => [
2465
            'inner join company on book.comparny_id = company.id'
2466
        ],
2467
    );
2468

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

            
2472
   $dbi->model('book')->select(...);
2473

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

            
2476
    my $dbh = $dbi->dbh;
2477

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

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

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

            
2485
Execute delete statement.
2486

            
2487
The following opitons are available.
2488

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

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

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

            
2496
=item C<id>
2497

            
2498
    id => 4
2499
    id => [4, 5]
2500

            
2501
ID corresponding to C<primary_key>.
2502
You can delete rows by C<id> and C<primary_key>.
2503

            
2504
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2505
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2506
        id => [4, 5],
2507
        table => 'book',
2508
    );
2509

            
2510
The above is same as the followin one.
2511

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

            
2514
=item C<prefix>
2515

            
2516
    prefix => 'some'
2517

            
2518
prefix before table name section.
2519

            
2520
    delete some from book
2521

            
2522
=item C<table>
2523

            
2524
    table => 'book'
2525

            
2526
Table name.
2527

            
2528
=item C<where>
2529

            
2530
Same as C<select> method's C<where> option.
2531

            
2532
=back
2533

            
2534
=head2 C<delete_all>
2535

            
2536
    $dbi->delete_all(table => $table);
2537

            
2538
Execute delete statement for all rows.
2539
Options is same as C<delete>.
2540

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

            
2543
    $dbi->each_column(
2544
        sub {
2545
            my ($dbi, $table, $column, $column_info) = @_;
2546
            
2547
            my $type = $column_info->{TYPE_NAME};
2548
            
2549
            if ($type eq 'DATE') {
2550
                # ...
2551
            }
2552
        }
2553
    );
2554

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

            
2560
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2561
infromation, you can improve the performance of C<each_column> in
2562
the following way.
2563

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

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

            
2570
    $dbi->each_table(
2571
        sub {
2572
            my ($dbi, $table, $table_info) = @_;
2573
            
2574
            my $table_name = $table_info->{TABLE_NAME};
2575
        }
2576
    );
2577

            
improved pod
Yuki Kimoto authored on 2011-10-14
2578
Iterate all table informationsfrom in database.
2579
Argument is callback which is executed when one table is found.
2580
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2581
C<table information>.
2582

            
2583
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2584
infromation, you can improve the performance of C<each_table> in
2585
the following way.
2586

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

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

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

            
2598
    my $result = $dbi->execute(
2599
      "select * from book where title = :book.title and author like :book.author",
2600
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2601
    );
2602

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2609
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2610
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2611
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2612
    select * from book where title = :title and author like :author
2613
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2614
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2615
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2616

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2620
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2621
    select * from book where :title{=} and :author{like}
2622
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2623
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2624
    select * from where title = ? and author like ?;
2625

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

            
2630
    select * from where title = "aa\\:bb";
2631

            
cleanup
Yuki Kimoto authored on 2011-10-20
2632
B<OPTIONS>
2633

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

            
2636
=over 4
2637

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

            
2640
You can filter sql after the sql is build.
2641

            
2642
    after_build_sql => $code_ref
2643

            
2644
The following one is one example.
2645

            
2646
    $dbi->select(
2647
        table => 'book',
2648
        column => 'distinct(name)',
2649
        after_build_sql => sub {
2650
            "select count(*) from ($_[0]) as t1"
2651
        }
2652
    );
2653

            
2654
The following SQL is executed.
2655

            
2656
    select count(*) from (select distinct(name) from book) as t1;
2657

            
cleanup
Yuki Kimoto authored on 2011-10-20
2658
=item C<append>
2659

            
2660
    append => 'order by name'
2661

            
2662
Append some statement after SQL.
2663

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

            
2666
Specify database bind data type.
2667

            
2668
    bind_type => [image => DBI::SQL_BLOB]
2669
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2670

            
2671
This is used to bind parameter by C<bind_param> of statment handle.
2672

            
2673
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2674

            
update pod
Yuki Kimoto authored on 2011-03-13
2675
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2676
    
2677
    filter => {
2678
        title  => sub { uc $_[0] }
2679
        author => sub { uc $_[0] }
2680
    }
update pod
Yuki Kimoto authored on 2011-03-13
2681

            
updated pod
Yuki Kimoto authored on 2011-06-09
2682
    # Filter name
2683
    filter => {
2684
        title  => 'upper_case',
2685
        author => 'upper_case'
2686
    }
2687
        
2688
    # At once
2689
    filter => [
2690
        [qw/title author/]  => sub { uc $_[0] }
2691
    ]
2692

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

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

            
2700
    query => 1
2701

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2705
    my $sql = $query->{sql};
2706
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2707
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2708
=item C<reuse>
2709
    
2710
    reuse => $hash_ref
2711

            
2712
Reuse query object if the hash reference variable is set.
2713
    
2714
    my $queries = {};
2715
    $dbi->execute($sql, $param, reuse => $queries);
2716

            
2717
This will improved performance when you want to execute same query repeatedly
2718
because generally creating query object is slow.
2719

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2722
    primary_key => 'id'
2723
    primary_key => ['id1', 'id2']
2724

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2727
=item C<table>
2728
    
2729
    table => 'author'
2730

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2738
    # Same
2739
    $dbi->execute(
2740
      "select * from book where title = :book.title and author = :book.author",
2741
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2742

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

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

            
2747
Table alias. Key is real table name, value is alias table name.
2748
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2749
on alias table name.
2750

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

            
2753
    type_rule_off => 1
2754

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

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

            
2759
    type_rule1_off => 1
2760

            
2761
Turn C<into1> type rule off.
2762

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

            
2765
    type_rule2_off => 1
2766

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

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

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

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

            
2775
get column infomation except for one which match C<exclude_table> pattern.
2776

            
2777
    [
2778
        {table => 'book', column => 'title', info => {...}},
2779
        {table => 'author', column => 'name' info => {...}}
2780
    ]
2781

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

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

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

            
2788
    [
2789
        {table => 'book', info => {...}},
2790
        {table => 'author', info => {...}}
2791
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2792

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

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

            
2797
    $dbi->helper(
2798
        find_or_create   => sub {
2799
            my $self = shift;
2800
            
2801
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2802
        },
2803
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2804
    );
2805

            
2806
Register helper. These helper is called directly from L<DBIx::Custom> object.
2807

            
2808
    $dbi->find_or_create;
2809

            
cleanup
yuki-kimoto authored on 2010-10-17
2810
=head2 C<insert>
2811

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

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

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

            
2820
    {date => \"NOW()"}
2821

            
updated pod
Yuki Kimoto authored on 2011-11-25
2822
You can pass multiple parameters, this is very fast.
2823
This is EXPERIMETNAL.
2824

            
2825
    $dbi->insert(
2826
        [
2827
            {title => 'Perl', author => 'Ken'},
2828
            {title => 'Ruby', author => 'Tom'}
2829
        ],
2830
        table  => 'book'
2831
    );
2832

            
2833
In multiple insert, you can't use C<id> option.
2834
and only first parameter is used by creating sql.
2835

            
cleanup
Yuki Kimoto authored on 2011-10-20
2836
B<options>
2837

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2841
=over 4
improved bulk_insert perform...
Yuki Kimoto authored on 2011-11-29
2842
b
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
2843
=item C<bulk_insert> EXPERIMENTAL
2844

            
2845
    bulk_insert => 1
2846

            
2847
bulk insert is executed if database support bulk insert and 
2848
multiple parameters is passed to C<insert>.
2849
The SQL like the following one is executed.
2850

            
2851
    insert into book (id, title) values (?, ?), (?, ?);
2852

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

            
2855
    created_at => 'created_datetime'
2856

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2863
    id => 4
2864
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2865

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2869
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2870
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2871
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2872
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2873
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2874
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2875

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

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

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

            
2885
    prefix => 'or replace'
2886

            
2887
prefix before table name section
2888

            
2889
    insert or replace into book
2890

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

            
2893
    table => 'book'
2894

            
2895
Table name.
2896

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

            
2899
This option is same as C<update> method C<updated_at> option.
2900

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

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

            
2905
placeholder wrapped string.
2906

            
2907
If the following statement
2908

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

            
2912
is executed, the following SQL is executed.
2913

            
2914
    insert into book price values ( ? + 5 );
2915

            
update pod
Yuki Kimoto authored on 2011-03-13
2916
=back
2917

            
2918
=over 4
2919

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2927
    lib / MyModel.pm
2928
        / MyModel / book.pm
2929
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2930

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

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

            
2935
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2936
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2937
    
2938
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2939

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2944
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2945
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2946
    
2947
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2948

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2951
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2952
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2953
    
2954
    1;
2955
    
updated pod
Yuki Kimoto authored on 2011-06-21
2956
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2957

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

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

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

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

            
2967
    my $like_value = $dbi->like_value
2968

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

            
2971
    sub { "%$_[0]%" }
2972

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

            
2975
    my $mapper = $dbi->mapper(param => $param);
2976

            
2977
Create a new L<DBIx::Custom::Mapper> object.
2978

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

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

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

            
2985
    {key1 => [1, 1], key2 => 2}
2986

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

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

            
2991
    my $model = $dbi->model('book');
2992

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

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

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

            
3000
Create column clause for myself. The follwoing column clause is created.
3001

            
3002
    book.author as author,
3003
    book.title as title
3004

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

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

            
3014
Create a new L<DBIx::Custom> object.
3015

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

            
3018
    my $not_exists = $dbi->not_exists;
3019

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

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

            
3025
    my $order = $dbi->order;
3026

            
3027
Create a new L<DBIx::Custom::Order> object.
3028

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

            
3031
    my $quooted = $dbi->q("title");
3032

            
3033
Quote string by value of C<quote>.
3034

            
cleanup
yuki-kimoto authored on 2010-10-17
3035
=head2 C<register_filter>
3036

            
update pod
Yuki Kimoto authored on 2011-03-13
3037
    $dbi->register_filter(
3038
        # Time::Piece object to database DATE format
3039
        tp_to_date => sub {
3040
            my $tp = shift;
3041
            return $tp->strftime('%Y-%m-%d');
3042
        },
3043
        # database DATE format to Time::Piece object
3044
        date_to_tp => sub {
3045
           my $date = shift;
3046
           return Time::Piece->strptime($date, '%Y-%m-%d');
3047
        }
3048
    );
cleanup
yuki-kimoto authored on 2010-10-17
3049
    
update pod
Yuki Kimoto authored on 2011-03-13
3050
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3051

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3054
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3055
        column => ['author', 'title'],
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
3056
        table  => 'book',
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3057
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3058
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3059
    
updated document
Yuki Kimoto authored on 2011-06-09
3060
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3061

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3074
=item C<column>
3075
    
updated document
Yuki Kimoto authored on 2011-06-09
3076
    column => 'author'
3077
    column => ['author', 'title']
3078

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3087
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3088
        {book => [qw/author title/]},
3089
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3090
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3091

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

            
3094
    book.author as "book.author",
3095
    book.title as "book.title",
3096
    person.name as "person.name",
3097
    person.age as "person.age"
3098

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

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

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

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

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

            
3112
    id => 4
3113
    id => [4, 5]
3114

            
3115
ID corresponding to C<primary_key>.
3116
You can select rows by C<id> and C<primary_key>.
3117

            
3118
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3119
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3120
        id => [4, 5],
3121
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3122
    );
3123

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3126
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3127
        where => {id1 => 4, id2 => 5},
3128
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3129
    );
3130
    
cleanup
Yuki Kimoto authored on 2011-10-20
3131
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3132

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

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

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

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

            
3145
    prefix => 'SQL_CALC_FOUND_ROWS'
3146

            
3147
Prefix of column cluase
3148

            
3149
    select SQL_CALC_FOUND_ROWS title, author from book;
3150

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

            
3153
    join => [
3154
        'left outer join company on book.company_id = company_id',
3155
        'left outer join location on company.location_id = location.id'
3156
    ]
3157
        
3158
Join clause. If column cluase or where clause contain table name like "company.name",
3159
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3160

            
3161
    $dbi->select(
3162
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3163
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3164
        where => {'company.name' => 'Orange'},
3165
        join => [
3166
            'left outer join company on book.company_id = company.id',
3167
            'left outer join location on company.location_id = location.id'
3168
        ]
3169
    );
3170

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3174
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3175
    from book
3176
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3177
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3178

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3179
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
3180
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3181

            
3182
    $dbi->select(
3183
        table => 'book',
3184
        column => ['company.location_id as location_id'],
3185
        where => {'company.name' => 'Orange'},
3186
        join => [
3187
            {
3188
                clause => 'left outer join location on company.location_id = location.id',
3189
                table => ['company', 'location']
3190
            }
3191
        ]
3192
    );
3193

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3198
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3199

            
updated document
Yuki Kimoto authored on 2011-06-09
3200
=item C<where>
3201
    
3202
    # Hash refrence
3203
    where => {author => 'Ken', 'title' => 'Perl'}
3204
    
3205
    # DBIx::Custom::Where object
3206
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3207
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3208
        param  => {author => 'Ken', title => '%Perl%'}
3209
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3210
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3211
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3212
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3213
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3214
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3215
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3216
    
3217
    # String
3218
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3219

            
cleanup
Yuki Kimoto authored on 2011-10-20
3220
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3221
    
update pod
Yuki Kimoto authored on 2011-03-12
3222
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3223

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

            
3226
    $dbi->setup_model;
3227

            
3228
Setup all model objects.
3229
C<columns> of model object is automatically set, parsing database information.
3230

            
3231
=head2 C<type_rule>
3232

            
3233
    $dbi->type_rule(
3234
        into1 => {
3235
            date => sub { ... },
3236
            datetime => sub { ... }
3237
        },
3238
        into2 => {
3239
            date => sub { ... },
3240
            datetime => sub { ... }
3241
        },
3242
        from1 => {
3243
            # DATE
3244
            9 => sub { ... },
3245
            # DATETIME or TIMESTAMP
3246
            11 => sub { ... },
3247
        }
3248
        from2 => {
3249
            # DATE
3250
            9 => sub { ... },
3251
            # DATETIME or TIMESTAMP
3252
            11 => sub { ... },
3253
        }
3254
    );
3255

            
3256
Filtering rule when data is send into and get from database.
3257
This has a little complex problem.
3258

            
3259
In C<into1> and C<into2> you can specify
3260
type name as same as type name defined
3261
by create table, such as C<DATETIME> or C<DATE>.
3262

            
3263
Note that type name and data type don't contain upper case.
3264
If these contain upper case charactor, you convert it to lower case.
3265

            
3266
C<into2> is executed after C<into1>.
3267

            
3268
Type rule of C<into1> and C<into2> is enabled on the following
3269
column name.
3270

            
3271
=over 4
3272

            
3273
=item 1. column name
3274

            
3275
    issue_date
3276
    issue_datetime
3277

            
3278
This need C<table> option in each method.
3279

            
3280
=item 2. table name and column name, separator is dot
3281

            
3282
    book.issue_date
3283
    book.issue_datetime
3284

            
3285
=back
3286

            
3287
You get all type name used in database by C<available_typename>.
3288

            
3289
    print $dbi->available_typename;
3290

            
3291
In C<from1> and C<from2> you specify data type, not type name.
3292
C<from2> is executed after C<from1>.
3293
You get all data type by C<available_datatype>.
3294

            
3295
    print $dbi->available_datatype;
3296

            
3297
You can also specify multiple types at once.
3298

            
3299
    $dbi->type_rule(
3300
        into1 => [
3301
            [qw/DATE DATETIME/] => sub { ... },
3302
        ],
3303
    );
3304

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

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

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

            
3311
If you want to set constant value to row data, use scalar reference
3312
as parameter value.
3313

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3325
    id => 4
3326
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3327

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3331
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3332
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3333
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3334
        id => [4, 5],
3335
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3336
    );
update pod
Yuki Kimoto authored on 2011-03-13
3337

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3340
    $dbi->update(
3341
        {title => 'Perl', author => 'Ken'}
3342
        where => {id1 => 4, id2 => 5},
3343
        table => 'book'
3344
    );
update pod
Yuki Kimoto authored on 2011-03-13
3345

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

            
3348
    prefix => 'or replace'
3349

            
3350
prefix before table name section
3351

            
3352
    update or replace book
3353

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

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

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

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

            
3362
Same as C<select> method's C<where> option.
3363

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

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

            
3368
placeholder wrapped string.
3369

            
3370
If the following statement
3371

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

            
3375
is executed, the following SQL is executed.
3376

            
3377
    update book set price =  ? + 5;
3378

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

            
3381
    updated_at => 'updated_datetime'
3382

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3387
=back
update pod
Yuki Kimoto authored on 2011-03-13
3388

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3396
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3397
    
3398
    # ID
3399
    $dbi->update_or_insert(
3400
        {title => 'Perl'},
3401
        table => 'book',
3402
        id => 1,
3403
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3404
        option => {
3405
            select => {
3406
                 append => 'for update'
3407
            }
3408
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3409
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3410

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3411
Update or insert.
3412

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3417
C<OPTIONS>
3418

            
3419
C<update_or_insert> method use all common option
3420
in C<select>, C<update>, C<delete>, and has the following new ones.
3421

            
3422
=over 4
3423

            
3424
=item C<option>
3425

            
3426
    option => {
3427
        select => {
3428
            append => '...'
3429
        },
3430
        insert => {
3431
            prefix => '...'
3432
        },
3433
        update => {
3434
            filter => {}
3435
        }
3436
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3437

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

            
3441
=over 4
3442

            
3443
=item C<select_option>
3444

            
3445
    select_option => {append => 'for update'}
3446

            
3447
select method option,
3448
select method is used to check the row is already exists.
3449

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

            
3452
    $dbi->show_datatype($table);
3453

            
3454
Show data type of the columns of specified table.
3455

            
3456
    book
3457
    title: 5
3458
    issue_date: 91
3459

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

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

            
3464
    $dbi->show_tables;
3465

            
3466
Show tables.
3467

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

            
3470
    $dbi->show_typename($table);
3471

            
3472
Show type name of the columns of specified table.
3473

            
3474
    book
3475
    title: varchar
3476
    issue_date: date
3477

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

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

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

            
3484
Create values clause.
3485

            
3486
    (title, author) values (title = :title, age = :age);
3487

            
3488
You can use this in insert statement.
3489

            
3490
    my $insert_sql = "insert into book $values_clause";
3491

            
3492
=head2 C<where>
3493

            
3494
    my $where = $dbi->where(
3495
        clause => ['and', 'title = :title', 'author = :author'],
3496
        param => {title => 'Perl', author => 'Ken'}
3497
    );
3498

            
3499
Create a new L<DBIx::Custom::Where> object.
3500

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

            
3503
=head2 C<DBIX_CUSTOM_DEBUG>
3504

            
3505
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3506
executed SQL and bind values are printed to STDERR.
3507

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

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

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

            
3514
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3515

            
3516
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3517

            
3518
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3519
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3520

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

            
3523
L<DBIx::Custom>
3524

            
3525
    # Attribute methods
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3526
    tag_parse # will be removed 2017/1/1
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3527
    default_dbi_option # will be removed 2017/1/1
3528
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3529
    data_source # will be removed at 2017/1/1
3530
    dbi_options # will be removed at 2017/1/1
3531
    filter_check # will be removed at 2017/1/1
3532
    reserved_word_quote # will be removed at 2017/1/1
3533
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3534
    
3535
    # Methods
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3536
    update_timestamp # will be removed at 2017/1/1
3537
    insert_timestamp # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3538
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3539
    assign_param # will be removed at 2017/1/1
3540
    update_param # will be removed at 2017/1/1
3541
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3542
    create_query # will be removed at 2017/1/1
3543
    apply_filter # will be removed at 2017/1/1
3544
    select_at # will be removed at 2017/1/1
3545
    delete_at # will be removed at 2017/1/1
3546
    update_at # will be removed at 2017/1/1
3547
    insert_at # will be removed at 2017/1/1
3548
    register_tag # will be removed at 2017/1/1
3549
    default_bind_filter # will be removed at 2017/1/1
3550
    default_fetch_filter # will be removed at 2017/1/1
3551
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3552
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3553
    register_tag_processor # will be removed at 2017/1/1
3554
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3555
    
3556
    # Options
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
3557
    select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
3558
    execute method id option # will be removed 2017/1/1
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3559
    update timestamp option # will be removed 2017/1/1
3560
    insert timestamp option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3561
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3562
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3563
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3564
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3565
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3566
    select method relation option # will be removed at 2017/1/1
3567
    select method column option [COLUMN, as => ALIAS] format
3568
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3569
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3570
    
3571
    # Others
micro optimization and
Yuki Kimoto authored on 2011-10-25
3572
    execute($query, ...) # execute method receiving query object.
3573
                         # this is removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2011-07-28
3574
    execute("select * from {= title}"); # execute method's
3575
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3576
                                        # will be removed at 2017/1/1
3577
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3578

            
3579
L<DBIx::Custom::Model>
3580

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3581
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3582
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3583
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3584
    filter # will be removed at 2017/1/1
3585
    name # will be removed at 2017/1/1
3586
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3587

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

            
3590
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3591
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3592
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3593
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3594
    table # will be removed at 2017/1/1
3595
    filters # will be removed at 2017/1/1
3596
    
3597
    # Methods
3598
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3599

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

            
3602
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3603
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3604
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3605
    tags # will be removed at 2017/1/1
3606
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3607
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3608
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3609
    register_tag # will be removed at 2017/1/1
3610
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3611
    
3612
    # Others
3613
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3614
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3615

            
3616
L<DBIx::Custom::Result>
3617
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3618
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3619
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3620
    
3621
    # Methods
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
3622
    fetch_first # will be removed at 2017/2/1
3623
    fetch_hash_first # will be removed 2017/2/1
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3624
    filter_on # will be removed at 2017/1/1
3625
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3626
    end_filter # will be removed at 2017/1/1
3627
    remove_end_filter # will be removed at 2017/1/1
3628
    remove_filter # will be removed at 2017/1/1
3629
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3630

            
3631
L<DBIx::Custom::Tag>
3632

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

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

            
3637
    # Other
3638
    prepend method array reference receiving
3639
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3640

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

            
3643
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3644
except for attribute method.
3645
You can check all DEPRECATED functionalities by document.
3646
DEPRECATED functionality is removed after five years,
3647
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
3648
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3649

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

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

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

            
3656
C<< <kimoto.yuki at gmail.com> >>
3657

            
3658
L<http://github.com/yuki-kimoto/DBIx-Custom>
3659

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3660
=head1 AUTHOR
3661

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

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

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

            
3668
This program is free software; you can redistribute it and/or modify it
3669
under the same terms as Perl itself.
3670

            
3671
=cut