DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3614 lines | 94.899kb
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/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21
use DBIx::Custom::Class::Inspector;
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
use_next_version is renamed ...
Yuki Kimoto authored on 2011-11-16
1186
sub use_version1 {
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
1187
    my $self = shift;
use_next_version is renamed ...
Yuki Kimoto authored on 2011-11-16
1188
    
1189
    return if $VERSION >= 1;
1190
    
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
1191
    my @modules = ('', qw/::Where ::Util ::Result ::Order ::NotExists ::Model ::Mapper/);
1192
    
1193
    # Replace
1194
    for my $module (@modules) {
1195
        my $old = 'DBIx::Custom' . $module;
1196
        my $new = 'DBIx::Custom::Next' . $module;
1197
        
1198
        no strict 'refs';
1199
        no warnings 'redefine';
1200
        eval "require $old";
1201
        die $@ if $@;
1202
        eval "require $new";
1203
        die $@ if $@;
1204
        for my $method (@{DBIx::Custom::Class::Inspector->methods( $old, 'full', 'public' )}) {
1205
            next unless $method =~ /^DBIx::Custom/;
1206
            undef &{"$method"};
1207
            *{"$method"} = sub { die "$method method is removed" };
1208
        }
1209
        
1210
        for my $new_method (@{DBIx::Custom::Class::Inspector->methods( $new, 'full', 'public' )}) {
1211
            next unless $new_method =~ /^DBIx::Custom/;
1212
            my $old_method = $new_method;
1213
            $old_method =~ s/::Next//;
1214
            *{"$old_method"} = \&{"$new_method"};
1215
        }
1216
    }
1217

            
1218
    # Remove
1219
    for my $module (qw/DBIx::Custom::Tag DBIx::Custom::QueryBuilder/) {
1220
        no strict 'refs';
1221
        eval "require $module";
1222
        die $@ if $@;
1223
        for my $method (@{DBIx::Custom::Class::Inspector->methods( $module, 'full', 'public' )}) {
1224
            next unless $method =~ /^DBIx::Custom/;
1225
            undef &{"$method"};
1226
            *{"$method"} = sub { die "$method method is removed" };
1227
        }
1228
    }
1229
}
1230

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1231
sub values_clause {
1232
    my ($self, $param, $opts) = @_;
1233
    
1234
    my $wrap = $opts->{wrap} || {};
1235
    
1236
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-10-23
1237
    my $safety = $self->{safety_character} || $self->safety_character;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1238
    my $qp = $self->q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1239
    my $q = substr($qp, 0, 1) || '';
1240
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1241
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1242
    # Check unsafety keys
1243
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
1244
        for my $column (keys %$param) {
1245
            croak qq{"$column" is not safety column name } . _subname
1246
              unless $column =~ /^[$safety\.]+$/;
1247
        }
1248
    }
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1249
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1250
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1251
    '(' .
1252
    join(
1253
      ', ',
1254
      map { "$q$_$p" } sort keys %$param
1255
    ) .
1256
    ') values (' .
1257
    join(
1258
      ', ',
1259
      map {
1260
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1261
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1262
          ":$_";
1263
      } sort keys %$param
1264
    ) .
1265
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1266
}
1267

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

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

            
1296
        # Create query
1297
        my $builder = $self->query_builder;
1298
        $query = $builder->build_query($source);
1299

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

            
1306
        # Save query to cache
1307
        $self->cache_method->(
1308
            $self, $source,
1309
            {
1310
                sql     => $query->sql, 
1311
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1312
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1313
            }
1314
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1315
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1316

            
1317
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1318
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1319
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1320
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1321
        $query->sql($sql);
1322
    }
1323
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1324
    # Save sql
1325
    $self->last_sql($query->sql);
1326
    
updated pod
Yuki Kimoto authored on 2011-06-21
1327
    # Prepare statement handle
1328
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1329
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1330
    
1331
    if ($@) {
1332
        $self->_croak($@, qq{. Following SQL is executed.\n}
1333
                        . qq{$query->{sql}\n} . _subname);
1334
    }
1335
    
1336
    # Set statement handle
1337
    $query->sth($sth);
1338
    
1339
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1340
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1341
    
1342
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1343
}
1344

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1401
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1402
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1403
    
1404
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1405
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1406
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1407
      unless defined $primary_keys;
1408
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1409
    
cleanup
Yuki Kimoto authored on 2011-06-08
1410
    # Create parameter
1411
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1412
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1413
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1414
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1415
           my $key = $primary_keys->[$i];
1416
           $key = "$table." . $key if $table;
1417
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1418
        }
1419
    }
1420
    
cleanup
Yuki Kimoto authored on 2011-06-08
1421
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1422
}
1423

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1456
sub _croak {
1457
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1458
    
1459
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1460
    $append ||= "";
1461
    
1462
    # Verbose
1463
    if ($Carp::Verbose) { croak $error }
1464
    
1465
    # Not verbose
1466
    else {
1467
        
1468
        # Remove line and module infromation
1469
        my $at_pos = rindex($error, ' at ');
1470
        $error = substr($error, 0, $at_pos);
1471
        $error =~ s/\s+$//;
1472
        croak "$error$append";
1473
    }
1474
}
1475

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1478
sub _need_tables {
1479
    my ($self, $tree, $need_tables, $tables) = @_;
1480
    
cleanup
Yuki Kimoto authored on 2011-04-02
1481
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1482
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1483
        if ($tree->{$table}) {
1484
            $need_tables->{$table} = 1;
1485
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1486
        }
1487
    }
