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

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
4
our $VERSION = '0.2103';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
520
            # Execute
521
            eval {
522
                if ($opt{bind_type} || $opt{type}) {
523
                    $sth->bind_param($_ + 1, $bind->[$_],
524
                        $bind_types->[$_] ? $bind_types->[$_] : ())
525
                      for (0 .. @$bind - 1);
526
                    $affected = $sth->execute;
527
                }
528
                else {
529
                    $affected = $sth->execute(@$bind);
530
                }
micro optimization
Yuki Kimoto authored on 2011-11-16
531

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

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

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

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

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
619
sub helper {
620
    my $self = shift;
621
    
622
    # Register method
623
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
624
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
625
    
626
    return $self;
627
}
628

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

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

            
700
    # Remove id from parameter
cleanup
Yuki Kimoto authored on 2011-11-25
701
    delete $params->[0]->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
702
    
703
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
704
    $opt{statement} = 'insert';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
705
    $opt{cleanup} = \@timestamp_cleanup;
cleanup
Yuki Kimoto authored on 2011-11-25
706
    $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
707
}
708

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
709
sub insert_timestamp {
710
    my $self = shift;
711
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
712
    warn "insert_timestamp method is DEPRECATED! use now attribute";
713
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
714
    if (@_) {
715
        $self->{insert_timestamp} = [@_];
716
        
717
        return $self;
718
    }
719
    return $self->{insert_timestamp};
720
}
721

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
722
sub include_model {
723
    my ($self, $name_space, $model_infos) = @_;
724
    
cleanup
Yuki Kimoto authored on 2011-04-02
725
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
726
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
727
    
728
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
729
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
730

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
789
sub mapper {
790
    my $self = shift;
791
    return DBIx::Custom::Mapper->new(@_);
792
}
793

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
794
sub merge_param {
795
    my ($self, @params) = @_;
796
    
cleanup
Yuki Kimoto authored on 2011-04-02
797
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
798
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
799
    for my $param (@params) {
800
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
801
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
802
            
803
            if (exists $merge->{$column}) {
804
                $merge->{$column} = [$merge->{$column}]
805
                  unless ref $merge->{$column} eq 'ARRAY';
806
                push @{$merge->{$column}},
807
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
808
            }
809
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
810
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
811
            }
812
        }
813
    }
814
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
815
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
816
}
817

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
818
sub model {
819
    my ($self, $name, $model) = @_;
820
    
cleanup
Yuki Kimoto authored on 2011-04-02
821
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
822
    if ($model) {
823
        $self->models->{$name} = $model;
824
        return $self;
825
    }
826
    
827
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
828
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
829
      unless $self->models->{$name};
830
    
cleanup
Yuki Kimoto authored on 2011-04-02
831
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
832
    return $self->models->{$name};
833
}
834

            
cleanup
Yuki Kimoto authored on 2011-03-21
835
sub mycolumn {
836
    my ($self, $table, $columns) = @_;
837
    
cleanup
Yuki Kimoto authored on 2011-04-02
838
    # Create column clause
839
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
840
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
841
    push @column, $self->q($table) . "." . $self->q($_) .
842
      " as " . $self->q($_)
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
843
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
844
    
845
    return join (', ', @column);
846
}
847

            
added dbi_options attribute
kimoto authored on 2010-12-20
848
sub new {
849
    my $self = shift->SUPER::new(@_);
850
    
cleanup
Yuki Kimoto authored on 2011-04-02
851
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
852
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
853
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
854
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
855
          unless $self->can($attr);
856
    }
cleanup
Yuki Kimoto authored on 2011-11-18
857
    
858
    $self->{safety_character} = 'a-zA-Z0-9_'
859
      unless exists $self->{safety_character};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
860

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
861
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
862
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
863
        '?'     => \&DBIx::Custom::Tag::placeholder,
864
        '='     => \&DBIx::Custom::Tag::equal,
865
        '<>'    => \&DBIx::Custom::Tag::not_equal,
866
        '>'     => \&DBIx::Custom::Tag::greater_than,
867
        '<'     => \&DBIx::Custom::Tag::lower_than,
868
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
869
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
870
        'like'  => \&DBIx::Custom::Tag::like,
871
        'in'    => \&DBIx::Custom::Tag::in,
872
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
873
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
874
    };
cleanup
Yuki Kimoto authored on 2011-11-18
875
    $self->{tag_parse} = 1 unless exists $self->{tag_parse};
876
    $self->{cache} = 0 unless exists $self->{cache};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
877
    
cleanup
Yuki Kimoto authored on 2011-08-13
878
    return $self;
879
}
880

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

            
883
sub order {
884
    my $self = shift;
885
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
886
}
887

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
888
sub q {
889
    my ($self, $value, $quotemeta) = @_;
890
    
891
    my $quote = $self->{reserved_word_quote}
892
      || $self->{quote} || $self->quote || '';
893
    return "$quote$value$quote"
894
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
895
    
896
    my $q = substr($quote, 0, 1) || '';
897
    my $p;
898
    if (defined $quote && length $quote > 1) {
899
        $p = substr($quote, 1, 1);
900
    }
901
    else { $p = $q }
902
    
903
    if ($quotemeta) {
904
        $q = quotemeta($q);
905
        $p = quotemeta($p);
906
    }
907
    
908
    return "$q$value$p";
909
}
910

            
cleanup
yuki-kimoto authored on 2010-10-17
911
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
912
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
913
    
914
    # Register filter
915
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
916
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
917
    
