DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3560 lines | 93.162kb
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 DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
4
our $VERSION = '0.1747';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
22
has [qw/connector dsn password quote user exclude_table user_table_info
23
        user_column_info/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
24
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
25
    cache_method => sub {
26
        sub {
27
            my $self = shift;
28
            
29
            $self->{_cached} ||= {};
30
            
31
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
32
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
33
            }
34
            else {
update pod
Yuki Kimoto authored on 2011-03-13
35
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
36
            }
37
        }
update pod
Yuki Kimoto authored on 2011-03-13
38
    },
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
39
    option => sub { {} },
40
    default_option => sub {
update pod
Yuki Kimoto authored on 2011-03-13
41
        {
42
            RaiseError => 1,
43
            PrintError => 0,
44
            AutoCommit => 1
45
        }
46
    },
fix tests
Yuki Kimoto authored on 2011-01-13
47
    filters => sub {
48
        {
49
            encode_utf8 => sub { encode_utf8($_[0]) },
50
            decode_utf8 => sub { decode_utf8($_[0]) }
51
        }
update pod
Yuki Kimoto authored on 2011-03-13
52
    },
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
53
    last_sql => '',
update pod
Yuki Kimoto authored on 2011-03-13
54
    models => sub { {} },
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
55
    now => sub {
56
        sub {
57
            my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
58
            $mon++;
59
            $year += 1900;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
60
            my $now = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
61
              $year, $mon, $mday, $hour, $min, $sec);
62
            return $now;
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
63
        }
64
    },
cleanup
Yuki Kimoto authored on 2011-08-13
65
    query_builder => sub {
66
        my $self = shift;
67
        my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
68
        weaken $builder->{dbi};
69
        return $builder;
70
    },
update pod
Yuki Kimoto authored on 2011-03-13
71
    result_class  => 'DBIx::Custom::Result',
72
    safety_character => '\w',
cleanup test
Yuki Kimoto authored on 2011-08-10
73
    separator => '.',
- 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-10-23
132
    my $safety = $self->{safety_character} || $self->safety_character;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
133
    my $qp = $self->q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
134
    my $q = substr($qp, 0, 1) || '';
135
    my $p = substr($qp, 1, 1) || '';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
136
    
micro optimization
Yuki Kimoto authored on 2011-10-23
137
    # Check unsafety keys
138
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
139
        for my $column (keys %$param) {
140
            croak qq{"$column" is not safety column name } . _subname
141
              unless $column =~ /^[$safety\.]+$/;
142
        }
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
143
    }
144
    
micro optimization
Yuki Kimoto authored on 2011-10-23
145
    # Assign clause (performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
146
    join(
147
      ', ',
148
      map {
149
          ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
150
          : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
151
          : "$q$_$p = :$_";
152
      } sort keys %$param
153
    );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
154
}
155

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
676
sub insert_timestamp {
677
    my $self = shift;
678
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
679
    warn "insert_timestamp method is DEPRECATED! use now attribute";
680
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
681
    if (@_) {
682
        $self->{insert_timestamp} = [@_];
683
        
684
        return $self;
685
    }
686
    return $self->{insert_timestamp};
687
}
688

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
689
sub include_model {
690
    my ($self, $name_space, $model_infos) = @_;
691
    
cleanup
Yuki Kimoto authored on 2011-04-02
692
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
693
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
694
    
695
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
696
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
697

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
756
sub mapper {
757
    my $self = shift;
758
    return DBIx::Custom::Mapper->new(@_);
759
}
760

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

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

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

            
added dbi_options attribute
kimoto authored on 2010-12-20
815
sub new {
816
    my $self = shift->SUPER::new(@_);
817
    
cleanup
Yuki Kimoto authored on 2011-04-02
818
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
819
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
820
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
821
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
822
          unless $self->can($attr);
823
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
824

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
825
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
826
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
827
        '?'     => \&DBIx::Custom::Tag::placeholder,
828
        '='     => \&DBIx::Custom::Tag::equal,
829
        '<>'    => \&DBIx::Custom::Tag::not_equal,
830
        '>'     => \&DBIx::Custom::Tag::greater_than,
831
        '<'     => \&DBIx::Custom::Tag::lower_than,
832
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
833
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
834
        'like'  => \&DBIx::Custom::Tag::like,
835
        'in'    => \&DBIx::Custom::Tag::in,
836
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
837
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
838
    };
839
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
840
    # DEPRECATED!
841
    $self->{tag_parse} = 1;
842
    
cleanup
Yuki Kimoto authored on 2011-08-13
843
    return $self;
844
}
845

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

            
848
sub order {
849
    my $self = shift;
850
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
851
}
852

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

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

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

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

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

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

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

            
1000
    my $columns = $sth->{NAME};
1001
    my $data_types = $sth->{TYPE};
1002
    
1003
    for (my $i = 0; $i < @$columns; $i++) {
1004
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1005
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1006
        print "$column: $data_type\n";
1007
    }
1008
}
1009

            
1010
sub show_typename {
1011
    my ($self, $t) = @_;
1012
    croak "Table name must be specified" unless defined $t;
1013
    print "$t\n";
1014
    
1015
    $self->each_column(sub {
1016
        my ($self, $table, $column, $infos) = @_;
1017
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1018
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1019
        print "$column: $typename\n";
1020
    });
1021
    
1022
    return $self;
1023
}
1024

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

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

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

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

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

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1124
    # Created time and updated time
1125
    my @timestamp_cleanup;
1126
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1127
        my $now = $self->now;
1128
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1129
        $param->{$opt{updated_at}} = $self->now->();
1130
        push @timestamp_cleanup, $opt{updated_at};
1131
    }
1132

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

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

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

            
1159
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1160
    if (@$rows == 0) {
1161
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1162
    }
1163
    elsif (@$rows == 1) {
1164
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1165
    }
1166
    else {
1167
        croak "selected row must be one " . _subname;
1168
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1169
}
1170

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1171
sub update_timestamp {
1172
    my $self = shift;
1173
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1174
    warn "update_timestamp method is DEPRECATED! use now method";
1175
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1176
    if (@_) {
1177
        $self->{update_timestamp} = [@_];
1178
        
1179
        return $self;
1180
    }
1181
    return $self->{update_timestamp};
1182
}
1183

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1184
sub values_clause {
1185
    my ($self, $param, $opts) = @_;
1186
    
1187
    my $wrap = $opts->{wrap} || {};
1188
    
1189
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-10-23
1190
    my $safety = $self->{safety_character} || $self->safety_character;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1191
    my $qp = $self->q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1192
    my $q = substr($qp, 0, 1) || '';
1193
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1194
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1195
    # Check unsafety keys
1196
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
1197
        for my $column (keys %$param) {
1198
            croak qq{"$column" is not safety column name } . _subname
1199
              unless $column =~ /^[$safety\.]+$/;
1200
        }
1201
    }
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1202
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1203
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1204
    '(' .