1488
}
1489

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1490
sub _option {
1491
    my $self = shift;
1492
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1493
    warn "dbi_options is DEPRECATED! use option instead\n"
1494
      if keys %{$self->dbi_options};
1495
    warn "dbi_option is DEPRECATED! use option instead\n"
1496
      if keys %{$self->dbi_option};
1497
    return $option;
1498
}
1499

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1500
sub _push_join {
1501
    my ($self, $sql, $join, $join_tables) = @_;
1502
    
cleanup
Yuki Kimoto authored on 2011-10-21
1503
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1504
    
cleanup
Yuki Kimoto authored on 2011-04-02
1505
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1506
    return unless @$join;
1507
    
cleanup
Yuki Kimoto authored on 2011-04-02
1508
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1509
    my $tree = {};
1510
    for (my $i = 0; $i < @$join; $i++) {
1511
        
cleanup
Yuki Kimoto authored on 2011-07-28
1512
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1513
        my $join_clause;;
1514
        my $option;
1515
        if (ref $join->[$i] eq 'HASH') {
1516
            $join_clause = $join->[$i]->{clause};
1517
            $option = {table => $join->[$i]->{table}};
1518
        }
1519
        else {
1520
            $join_clause = $join->[$i];
1521
            $option = {};
1522
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1523

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1571
sub _quote {
1572
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1573
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1574
}
1575

            
cleanup
Yuki Kimoto authored on 2011-04-02
1576
sub _remove_duplicate_table {
1577
    my ($self, $tables, $main_table) = @_;
1578
    
1579
    # Remove duplicate table
1580
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1581
    delete $tables{$main_table} if $main_table;
1582
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1583
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1584
    if (my $q = $self->_quote) {
1585
        $q = quotemeta($q);
1586
        $_ =~ s/[$q]//g for @$new_tables;
1587
    }
1588

            
1589
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1590
}
1591

            
cleanup
Yuki Kimoto authored on 2011-04-02
1592
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1593
    my ($self, $source) = @_;
1594
    
cleanup
Yuki Kimoto authored on 2011-04-02
1595
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1596
    my $tables = [];
1597
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1598
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1599
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1600
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1601
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1602
    while ($source =~ /$table_re/g) {
1603
        push @$tables, $1;
1604
    }
1605
    
1606
    return $tables;
1607
}
1608

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1612
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1613
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1614
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1615
    my $w = {};
1616
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1617

            
cleanup
Yuki Kimoto authored on 2011-10-25
1618
    my $obj;
1619
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1620
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1621
        if (ref $where eq 'HASH') {
1622
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1623
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1624
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1625
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1626
                my $table;
1627
                my $c;
1628
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1629
                    $table = $1;
1630
                    $c = $2;
1631
                }
1632
                
1633
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1634
                $table_quote = $self->q($table) if defined $table;
1635
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1636
                $column_quote = $table_quote . '.' . $column_quote
1637
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1638
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1639
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1640

            
1641
            # Check unsafety column
1642
            my $safety = $self->safety_character;
1643
            unless ($column_join =~ /^[$safety\.]+$/) {
1644
                for my $column (keys %$where) {
1645
                    croak qq{"$column" is not safety column name } . _subname
1646
                      unless $column =~ /^[$safety\.]+$/;
1647
                }
1648
            }
1649
            
cleanup
Yuki Kimoto authored on 2011-10-25
1650
            $obj = $self->where(clause => $clause, param => $where);
1651
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1652
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1653
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1654
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1655
        }
1656
        
1657
        # Check where argument
1658
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1659
            . qq{or array reference, which contains where clause and parameter}
1660
            . _subname
1661
          unless ref $obj eq 'DBIx::Custom::Where';
1662

            
1663
        $w->{param} = keys %$where_param
1664
                    ? $self->merge_param($where_param, $obj->param)
1665
                    : $obj->param;
1666
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1667
    }
1668
    elsif ($where) {
1669
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1670
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1671
    }
1672
    
1673
    return $w;
