DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3600 lines | 95.176kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
4
our $VERSION = '0.2102';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
502
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
503
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
504
    my $affected;
- fixed bug that DBIx::Custo...
Yuki Kimoto authored on 2011-11-25
505
    if (!$query->{duplicate} && $type_rule_off && !keys %$filter && !$self->{default_out_filter}
506
      && !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
micro optimization
Yuki Kimoto authored on 2011-11-16
507
    {
- 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 q method
Yuki Kimoto authored on 2011-10-27
686
    $sql .= "into " . $self->q($opt{table}) . " "
cleanup
Yuki Kimoto authored on 2011-11-25
687
      . $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " ";
micro optimization
Yuki Kimoto authored on 2011-10-23
688

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
711
sub include_model {
712
    my ($self, $name_space, $model_infos) = @_;
713
    
cleanup
Yuki Kimoto authored on 2011-04-02
714
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
715
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
716
    
717
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
718
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
719

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
778
sub mapper {
779
    my $self = shift;
780
    return DBIx::Custom::Mapper->new(@_);
781
}
782

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

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

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

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

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

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

            
872
sub order {
873
    my $self = shift;
874
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
875
}
876

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

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

            
910
sub select {
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
911
    my $self = shift;
912
    my $column = shift if @_ % 2;
913
    my %opt = @_;
914
    $opt{column} = $column if defined $column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
915

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

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

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

            
update pod
Yuki Kimoto authored on 2011-08-10
1019
sub show_datatype {
1020
    my ($self, $table) = @_;
1021
    croak "Table name must be specified" unless defined $table;
1022
    print "$table\n";
1023
    
1024
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1025
    my $sth = $result->sth;
1026

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1052
sub show_tables {
1053
    my $self = shift;
1054
    
1055
    my %tables;
1056
    $self->each_table(sub { $tables{$_[1]}++ });
1057
    print join("\n", sort keys %tables) . "\n";
1058
    return $self;
1059
}
1060

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1098
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1099
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1100
                }
1101
            });
1102
        }
1103

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

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

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

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

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

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

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

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

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

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

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

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

            
1266
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-18
1267
        my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1268
          ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1269

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

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

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

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

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

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

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1478
sub _option {
1479
    my $self = shift;
1480
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1481
    warn "dbi_options is DEPRECATED! use option instead\n"
1482
      if keys %{$self->dbi_options};
1483
    warn "dbi_option is DEPRECATED! use option instead\n"
1484
      if keys %{$self->dbi_option};
1485
    return $option;
1486
}
1487

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1559
sub _quote {
1560
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1561
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1562
}
1563

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

            
1577
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1578
}
1579

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1600
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1601
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1602
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1603
    my $w = {};
1604
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1605

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

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

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

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

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

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

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1757
# DEPRECATED!
1758
sub method {
1759
    warn "method is DEPRECATED! use helper instead";
1760
    return shift->helper(@_);
1761
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1762

            
1763
# DEPRECATED!
1764
sub assign_param {
1765
    my $self = shift;
1766
    warn "assing_param is DEPRECATED! use assign_clause instead";
1767
    return $self->assign_clause(@_);
1768
}
1769

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

            
1780
    return $tag;
1781
}
1782

            
updated pod
Yuki Kimoto authored on 2011-06-21
1783
# DEPRECATED!
1784
sub create_query {
1785
    warn "create_query is DEPRECATED! use query option of each method";
1786
    shift->_create_query(@_);
1787
}
1788

            
cleanup
Yuki Kimoto authored on 2011-06-13
1789
# DEPRECATED!
1790
sub apply_filter {
1791
    my $self = shift;
1792
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1793
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1794
    return $self->_apply_filter(@_);
1795
}
1796

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1823
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1824
    
cleanup
Yuki Kimoto authored on 2011-10-21
1825
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1826
    my $primary_keys = delete $opt{primary_key};
1827
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1828
    
1829
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1830
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1831
    