cleanup
Yuki Kimoto authored on 2011-04-02
918
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
919
}
packaging one directory
yuki-kimoto authored on 2009-11-16
920

            
921
sub select {
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
922
    my $self = shift;
923
    my $column = shift if @_ % 2;
924
    my %opt = @_;
925
    $opt{column} = $column if defined $column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
926

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1015
sub setup_model {
1016
    my $self = shift;
1017
    
cleanup
Yuki Kimoto authored on 2011-04-02
1018
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1019
    $self->each_column(
1020
        sub {
1021
            my ($self, $table, $column, $column_info) = @_;
1022
            if (my $model = $self->models->{$table}) {
1023
                push @{$model->columns}, $column;
1024
            }
1025
        }
1026
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1027
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1028
}
1029

            
update pod
Yuki Kimoto authored on 2011-08-10
1030
sub show_datatype {
1031
    my ($self, $table) = @_;
1032
    croak "Table name must be specified" unless defined $table;
1033
    print "$table\n";
1034
    
1035
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1036
    my $sth = $result->sth;
1037

            
1038
    my $columns = $sth->{NAME};
1039
    my $data_types = $sth->{TYPE};
1040
    
1041
    for (my $i = 0; $i < @$columns; $i++) {
1042
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1043
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1044
        print "$column: $data_type\n";
1045
    }
1046
}
1047

            
1048
sub show_typename {
1049
    my ($self, $t) = @_;
1050
    croak "Table name must be specified" unless defined $t;
1051
    print "$t\n";
1052
    
1053
    $self->each_column(sub {
1054
        my ($self, $table, $column, $infos) = @_;
1055
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1056
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1057
        print "$column: $typename\n";
1058
    });
1059
    
1060
    return $self;
1061
}
1062

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1063
sub show_tables {
1064
    my $self = shift;
1065
    
1066
    my %tables;
1067
    $self->each_table(sub { $tables{$_[1]}++ });
1068
    print join("\n", sort keys %tables) . "\n";
1069
    return $self;
1070
}
1071

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1109
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1110
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1111
                }
1112
            });
1113
        }
1114

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

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1162
    # Created time and updated time
1163
    my @timestamp_cleanup;
1164
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1165
        my $now = $self->now;
1166
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1167
        $param->{$opt{updated_at}} = $self->now->();
1168
        push @timestamp_cleanup, $opt{updated_at};
1169
    }
1170

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

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

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

            
1197
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1198
    if (@$rows == 0) {
1199
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1200
    }
1201
    elsif (@$rows == 1) {
- fixed update_or_insert bug...
Yuki Kimoto authored on 2011-11-18
1202
        return 0 unless keys %$param;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1203
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1204
    }
1205
    else {
1206
        croak "selected row must be one " . _subname;
1207
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1208
}
1209

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1210
sub update_timestamp {
1211
    my $self = shift;
1212
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1213
    warn "update_timestamp method is DEPRECATED! use now method";
1214
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1215
    if (@_) {
1216
        $self->{update_timestamp} = [@_];
1217
        
1218
        return $self;
1219
    }
1220
    return $self->{update_timestamp};
1221
}
1222

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1223
sub values_clause {
1224
    my ($self, $param, $opts) = @_;
1225
    
1226
    my $wrap = $opts->{wrap} || {};
1227
    
1228
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-11-16
1229
    my ($q, $p) = split //, $self->q('');
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1230
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1231
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1232
    '(' .
1233
    join(
1234
      ', ',
1235
      map { "$q$_$p" } sort keys %$param
1236
    ) .
1237
    ') values (' .
1238
    join(
1239
      ', ',
1240
      map {
1241
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1242
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1243
          ":$_";
1244
      } sort keys %$param
1245
    ) .
1246
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1247
}
1248

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1249
sub _multi_values_clause {
1250
    my ($self, $params, $opts) = @_;
1251
    
1252
    my $wrap = $opts->{wrap} || {};
1253
    
1254
    # Create insert parameter tag
1255
    my ($q, $p) = split //, $self->q('');
1256
    
1257
    # Multi values clause
1258
    my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1259
    
1260
    for (1 .. @$params) {
1261
        $clause .= '(' . join(', ', 
1262
          map {
1263
              ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1264
              $wrap->{$_} ? $wrap->{$_}->(":$_") :
1265
              ":$_";
1266
          } sort keys %{$params->[0]}
1267
        ) . '), '
1268
    }
1269
    $clause =~ s/, $//;
1270
    return $clause;
1271
}
1272

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

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

            
1301
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-18
1302
        my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1303
          ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1304

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

            
1329
            # Create query
micro optimization
Yuki Kimoto authored on 2011-11-18
1330
            $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
cleanup
Yuki Kimoto authored on 2011-11-16
1331
        }
cleanup
Yuki Kimoto authored on 2011-11-16
1332
        
updated pod
Yuki Kimoto authored on 2011-06-21
1333
        # Save query to cache
1334
        $self->cache_method->(
1335
            $self, $source,
1336
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1337
                sql     => $query->{sql}, 
1338
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1339
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1340
            }
1341
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1342
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1343

            
1344
    # Filter SQL
micro optimization
Yuki Kimoto authored on 2011-11-16
1345
    $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1346
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1347
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1348
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1349
    
updated pod
Yuki Kimoto authored on 2011-06-21
1350
    # Prepare statement handle
1351
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1352
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1353
    
1354
    if ($@) {
1355
        $self->_croak($@, qq{. Following SQL is executed.\n}
1356
                        . qq{$query->{sql}\n} . _subname);
1357
    }
1358
    
1359
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1360
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1361
    
1362
    # Set filters
cleanup
Yuki Kimoto authored on 2011-11-16
1363
    $query->{filters} = $self->{filters} || $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1364
    
1365
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1366
}
1367

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1479
sub _croak {
1480
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1481
    
1482
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1483
    $append ||= "";
1484
    
1485
    # Verbose
1486
    if ($Carp::Verbose) { croak $error }
1487
    
1488
    # Not verbose
1489
    else {
1490
        
1491
        # Remove line and module infromation
1492
        my $at_pos = rindex($error, ' at ');
1493
        $error = substr($error, 0, $at_pos);
1494
        $error =~ s/\s+$//;
1495
        croak "$error$append";
1496
    }
1497
}
1498

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1501
sub _need_tables {
1502
    my ($self, $tree, $need_tables, $tables) = @_;
1503
    
cleanup
Yuki Kimoto authored on 2011-04-02
1504
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1505
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1506
        if ($tree->{$table}) {
1507
            $need_tables->{$table} = 1;
1508
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1509
        }
1510
    }