1205
    join(
1206
      ', ',
1207
      map { "$q$_$p" } sort keys %$param
1208
    ) .
1209
    ') values (' .
1210
    join(
1211
      ', ',
1212
      map {
1213
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1214
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1215
          ":$_";
1216
      } sort keys %$param
1217
    ) .
1218
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1219
}
1220

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

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

            
1249
        # Create query
1250
        my $builder = $self->query_builder;
1251
        $query = $builder->build_query($source);
1252

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

            
1259
        # Save query to cache
1260
        $self->cache_method->(
1261
            $self, $source,
1262
            {
1263
                sql     => $query->sql, 
1264
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1265
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1266
            }
1267
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1268
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1269

            
1270
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1271
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1272
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1273
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1274
        $query->sql($sql);
1275
    }
1276
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1277
    # Save sql
1278
    $self->last_sql($query->sql);
1279
    
updated pod
Yuki Kimoto authored on 2011-06-21
1280
    # Prepare statement handle
1281
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1282
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1283
    
1284
    if ($@) {
1285
        $self->_croak($@, qq{. Following SQL is executed.\n}
1286
                        . qq{$query->{sql}\n} . _subname);
1287
    }
1288
    
1289
    # Set statement handle
1290
    $query->sth($sth);
1291
    
1292
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1293
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1294
    
1295
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1296
}
1297

            
cleanup
Yuki Kimoto authored on 2011-04-02
1298
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1299
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1300
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1301
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1302
    
cleanup
Yuki Kimoto authored on 2011-04-02
1303
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1304
    my @bind;
1305
    my @types;
1306
    my %count;
1307
    my %not_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1308
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1309
        
micro optimization
Yuki Kimoto authored on 2011-10-23
1310
        # Bind value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1311
        if(ref $params->{$column} eq 'ARRAY') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1312
            my $i = $count{$column} || 0;
1313
            $i += $not_exists{$column} || 0;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1314
            my $found;
1315
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1316
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1317
                    $not_exists{$column}++;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1318
                }
1319
                else  {
micro optimization
Yuki Kimoto authored on 2011-10-23
1320
                    push @bind, $params->{$column}->[$k];
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1321
                    $found = 1;
1322
                    last
1323
                }
1324
            }
1325
            next unless $found;
1326
        }
micro optimization
Yuki Kimoto authored on 2011-10-23
1327
        else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1328
        
cleanup
Yuki Kimoto authored on 2011-01-12
1329
        # Filter
micro optimization
Yuki Kimoto authored on 2011-10-23
1330
        if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1331
            $bind[-1] = $f->($bind[-1]);
micro optimization
Yuki Kimoto authored on 2011-10-23
1332
        }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1333
        
1334
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-23
1335
        if ($self->{_type_rule_is_called}) {
1336
            my $tf1 = $self->{"_into1"}->{dot}->{$column}
1337
              || $type_filters->{1}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1338
            $bind[-1] = $tf1->($bind[-1]) if $tf1;
micro optimization
Yuki Kimoto authored on 2011-10-23
1339
            my $tf2 = $self->{"_into2"}->{dot}->{$column}
1340
              || $type_filters->{2}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1341
            $bind[-1] = $tf2->($bind[-1]) if $tf2;
micro optimization
Yuki Kimoto authored on 2011-10-23
1342
        }
micro optimization
Yuki Kimoto authored on 2011-10-22
1343
       
micro optimization
Yuki Kimoto authored on 2011-10-23
1344
        # Bind types
micro optimization
Yuki Kimoto authored on 2011-10-23
1345
        push @types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1346
        
1347
        # Count up 
micro optimization
Yuki Kimoto authored on 2011-10-23
1348
        $count{$column}++;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1349
    }
1350
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1351
    return (\@bind, \@types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1352
}
1353

            
cleanup
Yuki Kimoto authored on 2011-10-21
1354
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1355
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1356
    
1357
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1358
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1359
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1360
      unless defined $primary_keys;
1361
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1362
    
cleanup
Yuki Kimoto authored on 2011-06-08
1363
    # Create parameter
1364
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1365
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1366
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1367
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1368
           my $key = $primary_keys->[$i];
1369
           $key = "$table." . $key if $table;
1370
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1371
        }
1372
    }
1373
    