1674
}
1675

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1746
# DEPRECATED!
1747
has 'data_source';
1748
has dbi_options => sub { {} };
1749
has filter_check  => 1;
1750
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1751
has dbi_option => sub { {} };
1752
has default_dbi_option => sub {
1753
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1754
    return shift->default_option;
1755
};
1756

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1757
# DEPRECATED
1758
sub tag_parse {
1759
   my $self = shift;
1760
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1761
         "environment variable";
1762
    if (@_) {
1763
        $self->{tag_parse} = $_[0];
1764
        return $self;
1765
    }
1766
    return $self->{tag_parse};
1767
}
1768

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1769
# DEPRECATED!
1770
sub method {
1771
    warn "method is DEPRECATED! use helper instead";
1772
    return shift->helper(@_);
1773
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1774

            
1775
# DEPRECATED!
1776
sub assign_param {
1777
    my $self = shift;
1778
    warn "assing_param is DEPRECATED! use assign_clause instead";
1779
    return $self->assign_clause(@_);
1780
}
1781

            
1782
# DEPRECATED
1783
sub update_param {
1784
    my ($self, $param, $opts) = @_;
1785
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1786
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1787
    
1788
    # Create update parameter tag
1789
    my $tag = $self->assign_clause($param, $opts);
1790
    $tag = "set $tag" unless $opts->{no_set};
1791

            
1792
    return $tag;
1793
}
1794

            
updated pod
Yuki Kimoto authored on 2011-06-21
1795
# DEPRECATED!
1796
sub create_query {
1797
    warn "create_query is DEPRECATED! use query option of each method";
1798
    shift->_create_query(@_);
1799
}
1800

            
cleanup
Yuki Kimoto authored on 2011-06-13
1801
# DEPRECATED!
1802
sub apply_filter {
1803
    my $self = shift;
1804
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1805
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1806
    return $self->_apply_filter(@_);
1807
}
1808

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1815
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1816
    my $primary_keys = delete $opt{primary_key};
1817
    my $where = delete $opt{where};
1818
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1819
    
1820
    # Table
1821
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1822
      unless $opt{table};
1823
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1824
    
1825
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1826
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1827
    
cleanup
Yuki Kimoto authored on 2011-10-21
1828
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1829
}
1830

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1835
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1836
    
cleanup
Yuki Kimoto authored on 2011-10-21
1837
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1838
    my $primary_keys = delete $opt{primary_key};
1839
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1840
    
1841
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1842
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1843
    
cleanup
Yuki Kimoto authored on 2011-10-21
1844
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1845
}
1846

            
cleanup
Yuki Kimoto authored on 2011-06-08
1847
# DEPRECATED!
1848
sub update_at {
1849
    my $self = shift;
1850

            
cleanup
Yuki Kimoto authored on 2011-10-21
1851
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1852
    
cleanup
Yuki Kimoto authored on 2011-10-21
1853
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1854
    my $param;
1855
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1856
    my %opt = @_;
1857
    my $primary_keys = delete $opt{primary_key};
1858
    my $where = delete $opt{where};
1859
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1860
    $param  ||= $p;
1861
    
1862
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1863
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1864
    
cleanup
Yuki Kimoto authored on 2011-10-21
1865
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1866
}
1867

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1868
# DEPRECATED!
1869
sub insert_at {
1870
    my $self = shift;
1871
    
cleanup
Yuki Kimoto authored on 2011-10-21
1872
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1873
    
cleanup
Yuki Kimoto authored on 2011-10-21
1874
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1875
    my $param;
1876
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1877
    my %opt = @_;
1878
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1879
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1880
    my $where = delete $opt{where};
1881
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1882
    $param  ||= $p;
1883
    
1884
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1885
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1886
    $param = $self->merge_param($where_param, $param);
1887
    
cleanup
Yuki Kimoto authored on 2011-10-21
1888
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1889
}
1890

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

            
1904
# DEPRECATED!
1905
sub register_tag_processor {
1906
    my $self = shift;
1907
    warn "register_tag_processor is DEPRECATED!";
1908
    # Merge tag
1909
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1910
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1911
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1912
}
1913

            
cleanup
Yuki Kimoto authored on 2011-01-25
1914
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1915
sub default_bind_filter {
1916
    my $self = shift;
1917
    
cleanup
Yuki Kimoto authored on 2011-06-13
1918
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1919
    
cleanup
Yuki Kimoto authored on 2011-01-12
1920
    if (@_) {
1921
        my $fname = $_[0];
1922
        
1923
        if (@_ && !$fname) {
1924
            $self->{default_out_filter} = undef;
1925
        }
1926
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1927
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1928
              unless exists $self->filters->{$fname};
1929
        
1930
            $self->{default_out_filter} = $self->filters->{$fname};
1931
        }
1932
        return $self;
1933
    }
1934
    
1935
    return $self->{default_out_filter};
1936
}
1937

            
cleanup
Yuki Kimoto authored on 2011-01-25
1938
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1939
sub default_fetch_filter {
1940
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1941

            
cleanup
Yuki Kimoto authored on 2011-06-13
1942
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1943
    
1944
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1945
        my $fname = $_[0];
1946

            
cleanup
Yuki Kimoto authored on 2011-01-12
1947
        if (@_ && !$fname) {
1948
            $self->{default_in_filter} = undef;
1949
        }
1950
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1951
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1952
              unless exists $self->filters->{$fname};
1953
        
1954
            $self->{default_in_filter} = $self->filters->{$fname};
1955
        }
1956
        
1957
        return $self;
1958
    }
1959
    