1511
}
1512

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1513
sub _option {
1514
    my $self = shift;
1515
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1516
    warn "dbi_options is DEPRECATED! use option instead\n"
1517
      if keys %{$self->dbi_options};
1518
    warn "dbi_option is DEPRECATED! use option instead\n"
1519
      if keys %{$self->dbi_option};
1520
    return $option;
1521
}
1522

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1594
sub _quote {
1595
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1596
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1597
}
1598

            
cleanup
Yuki Kimoto authored on 2011-04-02
1599
sub _remove_duplicate_table {
1600
    my ($self, $tables, $main_table) = @_;
1601
    
1602
    # Remove duplicate table
1603
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1604
    delete $tables{$main_table} if $main_table;
1605
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1606
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1607
    if (my $q = $self->_quote) {
1608
        $q = quotemeta($q);
1609
        $_ =~ s/[$q]//g for @$new_tables;
1610
    }
1611

            
1612
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1613
}
1614

            
cleanup
Yuki Kimoto authored on 2011-04-02
1615
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1616
    my ($self, $source) = @_;
1617
    
cleanup
Yuki Kimoto authored on 2011-04-02
1618
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1619
    my $tables = [];
cleanup
Yuki Kimoto authored on 2011-11-18
1620
    my $safety_character = $self->{safety_character};
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1621
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1622
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1623
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1624
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1625
    while ($source =~ /$table_re/g) {
1626
        push @$tables, $1;
1627
    }
1628
    
1629
    return $tables;
1630
}
1631

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1635
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1636
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1637
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1638
    my $w = {};
1639
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1640

            
cleanup
Yuki Kimoto authored on 2011-10-25
1641
    my $obj;
1642
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1643
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1644
        if (ref $where eq 'HASH') {
1645
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1646
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1647
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1648
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1649
                my $table;
1650
                my $c;
1651
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1652
                    $table = $1;
1653
                    $c = $2;
1654
                }
1655
                
1656
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1657
                $table_quote = $self->q($table) if defined $table;
1658
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1659
                $column_quote = $table_quote . '.' . $column_quote
1660
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1661
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1662
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1663

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

            
1686
        $w->{param} = keys %$where_param
1687
                    ? $self->merge_param($where_param, $obj->param)
1688
                    : $obj->param;
1689
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1690
    }
1691
    elsif ($where) {
1692
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1693
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1694
    }
1695
    
1696
    return $w;
1697
}
1698

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1769
# DEPRECATED!
1770
has 'data_source';
1771
has dbi_options => sub { {} };
1772
has filter_check  => 1;
1773
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1774
has dbi_option => sub { {} };
1775
has default_dbi_option => sub {
1776
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1777
    return shift->default_option;
1778
};
1779

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1780
# DEPRECATED
1781
sub tag_parse {
1782
   my $self = shift;
1783
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1784
         "environment variable";
1785
    if (@_) {
1786
        $self->{tag_parse} = $_[0];
1787
        return $self;
1788
    }
1789
    return $self->{tag_parse};
1790
}
1791

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1792
# DEPRECATED!
1793
sub method {
1794
    warn "method is DEPRECATED! use helper instead";
1795
    return shift->helper(@_);
1796
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1797

            
1798
# DEPRECATED!
1799
sub assign_param {
1800
    my $self = shift;
1801
    warn "assing_param is DEPRECATED! use assign_clause instead";
1802
    return $self->assign_clause(@_);
1803
}
1804

            
1805
# DEPRECATED
1806
sub update_param {
1807
    my ($self, $param, $opts) = @_;
1808
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1809
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1810
    
1811
    # Create update parameter tag
1812
    my $tag = $self->assign_clause($param, $opts);
1813
    $tag = "set $tag" unless $opts->{no_set};
1814

            
1815
    return $tag;
1816
}
1817

            
updated pod
Yuki Kimoto authored on 2011-06-21
1818
# DEPRECATED!
1819
sub create_query {
1820
    warn "create_query is DEPRECATED! use query option of each method";
1821
    shift->_create_query(@_);
1822
}
1823

            
cleanup
Yuki Kimoto authored on 2011-06-13
1824
# DEPRECATED!
1825
sub apply_filter {
1826
    my $self = shift;
1827
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1828
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1829
    return $self->_apply_filter(@_);
1830
}
1831

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1838
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1839
    my $primary_keys = delete $opt{primary_key};
1840
    my $where = delete $opt{where};
1841
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1842
    
1843
    # Table
1844
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1845
      unless $opt{table};
1846
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1847
    
1848
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1849
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1850
    
cleanup
Yuki Kimoto authored on 2011-10-21
1851
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1852
}
1853

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1858
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1859
    
cleanup
Yuki Kimoto authored on 2011-10-21
1860
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1861
    my $primary_keys = delete $opt{primary_key};
1862
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1863
    
1864
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1865
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1866
    