cleanup
Yuki Kimoto authored on 2011-06-08
1374
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1375
}
1376

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1377
sub _connect {
1378
    my $self = shift;
1379
    
1380
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1381
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1382
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1383
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1384
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1385
    croak qq{"dsn" must be specified } . _subname
1386
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1387
    my $user        = $self->user;
1388
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1389
    my $option = $self->_option;
1390
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1391
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1392
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1393
    my $dbh;
1394
    eval {
1395
        $dbh = DBI->connect(
1396
            $dsn,
1397
            $user,
1398
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1399
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1400
        );
1401
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1402
    
1403
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1404
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1405
    
1406
    return $dbh;
1407
}
1408

            
cleanup
yuki-kimoto authored on 2010-10-17
1409
sub _croak {
1410
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1411
    
1412
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1413
    $append ||= "";
1414
    
1415
    # Verbose
1416
    if ($Carp::Verbose) { croak $error }
1417
    
1418
    # Not verbose
1419
    else {
1420
        
1421
        # Remove line and module infromation
1422
        my $at_pos = rindex($error, ' at ');
1423
        $error = substr($error, 0, $at_pos);
1424
        $error =~ s/\s+$//;
1425
        croak "$error$append";
1426
    }
1427
}
1428

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1431
sub _need_tables {
1432
    my ($self, $tree, $need_tables, $tables) = @_;
1433
    
cleanup
Yuki Kimoto authored on 2011-04-02
1434
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1435
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1436
        if ($tree->{$table}) {
1437
            $need_tables->{$table} = 1;
1438
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1439
        }
1440
    }
1441
}
1442

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1443
sub _option {
1444
    my $self = shift;
1445
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1446
    warn "dbi_options is DEPRECATED! use option instead\n"
1447
      if keys %{$self->dbi_options};
1448
    warn "dbi_option is DEPRECATED! use option instead\n"
1449
      if keys %{$self->dbi_option};
1450
    return $option;
1451
}
1452

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1453
sub _push_join {
1454
    my ($self, $sql, $join, $join_tables) = @_;
1455
    
cleanup
Yuki Kimoto authored on 2011-10-21
1456
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1457
    
cleanup
Yuki Kimoto authored on 2011-04-02
1458
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1459
    return unless @$join;
1460
    
cleanup
Yuki Kimoto authored on 2011-04-02
1461
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1462
    my $tree = {};
1463
    for (my $i = 0; $i < @$join; $i++) {
1464
        
cleanup
Yuki Kimoto authored on 2011-07-28
1465
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1466
        my $join_clause;;
1467
        my $option;
1468
        if (ref $join->[$i] eq 'HASH') {
1469
            $join_clause = $join->[$i]->{clause};
1470
            $option = {table => $join->[$i]->{table}};
1471
        }
1472
        else {
1473
            $join_clause = $join->[$i];
1474
            $option = {};
1475
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1476

            
1477
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1478
        my $table1;
1479
        my $table2;
1480
        if (my $table = $option->{table}) {
1481
            $table1 = $table->[0];
1482
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1483
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1484
        else {
1485
            my $q = $self->_quote;
1486
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1487
            $j_clause =~ s/'.+?'//g;
1488
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1489
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1490
            
1491
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1492
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1493
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1494
            for my $clause (@j_clauses) {
1495
                if ($clause =~ $join_re) {
1496
                    $table1 = $1;
1497
                    $table2 = $2;
1498
                    last;
1499
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1500
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1501
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1502
        croak qq{join clause must have two table name after "on" keyword. } .
1503
              qq{"$join_clause" is passed }  . _subname
1504
          unless defined $table1 && defined $table2;
1505
        croak qq{right side table of "$join_clause" must be unique }
1506
            . _subname
1507
          if exists $tree->{$table2};
1508
        croak qq{Same table "$table1" is specified} . _subname
1509
          if $table1 eq $table2;
1510
        $tree->{$table2}
1511
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1512
    }
1513
    
cleanup
Yuki Kimoto authored on 2011-04-02
1514
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1515
    my $need_tables = {};
1516
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1517
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1518
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1519
    
1520
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1521
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1522
}
cleanup
Yuki Kimoto authored on 2011-03-08
1523

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1524
sub _quote {
1525
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1526
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1527
}
1528

            
cleanup
Yuki Kimoto authored on 2011-04-02
1529
sub _remove_duplicate_table {
1530
    my ($self, $tables, $main_table) = @_;
1531
    
1532
    # Remove duplicate table
1533
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1534
    delete $tables{$main_table} if $main_table;
1535
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1536
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1537
    if (my $q = $self->_quote) {
1538
        $q = quotemeta($q);
1539
        $_ =~ s/[$q]//g for @$new_tables;
1540
    }
1541

            
1542
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1543
}
1544

            
cleanup
Yuki Kimoto authored on 2011-04-02
1545
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1546
    my ($self, $source) = @_;
1547
    
cleanup
Yuki Kimoto authored on 2011-04-02
1548
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1549
    my $tables = [];
1550
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1551
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1552
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1553
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1554
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1555
    while ($source =~ /$table_re/g) {
1556
        push @$tables, $1;
1557
    }
1558
    
1559
    return $tables;
1560
}
1561

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1565
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1566
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1567
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1568
    my $w = {};
1569
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1570

            
cleanup
Yuki Kimoto authored on 2011-10-25
1571
    my $obj;
1572
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1573
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1574
        if (ref $where eq 'HASH') {
1575
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1576
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1577
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1578
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1579
                my $table;
1580
                my $c;
1581
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1582
                    $table = $1;
1583
                    $c = $2;
1584
                }
1585
                
1586
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1587
                $table_quote = $self->q($table) if defined $table;
1588
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1589
                $column_quote = $table_quote . '.' . $column_quote
1590
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1591
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1592
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1593

            
1594
            # Check unsafety column
1595
            my $safety = $self->safety_character;
1596
            unless ($column_join =~ /^[$safety\.]+$/) {
1597
                for my $column (keys %$where) {
1598
                    croak qq{"$column" is not safety column name } . _subname
1599
                      unless $column =~ /^[$safety\.]+$/;
1600
                }
1601
            }
1602
            
cleanup
Yuki Kimoto authored on 2011-10-25
1603
            $obj = $self->where(clause => $clause, param => $where);
1604
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1605
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1606
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1607
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1608
        }
1609
        
1610
        # Check where argument
1611
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1612
            . qq{or array reference, which contains where clause and parameter}
1613
            . _subname
1614
          unless ref $obj eq 'DBIx::Custom::Where';
1615

            
1616
        $w->{param} = keys %$where_param
1617
                    ? $self->merge_param($where_param, $obj->param)
1618
                    : $obj->param;
1619
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1620
    }
1621
    elsif ($where) {
1622
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1623
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1624
    }
1625
    
1626
    return $w;
1627
}
1628

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

            
1632
    # Initialize filters
1633
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1634
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1635
    $self->{filter}{out} ||= {};
1636
    $self->{filter}{in} ||= {};
1637
    $self->{filter}{end} ||= {};
1638
    
1639
    # Usage
1640
    my $usage = "Usage: \$dbi->apply_filter(" .
1641
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1642
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1643
    
1644
    # Apply filter
1645
    for (my $i = 0; $i < @cinfos; $i += 2) {
1646
        
1647
        # Column
1648
        my $column = $cinfos[$i];
1649
        if (ref $column eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-10-21
1650
            for my $c (@$column) {
updated pod
Yuki Kimoto authored on 2011-06-21
1651
                push @cinfos, $c, $cinfos[$i + 1];
1652
            }
1653
            next;
1654
        }
1655
        
1656
        # Filter infomation
1657
        my $finfo = $cinfos[$i + 1] || {};
1658
        croak "$usage (table: $table) " . _subname
1659
          unless  ref $finfo eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-10-21
1660
        for my $ftype (keys %$finfo) {
updated pod
Yuki Kimoto authored on 2011-06-21
1661
            croak "$usage (table: $table) " . _subname
1662
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1663
        }
1664
        
1665
        # Set filters
cleanup
Yuki Kimoto authored on 2011-10-21
1666
        for my $way (qw/in out end/) {
updated pod
Yuki Kimoto authored on 2011-06-21
1667
        
1668
            # Filter
1669
            my $filter = $finfo->{$way};
1670
            
1671
            # Filter state
1672
            my $state = !exists $finfo->{$way} ? 'not_exists'
1673
                      : !defined $filter        ? 'not_defined'
1674
                      : ref $filter eq 'CODE'   ? 'code'
1675
                      : 'name';
1676
            
1677
            # Filter is not exists
1678
            next if $state eq 'not_exists';
1679
            
1680
            # Check filter name
1681
            croak qq{Filter "$filter" is not registered } . _subname
1682
              if  $state eq 'name'
1683
               && ! exists $self->filters->{$filter};
1684
            
1685
            # Set filter
1686
            my $f = $state eq 'not_defined' ? undef
1687
                  : $state eq 'code'        ? $filter
1688
                  : $self->filters->{$filter};
1689
            $self->{filter}{$way}{$table}{$column} = $f;
1690
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1691
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1692
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1693
        }
1694
    }
1695
    
1696
    return $self;
1697
}
1698

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1699
# DEPRECATED!
1700
has 'data_source';
1701
has dbi_options => sub { {} };
1702
has filter_check  => 1;
1703
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1704
has dbi_option => sub { {} };
1705
has default_dbi_option => sub {
1706
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1707
    return shift->default_option;
1708
};
1709

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1710
# DEPRECATED
1711
sub tag_parse {
1712
   my $self = shift;
1713
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1714
         "environment variable";
1715
    if (@_) {
1716
        $self->{tag_parse} = $_[0];
1717
        return $self;
1718
    }
1719
    return $self->{tag_parse};
1720
}
1721

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1722
# DEPRECATED!
1723
sub method {
1724
    warn "method is DEPRECATED! use helper instead";
1725
    return shift->helper(@_);
1726
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1727

            
1728
# DEPRECATED!
1729
sub assign_param {
1730
    my $self = shift;
1731
    warn "assing_param is DEPRECATED! use assign_clause instead";
1732
    return $self->assign_clause(@_);
1733
}
1734

            
1735
# DEPRECATED
1736
sub update_param {
1737
    my ($self, $param, $opts) = @_;
1738
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1739
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1740
    
1741
    # Create update parameter tag
1742
    my $tag = $self->assign_clause($param, $opts);
1743
    $tag = "set $tag" unless $opts->{no_set};
1744

            
1745
    return $tag;
1746
}
1747

            
updated pod
Yuki Kimoto authored on 2011-06-21
1748
# DEPRECATED!
1749
sub create_query {
1750
    warn "create_query is DEPRECATED! use query option of each method";
1751
    shift->_create_query(@_);
1752
}
1753

            
cleanup
Yuki Kimoto authored on 2011-06-13
1754
# DEPRECATED!
1755
sub apply_filter {
1756
    my $self = shift;
1757
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1758
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1759
    return $self->_apply_filter(@_);
1760
}
1761

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1768
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1769
    my $primary_keys = delete $opt{primary_key};
1770
    my $where = delete $opt{where};
1771
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1772
    
1773
    # Table
1774
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1775
      unless $opt{table};
1776
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1777
    
1778
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1779
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1780
    
cleanup
Yuki Kimoto authored on 2011-10-21
1781
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1782
}
1783

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1788
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1789
    