many changed
Yuki Kimoto authored on 2011-01-23
1960
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1961
}
1962

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1963
# DEPRECATED!
1964
sub insert_param {
1965
    my $self = shift;
1966
    warn "insert_param is DEPRECATED! use values_clause instead";
1967
    return $self->values_clause(@_);
1968
}
1969

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1970
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1971
sub insert_param_tag {
1972
    warn "insert_param_tag is DEPRECATED! " .
1973
         "use insert_param instead!";
1974
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1975
}
1976

            
1977
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1978
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1979
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1980
         "use update_param instead";
1981
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1982
}
cleanup
Yuki Kimoto authored on 2011-03-08
1983
# DEPRECATED!
1984
sub _push_relation {
1985
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1986
    
1987
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1988
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1989
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1990
            my $table1 = (split (/\./, $rcolumn))[0];
1991
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1992
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1993
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1994
        }
1995
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1996
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1997
}
1998

            
1999
# DEPRECATED!
2000
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
2001
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
2002
    
2003
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
2004
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
2005
            my $table1 = (split (/\./, $rcolumn))[0];
2006
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2007
            my $table1_exists;
2008
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
2009
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
2010
                $table1_exists = 1 if $table eq $table1;
2011
                $table2_exists = 1 if $table eq $table2;
2012
            }
2013
            unshift @$tables, $table1 unless $table1_exists;
2014
            unshift @$tables, $table2 unless $table2_exists;
2015
        }
2016
    }
2017
}
2018

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2027
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2028
    
2029
    # Connect
2030
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2031
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2032
        user => 'ken',
2033
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2034
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2035
    );
cleanup
yuki-kimoto authored on 2010-08-05
2036

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2037
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2038
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2039
    
2040
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2041
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2042
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2043
    
2044
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2045
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2046

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2096
Named place holder support
2097

            
2098
=item *
2099

            
cleanup
Yuki Kimoto authored on 2011-07-29
2100
Model support
2101

            
2102
=item *
2103

            
2104
Connection manager support
2105

            
2106
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2107

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

            
2112
=item *
2113

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

            
2116
=item *
2117

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

            
2120
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2121

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2129
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2130
L<DBIx::Custom::Result>,
2131
L<DBIx::Custom::Query>,
2132
L<DBIx::Custom::Where>,
2133
L<DBIx::Custom::Model>,
2134
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2135

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

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

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

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

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

            
2149
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2150
        "dbi:mysql:database=$database",
2151
        $user,
2152
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2153
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2154
    );
2155
    
updated pod
Yuki Kimoto authored on 2011-06-21
2156
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2157

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

            
2161
    my $dbi = DBIx::Custom->connect(
2162
      dsn => $dsn, user => $user, password => $password, connector => 1);
2163
    
2164
    my $connector = $dbi->connector; # DBIx::Connector
2165

            
2166
Note that L<DBIx::Connector> must be installed.
2167

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2183
    {
2184
        RaiseError => 1,
2185
        PrintError => 0,
2186
        AutoCommit => 1,
2187
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2188

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

            
2191
    my $exclude_table = $dbi->exclude_table;
2192
    $dbi = $dbi->exclude_table(qr/pg_/);
2193

            
2194
Excluded table regex.
2195
C<each_column>, C<each_table>, C<type_rule>,
2196
and C<setup_model> methods ignore matching tables.
2197

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

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

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

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

            
2207
    my $last_sql = $dbi->last_sql;
2208
    $dbi = $dbi->last_sql($last_sql);
2209

            
2210
Get last successed SQL executed by C<execute> method.
2211

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

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

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

            
2219
    sub {
2220
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2221
        $mon++;
2222
        $year += 1900;
2223
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2224
    }
2225

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

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

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

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

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

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

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

            
2243
L<DBI> option, used when C<connect> method is executed.
2244
Each value in option override the value of C<default_option>.
2245

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2268
You can set quote pair.
2269

            
2270
    $dbi->quote('[]');
2271

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2281
    my $safety_character = $dbi->safety_character;
2282
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2283

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

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

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

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

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

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

            
2300
    my $tag_parse = $dbi->tag_parse(0);
2301
    $dbi = $dbi->tag_parse;
2302

            
2303
Enable DEPRECATED tag parsing functionality, default to 1.
2304
If you want to disable tag parsing functionality, set to 0.
2305

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

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

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

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

            
2315
    my $user_column_info = $dbi->user_column_info;
2316
    $dbi = $dbi->user_column_info($user_column_info);
2317

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

            
2320
    [
2321
        {table => 'book', column => 'title', info => {...}},
2322
        {table => 'author', column => 'name', info => {...}}
2323
    ]
2324

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

            
2327
    my $user_column_info
2328
      = $dbi->get_column_info(exclude_table => qr/^system/);
2329
    $dbi->user_column_info($user_column_info);
2330

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

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

            
2336
    my $user_table_info = $dbi->user_table_info;
2337
    $dbi = $dbi->user_table_info($user_table_info);
2338

            
2339
You can set the following data.
2340

            
2341
    [
2342
        {table => 'book', info => {...}},
2343
        {table => 'author', info => {...}}
2344
    ]
2345

            
2346
Usually, you can set return value of C<get_table_info>.
2347

            
2348
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2349
    $dbi->user_table_info($user_table_info);
2350

            
2351
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2352
to find table info.
2353

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2390
Create column clause. The follwoing column clause is created.
2391

            
2392
    book.author as "book.author",
2393
    book.title as "book.title"
2394

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2397
    # Separator is hyphen
2398
    $dbi->separator('-');
2399
    
2400
    book.author as "book-author",
2401
    book.title as "book-title"
2402
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2403
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2404

            
update pod
Yuki Kimoto authored on 2011-03-13
2405
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2406
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2407
        user => 'ken',
2408
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2409
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2410
    );