cleanup
Yuki Kimoto authored on 2011-10-21
1867
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1868
}
1869

            
cleanup
Yuki Kimoto authored on 2011-06-08
1870
# DEPRECATED!
1871
sub update_at {
1872
    my $self = shift;
1873

            
cleanup
Yuki Kimoto authored on 2011-10-21
1874
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1875
    
cleanup
Yuki Kimoto authored on 2011-10-21
1876
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1877
    my $param;
1878
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1879
    my %opt = @_;
1880
    my $primary_keys = delete $opt{primary_key};
1881
    my $where = delete $opt{where};
1882
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1883
    $param  ||= $p;
1884
    
1885
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1886
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1887
    
cleanup
Yuki Kimoto authored on 2011-10-21
1888
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1889
}
1890

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1891
# DEPRECATED!
1892
sub insert_at {
1893
    my $self = shift;
1894
    
cleanup
Yuki Kimoto authored on 2011-10-21
1895
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1896
    
cleanup
Yuki Kimoto authored on 2011-10-21
1897
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1898
    my $param;
1899
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1900
    my %opt = @_;
1901
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1902
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1903
    my $where = delete $opt{where};
1904
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1905
    $param  ||= $p;
1906
    
1907
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1908
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1909
    $param = $self->merge_param($where_param, $param);
1910
    
cleanup
Yuki Kimoto authored on 2011-10-21
1911
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1912
}
1913

            
added warnings
Yuki Kimoto authored on 2011-06-07
1914
# DEPRECATED!
1915
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1916
    my $self = shift;
1917
    
added warnings
Yuki Kimoto authored on 2011-06-07
1918
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1919
    
1920
    # Merge tag
1921
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1922
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1923
    
1924
    return $self;
1925
}
1926

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1937
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1938
sub default_bind_filter {
1939
    my $self = shift;
1940
    
cleanup
Yuki Kimoto authored on 2011-06-13
1941
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1942
    
cleanup
Yuki Kimoto authored on 2011-01-12
1943
    if (@_) {
1944
        my $fname = $_[0];
1945
        
1946
        if (@_ && !$fname) {
1947
            $self->{default_out_filter} = undef;
1948
        }
1949
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1950
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1951
              unless exists $self->filters->{$fname};
1952
        
1953
            $self->{default_out_filter} = $self->filters->{$fname};
1954
        }
1955
        return $self;
1956
    }
1957
    
1958
    return $self->{default_out_filter};
1959
}
1960

            
cleanup
Yuki Kimoto authored on 2011-01-25
1961
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1962
sub default_fetch_filter {
1963
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1964

            
cleanup
Yuki Kimoto authored on 2011-06-13
1965
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1966
    
1967
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1968
        my $fname = $_[0];
1969

            
cleanup
Yuki Kimoto authored on 2011-01-12
1970
        if (@_ && !$fname) {
1971
            $self->{default_in_filter} = undef;
1972
        }
1973
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1974
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1975
              unless exists $self->filters->{$fname};
1976
        
1977
            $self->{default_in_filter} = $self->filters->{$fname};
1978
        }
1979
        
1980
        return $self;
1981
    }
1982
    
many changed
Yuki Kimoto authored on 2011-01-23
1983
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1984
}
1985

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1986
# DEPRECATED!
1987
sub insert_param {
1988
    my $self = shift;
1989
    warn "insert_param is DEPRECATED! use values_clause instead";
1990
    return $self->values_clause(@_);
1991
}
1992

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1993
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1994
sub insert_param_tag {
1995
    warn "insert_param_tag is DEPRECATED! " .
1996
         "use insert_param instead!";
1997
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1998
}
1999

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

            
2022
# DEPRECATED!
2023
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
2024
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
2025
    
2026
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
2027
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
2028
            my $table1 = (split (/\./, $rcolumn))[0];
2029
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2030
            my $table1_exists;
2031
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
2032
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
2033
                $table1_exists = 1 if $table eq $table1;
2034
                $table2_exists = 1 if $table eq $table2;
2035
            }
2036
            unshift @$tables, $table1 unless $table1_exists;
2037
            unshift @$tables, $table2 unless $table2_exists;
2038
        }
2039
    }
2040
}
2041

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2044
=head1 NAME
2045

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2050
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2051
    
2052
    # Connect
2053
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2054
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2055
        user => 'ken',
2056
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2057
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2058
    );
cleanup
yuki-kimoto authored on 2010-08-05
2059

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2060
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2061
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2062
    
2063
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2064
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2065
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2066
    
2067
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2068
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2069

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2119
Named place holder support
2120

            
2121
=item *
2122

            
cleanup
Yuki Kimoto authored on 2011-07-29
2123
Model support
2124

            
2125
=item *
2126

            
2127
Connection manager support
2128

            
2129
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2130

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

            
2135
=item *
2136

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

            
2139
=item *
2140

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

            
2143
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2144

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2152
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2153
L<DBIx::Custom::Result>,
2154
L<DBIx::Custom::Query>,
2155
L<DBIx::Custom::Where>,
2156
L<DBIx::Custom::Model>,
2157
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2158

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

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

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

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

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

            
2172
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2173
        "dbi:mysql:database=$database",
2174
        $user,
2175
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2176
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2177
    );
2178
    
updated pod
Yuki Kimoto authored on 2011-06-21
2179
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2180

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

            
2184
    my $dbi = DBIx::Custom->connect(
2185
      dsn => $dsn, user => $user, password => $password, connector => 1);
2186
    
2187
    my $connector = $dbi->connector; # DBIx::Connector