cleanup
Yuki Kimoto authored on 2011-10-21
1790
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1791
    my $primary_keys = delete $opt{primary_key};
1792
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1793
    
1794
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1795
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1796
    
cleanup
Yuki Kimoto authored on 2011-10-21
1797
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1798
}
1799

            
cleanup
Yuki Kimoto authored on 2011-06-08
1800
# DEPRECATED!
1801
sub update_at {
1802
    my $self = shift;
1803

            
cleanup
Yuki Kimoto authored on 2011-10-21
1804
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1805
    
cleanup
Yuki Kimoto authored on 2011-10-21
1806
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1807
    my $param;
1808
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1809
    my %opt = @_;
1810
    my $primary_keys = delete $opt{primary_key};
1811
    my $where = delete $opt{where};
1812
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1813
    $param  ||= $p;
1814
    
1815
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1816
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1817
    
cleanup
Yuki Kimoto authored on 2011-10-21
1818
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1819
}
1820

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1844
# DEPRECATED!
1845
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1846
    my $self = shift;
1847
    
added warnings
Yuki Kimoto authored on 2011-06-07
1848
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1849
    
1850
    # Merge tag
1851
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1852
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1853
    
1854
    return $self;
1855
}
1856

            
1857
# DEPRECATED!
1858
sub register_tag_processor {
1859
    my $self = shift;
1860
    warn "register_tag_processor is DEPRECATED!";
1861
    # Merge tag
1862
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1863
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1864
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1865
}
1866

            
cleanup
Yuki Kimoto authored on 2011-01-25
1867
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1868
sub default_bind_filter {
1869
    my $self = shift;
1870
    
cleanup
Yuki Kimoto authored on 2011-06-13
1871
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1872
    
cleanup
Yuki Kimoto authored on 2011-01-12
1873
    if (@_) {
1874
        my $fname = $_[0];
1875
        
1876
        if (@_ && !$fname) {
1877
            $self->{default_out_filter} = undef;
1878
        }
1879
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1880
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1881
              unless exists $self->filters->{$fname};
1882
        
1883
            $self->{default_out_filter} = $self->filters->{$fname};
1884
        }
1885
        return $self;
1886
    }
1887
    
1888
    return $self->{default_out_filter};
1889
}
1890

            
cleanup
Yuki Kimoto authored on 2011-01-25
1891
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1892
sub default_fetch_filter {
1893
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1894

            
cleanup
Yuki Kimoto authored on 2011-06-13
1895
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1896
    
1897
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1898
        my $fname = $_[0];
1899

            
cleanup
Yuki Kimoto authored on 2011-01-12
1900
        if (@_ && !$fname) {
1901
            $self->{default_in_filter} = undef;
1902
        }
1903
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1904
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1905
              unless exists $self->filters->{$fname};
1906
        
1907
            $self->{default_in_filter} = $self->filters->{$fname};
1908
        }
1909
        
1910
        return $self;
1911
    }
1912
    