2411

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

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

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

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

            
2422
Get rows count.
2423

            
2424
Options is same as C<select> method's ones.
2425

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2428
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2429
        table => 'book',
2430
        primary_key => 'id',
2431
        join => [
2432
            'inner join company on book.comparny_id = company.id'
2433
        ],
2434
    );
2435

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

            
2439
   $dbi->model('book')->select(...);
2440

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

            
2443
    my $dbh = $dbi->dbh;
2444

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

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

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

            
2452
Execute delete statement.
2453

            
2454
The following opitons are available.
2455

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

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

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

            
2463
=item C<id>
2464

            
2465
    id => 4
2466
    id => [4, 5]
2467

            
2468
ID corresponding to C<primary_key>.
2469
You can delete rows by C<id> and C<primary_key>.
2470

            
2471
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2472
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2473
        id => [4, 5],
2474
        table => 'book',
2475
    );
2476

            
2477
The above is same as the followin one.
2478

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

            
2481
=item C<prefix>
2482

            
2483
    prefix => 'some'
2484

            
2485
prefix before table name section.
2486

            
2487
    delete some from book
2488

            
2489
=item C<table>
2490

            
2491
    table => 'book'
2492

            
2493
Table name.
2494

            
2495
=item C<where>
2496

            
2497
Same as C<select> method's C<where> option.
2498

            
2499
=back
2500

            
2501
=head2 C<delete_all>
2502

            
2503
    $dbi->delete_all(table => $table);
2504

            
2505
Execute delete statement for all rows.
2506
Options is same as C<delete>.
2507

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

            
2510
    $dbi->each_column(
2511
        sub {
2512
            my ($dbi, $table, $column, $column_info) = @_;
2513
            
2514
            my $type = $column_info->{TYPE_NAME};
2515
            
2516
            if ($type eq 'DATE') {
2517
                # ...
2518
            }
2519
        }
2520
    );
2521

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

            
2527
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2528
infromation, you can improve the performance of C<each_column> in
2529
the following way.
2530

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

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

            
2537
    $dbi->each_table(
2538
        sub {
2539
            my ($dbi, $table, $table_info) = @_;
2540
            
2541
            my $table_name = $table_info->{TABLE_NAME};
2542
        }
2543
    );
2544

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

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

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

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

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

            
2565
    my $result = $dbi->execute(
2566
      "select * from book where title = :book.title and author like :book.author",
2567
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2568
    );
2569

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2576
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2577
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2578
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2579
    select * from book where title = :title and author like :author
2580
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2581
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2582
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2583

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2587
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2588
    select * from book where :title{=} and :author{like}
2589
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2590
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2591
    select * from where title = ? and author like ?;
2592

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

            
2597
    select * from where title = "aa\\:bb";
2598

            
cleanup
Yuki Kimoto authored on 2011-10-20
2599
B<OPTIONS>
2600

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

            
2603
=over 4
2604

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

            
2607
You can filter sql after the sql is build.
2608

            
2609
    after_build_sql => $code_ref
2610

            
2611
The following one is one example.
2612

            
2613
    $dbi->select(
2614
        table => 'book',
2615
        column => 'distinct(name)',
2616
        after_build_sql => sub {
2617
            "select count(*) from ($_[0]) as t1"
2618
        }
2619
    );
2620

            
2621
The following SQL is executed.
2622

            
2623
    select count(*) from (select distinct(name) from book) as t1;
2624

            
cleanup
Yuki Kimoto authored on 2011-10-20
2625
=item C<append>
2626

            
2627
    append => 'order by name'
2628

            
2629
Append some statement after SQL.
2630

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

            
2633
Specify database bind data type.
2634

            
2635
    bind_type => [image => DBI::SQL_BLOB]
2636
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2637

            
2638
This is used to bind parameter by C<bind_param> of statment handle.
2639

            
2640
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2641

            
update pod
Yuki Kimoto authored on 2011-03-13
2642
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2643
    
2644
    filter => {
2645
        title  => sub { uc $_[0] }
2646
        author => sub { uc $_[0] }
2647
    }
update pod
Yuki Kimoto authored on 2011-03-13
2648

            
updated pod
Yuki Kimoto authored on 2011-06-09
2649
    # Filter name
2650
    filter => {
2651
        title  => 'upper_case',
2652
        author => 'upper_case'
2653
    }
2654
        
2655
    # At once
2656
    filter => [
2657
        [qw/title author/]  => sub { uc $_[0] }
2658
    ]
2659

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

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

            
2667
    query => 1