2188

            
2189
Note that L<DBIx::Connector> must be installed.
2190

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2206
    {
2207
        RaiseError => 1,
2208
        PrintError => 0,
2209
        AutoCommit => 1,
2210
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2211

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

            
2214
    my $exclude_table = $dbi->exclude_table;
2215
    $dbi = $dbi->exclude_table(qr/pg_/);
2216

            
2217
Excluded table regex.
2218
C<each_column>, C<each_table>, C<type_rule>,
2219
and C<setup_model> methods ignore matching tables.
2220

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

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

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

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

            
2230
    my $last_sql = $dbi->last_sql;
2231
    $dbi = $dbi->last_sql($last_sql);
2232

            
2233
Get last successed SQL executed by C<execute> method.
2234

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

            
2237
    my $now = $dbi->now;
2238
    $dbi = $dbi->now($now);
2239

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

            
2242
    sub {
2243
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2244
        $mon++;
2245
        $year += 1900;
2246
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2247
    }
2248

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

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

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

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

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

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

            
2263
    my $option = $dbi->option;
2264
    $dbi = $dbi->option($option);
2265

            
2266
L<DBI> option, used when C<connect> method is executed.
2267
Each value in option override the value of C<default_option>.
2268

            
cleanup
yuki-kimoto authored on 2010-10-17
2269
=head2 C<password>
2270

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2291
You can set quote pair.
2292

            
2293
    $dbi->quote('[]');
2294

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2304
    my $safety_character = $dbi->safety_character;
2305
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2306

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

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

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

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

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

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

            
2323
    my $tag_parse = $dbi->tag_parse(0);
2324
    $dbi = $dbi->tag_parse;
2325

            
2326
Enable DEPRECATED tag parsing functionality, default to 1.
2327
If you want to disable tag parsing functionality, set to 0.
2328

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

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

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

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

            
2338
    my $user_column_info = $dbi->user_column_info;
2339
    $dbi = $dbi->user_column_info($user_column_info);
2340

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

            
2343
    [
2344
        {table => 'book', column => 'title', info => {...}},
2345
        {table => 'author', column => 'name', info => {...}}
2346
    ]
2347

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

            
2350
    my $user_column_info
2351
      = $dbi->get_column_info(exclude_table => qr/^system/);
2352
    $dbi->user_column_info($user_column_info);
2353

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

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

            
2359
    my $user_table_info = $dbi->user_table_info;
2360
    $dbi = $dbi->user_table_info($user_table_info);
2361

            
2362
You can set the following data.
2363

            
2364
    [
2365
        {table => 'book', info => {...}},
2366
        {table => 'author', info => {...}}
2367
    ]
2368

            
2369
Usually, you can set return value of C<get_table_info>.
2370

            
2371
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2372
    $dbi->user_table_info($user_table_info);
2373

            
2374
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2375
to find table info.
2376

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2413
Create column clause. The follwoing column clause is created.
2414

            
2415
    book.author as "book.author",
2416
    book.title as "book.title"
2417

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2420
    # Separator is hyphen
2421
    $dbi->separator('-');
2422
    
2423
    book.author as "book-author",
2424
    book.title as "book-title"
2425
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2426
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2427

            
update pod
Yuki Kimoto authored on 2011-03-13
2428
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2429
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2430
        user => 'ken',
2431
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2432
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2433
    );
2434

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

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

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

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

            
2445
Get rows count.
2446

            
2447
Options is same as C<select> method's ones.
2448

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2451
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2452
        table => 'book',
2453
        primary_key => 'id',
2454
        join => [
2455
            'inner join company on book.comparny_id = company.id'
2456
        ],
2457
    );
2458

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

            
2462
   $dbi->model('book')->select(...);
2463

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

            
2466
    my $dbh = $dbi->dbh;
2467

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

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

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

            
2475
Execute delete statement.
2476

            
2477
The following opitons are available.
2478

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

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

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

            
2486
=item C<id>
2487

            
2488
    id => 4
2489
    id => [4, 5]
2490

            
2491
ID corresponding to C<primary_key>.
2492
You can delete rows by C<id> and C<primary_key>.
2493

            
2494
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2495
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2496
        id => [4, 5],
2497
        table => 'book',
2498
    );
2499

            
2500
The above is same as the followin one.
2501

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

            
2504
=item C<prefix>
2505

            
2506
    prefix => 'some'
2507

            
2508
prefix before table name section.
2509

            
2510
    delete some from book
2511

            
2512
=item C<table>
2513

            
2514
    table => 'book'
2515

            
2516
Table name.
2517

            
2518
=item C<where>
2519

            
2520
Same as C<select> method's C<where> option.
2521

            
2522
=back
2523

            
2524
=head2 C<delete_all>
2525

            
2526
    $dbi->delete_all(table => $table);
2527

            
2528
Execute delete statement for all rows.
2529
Options is same as C<delete>.
2530

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

            
2533
    $dbi->each_column(
2534
        sub {
2535
            my ($dbi, $table, $column, $column_info) = @_;
2536
            
2537
            my $type = $column_info->{TYPE_NAME};
2538
            
2539
            if ($type eq 'DATE') {
2540
                # ...
2541
            }
2542
        }
2543
    );
2544

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

            
2550
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2551
infromation, you can improve the performance of C<each_column> in
2552
the following way.
2553

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

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

            
2560
    $dbi->each_table(
2561
        sub {
2562
            my ($dbi, $table, $table_info) = @_;
2563
            
2564
            my $table_name = $table_info->{TABLE_NAME};
2565
        }
2566
    );
2567

            
improved pod
Yuki Kimoto authored on 2011-10-14
2568
Iterate all table informationsfrom in database.
2569
Argument is callback which is executed when one table is found.
2570
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2571
C<table information>.
2572

            
2573
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2574
infromation, you can improve the performance of C<each_table> in
2575
the following way.
2576

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

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

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

            
2588
    my $result = $dbi->execute(
2589
      "select * from book where title = :book.title and author like :book.author",
2590
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2591
    );
2592

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2599
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2600
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2601
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2602
    select * from book where title = :title and author like :author
2603
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2604
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2605
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2606

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2610
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2611
    select * from book where :title{=} and :author{like}
2612
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2613
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2614
    select * from where title = ? and author like ?;
2615

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

            
2620
    select * from where title = "aa\\:bb";
2621

            
cleanup
Yuki Kimoto authored on 2011-10-20
2622
B<OPTIONS>
2623

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

            
2626
=over 4
2627

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

            
2630
You can filter sql after the sql is build.
2631

            
2632
    after_build_sql => $code_ref
2633

            
2634
The following one is one example.
2635

            
2636
    $dbi->select(
2637
        table => 'book',
2638
        column => 'distinct(name)',
2639
        after_build_sql => sub {
2640
            "select count(*) from ($_[0]) as t1"
2641
        }
2642
    );