many changed
Yuki Kimoto authored on 2011-01-23
1913
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1914
}
1915

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1916
# DEPRECATED!
1917
sub insert_param {
1918
    my $self = shift;
1919
    warn "insert_param is DEPRECATED! use values_clause instead";
1920
    return $self->values_clause(@_);
1921
}
1922

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1923
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1924
sub insert_param_tag {
1925
    warn "insert_param_tag is DEPRECATED! " .
1926
         "use insert_param instead!";
1927
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1928
}
1929

            
1930
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1931
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1932
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1933
         "use update_param instead";
1934
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1935
}
cleanup
Yuki Kimoto authored on 2011-03-08
1936
# DEPRECATED!
1937
sub _push_relation {
1938
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1939
    
1940
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1941
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1942
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1943
            my $table1 = (split (/\./, $rcolumn))[0];
1944
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1945
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1946
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1947
        }
1948
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1949
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1950
}
1951

            
1952
# DEPRECATED!
1953
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1954
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1955
    
1956
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1957
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1958
            my $table1 = (split (/\./, $rcolumn))[0];
1959
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1960
            my $table1_exists;
1961
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1962
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1963
                $table1_exists = 1 if $table eq $table1;
1964
                $table2_exists = 1 if $table eq $table2;
1965
            }
1966
            unshift @$tables, $table1 unless $table1_exists;
1967
            unshift @$tables, $table2 unless $table2_exists;
1968
        }
1969
    }
1970
}
1971

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1980
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1981
    
1982
    # Connect
1983
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1984
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1985
        user => 'ken',
1986
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1987
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1988
    );
cleanup
yuki-kimoto authored on 2010-08-05
1989

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1990
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1991
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1992
    
1993
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1994
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1995
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1996
    
1997
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1998
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1999

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2004
    # Select, more complex
2005
    my $result = $dbi->select(
2006
        table  => 'book',
2007
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
2008
            {book => [qw/title author/]},
2009
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2010
        ],
2011
        where  => {'book.author' => 'Ken'},
2012
        join => ['left outer join company on book.company_id = company.id'],
2013
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2014
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2015
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2016
    # Fetch
2017
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2018
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2019
    }
2020
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2021
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2022
    while (my $row = $result->fetch_hash) {
2023
        
2024
    }
2025
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2026
    # Execute SQL with parameter.
2027
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2028
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2029
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2030
    );
2031
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2032
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2033

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2049
Named place holder support
2050

            
2051
=item *
2052

            
cleanup
Yuki Kimoto authored on 2011-07-29
2053
Model support
2054

            
2055
=item *
2056

            
2057
Connection manager support
2058

            
2059
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2060

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

            
2065
=item *
2066

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

            
2069
=item *
2070

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

            
2073
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2074

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2082
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2083
L<DBIx::Custom::Result>,
2084
L<DBIx::Custom::Query>,
2085
L<DBIx::Custom::Where>,
2086
L<DBIx::Custom::Model>,
2087
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2088

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

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

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

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

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

            
2102
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2103
        "dbi:mysql:database=$database",
2104
        $user,
2105
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2106
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2107
    );
2108
    
updated pod
Yuki Kimoto authored on 2011-06-21
2109
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2110

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

            
2114
    my $dbi = DBIx::Custom->connect(
2115
      dsn => $dsn, user => $user, password => $password, connector => 1);
2116
    
2117
    my $connector = $dbi->connector; # DBIx::Connector
2118

            
2119
Note that L<DBIx::Connector> must be installed.
2120

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2136
    {
2137
        RaiseError => 1,
2138
        PrintError => 0,
2139
        AutoCommit => 1,
2140
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2141

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

            
2144
    my $exclude_table = $dbi->exclude_table;
2145
    $dbi = $dbi->exclude_table(qr/pg_/);
2146

            
2147
Excluded table regex.
2148
C<each_column>, C<each_table>, C<type_rule>,
2149
and C<setup_model> methods ignore matching tables.
2150

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

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

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

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

            
2160
    my $last_sql = $dbi->last_sql;
2161
    $dbi = $dbi->last_sql($last_sql);
2162

            
2163
Get last successed SQL executed by C<execute> method.
2164

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

            
2167
    my $now = $dbi->now;
2168
    $dbi = $dbi->now($now);
2169

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

            
2172
    sub {
2173
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2174
        $mon++;
2175
        $year += 1900;
2176
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2177
    }
2178

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

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

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

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

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

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

            
2193
    my $option = $dbi->option;
2194
    $dbi = $dbi->option($option);
2195

            
2196
L<DBI> option, used when C<connect> method is executed.
2197
Each value in option override the value of C<default_option>.
2198

            
cleanup
yuki-kimoto authored on 2010-10-17
2199
=head2 C<password>
2200

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2221
You can set quote pair.
2222

            
2223
    $dbi->quote('[]');
2224

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2234
    my $safety_character = $dbi->safety_character;
2235
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2236

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

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

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

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

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

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

            
2253
    my $tag_parse = $dbi->tag_parse(0);
2254
    $dbi = $dbi->tag_parse;
2255

            
2256
Enable DEPRECATED tag parsing functionality, default to 1.
2257
If you want to disable tag parsing functionality, set to 0.
2258

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

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

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

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

            
2268
    my $user_column_info = $dbi->user_column_info;
2269
    $dbi = $dbi->user_column_info($user_column_info);
2270

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

            
2273
    [
2274
        {table => 'book', column => 'title', info => {...}},
2275
        {table => 'author', column => 'name', info => {...}}
2276
    ]
2277

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

            
2280
    my $user_column_info
2281
      = $dbi->get_column_info(exclude_table => qr/^system/);
2282
    $dbi->user_column_info($user_column_info);
2283

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

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

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

            
2292
You can set the following data.
2293

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

            
2299
Usually, you can set return value of C<get_table_info>.
2300

            
2301
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2302
    $dbi->user_table_info($user_table_info);
2303

            
2304
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2305
to find table info.
2306

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2343
Create column clause. The follwoing column clause is created.
2344

            
2345
    book.author as "book.author",
2346
    book.title as "book.title"
2347

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2350
    # Separator is hyphen
2351
    $dbi->separator('-');
2352
    
2353
    book.author as "book-author",
2354
    book.title as "book-title"
2355
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2356
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2357

            
update pod
Yuki Kimoto authored on 2011-03-13
2358
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2359
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2360
        user => 'ken',
2361
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2362
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2363
    );