2668

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2672
    my $sql = $query->{sql};
2673
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2674
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2675
=item C<reuse>
2676
    
2677
    reuse => $hash_ref
2678

            
2679
Reuse query object if the hash reference variable is set.
2680
    
2681
    my $queries = {};
2682
    $dbi->execute($sql, $param, reuse => $queries);
2683

            
2684
This will improved performance when you want to execute same query repeatedly
2685
because generally creating query object is slow.
2686

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2689
    primary_key => 'id'
2690
    primary_key => ['id1', 'id2']
2691

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2694
=item C<table>
2695
    
2696
    table => 'author'
2697

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2705
    # Same
2706
    $dbi->execute(
2707
      "select * from book where title = :book.title and author = :book.author",
2708
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2709

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

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

            
2714
Table alias. Key is real table name, value is alias table name.
2715
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2716
on alias table name.
2717

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

            
2720
    type_rule_off => 1
2721

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

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

            
2726
    type_rule1_off => 1
2727

            
2728
Turn C<into1> type rule off.
2729

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

            
2732
    type_rule2_off => 1
2733

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

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

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

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

            
2742
get column infomation except for one which match C<exclude_table> pattern.
2743

            
2744
    [
2745
        {table => 'book', column => 'title', info => {...}},
2746
        {table => 'author', column => 'name' info => {...}}
2747
    ]
2748

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

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

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

            
2755
    [
2756
        {table => 'book', info => {...}},
2757
        {table => 'author', info => {...}}
2758
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2759

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

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

            
2764
    $dbi->helper(
2765
        find_or_create   => sub {
2766
            my $self = shift;
2767
            
2768
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2769
        },
2770
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2771
    );
2772

            
2773
Register helper. These helper is called directly from L<DBIx::Custom> object.
2774

            
2775
    $dbi->find_or_create;
2776

            
cleanup
yuki-kimoto authored on 2010-10-17
2777
=head2 C<insert>
2778

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

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

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

            
2787
    {date => \"NOW()"}
2788

            
cleanup
Yuki Kimoto authored on 2011-10-20
2789
B<options>
2790

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

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

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

            
2798
    created_at => 'created_datetime'
2799

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2806
    id => 4
2807
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2808

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2812
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2813
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2814
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2815
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2816
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2817
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2818

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

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

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

            
2828
    prefix => 'or replace'
2829

            
2830
prefix before table name section
2831

            
2832
    insert or replace into book
2833

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

            
2836
    table => 'book'
2837

            
2838
Table name.
2839

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

            
2842
This option is same as C<update> method C<updated_at> option.
2843

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

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

            
2848
placeholder wrapped string.
2849

            
2850
If the following statement
2851

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

            
2855
is executed, the following SQL is executed.
2856

            
2857
    insert into book price values ( ? + 5 );
2858

            
update pod
Yuki Kimoto authored on 2011-03-13
2859
=back
2860

            
2861
=over 4
2862

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2870
    lib / MyModel.pm
2871
        / MyModel / book.pm
2872
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2873

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

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

            
2878
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2879
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2880
    
2881
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2882

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2887
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2888
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2889
    
2890
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2891

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2894
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2895
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2896
    
2897
    1;
2898
    
updated pod
Yuki Kimoto authored on 2011-06-21
2899
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2900

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

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

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

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

            
2910
    my $like_value = $dbi->like_value
2911

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

            
2914
    sub { "%$_[0]%" }
2915

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

            
2918
    my $mapper = $dbi->mapper(param => $param);
2919

            
2920
Create a new L<DBIx::Custom::Mapper> object.
2921

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

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

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

            
2928
    {key1 => [1, 1], key2 => 2}
2929

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

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

            
2934
    my $model = $dbi->model('book');
2935

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

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

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

            
2943
Create column clause for myself. The follwoing column clause is created.
2944

            
2945
    book.author as author,
2946
    book.title as title
2947

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

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

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

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

            
2961
    my $not_exists = $dbi->not_exists;
2962

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

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

            
2968
    my $order = $dbi->order;
2969

            
2970
Create a new L<DBIx::Custom::Order> object.
2971

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

            
2974
    my $quooted = $dbi->q("title");
2975

            
2976
Quote string by value of C<quote>.
2977

            
cleanup
yuki-kimoto authored on 2010-10-17
2978
=head2 C<register_filter>
2979

            
update pod
Yuki Kimoto authored on 2011-03-13
2980
    $dbi->register_filter(
2981
        # Time::Piece object to database DATE format
2982
        tp_to_date => sub {
2983
            my $tp = shift;
2984
            return $tp->strftime('%Y-%m-%d');
2985
        },
2986
        # database DATE format to Time::Piece object
2987
        date_to_tp => sub {
2988
           my $date = shift;
2989
           return Time::Piece->strptime($date, '%Y-%m-%d');
2990
        }
2991
    );
cleanup
yuki-kimoto authored on 2010-10-17
2992
    
update pod
Yuki Kimoto authored on 2011-03-13
2993
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2994

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2997
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2998
        table  => 'book',
2999
        column => ['author', 'title'],
3000
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3001
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3002
    
updated document
Yuki Kimoto authored on 2011-06-09
3003
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3004

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3012
=item C<column>
3013
    
updated document
Yuki Kimoto authored on 2011-06-09
3014
    column => 'author'
3015
    column => ['author', 'title']
3016

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3025
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3026
        {book => [qw/author title/]},
3027
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3028
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3029

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

            
3032
    book.author as "book.author",
3033
    book.title as "book.title",
3034
    person.name as "person.name",
3035
    person.age as "person.age"
3036

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

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

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

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

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

            
3050
    id => 4
3051
    id => [4, 5]
3052

            
3053
ID corresponding to C<primary_key>.
3054
You can select rows by C<id> and C<primary_key>.
3055

            
3056
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3057
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3058
        id => [4, 5],
3059
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3060
    );
3061

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3064
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3065
        where => {id1 => 4, id2 => 5},
3066
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3067
    );