2643

            
2644
The following SQL is executed.
2645

            
2646
    select count(*) from (select distinct(name) from book) as t1;
2647

            
cleanup
Yuki Kimoto authored on 2011-10-20
2648
=item C<append>
2649

            
2650
    append => 'order by name'
2651

            
2652
Append some statement after SQL.
2653

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

            
2656
Specify database bind data type.
2657

            
2658
    bind_type => [image => DBI::SQL_BLOB]
2659
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2660

            
2661
This is used to bind parameter by C<bind_param> of statment handle.
2662

            
2663
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2664

            
update pod
Yuki Kimoto authored on 2011-03-13
2665
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2666
    
2667
    filter => {
2668
        title  => sub { uc $_[0] }
2669
        author => sub { uc $_[0] }
2670
    }
update pod
Yuki Kimoto authored on 2011-03-13
2671

            
updated pod
Yuki Kimoto authored on 2011-06-09
2672
    # Filter name
2673
    filter => {
2674
        title  => 'upper_case',
2675
        author => 'upper_case'
2676
    }
2677
        
2678
    # At once
2679
    filter => [
2680
        [qw/title author/]  => sub { uc $_[0] }
2681
    ]
2682

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

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

            
2690
    query => 1
2691

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2695
    my $sql = $query->{sql};
2696
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2697
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2698
=item C<reuse>
2699
    
2700
    reuse => $hash_ref
2701

            
2702
Reuse query object if the hash reference variable is set.
2703
    
2704
    my $queries = {};
2705
    $dbi->execute($sql, $param, reuse => $queries);
2706

            
2707
This will improved performance when you want to execute same query repeatedly
2708
because generally creating query object is slow.
2709

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2712
    primary_key => 'id'
2713
    primary_key => ['id1', 'id2']
2714

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2717
=item C<table>
2718
    
2719
    table => 'author'
2720

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2728
    # Same
2729
    $dbi->execute(
2730
      "select * from book where title = :book.title and author = :book.author",
2731
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2732

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

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

            
2737
Table alias. Key is real table name, value is alias table name.
2738
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2739
on alias table name.
2740

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

            
2743
    type_rule_off => 1
2744

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

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

            
2749
    type_rule1_off => 1
2750

            
2751
Turn C<into1> type rule off.
2752

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

            
2755
    type_rule2_off => 1
2756

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

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

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

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

            
2765
get column infomation except for one which match C<exclude_table> pattern.
2766

            
2767
    [
2768
        {table => 'book', column => 'title', info => {...}},
2769
        {table => 'author', column => 'name' info => {...}}
2770
    ]
2771

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

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

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

            
2778
    [
2779
        {table => 'book', info => {...}},
2780
        {table => 'author', info => {...}}
2781
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2782

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

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

            
2787
    $dbi->helper(
2788
        find_or_create   => sub {
2789
            my $self = shift;
2790
            
2791
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2792
        },
2793
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2794
    );
2795

            
2796
Register helper. These helper is called directly from L<DBIx::Custom> object.
2797

            
2798
    $dbi->find_or_create;
2799

            
cleanup
yuki-kimoto authored on 2010-10-17
2800
=head2 C<insert>
2801

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

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

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

            
2810
    {date => \"NOW()"}
2811

            
updated pod
Yuki Kimoto authored on 2011-11-25
2812
You can pass multiple parameters, this is very fast.
2813
This is EXPERIMETNAL.
2814

            
2815
    $dbi->insert(
2816
        [
2817
            {title => 'Perl', author => 'Ken'},
2818
            {title => 'Ruby', author => 'Tom'}
2819
        ],
2820
        table  => 'book'
2821
    );
2822

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2826
B<options>
2827

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

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

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
2833
=item C<bulk_insert> EXPERIMENTAL
2834

            
2835
    bulk_insert => 1
2836

            
2837
bulk insert is executed if database support bulk insert and 
2838
multiple parameters is passed to C<insert>.
2839
The SQL like the following one is executed.
2840

            
2841
    insert into book (id, title) values (?, ?), (?, ?);
2842

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

            
2845
    created_at => 'created_datetime'
2846

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2853
    id => 4
2854
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2855

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2859
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2860
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2861
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2862
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2863
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2864
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2865

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

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

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

            
2875
    prefix => 'or replace'
2876

            
2877
prefix before table name section
2878

            
2879
    insert or replace into book
2880

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

            
2883
    table => 'book'
2884

            
2885
Table name.
2886

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

            
2889
This option is same as C<update> method C<updated_at> option.
2890

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

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

            
2895
placeholder wrapped string.
2896

            
2897
If the following statement
2898

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

            
2902
is executed, the following SQL is executed.
2903

            
2904
    insert into book price values ( ? + 5 );
2905

            
update pod
Yuki Kimoto authored on 2011-03-13
2906
=back
2907

            
2908
=over 4
2909

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2917
    lib / MyModel.pm
2918
        / MyModel / book.pm
2919
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2920

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

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

            
2925
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2926
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2927
    
2928
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2929

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2934
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2935
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2936
    
2937
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2938

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2941
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2942
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2943
    
2944
    1;
2945
    
updated pod
Yuki Kimoto authored on 2011-06-21
2946
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2947

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

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

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

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

            
2957
    my $like_value = $dbi->like_value
2958

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

            
2961
    sub { "%$_[0]%" }
2962

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

            
2965
    my $mapper = $dbi->mapper(param => $param);
2966

            
2967
Create a new L<DBIx::Custom::Mapper> object.
2968

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

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

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

            
2975
    {key1 => [1, 1], key2 => 2}
2976

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

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

            
2981
    my $model = $dbi->model('book');
2982

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

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

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

            
2990
Create column clause for myself. The follwoing column clause is created.
2991

            
2992
    book.author as author,
2993
    book.title as title
2994

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

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

            
3004
Create a new L<DBIx::Custom> object.
3005

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

            
3008
    my $not_exists = $dbi->not_exists;
3009

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

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

            
3015
    my $order = $dbi->order;
3016

            
3017
Create a new L<DBIx::Custom::Order> object.
3018

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

            
3021
    my $quooted = $dbi->q("title");
3022

            
3023
Quote string by value of C<quote>.
3024

            
cleanup
yuki-kimoto authored on 2010-10-17
3025
=head2 C<register_filter>
3026

            
update pod
Yuki Kimoto authored on 2011-03-13
3027
    $dbi->register_filter(
3028
        # Time::Piece object to database DATE format
3029
        tp_to_date => sub {
3030
            my $tp = shift;
3031
            return $tp->strftime('%Y-%m-%d');
3032
        },
3033
        # database DATE format to Time::Piece object
3034
        date_to_tp => sub {
3035
           my $date = shift;
3036
           return Time::Piece->strptime($date, '%Y-%m-%d');
3037
        }
3038
    );
cleanup
yuki-kimoto authored on 2010-10-17
3039
    
update pod
Yuki Kimoto authored on 2011-03-13
3040
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3041

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3044
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3045
        column => ['author', 'title'],
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
3046
        table  => 'book',
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3047
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3048
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3049
    
updated document
Yuki Kimoto authored on 2011-06-09
3050
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3051

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3064
=item C<column>
3065
    
updated document
Yuki Kimoto authored on 2011-06-09
3066
    column => 'author'
3067
    column => ['author', 'title']
3068

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3077
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3078
        {book => [qw/author title/]},
3079
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3080
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3081

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

            
3084
    book.author as "book.author",
3085
    book.title as "book.title",
3086
    person.name as "person.name",
3087
    person.age as "person.age"
3088

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

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

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

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

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

            
3102
    id => 4
3103
    id => [4, 5]
3104

            
3105
ID corresponding to C<primary_key>.
3106
You can select rows by C<id> and C<primary_key>.
3107

            
3108
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3109
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3110
        id => [4, 5],
3111
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3112
    );
3113

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3116
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3117
        where => {id1 => 4, id2 => 5},
3118
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3119
    );