2364

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

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

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

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

            
2375
Get rows count.
2376

            
2377
Options is same as C<select> method's ones.
2378

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2381
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2382
        table => 'book',
2383
        primary_key => 'id',
2384
        join => [
2385
            'inner join company on book.comparny_id = company.id'
2386
        ],
2387
    );
2388

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

            
2392
   $dbi->model('book')->select(...);
2393

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

            
2396
    my $dbh = $dbi->dbh;
2397

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

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

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

            
2405
Execute delete statement.
2406

            
2407
The following opitons are available.
2408

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

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

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

            
2416
=item C<id>
2417

            
2418
    id => 4
2419
    id => [4, 5]
2420

            
2421
ID corresponding to C<primary_key>.
2422
You can delete rows by C<id> and C<primary_key>.
2423

            
2424
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2425
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2426
        id => [4, 5],
2427
        table => 'book',
2428
    );
2429

            
2430
The above is same as the followin one.
2431

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

            
2434
=item C<prefix>
2435

            
2436
    prefix => 'some'
2437

            
2438
prefix before table name section.
2439

            
2440
    delete some from book
2441

            
2442
=item C<table>
2443

            
2444
    table => 'book'
2445

            
2446
Table name.
2447

            
2448
=item C<where>
2449

            
2450
Same as C<select> method's C<where> option.
2451

            
2452
=back
2453

            
2454
=head2 C<delete_all>
2455

            
2456
    $dbi->delete_all(table => $table);
2457

            
2458
Execute delete statement for all rows.
2459
Options is same as C<delete>.
2460

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

            
2463
    $dbi->each_column(
2464
        sub {
2465
            my ($dbi, $table, $column, $column_info) = @_;
2466
            
2467
            my $type = $column_info->{TYPE_NAME};
2468
            
2469
            if ($type eq 'DATE') {
2470
                # ...
2471
            }
2472
        }
2473
    );
2474

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

            
2480
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2481
infromation, you can improve the performance of C<each_column> in
2482
the following way.
2483

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

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

            
2490
    $dbi->each_table(
2491
        sub {
2492
            my ($dbi, $table, $table_info) = @_;
2493
            
2494
            my $table_name = $table_info->{TABLE_NAME};
2495
        }
2496
    );
2497

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

            
2503
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2504
infromation, you can improve the performance of C<each_table> in
2505
the following way.
2506

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

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

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

            
2518
    my $result = $dbi->execute(
2519
      "select * from book where title = :book.title and author like :book.author",
2520
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2521
    );
2522

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2529
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2530
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2531
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2532
    select * from book where title = :title and author like :author
2533
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2534
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2535
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2536

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2540
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2541
    select * from book where :title{=} and :author{like}
2542
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2543
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2544
    select * from where title = ? and author like ?;
2545

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

            
2550
    select * from where title = "aa\\:bb";
2551

            
cleanup
Yuki Kimoto authored on 2011-10-20
2552
B<OPTIONS>
2553

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

            
2556
=over 4
2557

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

            
2560
You can filter sql after the sql is build.
2561

            
2562
    after_build_sql => $code_ref
2563

            
2564
The following one is one example.
2565

            
2566
    $dbi->select(
2567
        table => 'book',
2568
        column => 'distinct(name)',
2569
        after_build_sql => sub {
2570
            "select count(*) from ($_[0]) as t1"
2571
        }
2572
    );
2573

            
2574
The following SQL is executed.
2575

            
2576
    select count(*) from (select distinct(name) from book) as t1;
2577

            
cleanup
Yuki Kimoto authored on 2011-10-20
2578
=item C<append>
2579

            
2580
    append => 'order by name'
2581

            
2582
Append some statement after SQL.
2583

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

            
2586
Specify database bind data type.
2587

            
2588
    bind_type => [image => DBI::SQL_BLOB]
2589
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2590

            
2591
This is used to bind parameter by C<bind_param> of statment handle.
2592

            
2593
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2594

            
update pod
Yuki Kimoto authored on 2011-03-13
2595
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2596
    
2597
    filter => {
2598
        title  => sub { uc $_[0] }
2599
        author => sub { uc $_[0] }
2600
    }
update pod
Yuki Kimoto authored on 2011-03-13
2601

            
updated pod
Yuki Kimoto authored on 2011-06-09
2602
    # Filter name
2603
    filter => {
2604
        title  => 'upper_case',
2605
        author => 'upper_case'
2606
    }
2607
        
2608
    # At once
2609
    filter => [
2610
        [qw/title author/]  => sub { uc $_[0] }
2611
    ]
2612

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

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

            
2620
    query => 1
2621

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2625
    my $sql = $query->{sql};
2626
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2627
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2628
=item C<reuse>
2629
    
2630
    reuse => $hash_ref
2631

            
2632
Reuse query object if the hash reference variable is set.
2633
    
2634
    my $queries = {};
2635
    $dbi->execute($sql, $param, reuse => $queries);
2636

            
2637
This will improved performance when you want to execute same query repeatedly
2638
because generally creating query object is slow.
2639

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2642
    primary_key => 'id'
2643
    primary_key => ['id1', 'id2']
2644

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2647
=item C<table>
2648
    
2649
    table => 'author'
2650

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2658
    # Same