3068
    
cleanup
Yuki Kimoto authored on 2011-10-20
3069
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3070

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

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

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

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

            
3083
    prefix => 'SQL_CALC_FOUND_ROWS'
3084

            
3085
Prefix of column cluase
3086

            
3087
    select SQL_CALC_FOUND_ROWS title, author from book;
3088

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

            
3091
    join => [
3092
        'left outer join company on book.company_id = company_id',
3093
        'left outer join location on company.location_id = location.id'
3094
    ]
3095
        
3096
Join clause. If column cluase or where clause contain table name like "company.name",
3097
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3098

            
3099
    $dbi->select(
3100
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3101
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3102
        where => {'company.name' => 'Orange'},
3103
        join => [
3104
            'left outer join company on book.company_id = company.id',
3105
            'left outer join location on company.location_id = location.id'
3106
        ]
3107
    );
3108

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3112
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3113
    from book
3114
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3115
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3116

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3117
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
3118
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3119

            
3120
    $dbi->select(
3121
        table => 'book',
3122
        column => ['company.location_id as location_id'],
3123
        where => {'company.name' => 'Orange'},
3124
        join => [
3125
            {
3126
                clause => 'left outer join location on company.location_id = location.id',
3127
                table => ['company', 'location']
3128
            }
3129
        ]
3130
    );
3131

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3136
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3137

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3158
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3159
    
update pod
Yuki Kimoto authored on 2011-03-12
3160
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3161

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

            
3164
    $dbi->setup_model;
3165

            
3166
Setup all model objects.
3167
C<columns> of model object is automatically set, parsing database information.
3168

            
3169
=head2 C<type_rule>
3170

            
3171
    $dbi->type_rule(
3172
        into1 => {
3173
            date => sub { ... },
3174
            datetime => sub { ... }
3175
        },
3176
        into2 => {
3177
            date => sub { ... },
3178
            datetime => sub { ... }
3179
        },
3180
        from1 => {
3181
            # DATE
3182
            9 => sub { ... },
3183
            # DATETIME or TIMESTAMP
3184
            11 => sub { ... },
3185
        }
3186
        from2 => {
3187
            # DATE
3188
            9 => sub { ... },
3189
            # DATETIME or TIMESTAMP
3190
            11 => sub { ... },
3191
        }
3192
    );
3193

            
3194
Filtering rule when data is send into and get from database.
3195
This has a little complex problem.
3196

            
3197
In C<into1> and C<into2> you can specify
3198
type name as same as type name defined
3199
by create table, such as C<DATETIME> or C<DATE>.
3200

            
3201
Note that type name and data type don't contain upper case.
3202
If these contain upper case charactor, you convert it to lower case.
3203

            
3204
C<into2> is executed after C<into1>.
3205

            
3206
Type rule of C<into1> and C<into2> is enabled on the following
3207
column name.
3208

            
3209
=over 4
3210

            
3211
=item 1. column name
3212

            
3213
    issue_date
3214
    issue_datetime
3215

            
3216
This need C<table> option in each method.
3217

            
3218
=item 2. table name and column name, separator is dot
3219

            
3220
    book.issue_date
3221
    book.issue_datetime
3222

            
3223
=back
3224

            
3225
You get all type name used in database by C<available_typename>.
3226

            
3227
    print $dbi->available_typename;
3228

            
3229
In C<from1> and C<from2> you specify data type, not type name.
3230
C<from2> is executed after C<from1>.
3231
You get all data type by C<available_datatype>.
3232

            
3233
    print $dbi->available_datatype;
3234

            
3235
You can also specify multiple types at once.
3236

            
3237
    $dbi->type_rule(
3238
        into1 => [
3239
            [qw/DATE DATETIME/] => sub { ... },
3240
        ],
3241
    );
3242

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

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

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

            
3249
If you want to set constant value to row data, use scalar reference
3250
as parameter value.
3251

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3263
    id => 4
3264
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3265

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3269
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3270
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3271
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3272
        id => [4, 5],
3273
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3274
    );
update pod
Yuki Kimoto authored on 2011-03-13
3275

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3278
    $dbi->update(
3279
        {title => 'Perl', author => 'Ken'}
3280
        where => {id1 => 4, id2 => 5},
3281
        table => 'book'
3282
    );