3120
    
cleanup
Yuki Kimoto authored on 2011-10-20
3121
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3122

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

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

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

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

            
3135
    prefix => 'SQL_CALC_FOUND_ROWS'
3136

            
3137
Prefix of column cluase
3138

            
3139
    select SQL_CALC_FOUND_ROWS title, author from book;
3140

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

            
3143
    join => [
3144
        'left outer join company on book.company_id = company_id',
3145
        'left outer join location on company.location_id = location.id'
3146
    ]
3147
        
3148
Join clause. If column cluase or where clause contain table name like "company.name",
3149
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3150

            
3151
    $dbi->select(
3152
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3153
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3154
        where => {'company.name' => 'Orange'},
3155
        join => [
3156
            'left outer join company on book.company_id = company.id',
3157
            'left outer join location on company.location_id = location.id'
3158
        ]
3159
    );
3160

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3164
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3165
    from book
3166
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3167
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3168

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3169
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
3170
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3171

            
3172
    $dbi->select(
3173
        table => 'book',
3174
        column => ['company.location_id as location_id'],
3175
        where => {'company.name' => 'Orange'},
3176
        join => [
3177
            {
3178
                clause => 'left outer join location on company.location_id = location.id',
3179
                table => ['company', 'location']
3180
            }
3181
        ]
3182
    );
3183

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3188
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3189

            
updated document
Yuki Kimoto authored on 2011-06-09
3190
=item C<where>
3191
    
3192
    # Hash refrence
3193
    where => {author => 'Ken', 'title' => 'Perl'}
3194
    
3195
    # DBIx::Custom::Where object
3196
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3197
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3198
        param  => {author => 'Ken', title => '%Perl%'}
3199
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3200
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3201
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3202
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3203
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3204
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3205
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3206
    
3207
    # String
3208
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3209

            
cleanup
Yuki Kimoto authored on 2011-10-20
3210
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3211
    
update pod
Yuki Kimoto authored on 2011-03-12
3212
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3213

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

            
3216
    $dbi->setup_model;
3217

            
3218
Setup all model objects.
3219
C<columns> of model object is automatically set, parsing database information.
3220

            
3221
=head2 C<type_rule>
3222

            
3223
    $dbi->type_rule(
3224
        into1 => {
3225
            date => sub { ... },
3226
            datetime => sub { ... }
3227
        },
3228
        into2 => {
3229
            date => sub { ... },
3230
            datetime => sub { ... }
3231
        },
3232
        from1 => {
3233
            # DATE
3234
            9 => sub { ... },
3235
            # DATETIME or TIMESTAMP
3236
            11 => sub { ... },
3237
        }
3238
        from2 => {
3239
            # DATE
3240
            9 => sub { ... },
3241
            # DATETIME or TIMESTAMP
3242
            11 => sub { ... },
3243
        }
3244
    );
3245

            
3246
Filtering rule when data is send into and get from database.
3247
This has a little complex problem.
3248

            
3249
In C<into1> and C<into2> you can specify
3250
type name as same as type name defined
3251
by create table, such as C<DATETIME> or C<DATE>.
3252

            
3253
Note that type name and data type don't contain upper case.
3254
If these contain upper case charactor, you convert it to lower case.
3255

            
3256
C<into2> is executed after C<into1>.
3257

            
3258
Type rule of C<into1> and C<into2> is enabled on the following
3259
column name.
3260

            
3261
=over 4
3262

            
3263
=item 1. column name
3264

            
3265
    issue_date
3266
    issue_datetime
3267

            
3268
This need C<table> option in each method.
3269

            
3270
=item 2. table name and column name, separator is dot
3271

            
3272
    book.issue_date