2659
    $dbi->execute(
2660
      "select * from book where title = :book.title and author = :book.author",
2661
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2662

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

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

            
2667
Table alias. Key is real table name, value is alias table name.
2668
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2669
on alias table name.
2670

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

            
2673
    type_rule_off => 1
2674

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

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

            
2679
    type_rule1_off => 1
2680

            
2681
Turn C<into1> type rule off.
2682

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

            
2685
    type_rule2_off => 1
2686

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

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

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

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

            
2695
get column infomation except for one which match C<exclude_table> pattern.
2696

            
2697
    [
2698
        {table => 'book', column => 'title', info => {...}},
2699
        {table => 'author', column => 'name' info => {...}}
2700
    ]
2701

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

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

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

            
2708
    [
2709
        {table => 'book', info => {...}},
2710
        {table => 'author', info => {...}}
2711
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2712

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

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

            
2717
    $dbi->helper(
2718
        find_or_create   => sub {
2719
            my $self = shift;
2720
            
2721
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2722
        },
2723
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2724
    );
2725

            
2726
Register helper. These helper is called directly from L<DBIx::Custom> object.
2727

            
2728
    $dbi->find_or_create;
2729

            
cleanup
yuki-kimoto authored on 2010-10-17
2730
=head2 C<insert>
2731

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

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

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

            
2740
    {date => \"NOW()"}
2741

            
cleanup
Yuki Kimoto authored on 2011-10-20
2742
B<options>
2743

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

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

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

            
2751
    created_at => 'created_datetime'
2752

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2759
    id => 4
2760
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2761

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2765
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2766
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2767
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2768
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2769
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2770
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2771

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

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

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

            
2781
    prefix => 'or replace'
2782

            
2783
prefix before table name section
2784

            
2785
    insert or replace into book
2786

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

            
2789
    table => 'book'
2790

            
2791
Table name.
2792

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

            
2795
This option is same as C<update> method C<updated_at> option.
2796

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

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

            
2801
placeholder wrapped string.
2802

            
2803
If the following statement
2804

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

            
2808
is executed, the following SQL is executed.
2809

            
2810
    insert into book price values ( ? + 5 );
2811

            
update pod
Yuki Kimoto authored on 2011-03-13
2812
=back
2813

            
2814
=over 4
2815

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2823
    lib / MyModel.pm
2824
        / MyModel / book.pm
2825
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2826

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

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

            
2831
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2832
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2833
    
2834
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2835

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2840
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2841
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2842
    
2843
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2844

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2847
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2848
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2849
    
2850
    1;
2851
    
updated pod
Yuki Kimoto authored on 2011-06-21
2852
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2853

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

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

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

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

            
2863
    my $like_value = $dbi->like_value
2864

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

            
2867
    sub { "%$_[0]%" }
2868

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

            
2871
    my $mapper = $dbi->mapper(param => $param);
2872

            
2873
Create a new L<DBIx::Custom::Mapper> object.
2874

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

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

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

            
2881
    {key1 => [1, 1], key2 => 2}
2882

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

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

            
2887
    my $model = $dbi->model('book');
2888

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

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

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

            
2896
Create column clause for myself. The follwoing column clause is created.
2897

            
2898
    book.author as author,
2899
    book.title as title
2900

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

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

            
2910
Create a new L<DBIx::Custom> object.
2911

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

            
2914
    my $not_exists = $dbi->not_exists;
2915

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

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

            
2921
    my $order = $dbi->order;
2922

            
2923
Create a new L<DBIx::Custom::Order> object.
2924

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

            
2927
    my $quooted = $dbi->q("title");
2928

            
2929
Quote string by value of C<quote>.
2930

            
cleanup
yuki-kimoto authored on 2010-10-17
2931
=head2 C<register_filter>
2932

            
update pod
Yuki Kimoto authored on 2011-03-13
2933
    $dbi->register_filter(
2934
        # Time::Piece object to database DATE format
2935
        tp_to_date => sub {
2936
            my $tp = shift;
2937
            return $tp->strftime('%Y-%m-%d');
2938
        },
2939
        # database DATE format to Time::Piece object
2940
        date_to_tp => sub {
2941
           my $date = shift;
2942
           return Time::Piece->strptime($date, '%Y-%m-%d');
2943
        }
2944
    );
cleanup
yuki-kimoto authored on 2010-10-17
2945
    
update pod
Yuki Kimoto authored on 2011-03-13
2946
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2947

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2950
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2951
        table  => 'book',
2952
        column => ['author', 'title'],
2953
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2954
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2955
    
updated document
Yuki Kimoto authored on 2011-06-09
2956
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2957

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2965
=item C<column>
2966
    
updated document
Yuki Kimoto authored on 2011-06-09
2967
    column => 'author'
2968
    column => ['author', 'title']
2969

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2978
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2979
        {book => [qw/author title/]},
2980
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2981
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2982

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

            
2985
    book.author as "book.author",
2986
    book.title as "book.title",
2987
    person.name as "person.name",
2988
    person.age as "person.age"
2989

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

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

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

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

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

            
3003
    id => 4
3004
    id => [4, 5]
3005

            
3006
ID corresponding to C<primary_key>.
3007
You can select rows by C<id> and C<primary_key>.
3008

            
3009
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3010
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3011
        id => [4, 5],
3012
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3013
    );
3014

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3017
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3018
        where => {id1 => 4, id2 => 5},
3019
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3020
    );
3021
    
cleanup
Yuki Kimoto authored on 2011-10-20
3022
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3023

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

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

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

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

            
3036
    prefix => 'SQL_CALC_FOUND_ROWS'
3037

            
3038
Prefix of column cluase
3039

            
3040
    select SQL_CALC_FOUND_ROWS title, author from book;
3041

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

            
3044
    join => [
3045
        'left outer join company on book.company_id = company_id',
3046
        'left outer join location on company.location_id = location.id'
3047
    ]
3048
        
3049
Join clause. If column cluase or where clause contain table name like "company.name",
3050
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3051

            
3052
    $dbi->select(
3053
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3054
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3055
        where => {'company.name' => 'Orange'},
3056
        join => [
3057
            'left outer join company on book.company_id = company.id',
3058
            'left outer join location on company.location_id = location.id'
3059
        ]
3060
    );
3061

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3065
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3066
    from book
3067
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3068
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3069

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3070
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
3071
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3072

            
3073
    $dbi->select(
3074
        table => 'book',
3075
        column => ['company.location_id as location_id'],
3076
        where => {'company.name' => 'Orange'},
3077
        join => [
3078
            {
3079
                clause => 'left outer join location on company.location_id = location.id',
3080
                table => ['company', 'location']
3081
            }
3082
        ]
3083
    );
3084

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3089
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3090

            
updated document
Yuki Kimoto authored on 2011-06-09
3091
=item C<where>
3092
    
3093
    # Hash refrence
3094
    where => {author => 'Ken', 'title' => 'Perl'}
3095
    
3096
    # DBIx::Custom::Where object
3097
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3098
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3099
        param  => {author => 'Ken', title => '%Perl%'}
3100
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3101
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3102
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3103
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3104
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3105
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3106
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3107
    
3108
    # String
3109
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3110

            
cleanup
Yuki Kimoto authored on 2011-10-20
3111
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3112
    
update pod
Yuki Kimoto authored on 2011-03-12
3113
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3114

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

            
3117
    $dbi->setup_model;