cleanup
Yuki Kimoto authored on 2011-10-21
1832
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1833
}
1834

            
cleanup
Yuki Kimoto authored on 2011-06-08
1835
# DEPRECATED!
1836
sub update_at {
1837
    my $self = shift;
1838

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1926
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1927
sub default_fetch_filter {
1928
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1929

            
cleanup
Yuki Kimoto authored on 2011-06-13
1930
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1931
    
1932
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1933
        my $fname = $_[0];
1934

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1951
# DEPRECATED!
1952
sub insert_param {
1953
    my $self = shift;
1954
    warn "insert_param is DEPRECATED! use values_clause instead";
1955
    return $self->values_clause(@_);
1956
}
1957

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1958
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1959
sub insert_param_tag {
1960
    warn "insert_param_tag is DEPRECATED! " .
1961
         "use insert_param instead!";
1962
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1963
}
1964

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2084
Named place holder support
2085

            
2086
=item *
2087

            
cleanup
Yuki Kimoto authored on 2011-07-29
2088
Model support
2089

            
2090
=item *
2091

            
2092
Connection manager support
2093

            
2094
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2095

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

            
2100
=item *
2101

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

            
2104
=item *
2105

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

            
2108
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2109

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2117
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2118
L<DBIx::Custom::Result>,
2119
L<DBIx::Custom::Query>,
2120
L<DBIx::Custom::Where>,
2121
L<DBIx::Custom::Model>,
2122
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2123

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

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

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

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

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

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

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

            
2149
    my $dbi = DBIx::Custom->connect(
2150
      dsn => $dsn, user => $user, password => $password, connector => 1);
2151
    
2152
    my $connector = $dbi->connector; # DBIx::Connector
2153

            
2154
Note that L<DBIx::Connector> must be installed.
2155

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2171
    {
2172
        RaiseError => 1,
2173
        PrintError => 0,
2174
        AutoCommit => 1,
2175
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2176

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

            
2179
    my $exclude_table = $dbi->exclude_table;
2180
    $dbi = $dbi->exclude_table(qr/pg_/);
2181

            
2182
Excluded table regex.
2183
C<each_column>, C<each_table>, C<type_rule>,
2184
and C<setup_model> methods ignore matching tables.
2185

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

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

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

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

            
2195
    my $last_sql = $dbi->last_sql;
2196
    $dbi = $dbi->last_sql($last_sql);
2197

            
2198
Get last successed SQL executed by C<execute> method.
2199

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

            
2202
    my $now = $dbi->now;
2203
    $dbi = $dbi->now($now);
2204

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

            
2207
    sub {
2208
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2209
        $mon++;
2210
        $year += 1900;
2211
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2212
    }
2213

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

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

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

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

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

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

            
2228
    my $option = $dbi->option;
2229
    $dbi = $dbi->option($option);
2230

            
2231
L<DBI> option, used when C<connect> method is executed.
2232
Each value in option override the value of C<default_option>.
2233

            
cleanup
yuki-kimoto authored on 2010-10-17
2234
=head2 C<password>
2235

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2256
You can set quote pair.
2257

            
2258
    $dbi->quote('[]');
2259

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2269
    my $safety_character = $dbi->safety_character;
2270
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2271

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

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

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

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

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

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

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

            
2291
Enable DEPRECATED tag parsing functionality, default to 1.
2292
If you want to disable tag parsing functionality, set to 0.
2293

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

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

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

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

            
2303
    my $user_column_info = $dbi->user_column_info;
2304
    $dbi = $dbi->user_column_info($user_column_info);
2305

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

            
2308
    [
2309
        {table => 'book', column => 'title', info => {...}},
2310
        {table => 'author', column => 'name', info => {...}}
2311
    ]
2312

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

            
2315
    my $user_column_info
2316
      = $dbi->get_column_info(exclude_table => qr/^system/);
2317
    $dbi->user_column_info($user_column_info);
2318

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

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

            
2324
    my $user_table_info = $dbi->user_table_info;
2325
    $dbi = $dbi->user_table_info($user_table_info);
2326

            
2327
You can set the following data.
2328

            
2329
    [
2330
        {table => 'book', info => {...}},
2331
        {table => 'author', info => {...}}
2332
    ]
2333

            
2334
Usually, you can set return value of C<get_table_info>.
2335

            
2336
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2337
    $dbi->user_table_info($user_table_info);
2338

            
2339
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2340
to find table info.
2341

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2378
Create column clause. The follwoing column clause is created.
2379

            
2380
    book.author as "book.author",
2381
    book.title as "book.title"
2382

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

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

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

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

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

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

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

            
2410
Get rows count.
2411

            
2412
Options is same as C<select> method's ones.
2413

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2416
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2417
        table => 'book',
2418
        primary_key => 'id',
2419
        join => [
2420
            'inner join company on book.comparny_id = company.id'
2421
        ],
2422
    );
2423

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

            
2427
   $dbi->model('book')->select(...);
2428

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

            
2431
    my $dbh = $dbi->dbh;
2432

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

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

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

            
2440
Execute delete statement.
2441

            
2442
The following opitons are available.
2443

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

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

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

            
2451
=item C<id>
2452

            
2453
    id => 4
2454
    id => [4, 5]
2455

            
2456
ID corresponding to C<primary_key>.
2457
You can delete rows by C<id> and C<primary_key>.
2458

            
2459
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2460
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2461
        id => [4, 5],
2462
        table => 'book',
2463
    );
2464

            
2465
The above is same as the followin one.
2466

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

            
2469
=item C<prefix>
2470

            
2471
    prefix => 'some'
2472

            
2473
prefix before table name section.
2474

            
2475
    delete some from book
2476

            
2477
=item C<table>
2478

            
2479
    table => 'book'
2480

            
2481
Table name.
2482

            
2483
=item C<where>
2484

            
2485
Same as C<select> method's C<where> option.
2486

            
2487
=back
2488

            
2489
=head2 C<delete_all>
2490

            
2491
    $dbi->delete_all(table => $table);
2492

            
2493
Execute delete statement for all rows.
2494
Options is same as C<delete>.
2495

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

            
2498
    $dbi->each_column(
2499
        sub {
2500
            my ($dbi, $table, $column, $column_info) = @_;
2501
            
2502
            my $type = $column_info->{TYPE_NAME};
2503
            
2504
            if ($type eq 'DATE') {
2505
                # ...
2506
            }
2507
        }
2508
    );
2509

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

            
2515
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2516
infromation, you can improve the performance of C<each_column> in
2517
the following way.
2518

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

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

            
2525
    $dbi->each_table(
2526
        sub {
2527
            my ($dbi, $table, $table_info) = @_;
2528
            
2529
            my $table_name = $table_info->{TABLE_NAME};
2530
        }
2531
    );
2532

            
improved pod
Yuki Kimoto authored on 2011-10-14
2533
Iterate all table informationsfrom in database.
2534
Argument is callback which is executed when one table is found.
2535
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2536
C<table information>.
2537

            
2538
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2539
infromation, you can improve the performance of C<each_table> in
2540
the following way.
2541

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

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

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

            
2553
    my $result = $dbi->execute(
2554
      "select * from book where title = :book.title and author like :book.author",
2555
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2556
    );
2557

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2575
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2576
    select * from book where :title{=} and :author{like}
2577
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2578
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2579
    select * from where title = ? and author like ?;
2580

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

            
2585
    select * from where title = "aa\\:bb";
2586

            
cleanup
Yuki Kimoto authored on 2011-10-20
2587
B<OPTIONS>
2588

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

            
2591
=over 4
2592

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

            
2595
You can filter sql after the sql is build.
2596

            
2597
    after_build_sql => $code_ref
2598

            
2599
The following one is one example.
2600

            
2601
    $dbi->select(
2602
        table => 'book',
2603
        column => 'distinct(name)',
2604
        after_build_sql => sub {
2605
            "select count(*) from ($_[0]) as t1"
2606
        }
2607
    );
2608

            
2609
The following SQL is executed.
2610

            
2611
    select count(*) from (select distinct(name) from book) as t1;
2612

            
cleanup
Yuki Kimoto authored on 2011-10-20
2613
=item C<append>
2614

            
2615
    append => 'order by name'
2616

            
2617
Append some statement after SQL.
2618

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

            
2621
Specify database bind data type.
2622

            
2623
    bind_type => [image => DBI::SQL_BLOB]
2624
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2625

            
2626
This is used to bind parameter by C<bind_param> of statment handle.
2627

            
2628
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2629

            
update pod
Yuki Kimoto authored on 2011-03-13
2630
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2631
    
2632
    filter => {
2633
        title  => sub { uc $_[0] }
2634
        author => sub { uc $_[0] }
2635
    }
update pod
Yuki Kimoto authored on 2011-03-13
2636

            
updated pod
Yuki Kimoto authored on 2011-06-09
2637
    # Filter name
2638
    filter => {
2639
        title  => 'upper_case',
2640
        author => 'upper_case'
2641
    }
2642
        
2643
    # At once
2644
    filter => [
2645
        [qw/title author/]  => sub { uc $_[0] }
2646
    ]
2647

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

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

            
2655
    query => 1
2656

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2660
    my $sql = $query->{sql};
2661
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2662
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2663
=item C<reuse>
2664
    
2665
    reuse => $hash_ref
2666

            
2667
Reuse query object if the hash reference variable is set.
2668
    
2669
    my $queries = {};
2670
    $dbi->execute($sql, $param, reuse => $queries);
2671

            
2672
This will improved performance when you want to execute same query repeatedly
2673
because generally creating query object is slow.
2674

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2677
    primary_key => 'id'
2678
    primary_key => ['id1', 'id2']
2679

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2682
=item C<table>
2683
    
2684
    table => 'author'
2685

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2693
    # Same
2694
    $dbi->execute(
2695
      "select * from book where title = :book.title and author = :book.author",
2696
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2697

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

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

            
2702
Table alias. Key is real table name, value is alias table name.
2703
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2704
on alias table name.
2705

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

            
2708
    type_rule_off => 1
2709

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

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

            
2714
    type_rule1_off => 1
2715

            
2716
Turn C<into1> type rule off.
2717

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

            
2720
    type_rule2_off => 1
2721

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

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

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

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

            
2730
get column infomation except for one which match C<exclude_table> pattern.
2731

            
2732
    [
2733
        {table => 'book', column => 'title', info => {...}},
2734
        {table => 'author', column => 'name' info => {...}}
2735
    ]
2736

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

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

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

            
2743
    [
2744
        {table => 'book', info => {...}},
2745
        {table => 'author', info => {...}}
2746
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2747

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

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

            
2752
    $dbi->helper(
2753
        find_or_create   => sub {
2754
            my $self = shift;
2755
            
2756
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2757
        },
2758
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2759
    );
2760

            
2761
Register helper. These helper is called directly from L<DBIx::Custom> object.
2762

            
2763
    $dbi->find_or_create;
2764

            
cleanup
yuki-kimoto authored on 2010-10-17
2765
=head2 C<insert>
2766

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

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

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

            
2775
    {date => \"NOW()"}
2776

            
cleanup
Yuki Kimoto authored on 2011-10-20
2777
B<options>
2778

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

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

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

            
2786
    created_at => 'created_datetime'
2787

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2794
    id => 4
2795
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2796

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

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

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

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

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

            
2816
    prefix => 'or replace'
2817

            
2818
prefix before table name section
2819

            
2820
    insert or replace into book
2821

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

            
2824
    table => 'book'
2825

            
2826
Table name.
2827

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

            
2830
This option is same as C<update> method C<updated_at> option.
2831

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

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

            
2836
placeholder wrapped string.
2837

            
2838
If the following statement
2839

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

            
2843
is executed, the following SQL is executed.
2844

            
2845
    insert into book price values ( ? + 5 );
2846

            
update pod
Yuki Kimoto authored on 2011-03-13
2847
=back
2848

            
2849
=over 4
2850

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2858
    lib / MyModel.pm
2859
        / MyModel / book.pm
2860
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2861

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

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

            
2866
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2867
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2868
    
2869
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2870

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2875
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2876
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2877
    
2878
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2879

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2882
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2883
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2884
    
2885
    1;
2886
    
updated pod
Yuki Kimoto authored on 2011-06-21
2887
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2888

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

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

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

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

            
2898
    my $like_value = $dbi->like_value
2899

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

            
2902
    sub { "%$_[0]%" }
2903

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

            
2906
    my $mapper = $dbi->mapper(param => $param);
2907

            
2908
Create a new L<DBIx::Custom::Mapper> object.
2909

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

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

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

            
2916
    {key1 => [1, 1], key2 => 2}
2917

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

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

            
2922
    my $model = $dbi->model('book');
2923

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

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

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

            
2931
Create column clause for myself. The follwoing column clause is created.
2932

            
2933
    book.author as author,
2934
    book.title as title
2935

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

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

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

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

            
2949
    my $not_exists = $dbi->not_exists;
2950

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

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

            
2956
    my $order = $dbi->order;
2957

            
2958
Create a new L<DBIx::Custom::Order> object.
2959

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

            
2962
    my $quooted = $dbi->q("title");
2963

            
2964
Quote string by value of C<quote>.
2965

            
cleanup
yuki-kimoto authored on 2010-10-17
2966
=head2 C<register_filter>
2967

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

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

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3005
=item C<column>
3006
    
updated document
Yuki Kimoto authored on 2011-06-09
3007
    column => 'author'
3008
    column => ['author', 'title']
3009

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3018
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3019
        {book => [qw/author title/]},
3020
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3021
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3022

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

            
3025
    book.author as "book.author",
3026
    book.title as "book.title",
3027
    person.name as "person.name",
3028
    person.age as "person.age"
3029

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

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

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

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

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

            
3043
    id => 4
3044
    id => [4, 5]
3045

            
3046
ID corresponding to C<primary_key>.
3047
You can select rows by C<id> and C<primary_key>.
3048

            
3049
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3050
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3051
        id => [4, 5],
3052
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3053
    );
3054

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

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

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

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

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

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

            
3076
    prefix => 'SQL_CALC_FOUND_ROWS'
3077

            
3078
Prefix of column cluase
3079

            
3080
    select SQL_CALC_FOUND_ROWS title, author from book;
3081

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

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

            
3092
    $dbi->select(
3093
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3094
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3095
        where => {'company.name' => 'Orange'},
3096
        join => [
3097
            'left outer join company on book.company_id = company.id',
3098
            'left outer join location on company.location_id = location.id'
3099
        ]
3100
    );
3101

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3105
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3106
    from book
3107
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3108
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3109

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3110
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
3111
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3112

            
3113
    $dbi->select(
3114
        table => 'book',
3115
        column => ['company.location_id as location_id'],
3116
        where => {'company.name' => 'Orange'},
3117
        join => [
3118
            {
3119
                clause => 'left outer join location on company.location_id = location.id',
3120
                table => ['company', 'location']
3121
            }
3122
        ]
3123
    );
3124

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3129
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3130

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3151
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3152
    
update pod
Yuki Kimoto authored on 2011-03-12
3153
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3154

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

            
3157
    $dbi->setup_model;
3158

            
3159
Setup all model objects.
3160
C<columns> of model object is automatically set, parsing database information.
3161

            
3162
=head2 C<type_rule>
3163

            
3164
    $dbi->type_rule(
3165
        into1 => {
3166
            date => sub { ... },
3167
            datetime => sub { ... }
3168
        },
3169
        into2 => {
3170
            date => sub { ... },
3171
            datetime => sub { ... }
3172
        },
3173
        from1 => {
3174
            # DATE
3175
            9 => sub { ... },
3176
            # DATETIME or TIMESTAMP
3177
            11 => sub { ... },
3178
        }
3179
        from2 => {
3180
            # DATE
3181
            9 => sub { ... },
3182
            # DATETIME or TIMESTAMP
3183
            11 => sub { ... },
3184
        }
3185
    );
3186

            
3187
Filtering rule when data is send into and get from database.
3188
This has a little complex problem.
3189

            
3190
In C<into1> and C<into2> you can specify
3191
type name as same as type name defined
3192
by create table, such as C<DATETIME> or C<DATE>.
3193

            
3194
Note that type name and data type don't contain upper case.
3195
If these contain upper case charactor, you convert it to lower case.
3196

            
3197
C<into2> is executed after C<into1>.
3198

            
3199
Type rule of C<into1> and C<into2> is enabled on the following
3200
column name.
3201

            
3202
=over 4
3203

            
3204
=item 1. column name
3205

            
3206
    issue_date
3207
    issue_datetime
3208

            
3209
This need C<table> option in each method.
3210

            
3211
=item 2. table name and column name, separator is dot
3212

            
3213
    book.issue_date
3214
    book.issue_datetime
3215

            
3216
=back
3217

            
3218
You get all type name used in database by C<available_typename>.
3219

            
3220
    print $dbi->available_typename;
3221

            
3222
In C<from1> and C<from2> you specify data type, not type name.
3223
C<from2> is executed after C<from1>.
3224
You get all data type by C<available_datatype>.
3225

            
3226
    print $dbi->available_datatype;
3227

            
3228
You can also specify multiple types at once.
3229

            
3230
    $dbi->type_rule(
3231
        into1 => [
3232
            [qw/DATE DATETIME/] => sub { ... },
3233
        ],
3234
    );
3235

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

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

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

            
3242
If you want to set constant value to row data, use scalar reference
3243
as parameter value.
3244

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3256
    id => 4
3257
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3258

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3271
    $dbi->update(
3272
        {title => 'Perl', author => 'Ken'}
3273
        where => {id1 => 4, id2 => 5},
3274
        table => 'book'
3275
    );
update pod
Yuki Kimoto authored on 2011-03-13
3276

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

            
3279
    prefix => 'or replace'
3280

            
3281
prefix before table name section
3282

            
3283
    update or replace book
3284

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

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

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

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

            
3293
Same as C<select> method's C<where> option.
3294

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

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

            
3299
placeholder wrapped string.
3300

            
3301
If the following statement
3302

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

            
3306
is executed, the following SQL is executed.
3307

            
3308
    update book set price =  ? + 5;
3309

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

            
3312
    updated_at => 'updated_datetime'
3313

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3318
=back
update pod
Yuki Kimoto authored on 2011-03-13
3319

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3342
Update or insert.
3343

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3348
C<OPTIONS>
3349

            
3350
C<update_or_insert> method use all common option
3351
in C<select>, C<update>, C<delete>, and has the following new ones.
3352

            
3353
=over 4
3354

            
3355
=item C<option>
3356

            
3357
    option => {
3358
        select => {
3359
            append => '...'
3360
        },
3361
        insert => {
3362
            prefix => '...'
3363
        },
3364
        update => {
3365
            filter => {}
3366
        }
3367
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3368

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

            
3372
=over 4
3373

            
3374
=item C<select_option>
3375

            
3376
    select_option => {append => 'for update'}
3377

            
3378
select method option,
3379
select method is used to check the row is already exists.
3380

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

            
3383
    $dbi->show_datatype($table);
3384

            
3385
Show data type of the columns of specified table.
3386

            
3387
    book
3388
    title: 5
3389
    issue_date: 91
3390

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

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

            
3395
    $dbi->show_tables;
3396

            
3397
Show tables.
3398

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

            
3401
    $dbi->show_typename($table);
3402

            
3403
Show type name of the columns of specified table.
3404

            
3405
    book
3406
    title: varchar
3407
    issue_date: date
3408

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

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

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

            
3415
Create values clause.
3416

            
3417
    (title, author) values (title = :title, age = :age);
3418

            
3419
You can use this in insert statement.
3420

            
3421
    my $insert_sql = "insert into book $values_clause";
3422

            
3423
=head2 C<where>
3424

            
3425
    my $where = $dbi->where(
3426
        clause => ['and', 'title = :title', 'author = :author'],
3427
        param => {title => 'Perl', author => 'Ken'}
3428
    );
3429

            
3430
Create a new L<DBIx::Custom::Where> object.
3431

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

            
3434
=head2 C<DBIX_CUSTOM_DEBUG>
3435

            
3436
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3437
executed SQL and bind values are printed to STDERR.
3438

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

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

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

            
3445
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3446

            
3447
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3448

            
3449
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3450
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3451

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

            
3454
L<DBIx::Custom>
3455

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

            
3510
L<DBIx::Custom::Model>
3511

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3512
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3513
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3514
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3515
    filter # will be removed at 2017/1/1
3516
    name # will be removed at 2017/1/1
3517
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3518

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

            
3521
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3522
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3523
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3524
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3525
    table # will be removed at 2017/1/1
3526
    filters # will be removed at 2017/1/1
3527
    
3528
    # Methods
3529
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3530

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

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

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

            
3560
L<DBIx::Custom::Tag>
3561

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

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

            
3566
    # Other
3567
    prepend method array reference receiving
3568
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3569

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

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

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

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

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

            
3585
C<< <kimoto.yuki at gmail.com> >>
3586

            
3587
L<http://github.com/yuki-kimoto/DBIx-Custom>
3588

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3589
=head1 AUTHOR
3590

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

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

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

            
3597
This program is free software; you can redistribute it and/or modify it
3598
under the same terms as Perl itself.
3599

            
3600
=cut