3273
    book.issue_datetime
3274

            
3275
=back
3276

            
3277
You get all type name used in database by C<available_typename>.
3278

            
3279
    print $dbi->available_typename;
3280

            
3281
In C<from1> and C<from2> you specify data type, not type name.
3282
C<from2> is executed after C<from1>.
3283
You get all data type by C<available_datatype>.
3284

            
3285
    print $dbi->available_datatype;
3286

            
3287
You can also specify multiple types at once.
3288

            
3289
    $dbi->type_rule(
3290
        into1 => [
3291
            [qw/DATE DATETIME/] => sub { ... },
3292
        ],
3293
    );
3294

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

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

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

            
3301
If you want to set constant value to row data, use scalar reference
3302
as parameter value.
3303

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3315
    id => 4
3316
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3317

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3321
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3322
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3323
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3324
        id => [4, 5],
3325
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3326
    );
update pod
Yuki Kimoto authored on 2011-03-13
3327

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3330
    $dbi->update(
3331
        {title => 'Perl', author => 'Ken'}
3332
        where => {id1 => 4, id2 => 5},
3333
        table => 'book'
3334
    );
update pod
Yuki Kimoto authored on 2011-03-13
3335

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

            
3338
    prefix => 'or replace'
3339

            
3340
prefix before table name section
3341

            
3342
    update or replace book
3343

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

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

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

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

            
3352
Same as C<select> method's C<where> option.
3353

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

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

            
3358
placeholder wrapped string.
3359

            
3360
If the following statement
3361

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

            
3365
is executed, the following SQL is executed.
3366

            
3367
    update book set price =  ? + 5;
3368

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

            
3371
    updated_at => 'updated_datetime'
3372

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3377
=back
update pod
Yuki Kimoto authored on 2011-03-13
3378

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3386
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3387
    
3388
    # ID
3389
    $dbi->update_or_insert(
3390
        {title => 'Perl'},
3391
        table => 'book',
3392
        id => 1,
3393
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3394
        option => {
3395
            select => {
3396
                 append => 'for update'
3397
            }
3398
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3399
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3400

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3401
Update or insert.
3402

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3407
C<OPTIONS>
3408

            
3409
C<update_or_insert> method use all common option
3410
in C<select>, C<update>, C<delete>, and has the following new ones.
3411

            
3412
=over 4
3413

            
3414
=item C<option>
3415

            
3416
    option => {
3417
        select => {
3418
            append => '...'
3419
        },
3420
        insert => {
3421
            prefix => '...'
3422
        },
3423
        update => {
3424
            filter => {}
3425
        }
3426
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3427

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

            
3431
=over 4
3432

            
3433
=item C<select_option>
3434

            
3435
    select_option => {append => 'for update'}
3436

            
3437
select method option,
3438
select method is used to check the row is already exists.
3439

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

            
3442
    $dbi->show_datatype($table);
3443

            
3444
Show data type of the columns of specified table.
3445

            
3446
    book
3447
    title: 5
3448
    issue_date: 91
3449

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

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

            
3454
    $dbi->show_tables;
3455

            
3456
Show tables.
3457

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

            
3460
    $dbi->show_typename($table);
3461

            
3462
Show type name of the columns of specified table.
3463

            
3464
    book
3465
    title: varchar
3466
    issue_date: date
3467

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

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

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

            
3474
Create values clause.
3475

            
3476
    (title, author) values (title = :title, age = :age);
3477

            
3478
You can use this in insert statement.
3479

            
3480
    my $insert_sql = "insert into book $values_clause";
3481

            
3482
=head2 C<where>
3483

            
3484
    my $where = $dbi->where(
3485
        clause => ['and', 'title = :title', 'author = :author'],
3486
        param => {title => 'Perl', author => 'Ken'}
3487
    );
3488

            
3489
Create a new L<DBIx::Custom::Where> object.
3490

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

            
3493
=head2 C<DBIX_CUSTOM_DEBUG>
3494

            
3495
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3496
executed SQL and bind values are printed to STDERR.
3497

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

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

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

            
3504
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3505

            
3506
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3507

            
3508
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3509
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3510

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

            
3513
L<DBIx::Custom>
3514

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

            
3569
L<DBIx::Custom::Model>
3570

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3571
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3572
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3573
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3574
    filter # will be removed at 2017/1/1
3575
    name # will be removed at 2017/1/1
3576
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3577

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

            
3580
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3581
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3582
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3583
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3584
    table # will be removed at 2017/1/1
3585
    filters # will be removed at 2017/1/1
3586
    
3587
    # Methods
3588
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3589

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

            
3592
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3593
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3594
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3595
    tags # will be removed at 2017/1/1
3596
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3597
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3598
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3599
    register_tag # will be removed at 2017/1/1
3600
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3601
    
3602
    # Others
3603
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3604
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3605

            
3606
L<DBIx::Custom::Result>
3607
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3608
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3609
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3610
    
3611
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3612
    filter_on # will be removed at 2017/1/1
3613
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3614
    end_filter # will be removed at 2017/1/1
3615
    remove_end_filter # will be removed at 2017/1/1
3616
    remove_filter # will be removed at 2017/1/1
3617
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3618

            
3619
L<DBIx::Custom::Tag>
3620

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

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

            
3625
    # Other
3626
    prepend method array reference receiving
3627
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3628

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

            
3631
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3632
except for attribute method.
3633
You can check all DEPRECATED functionalities by document.
3634
DEPRECATED functionality is removed after five years,
3635
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
3636
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3637

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

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

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

            
3644
C<< <kimoto.yuki at gmail.com> >>
3645

            
3646
L<http://github.com/yuki-kimoto/DBIx-Custom>
3647

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3648
=head1 AUTHOR
3649

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

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

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

            
3656
This program is free software; you can redistribute it and/or modify it
3657
under the same terms as Perl itself.
3658

            
3659
=cut