3118

            
3119
Setup all model objects.
3120
C<columns> of model object is automatically set, parsing database information.
3121

            
3122
=head2 C<type_rule>
3123

            
3124
    $dbi->type_rule(
3125
        into1 => {
3126
            date => sub { ... },
3127
            datetime => sub { ... }
3128
        },
3129
        into2 => {
3130
            date => sub { ... },
3131
            datetime => sub { ... }
3132
        },
3133
        from1 => {
3134
            # DATE
3135
            9 => sub { ... },
3136
            # DATETIME or TIMESTAMP
3137
            11 => sub { ... },
3138
        }
3139
        from2 => {
3140
            # DATE
3141
            9 => sub { ... },
3142
            # DATETIME or TIMESTAMP
3143
            11 => sub { ... },
3144
        }
3145
    );
3146

            
3147
Filtering rule when data is send into and get from database.
3148
This has a little complex problem.
3149

            
3150
In C<into1> and C<into2> you can specify
3151
type name as same as type name defined
3152
by create table, such as C<DATETIME> or C<DATE>.
3153

            
3154
Note that type name and data type don't contain upper case.
3155
If these contain upper case charactor, you convert it to lower case.
3156

            
3157
C<into2> is executed after C<into1>.
3158

            
3159
Type rule of C<into1> and C<into2> is enabled on the following
3160
column name.
3161

            
3162
=over 4
3163

            
3164
=item 1. column name
3165

            
3166
    issue_date
3167
    issue_datetime
3168

            
3169
This need C<table> option in each method.
3170

            
3171
=item 2. table name and column name, separator is dot
3172

            
3173
    book.issue_date
3174
    book.issue_datetime
3175

            
3176
=back
3177

            
3178
You get all type name used in database by C<available_typename>.
3179

            
3180
    print $dbi->available_typename;
3181

            
3182
In C<from1> and C<from2> you specify data type, not type name.
3183
C<from2> is executed after C<from1>.
3184
You get all data type by C<available_datatype>.
3185

            
3186
    print $dbi->available_datatype;
3187

            
3188
You can also specify multiple types at once.
3189

            
3190
    $dbi->type_rule(
3191
        into1 => [
3192
            [qw/DATE DATETIME/] => sub { ... },
3193
        ],
3194
    );
3195

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

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

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

            
3202
If you want to set constant value to row data, use scalar reference
3203
as parameter value.
3204

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3216
    id => 4
3217
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3218

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3222
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3223
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3224
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3225
        id => [4, 5],
3226
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3227
    );
update pod
Yuki Kimoto authored on 2011-03-13
3228

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3231
    $dbi->update(
3232
        {title => 'Perl', author => 'Ken'}
3233
        where => {id1 => 4, id2 => 5},
3234
        table => 'book'
3235
    );
update pod
Yuki Kimoto authored on 2011-03-13
3236

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

            
3239
    prefix => 'or replace'
3240

            
3241
prefix before table name section
3242

            
3243
    update or replace book
3244

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

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

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

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

            
3253
Same as C<select> method's C<where> option.
3254

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

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

            
3259
placeholder wrapped string.
3260

            
3261
If the following statement
3262

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

            
3266
is executed, the following SQL is executed.
3267

            
3268
    update book set price =  ? + 5;
3269

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

            
3272
    updated_at => 'updated_datetime'
3273

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3278
=back
update pod
Yuki Kimoto authored on 2011-03-13
3279

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3287
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3288
    
3289
    # ID
3290
    $dbi->update_or_insert(
3291
        {title => 'Perl'},
3292
        table => 'book',
3293
        id => 1,
3294
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3295
        option => {
3296
            select => {
3297
                 append => 'for update'
3298
            }
3299
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3300
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3301

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3302
Update or insert.
3303

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3308
C<OPTIONS>
3309

            
3310
C<update_or_insert> method use all common option
3311
in C<select>, C<update>, C<delete>, and has the following new ones.
3312

            
3313
=over 4
3314

            
3315
=item C<option>
3316

            
3317
    option => {
3318
        select => {
3319
            append => '...'
3320
        },
3321
        insert => {
3322
            prefix => '...'
3323
        },
3324
        update => {
3325
            filter => {}
3326
        }
3327
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3328

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

            
3332
=over 4
3333

            
3334
=item C<select_option>
3335

            
3336
    select_option => {append => 'for update'}
3337

            
3338
select method option,
3339
select method is used to check the row is already exists.
3340

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

            
3343
    $dbi->show_datatype($table);
3344

            
3345
Show data type of the columns of specified table.
3346

            
3347
    book
3348
    title: 5
3349
    issue_date: 91
3350

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

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

            
3355
    $dbi->show_tables;
3356

            
3357
Show tables.
3358

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

            
3361
    $dbi->show_typename($table);
3362

            
3363
Show type name of the columns of specified table.
3364

            
3365
    book
3366
    title: varchar
3367
    issue_date: date
3368

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

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

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

            
3375
Create values clause.
3376

            
3377
    (title, author) values (title = :title, age = :age);
3378

            
3379
You can use this in insert statement.
3380

            
3381
    my $insert_sql = "insert into book $values_clause";
3382

            
3383
=head2 C<where>
3384

            
3385
    my $where = $dbi->where(
3386
        clause => ['and', 'title = :title', 'author = :author'],
3387
        param => {title => 'Perl', author => 'Ken'}
3388
    );
3389

            
3390
Create a new L<DBIx::Custom::Where> object.
3391

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

            
3394
=head2 C<DBIX_CUSTOM_DEBUG>
3395

            
3396
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3397
executed SQL and bind values are printed to STDERR.
3398

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

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

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

            
3405
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3406

            
3407
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3408

            
3409
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3410
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3411

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

            
3414
L<DBIx::Custom>
3415

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

            
3470
L<DBIx::Custom::Model>
3471

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

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

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

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

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

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

            
3520
L<DBIx::Custom::Tag>
3521

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

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

            
3526
    # Other
3527
    prepend method array reference receiving
3528
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3529

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

            
3532
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3533
except for attribute method.
3534
You can check all DEPRECATED functionalities by document.
3535
DEPRECATED functionality is removed after five years,
3536
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
3537
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3538

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

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

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

            
3545
C<< <kimoto.yuki at gmail.com> >>
3546

            
3547
L<http://github.com/yuki-kimoto/DBIx-Custom>
3548

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3549
=head1 AUTHOR
3550

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

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

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

            
3557
This program is free software; you can redistribute it and/or modify it
3558
under the same terms as Perl itself.
3559

            
3560
=cut