update pod
Yuki Kimoto authored on 2011-03-13
3283

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

            
3286
    prefix => 'or replace'
3287

            
3288
prefix before table name section
3289

            
3290
    update or replace book
3291

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

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

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

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

            
3300
Same as C<select> method's C<where> option.
3301

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

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

            
3306
placeholder wrapped string.
3307

            
3308
If the following statement
3309

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

            
3313
is executed, the following SQL is executed.
3314

            
3315
    update book set price =  ? + 5;
3316

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

            
3319
    updated_at => 'updated_datetime'
3320

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3325
=back
update pod
Yuki Kimoto authored on 2011-03-13
3326

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3349
Update or insert.
3350

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3355
C<OPTIONS>
3356

            
3357
C<update_or_insert> method use all common option
3358
in C<select>, C<update>, C<delete>, and has the following new ones.
3359

            
3360
=over 4
3361

            
3362
=item C<option>
3363

            
3364
    option => {
3365
        select => {
3366
            append => '...'
3367
        },
3368
        insert => {
3369
            prefix => '...'
3370
        },
3371
        update => {
3372
            filter => {}
3373
        }
3374
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3375

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

            
3379
=over 4
3380

            
3381
=item C<select_option>
3382

            
3383
    select_option => {append => 'for update'}
3384

            
3385
select method option,
3386
select method is used to check the row is already exists.
3387

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

            
3390
    $dbi->show_datatype($table);
3391

            
3392
Show data type of the columns of specified table.
3393

            
3394
    book
3395
    title: 5
3396
    issue_date: 91
3397

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

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

            
3402
    $dbi->show_tables;
3403

            
3404
Show tables.
3405

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

            
3408
    $dbi->show_typename($table);
3409

            
3410
Show type name of the columns of specified table.
3411

            
3412
    book
3413
    title: varchar
3414
    issue_date: date
3415

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

            
use_next_version is renamed ...
Yuki Kimoto authored on 2011-11-16
3418
=head2 C<use_version1 EXPERIMENTAL>
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
3419

            
use_next_version is renamed ...
Yuki Kimoto authored on 2011-11-16
3420
    DBIx::Custom->use_version1;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
3421

            
use_next_version is renamed ...
Yuki Kimoto authored on 2011-11-16
3422
Upgrade L<DBIx::Custom> to major version 1 if version is lower than 1.
3423
You can't use DEPRECATED method and method performance is improved.
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
3424

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

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

            
3429
Create values clause.
3430

            
3431
    (title, author) values (title = :title, age = :age);
3432

            
3433
You can use this in insert statement.
3434

            
3435
    my $insert_sql = "insert into book $values_clause";
3436

            
3437
=head2 C<where>
3438

            
3439
    my $where = $dbi->where(
3440
        clause => ['and', 'title = :title', 'author = :author'],
3441
        param => {title => 'Perl', author => 'Ken'}
3442
    );
3443

            
3444
Create a new L<DBIx::Custom::Where> object.
3445

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

            
3448
=head2 C<DBIX_CUSTOM_DEBUG>
3449

            
3450
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3451
executed SQL and bind values are printed to STDERR.
3452

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

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

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

            
3459
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3460

            
3461
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3462

            
3463
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3464
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3465

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

            
3468
L<DBIx::Custom>
3469

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

            
3524
L<DBIx::Custom::Model>
3525

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3526
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3527
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3528
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3529
    filter # will be removed at 2017/1/1
3530
    name # will be removed at 2017/1/1
3531
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3532

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

            
3535
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3536
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3537
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3538
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3539
    table # will be removed at 2017/1/1
3540
    filters # will be removed at 2017/1/1
3541
    
3542
    # Methods
3543
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3544

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

            
3547
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3548
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3549
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3550
    tags # will be removed at 2017/1/1
3551
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3552
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3553
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3554
    register_tag # will be removed at 2017/1/1
3555
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3556
    
3557
    # Others
3558
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3559
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3560

            
3561
L<DBIx::Custom::Result>
3562
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3563
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3564
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3565
    
3566
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3567
    filter_on # will be removed at 2017/1/1
3568
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3569
    end_filter # will be removed at 2017/1/1
3570
    remove_end_filter # will be removed at 2017/1/1
3571
    remove_filter # will be removed at 2017/1/1
3572
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3573

            
3574
L<DBIx::Custom::Tag>
3575

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

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

            
3580
    # Other
3581
    prepend method array reference receiving
3582
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3583

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

            
3586
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3587
except for attribute method.
3588
You can check all DEPRECATED functionalities by document.
3589
DEPRECATED functionality is removed after five years,
3590
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
3591
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3592

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

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

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

            
3599
C<< <kimoto.yuki at gmail.com> >>
3600

            
3601
L<http://github.com/yuki-kimoto/DBIx-Custom>
3602

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3603
=head1 AUTHOR
3604

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

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

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

            
3611
This program is free software; you can redistribute it and/or modify it
3612
under the same terms as Perl itself.
3613

            
3614
=cut