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

            
micro optimization
Yuki Kimoto authored on 2011-10-23
4
our $VERSION = '0.1735';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
23
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
24

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
101
our $AUTOLOAD;
102
sub AUTOLOAD {
103
    my $self = shift;
104

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
122
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
123
    my ($self, $param, $opts) = @_;
124
    
125
    my $wrap = $opts->{wrap} || {};
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
126

            
127
    my $qp = $self->_q('');
128
    my $q = substr($qp, 0, 1) || '';
129
    my $p = substr($qp, 1, 1) || '';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
130
    
131
    # Create set tag
132
    my @params;
133
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-10-21
134
    for my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
135
        croak qq{"$column" is not safety column name } . _subname
136
          unless $column =~ /^[$safety\.]+$/;
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
137
        my $column_quote = "$q$column$p";
138
        $column_quote =~ s/\./$p.$q/;
updated pod
Yuki Kimoto authored on 2011-09-02
139
        my $func = $wrap->{$column} || sub { $_[0] };
140
        push @params,
141
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
142
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
143
    }
144
    my $tag = join(', ', @params);
145
    
146
    return $tag;
147
}
148

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
236
sub delete {
237
    my ($self, %opt) = @_;
238
    warn "delete method where_param option is DEPRECATED!"
239
      if $opt{where_param};
240
    
cleanup
Yuki Kimoto authored on 2011-10-21
241
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
242
    croak qq{delete method where or id option must be specified } . _subname
243
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
244
    
245
    # Where
246
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
247
           ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
248
           : $opt{where};
249
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250

            
cleanup
Yuki Kimoto authored on 2011-04-02
251
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
252
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
253
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
254
    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
255
    
256
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
257
    return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
258
}
259

            
cleanup
yuki-kimoto authored on 2010-10-17
260
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
261

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

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

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

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

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

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

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

            
356
    # Options
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
357
    my $param;
358
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
359
    my %opt = @_;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
360
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
361
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
362
    my $tables = $opt{table} || [];
cleanup
Yuki Kimoto authored on 2011-04-02
363
    $tables = [$tables] unless ref $tables eq 'ARRAY';
micro optimization
Yuki Kimoto authored on 2011-10-23
364
    my $filter = ref $opt{filter} eq 'ARRAY' ?
365
      _array_to_hash($opt{filter}) : $opt{filter};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
366
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
367
    # Append
368
    $sql .= $opt{append} if defined $opt{append} && !ref $sql;
369
    
370
    # Query
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
371
    my $query;
372
    if (ref $sql) { $query = $sql }
373
    else {
374
        $query = $opt{reuse}->{$sql} if $opt{reuse};
375
        $query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter})
376
          unless $query;
377
        $opt{reuse}->{$sql} = $query if $opt{reuse};
378
    }
379
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
380
    # Save query
micro optimization
Yuki Kimoto authored on 2011-10-23
381
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
382

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
383
    # Return query
384
    return $query if $opt{query};
micro optimization
Yuki Kimoto authored on 2011-07-30
385
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
386
    # Merge query filter(DEPRECATED!)
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
387
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
388
    
cleanup
Yuki Kimoto authored on 2011-04-02
389
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
390
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
391
    my $main_table = @{$tables}[-1];
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
392
    
393
    # Convert id to parameter
394
    if (defined $opt{id}) {
395
        my $id_param = $self->_id_to_param($opt{id}, $opt{primary_key}, $main_table);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
396
        $param = $self->merge_param($id_param, $param);
397
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
398
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
399
    # Cleanup tables(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
400
    $tables = $self->_remove_duplicate_table($tables, $main_table)
401
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
402
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
403
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
404
    my $type_filters = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
405
    if ($self->{_type_rule_is_called}) {
406
        unless ($opt{type_rule_off}) {
407
            my $type_rule_off_parts = {
408
                1 => $opt{type_rule1_off},
409
                2 => $opt{type_rule2_off}
410
            };
411
            for my $i (1, 2) {
412
                unless ($type_rule_off_parts->{$i}) {
413
                    $type_filters->{$i} = {};
414
                    my $table_alias = $opt{table_alias} || {};
415
                    for my $alias (keys %$table_alias) {
416
                        my $table = $table_alias->{$alias};
417
                        
418
                        for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
419
                            $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
420
                        }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
421
                    }
micro optimization
Yuki Kimoto authored on 2011-10-23
422
                    $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
423
                      if $main_table;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
424
                }
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
425
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
426
        }
427
    }
cleanup
Yuki Kimoto authored on 2011-04-02
428
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
429
    # Applied filter(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
430
    if ($self->{filter}{on}) {
431
        my $applied_filter = {};
cleanup
Yuki Kimoto authored on 2011-10-21
432
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
433
            $applied_filter = {
434
                %$applied_filter,
435
                %{$self->{filter}{out}->{$table} || {}}
436
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
437
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
438
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
439
    }
440
    
cleanup
Yuki Kimoto authored on 2011-04-02
441
    # Replace filter name to code
cleanup
Yuki Kimoto authored on 2011-10-21
442
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
443
        my $name = $filter->{$column};
444
        if (!defined $name) {
445
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
446
        }
cleanup
Yuki Kimoto authored on 2011-04-02
447
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
448
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
449
            unless exists $self->filters->{$name};
450
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
451
        }
452
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
453
    
cleanup
Yuki Kimoto authored on 2011-04-02
454
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
455
    my ($bind, $bind_types) = $self->_create_bind_values($param, $query->columns,
456
      $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
457

            
cleanup
yuki-kimoto authored on 2010-10-17
458
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
459
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
460
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
461
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-23
462
        if ($opt{bind_type} || $opt{type}) {
463
            $sth->bind_param($_ + 1, $bind->[$_],
464
                $bind_types->[$_] ? $bind_types->[$_] : ())
465
              for (0 .. @$bind - 1);
466
            $affected = $sth->execute;
467
        }
468
        else {
469
            $affected = $sth->execute(@$bind);
470
        }
cleanup
Yuki Kimoto authored on 2011-03-21
471
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
472
    
micro optimization
Yuki Kimoto authored on 2011-07-30
473
    $self->_croak($@, qq{. Following SQL is executed.\n}
474
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
475
    
improved debug message
Yuki Kimoto authored on 2011-05-23
476
    # DEBUG message
477
    if (DEBUG) {
478
        print STDERR "SQL:\n" . $query->sql . "\n";
479
        my @output;
cleanup
Yuki Kimoto authored on 2011-10-21
480
        for my $b (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
481
            my $value = $b->{value};
482
            $value = 'undef' unless defined $value;
483
            $value = encode(DEBUG_ENCODING(), $value)
484
              if utf8::is_utf8($value);
485
            push @output, $value;
486
        }
487
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
488
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
489
    
micro optimization
Yuki Kimoto authored on 2011-10-23
490
    # Not select statement
491
    return $affected unless $sth->{NUM_OF_FIELDS};
492

            
493
    # Filter(DEPRECATED!)
494
    my $infilter = {};
495
    if ($self->{filter}{on}) {
496
        $infilter->{in}  = {};
497
        $infilter->{end} = {};
498
        push @$tables, $main_table if $main_table;
499
        for my $table (@$tables) {
500
            for my $way (qw/in end/) {
501
                $infilter->{$way} = {%{$infilter->{$way}},
502
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
503
            }
cleanup
Yuki Kimoto authored on 2011-01-12
504
        }
cleanup
yuki-kimoto authored on 2010-10-17
505
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
506
    
507
    # Result
508
    my $result = $self->result_class->new(
509
        sth => $sth,
510
        dbi => $self,
511
        default_filter => $self->{default_in_filter},
512
        filter => $infilter->{in} || {},
513
        end_filter => $infilter->{end} || {},
514
        type_rule => {
515
            from1 => $self->type_rule->{from1},
516
            from2 => $self->type_rule->{from2}
517
        },
518
    );
519
    $result;
cleanup
yuki-kimoto authored on 2010-10-17
520
}
521

            
added test
Yuki Kimoto authored on 2011-08-16
522
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
523
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
524
    
cleanup
Yuki Kimoto authored on 2011-10-21
525
    my $exclude = delete $opt{exclude};
526
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
527
    
added test
Yuki Kimoto authored on 2011-08-16
528
    my $table_info = [];
529
    $self->each_table(
530
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
531
        exclude => $exclude
532
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
533
    
cleanup test
Yuki Kimoto authored on 2011-08-16
534
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
535
}
536

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
537
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
538
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
539
    
cleanup
Yuki Kimoto authored on 2011-10-21
540
    my $exclude_table = delete $opt{exclude_table};
541
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
542
    
543
    my $column_info = [];
544
    $self->each_column(
545
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
546
        exclude_table => $exclude_table
547
    );
548
    
549
    return [
550
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
551
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
552
}
553

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
554
sub helper {
555
    my $self = shift;
556
    
557
    # Register method
558
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
559
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
560
    
561
    return $self;
562
}
563

            
cleanup
yuki-kimoto authored on 2010-10-17
564
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
565
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
566
    
cleanup
Yuki Kimoto authored on 2011-10-21
567
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
568
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
569
    my %opt = @_;
570
    warn "insert method param option is DEPRECATED" if $opt{param};
571
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
572
    
573
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
574
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
575
        my $columns = $insert_timestamp->[0];
576
        $columns = [$columns] unless ref $columns eq 'ARRAY';
577
        my $value = $insert_timestamp->[1];
578
        $value = $value->() if ref $value eq 'CODE';
579
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
580
    }
cleanup
Yuki Kimoto authored on 2011-10-21
581
    
582
    # Merge id to parameter
583
    $param = $self->merge_param(
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
584
        $self->_id_to_param(delete $opt{id}, $opt{primary_key}), $param)
cleanup
Yuki Kimoto authored on 2011-10-21
585
      if defined $opt{id};
cleanup
Yuki Kimoto authored on 2011-10-21
586
    
cleanup
Yuki Kimoto authored on 2011-04-02
587
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
588
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
589
    $sql .= "$opt{prefix} " if defined $opt{prefix};
590
    $sql .= "into " . $self->_q($opt{table}) . " "
591
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
592
    
593
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
594
    return $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
595
}
596

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
597
sub insert_timestamp {
598
    my $self = shift;
599
    
600
    if (@_) {
601
        $self->{insert_timestamp} = [@_];
602
        
603
        return $self;
604
    }
605
    return $self->{insert_timestamp};
606
}
607

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
608
sub include_model {
609
    my ($self, $name_space, $model_infos) = @_;
610
    
cleanup
Yuki Kimoto authored on 2011-04-02
611
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
612
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
613
    
614
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
615
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
616

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
617
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
618
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
619
          if $name_space =~ /[^\w:]/;
620
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
621
        croak qq{Name space module "$name_space.pm" is needed. $@ }
622
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
623
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
624
        
625
        # Search model modules
626
        my $path = $INC{"$name_space.pm"};
627
        $path =~ s/\.pm$//;
628
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
629
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
630
        $model_infos = [];
631
        while (my $module = readdir $dh) {
632
            push @$model_infos, $module
633
              if $module =~ s/\.pm$//;
634
        }
635
        close $dh;
636
    }
637
    
cleanup
Yuki Kimoto authored on 2011-04-02
638
    # Include models
cleanup
Yuki Kimoto authored on 2011-10-21
639
    for my $model_info (@$model_infos) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
640
        
cleanup
Yuki Kimoto authored on 2011-04-02
641
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
642
        my $model_class;
643
        my $model_name;
644
        my $model_table;
645
        if (ref $model_info eq 'HASH') {
646
            $model_class = $model_info->{class};
647
            $model_name  = $model_info->{name};
648
            $model_table = $model_info->{table};
649
            
650
            $model_name  ||= $model_class;
651
            $model_table ||= $model_name;
652
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
653
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
654
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
655
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
656
          if $mclass =~ /[^\w:]/;
657
        unless ($mclass->can('isa')) {
658
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
659
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
660
        }
661
        
cleanup
Yuki Kimoto authored on 2011-04-02
662
        # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
663
        my $opt = {};
664
        $opt->{model_class} = $mclass if $mclass;
665
        $opt->{name}        = $model_name if $model_name;
666
        $opt->{table}       = $model_table if $model_table;
667
        $self->create_model($opt);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
668
    }
669
    
670
    return $self;
671
}
672

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
675
sub mapper {
676
    my $self = shift;
677
    return DBIx::Custom::Mapper->new(@_);
678
}
679

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
680
sub merge_param {
681
    my ($self, @params) = @_;
682
    
cleanup
Yuki Kimoto authored on 2011-04-02
683
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
684
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
685
    for my $param (@params) {
686
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
687
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
688
            
689
            if (exists $merge->{$column}) {
690
                $merge->{$column} = [$merge->{$column}]
691
                  unless ref $merge->{$column} eq 'ARRAY';
692
                push @{$merge->{$column}},
693
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
694
            }
695
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
696
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
697
            }
698
        }
699
    }
700
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
701
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
702
}
703

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
704
sub model {
705
    my ($self, $name, $model) = @_;
706
    
cleanup
Yuki Kimoto authored on 2011-04-02
707
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
708
    if ($model) {
709
        $self->models->{$name} = $model;
710
        return $self;
711
    }
712
    
713
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
714
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
715
      unless $self->models->{$name};
716
    
cleanup
Yuki Kimoto authored on 2011-04-02
717
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
718
    return $self->models->{$name};
719
}
720

            
cleanup
Yuki Kimoto authored on 2011-03-21
721
sub mycolumn {
722
    my ($self, $table, $columns) = @_;
723
    
cleanup
Yuki Kimoto authored on 2011-04-02
724
    # Create column clause
725
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
726
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
727
    push @column, $self->_q($table) . "." . $self->_q($_) .
728
      " as " . $self->_q($_)
729
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
730
    
731
    return join (', ', @column);
732
}
733

            
added dbi_options attribute
kimoto authored on 2010-12-20
734
sub new {
735
    my $self = shift->SUPER::new(@_);
736
    
cleanup
Yuki Kimoto authored on 2011-04-02
737
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
738
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
739
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
740
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
741
          unless $self->can($attr);
742
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
743

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
744
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
745
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
746
        '?'     => \&DBIx::Custom::Tag::placeholder,
747
        '='     => \&DBIx::Custom::Tag::equal,
748
        '<>'    => \&DBIx::Custom::Tag::not_equal,
749
        '>'     => \&DBIx::Custom::Tag::greater_than,
750
        '<'     => \&DBIx::Custom::Tag::lower_than,
751
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
752
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
753
        'like'  => \&DBIx::Custom::Tag::like,
754
        'in'    => \&DBIx::Custom::Tag::in,
755
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
756
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
757
    };
758
    
759
    return $self;
760
}
761

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

            
764
sub order {
765
    my $self = shift;
766
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
767
}
768

            
cleanup
yuki-kimoto authored on 2010-10-17
769
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
770
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
771
    
772
    # Register filter
773
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
774
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
775
    
cleanup
Yuki Kimoto authored on 2011-04-02
776
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
777
}
packaging one directory
yuki-kimoto authored on 2009-11-16
778

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
782
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
783
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
784
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
785
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
786
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
787
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
788
    
cleanup
Yuki Kimoto authored on 2011-03-09
789
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
790
    if ($opt{relation}) {
791
        warn "select() relation option is DEPRECATED!";
792
        $self->_add_relation_table($tables, $opt{relation});
793
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
794
    
cleanup
Yuki Kimoto authored on 2011-04-02
795
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
796
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
797
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
798
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
799
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
800
    
cleanup
Yuki Kimoto authored on 2011-10-21
801
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
802
    if (defined $opt{column}) {
803
        my $columns
804
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
805
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
806
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
807
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
808
            }
809
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
810
                if (@$column == 3 && $column->[1] eq 'as') {
811
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
812
                    splice @$column, 1, 1;
813
                }
814
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
815
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
816
            }
cleanup
Yuki Kimoto authored on 2011-04-02
817
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
818
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
819
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
820
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
821
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
822
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
823
    
824
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
825
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
826
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
827
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
828
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
829
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
830
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
831
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
832
    }
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
833
    else { $sql .= $self->_q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
834
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
835
    croak "select method table option must be specified " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
836
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
837

            
cleanup
Yuki Kimoto authored on 2011-04-02
838
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
839
    unshift @$tables,
840
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
841
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
842
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
843
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
844
              ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $tables->[-1])
cleanup
Yuki Kimoto authored on 2011-10-21
845
              : $opt{where};
846
    my $w = $self->_where_clause_and_param($where, $where_param);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
847
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
848
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
849
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
850
    
cleanup
Yuki Kimoto authored on 2011-10-21
851
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
852
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
853
    
cleanup
Yuki Kimoto authored on 2011-03-09
854
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
855
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
856
    
cleanup
Yuki Kimoto authored on 2011-03-08
857
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
858
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
859
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
860
    
packaging one directory
yuki-kimoto authored on 2009-11-16
861
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
862
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
863
    
864
    return $result;
865
}
866

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
867
sub setup_model {
868
    my $self = shift;
869
    
cleanup
Yuki Kimoto authored on 2011-04-02
870
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
871
    $self->each_column(
872
        sub {
873
            my ($self, $table, $column, $column_info) = @_;
874
            if (my $model = $self->models->{$table}) {
875
                push @{$model->columns}, $column;
876
            }
877
        }
878
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
879
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
880
}
881

            
update pod
Yuki Kimoto authored on 2011-08-10
882
sub show_datatype {
883
    my ($self, $table) = @_;
884
    croak "Table name must be specified" unless defined $table;
885
    print "$table\n";
886
    
887
    my $result = $self->select(table => $table, where => "'0' <> '0'");
888
    my $sth = $result->sth;
889

            
890
    my $columns = $sth->{NAME};
891
    my $data_types = $sth->{TYPE};
892
    
893
    for (my $i = 0; $i < @$columns; $i++) {
894
        my $column = $columns->[$i];
895
        my $data_type = $data_types->[$i];
896
        print "$column: $data_type\n";
897
    }
898
}
899

            
900
sub show_typename {
901
    my ($self, $t) = @_;
902
    croak "Table name must be specified" unless defined $t;
903
    print "$t\n";
904
    
905
    $self->each_column(sub {
906
        my ($self, $table, $column, $infos) = @_;
907
        return unless $table eq $t;
908
        my $typename = $infos->{TYPE_NAME};
909
        print "$column: $typename\n";
910
    });
911
    
912
    return $self;
913
}
914

            
test cleanup
Yuki Kimoto authored on 2011-08-15
915
sub show_tables {
916
    my $self = shift;
917
    
918
    my %tables;
919
    $self->each_table(sub { $tables{$_[1]}++ });
920
    print join("\n", sort keys %tables) . "\n";
921
    return $self;
922
}
923

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

            
927
    $self->{_type_rule_is_called} = 1;
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
928
    
929
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
930
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
931
        
932
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
933
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
934
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
935
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
936
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
937
            $self->{type_rule} = $type_rule;
938
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
939
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
940
                croak qq{type name of $into section must be lower case}
941
                  if $type_name =~ /[A-Z]/;
942
            }
cleanup
Yuki Kimoto authored on 2011-08-16
943
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
944
            $self->each_column(sub {
945
                my ($dbi, $table, $column, $column_info) = @_;
946
                
947
                my $type_name = lc $column_info->{TYPE_NAME};
948
                if ($type_rule->{$into} &&
949
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
950
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
951
                    return unless exists $type_rule->{$into}->{$type_name};
952
                    if  (defined $filter && ref $filter ne 'CODE') 
953
                    {
954
                        my $fname = $filter;
955
                        croak qq{Filter "$fname" is not registered" } . _subname
956
                          unless exists $self->filters->{$fname};
957
                        
958
                        $filter = $self->filters->{$fname};
959
                    }
960

            
micro optimization
Yuki Kimoto authored on 2011-07-30
961
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
962
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
963
                }
964
            });
965
        }
966

            
967
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
968
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
969
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
970
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
971
                croak qq{data type of from$i section must be lower case or number}
972
                  if $data_type =~ /[A-Z]/;
973
                my $fname = $type_rule->{"from$i"}{$data_type};
974
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
975
                    croak qq{Filter "$fname" is not registered" } . _subname
976
                      unless exists $self->filters->{$fname};
977
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
978
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
979
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
980
            }
981
        }
982
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
983
        return $self;
984
    }
985
    
986
    return $self->{type_rule} || {};
987
}
988

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
992
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
993
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
994
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
995
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
996
    warn "update method where_param option is DEPRECATED!"
997
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
998
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
999
    
cleanup
Yuki Kimoto authored on 2011-10-21
1000
    # Don't allow update all rows
1001
    croak qq{update method where option must be specified } . _subname
1002
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1003
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1004
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1005
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1006
        my $columns = $update_timestamp->[0];
1007
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1008
        my $value = $update_timestamp->[1];
1009
        $value = $value->() if ref $value eq 'CODE';
1010
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1011
    }
1012

            
cleanup
Yuki Kimoto authored on 2011-10-21
1013
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1014
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1015
    
1016
    # Convert id to where parameter
1017
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1018
      ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
1019
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1020

            
1021
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1022
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1023
    
cleanup
Yuki Kimoto authored on 2011-10-21
1024
    # Merge where parameter to parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1025
    $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1026
    
cleanup
Yuki Kimoto authored on 2011-04-02
1027
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1028
    my $sql = "update ";
1029
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1030
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1031
    
cleanup
yuki-kimoto authored on 2010-10-17
1032
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1033
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1034
}
1035

            
cleanup
yuki-kimoto authored on 2010-10-17
1036
sub update_all { shift->update(allow_update_all => 1, @_) };
1037

            
cleanup
Yuki Kimoto authored on 2011-10-21
1038
sub update_or_insert {
1039
    my $self = shift;
1040

            
cleanup
Yuki Kimoto authored on 2011-10-21
1041
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1042
    my $param  = shift;
1043
    my %opt = @_;
1044
    my $id = $opt{id};
1045
    my $primary_key = $opt{primary_key};
1046
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1047
    croak "update_or_insert method need primary_key option " .
1048
          "when id is specified" . _subname
1049
      if defined $id && !defined $primary_key;
1050
    my $table  = $opt{table};
1051
    croak qq{"table" option must be specified } . _subname
1052
      unless defined $table;
1053
    my $select_option = $opt{select_option};
1054
    
1055
    my $rows = $self->select(table => $table, id => $id,
1056
        primary_key => $primary_key, %$select_option)->all;
1057
    
1058
    croak "selected row count must be one or zero" . _subname
1059
      if @$rows > 1;
1060
    
1061
    my $row = $rows->[0];
1062
    my @opt = (table => $table);
1063
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1064
    push @opt, %opt;
1065
    
1066
    if ($row) {
1067
        return $self->update($param, @opt);
1068
    }
1069
    else {
1070
        return $self->insert($param, @opt);
1071
    }
1072
}
1073

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1074
sub update_timestamp {
1075
    my $self = shift;
1076
    
1077
    if (@_) {
1078
        $self->{update_timestamp} = [@_];
1079
        
1080
        return $self;
1081
    }
1082
    return $self->{update_timestamp};
1083
}
1084

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1085
sub values_clause {
1086
    my ($self, $param, $opts) = @_;
1087
    
1088
    my $wrap = $opts->{wrap} || {};
1089
    
1090
    # Create insert parameter tag
1091
    my $safety = $self->safety_character;
1092
    my @columns;
1093
    my @placeholders;
improved performance
Yuki Kimoto authored on 2011-10-22
1094
    my $qp = $self->_q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1095
    my $q = substr($qp, 0, 1) || '';
1096
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1097
    
cleanup
Yuki Kimoto authored on 2011-10-21
1098
    for my $column (sort keys %$param) {
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1099
        croak qq{"$column" is not safety column name } . _subname
1100
          unless $column =~ /^[$safety\.]+$/;
improved performance
Yuki Kimoto authored on 2011-10-22
1101
        my $column_quote = "$q$column$p";
1102
        $column_quote =~ s/\./$p.$q/;
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1103
        push @columns, $column_quote;
1104
        
1105
        my $func = $wrap->{$column} || sub { $_[0] };
1106
        push @placeholders,
1107
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1108
        : $func->(":$column");
1109
    }
1110
    
1111
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1112
           '(' . join(', ', @placeholders) . ')'
1113
}
1114

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1117
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1118
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1119
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1120
    
updated pod
Yuki Kimoto authored on 2011-06-21
1121
    # Cache
1122
    my $cache = $self->cache;
1123
    
1124
    # Query
1125
    my $query;
1126
    
1127
    # Get cached query
1128
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1129
        
updated pod
Yuki Kimoto authored on 2011-06-21
1130
        # Get query
1131
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1132
        
updated pod
Yuki Kimoto authored on 2011-06-21
1133
        # Create query
1134
        if ($q) {
1135
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1136
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1137
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1138
    }
1139
    
1140
    # Create query
1141
    unless ($query) {
1142

            
1143
        # Create query
1144
        my $builder = $self->query_builder;
1145
        $query = $builder->build_query($source);
1146

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

            
1153
        # Save query to cache
1154
        $self->cache_method->(
1155
            $self, $source,
1156
            {
1157
                sql     => $query->sql, 
1158
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1159
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1160
            }
1161
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1162
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1163

            
1164
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1165
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1166
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1167
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1168
        $query->sql($sql);
1169
    }
1170
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1171
    # Save sql
1172
    $self->last_sql($query->sql);
1173
    
updated pod
Yuki Kimoto authored on 2011-06-21
1174
    # Prepare statement handle
1175
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1176
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1177
    
1178
    if ($@) {
1179
        $self->_croak($@, qq{. Following SQL is executed.\n}
1180
                        . qq{$query->{sql}\n} . _subname);
1181
    }
1182
    
1183
    # Set statement handle
1184
    $query->sth($sth);
1185
    
1186
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1187
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1188
    
1189
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1190
}
1191

            
cleanup
Yuki Kimoto authored on 2011-04-02
1192
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1193
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1194
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1195
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1196
    
cleanup
Yuki Kimoto authored on 2011-04-02
1197
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1198
    my $bind = [];
micro optimization
Yuki Kimoto authored on 2011-10-23
1199
    my $types = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1200
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1201
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-10-21
1202
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1203
        
1204
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1205
        my $value;
1206
        if(ref $params->{$column} eq 'ARRAY') {
1207
            my $i = $count->{$column} || 0;
1208
            $i += $not_exists->{$column} || 0;
1209
            my $found;
1210
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1211
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1212
                    $not_exists->{$column}++;
1213
                }
1214
                else  {
1215
                    $value = $params->{$column}->[$k];
1216
                    $found = 1;
1217
                    last
1218
                }
1219
            }
1220
            next unless $found;
1221
        }
1222
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1223
        
cleanup
Yuki Kimoto authored on 2011-01-12
1224
        # Filter
1225
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1226
        $value = $f->($value) if $f;
1227
        
1228
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-22
1229
        my $tf1 = $self->{"_into1"}->{dot}->{$column}
1230
          || $type_filters->{1}->{$column};
1231
        $value = $tf1->($value) if $tf1;
1232
        my $tf2 = $self->{"_into2"}->{dot}->{$column}
1233
          || $type_filters->{2}->{$column};
1234
        $value = $tf2->($value) if $tf2;
1235
       
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1236
        # Bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1237
        push @$bind, $value;
1238
        push @$types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1239
        
1240
        # Count up 
1241
        $count->{$column}++;
1242
    }
1243
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1244
    return ($bind, $types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1245
}
1246

            
cleanup
Yuki Kimoto authored on 2011-10-21
1247
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1248
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1249
    
1250
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1251
    croak "primary_key option " .
1252
          "must be specified with id option " . _subname
1253
      unless defined $primary_keys;
1254
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1255
    
cleanup
Yuki Kimoto authored on 2011-06-08
1256
    # Create parameter
1257
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1258
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1259
        $id = [$id] unless ref $id;
1260
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1261
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1262
          unless !ref $id || ref $id eq 'ARRAY';
1263
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1264
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1265
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1266
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1267
           my $key = $primary_keys->[$i];
1268
           $key = "$table." . $key if $table;
1269
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1270
        }
1271
    }
1272
    
cleanup
Yuki Kimoto authored on 2011-06-08
1273
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1274
}
1275

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1276
sub _connect {
1277
    my $self = shift;
1278
    
1279
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1280
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1281
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1282
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1283
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1284
    croak qq{"dsn" must be specified } . _subname
1285
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1286
    my $user        = $self->user;
1287
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1288
    my $option = $self->_option;
1289
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1290
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1291
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1292
    my $dbh;
1293
    eval {
1294
        $dbh = DBI->connect(
1295
            $dsn,
1296
            $user,
1297
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1298
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1299
        );
1300
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1301
    
1302
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1303
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1304
    
1305
    return $dbh;
1306
}
1307

            
cleanup
yuki-kimoto authored on 2010-10-17
1308
sub _croak {
1309
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1310
    
1311
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1312
    $append ||= "";
1313
    
1314
    # Verbose
1315
    if ($Carp::Verbose) { croak $error }
1316
    
1317
    # Not verbose
1318
    else {
1319
        
1320
        # Remove line and module infromation
1321
        my $at_pos = rindex($error, ' at ');
1322
        $error = substr($error, 0, $at_pos);
1323
        $error =~ s/\s+$//;
1324
        croak "$error$append";
1325
    }
1326
}
1327

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1330
sub _need_tables {
1331
    my ($self, $tree, $need_tables, $tables) = @_;
1332
    
cleanup
Yuki Kimoto authored on 2011-04-02
1333
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1334
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1335
        if ($tree->{$table}) {
1336
            $need_tables->{$table} = 1;
1337
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1338
        }
1339
    }
1340
}
1341

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1342
sub _option {
1343
    my $self = shift;
1344
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1345
    warn "dbi_options is DEPRECATED! use option instead\n"
1346
      if keys %{$self->dbi_options};
1347
    warn "dbi_option is DEPRECATED! use option instead\n"
1348
      if keys %{$self->dbi_option};
1349
    return $option;
1350
}
1351

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1352
sub _push_join {
1353
    my ($self, $sql, $join, $join_tables) = @_;
1354
    
cleanup
Yuki Kimoto authored on 2011-10-21
1355
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1356
    
cleanup
Yuki Kimoto authored on 2011-04-02
1357
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1358
    return unless @$join;
1359
    
cleanup
Yuki Kimoto authored on 2011-04-02
1360
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1361
    my $tree = {};
1362
    for (my $i = 0; $i < @$join; $i++) {
1363
        
cleanup
Yuki Kimoto authored on 2011-07-28
1364
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1365
        my $join_clause;;
1366
        my $option;
1367
        if (ref $join->[$i] eq 'HASH') {
1368
            $join_clause = $join->[$i]->{clause};
1369
            $option = {table => $join->[$i]->{table}};
1370
        }
1371
        else {
1372
            $join_clause = $join->[$i];
1373
            $option = {};
1374
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1375

            
1376
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1377
        my $table1;
1378
        my $table2;
1379
        if (my $table = $option->{table}) {
1380
            $table1 = $table->[0];
1381
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1382
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1383
        else {
1384
            my $q = $self->_quote;
1385
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1386
            $j_clause =~ s/'.+?'//g;
1387
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1388
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1389
            
1390
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1391
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1392
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1393
            for my $clause (@j_clauses) {
1394
                if ($clause =~ $join_re) {
1395
                    $table1 = $1;
1396
                    $table2 = $2;
1397
                    last;
1398
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1399
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1400
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1401
        croak qq{join clause must have two table name after "on" keyword. } .
1402
              qq{"$join_clause" is passed }  . _subname
1403
          unless defined $table1 && defined $table2;
1404
        croak qq{right side table of "$join_clause" must be unique }
1405
            . _subname
1406
          if exists $tree->{$table2};
1407
        croak qq{Same table "$table1" is specified} . _subname
1408
          if $table1 eq $table2;
1409
        $tree->{$table2}
1410
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1411
    }
1412
    
cleanup
Yuki Kimoto authored on 2011-04-02
1413
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1414
    my $need_tables = {};
1415
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1416
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1417
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1418
    
1419
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1420
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1421
}
cleanup
Yuki Kimoto authored on 2011-03-08
1422

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1423
sub _quote {
1424
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1425
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1426
}
1427

            
cleanup
Yuki Kimoto authored on 2011-07-29
1428
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1429
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1430
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1431
    my $quote = $self->{reserved_word_quote}
1432
      || $self->{quote} || $self->quote || '';
1433
    return "$quote$value$quote"
1434
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
1435
    
cleanup
Yuki Kimoto authored on 2011-07-29
1436
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1437
    my $p;
1438
    if (defined $quote && length $quote > 1) {
1439
        $p = substr($quote, 1, 1);
1440
    }
1441
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1442
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1443
    if ($quotemeta) {
1444
        $q = quotemeta($q);
1445
        $p = quotemeta($p);
1446
    }
1447
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1448
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1449
}
1450

            
cleanup
Yuki Kimoto authored on 2011-04-02
1451
sub _remove_duplicate_table {
1452
    my ($self, $tables, $main_table) = @_;
1453
    
1454
    # Remove duplicate table
1455
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1456
    delete $tables{$main_table} if $main_table;
1457
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1458
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1459
    if (my $q = $self->_quote) {
1460
        $q = quotemeta($q);
1461
        $_ =~ s/[$q]//g for @$new_tables;
1462
    }
1463

            
1464
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1465
}
1466

            
cleanup
Yuki Kimoto authored on 2011-04-02
1467
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1468
    my ($self, $source) = @_;
1469
    
cleanup
Yuki Kimoto authored on 2011-04-02
1470
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1471
    my $tables = [];
1472
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1473
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1474
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1475
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1476
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1477
    while ($source =~ /$table_re/g) {
1478
        push @$tables, $1;
1479
    }
1480
    
1481
    return $tables;
1482
}
1483

            
cleanup
Yuki Kimoto authored on 2011-04-02
1484
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1485
    my ($self, $where) = @_;
1486
    
cleanup
Yuki Kimoto authored on 2011-04-02
1487
    my $obj;
1488
    
1489
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1490
    if (ref $where eq 'HASH') {
1491
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1492
        my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-10-21
1493
        for my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1494
            my $table;
1495
            my $c;
1496
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1497
                $table = $1;
1498
                $c = $2;
1499
            }
1500
            
1501
            my $table_quote;
1502
            $table_quote = $self->_q($table) if defined $table;
1503
            my $column_quote = $self->_q($c);
1504
            $column_quote = $table_quote . '.' . $column_quote
1505
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1506
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1507
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1508
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1509
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1510
    
1511
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1512
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1513
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1514
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1515
    
updated pod
Yuki Kimoto authored on 2011-06-21
1516
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1517
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1518
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1519
            clause => $where->[0],
1520
            param  => $where->[1]
1521
        );
1522
    }
1523
    
cleanup
Yuki Kimoto authored on 2011-04-02
1524
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1525
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1526
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1527
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1528
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1529
    
cleanup
Yuki Kimoto authored on 2011-04-02
1530
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1531
}
1532

            
cleanup
Yuki Kimoto authored on 2011-10-21
1533
sub _where_clause_and_param {
1534
    my ($self, $where, $param) = @_;
1535
 
1536
    $where ||= {};
1537
    $param ||= {};
1538
    my $w = {};
1539
    my $where_clause = '';
1540
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1541
        $w->{clause} = "where " . $where->[0];
1542
        $w->{param} = $where->[1];
1543
    }
1544
    elsif (ref $where) {
1545
        $where = $self->_where_to_obj($where);
1546
        $w->{param} = keys %$param
1547
                    ? $self->merge_param($param, $where->param)
1548
                    : $where->param;
1549
        $w->{clause} = $where->to_string;
1550
    }
1551
    elsif ($where) {
1552
        $w->{clause} = "where $where";
1553
        $w->{param} = $param;
1554
    }
1555
    
1556
    return $w;
1557
}
1558

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

            
1562
    # Initialize filters
1563
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1564
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1565
    $self->{filter}{out} ||= {};
1566
    $self->{filter}{in} ||= {};
1567
    $self->{filter}{end} ||= {};
1568
    
1569
    # Usage
1570
    my $usage = "Usage: \$dbi->apply_filter(" .
1571
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1572
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1573
    
1574
    # Apply filter
1575
    for (my $i = 0; $i < @cinfos; $i += 2) {
1576
        
1577
        # Column
1578
        my $column = $cinfos[$i];
1579
        if (ref $column eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-10-21
1580
            for my $c (@$column) {
updated pod
Yuki Kimoto authored on 2011-06-21
1581
                push @cinfos, $c, $cinfos[$i + 1];
1582
            }
1583
            next;
1584
        }
1585
        
1586
        # Filter infomation
1587
        my $finfo = $cinfos[$i + 1] || {};
1588
        croak "$usage (table: $table) " . _subname
1589
          unless  ref $finfo eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-10-21
1590
        for my $ftype (keys %$finfo) {
updated pod
Yuki Kimoto authored on 2011-06-21
1591
            croak "$usage (table: $table) " . _subname
1592
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1593
        }
1594
        
1595
        # Set filters
cleanup
Yuki Kimoto authored on 2011-10-21
1596
        for my $way (qw/in out end/) {
updated pod
Yuki Kimoto authored on 2011-06-21
1597
        
1598
            # Filter
1599
            my $filter = $finfo->{$way};
1600
            
1601
            # Filter state
1602
            my $state = !exists $finfo->{$way} ? 'not_exists'
1603
                      : !defined $filter        ? 'not_defined'
1604
                      : ref $filter eq 'CODE'   ? 'code'
1605
                      : 'name';
1606
            
1607
            # Filter is not exists
1608
            next if $state eq 'not_exists';
1609
            
1610
            # Check filter name
1611
            croak qq{Filter "$filter" is not registered } . _subname
1612
              if  $state eq 'name'
1613
               && ! exists $self->filters->{$filter};
1614
            
1615
            # Set filter
1616
            my $f = $state eq 'not_defined' ? undef
1617
                  : $state eq 'code'        ? $filter
1618
                  : $self->filters->{$filter};
1619
            $self->{filter}{$way}{$table}{$column} = $f;
1620
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1621
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1622
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1623
        }
1624
    }
1625
    
1626
    return $self;
1627
}
1628

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1629
# DEPRECATED!
1630
has 'data_source';
1631
has dbi_options => sub { {} };
1632
has filter_check  => 1;
1633
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1634
has dbi_option => sub { {} };
1635
has default_dbi_option => sub {
1636
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1637
    return shift->default_option;
1638
};
1639

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1640
# DEPRECATED!
1641
sub method {
1642
    warn "method is DEPRECATED! use helper instead";
1643
    return shift->helper(@_);
1644
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1645

            
1646
# DEPRECATED!
1647
sub assign_param {
1648
    my $self = shift;
1649
    warn "assing_param is DEPRECATED! use assign_clause instead";
1650
    return $self->assign_clause(@_);
1651
}
1652

            
1653
# DEPRECATED
1654
sub update_param {
1655
    my ($self, $param, $opts) = @_;
1656
    
1657
    warn "update_param is DEPRECATED! use assing_clause instead.";
1658
    
1659
    # Create update parameter tag
1660
    my $tag = $self->assign_clause($param, $opts);
1661
    $tag = "set $tag" unless $opts->{no_set};
1662

            
1663
    return $tag;
1664
}
1665

            
updated pod
Yuki Kimoto authored on 2011-06-21
1666
# DEPRECATED!
1667
sub create_query {
1668
    warn "create_query is DEPRECATED! use query option of each method";
1669
    shift->_create_query(@_);
1670
}
1671

            
cleanup
Yuki Kimoto authored on 2011-06-13
1672
# DEPRECATED!
1673
sub apply_filter {
1674
    my $self = shift;
1675
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1676
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1677
    return $self->_apply_filter(@_);
1678
}
1679

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1686
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1687
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1688
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1689
    my $where = delete $opt{where};
1690
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1691
    
1692
    # Table
1693
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1694
      unless $opt{table};
1695
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1696
    
1697
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1698
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1699
    
cleanup
Yuki Kimoto authored on 2011-10-21
1700
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1701
}
1702

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1707
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1708
    
cleanup
Yuki Kimoto authored on 2011-10-21
1709
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1710
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1711
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1712
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1713
    
1714
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1715
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1716
    
cleanup
Yuki Kimoto authored on 2011-10-21
1717
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1718
}
1719

            
cleanup
Yuki Kimoto authored on 2011-06-08
1720
# DEPRECATED!
1721
sub update_at {
1722
    my $self = shift;
1723

            
cleanup
Yuki Kimoto authored on 2011-10-21
1724
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1725
    
cleanup
Yuki Kimoto authored on 2011-10-21
1726
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1727
    my $param;
1728
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1729
    my %opt = @_;
1730
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1731
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1732
    my $where = delete $opt{where};
1733
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1734
    $param  ||= $p;
1735
    
1736
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1737
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1738
    
cleanup
Yuki Kimoto authored on 2011-10-21
1739
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1740
}
1741

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1742
# DEPRECATED!
1743
sub insert_at {
1744
    my $self = shift;
1745
    
cleanup
Yuki Kimoto authored on 2011-10-21
1746
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1747
    
cleanup
Yuki Kimoto authored on 2011-10-21
1748
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1749
    my $param;
1750
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1751
    my %opt = @_;
1752
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1753
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1754
    my $where = delete $opt{where};
1755
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1756
    $param  ||= $p;
1757
    
1758
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1759
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1760
    $param = $self->merge_param($where_param, $param);
1761
    
cleanup
Yuki Kimoto authored on 2011-10-21
1762
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1763
}
1764

            
added warnings
Yuki Kimoto authored on 2011-06-07
1765
# DEPRECATED!
1766
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1767
    my $self = shift;
1768
    
added warnings
Yuki Kimoto authored on 2011-06-07
1769
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1770
    
1771
    # Merge tag
1772
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1773
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1774
    
1775
    return $self;
1776
}
1777

            
1778
# DEPRECATED!
1779
sub register_tag_processor {
1780
    my $self = shift;
1781
    warn "register_tag_processor is DEPRECATED!";
1782
    # Merge tag
1783
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1784
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1785
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1786
}
1787

            
cleanup
Yuki Kimoto authored on 2011-01-25
1788
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1789
sub default_bind_filter {
1790
    my $self = shift;
1791
    
cleanup
Yuki Kimoto authored on 2011-06-13
1792
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1793
    
cleanup
Yuki Kimoto authored on 2011-01-12
1794
    if (@_) {
1795
        my $fname = $_[0];
1796
        
1797
        if (@_ && !$fname) {
1798
            $self->{default_out_filter} = undef;
1799
        }
1800
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1801
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1802
              unless exists $self->filters->{$fname};
1803
        
1804
            $self->{default_out_filter} = $self->filters->{$fname};
1805
        }
1806
        return $self;
1807
    }
1808
    
1809
    return $self->{default_out_filter};
1810
}
1811

            
cleanup
Yuki Kimoto authored on 2011-01-25
1812
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1813
sub default_fetch_filter {
1814
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1815

            
cleanup
Yuki Kimoto authored on 2011-06-13
1816
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1817
    
1818
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1819
        my $fname = $_[0];
1820

            
cleanup
Yuki Kimoto authored on 2011-01-12
1821
        if (@_ && !$fname) {
1822
            $self->{default_in_filter} = undef;
1823
        }
1824
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1825
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1826
              unless exists $self->filters->{$fname};
1827
        
1828
            $self->{default_in_filter} = $self->filters->{$fname};
1829
        }
1830
        
1831
        return $self;
1832
    }
1833
    
many changed
Yuki Kimoto authored on 2011-01-23
1834
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1835
}
1836

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1837
# DEPRECATED!
1838
sub insert_param {
1839
    my $self = shift;
1840
    warn "insert_param is DEPRECATED! use values_clause instead";
1841
    return $self->values_clause(@_);
1842
}
1843

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1844
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1845
sub insert_param_tag {
1846
    warn "insert_param_tag is DEPRECATED! " .
1847
         "use insert_param instead!";
1848
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1849
}
1850

            
1851
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1852
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1853
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1854
         "use update_param instead";
1855
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1856
}
cleanup
Yuki Kimoto authored on 2011-03-08
1857
# DEPRECATED!
1858
sub _push_relation {
1859
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1860
    
1861
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1862
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1863
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1864
            my $table1 = (split (/\./, $rcolumn))[0];
1865
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1866
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1867
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1868
        }
1869
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1870
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1871
}
1872

            
1873
# DEPRECATED!
1874
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1875
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1876
    
1877
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1878
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1879
            my $table1 = (split (/\./, $rcolumn))[0];
1880
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1881
            my $table1_exists;
1882
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1883
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1884
                $table1_exists = 1 if $table eq $table1;
1885
                $table2_exists = 1 if $table eq $table2;
1886
            }
1887
            unshift @$tables, $table1 unless $table1_exists;
1888
            unshift @$tables, $table2 unless $table2_exists;
1889
        }
1890
    }
1891
}
1892

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1901
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1902
    
1903
    # Connect
1904
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1905
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1906
        user => 'ken',
1907
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1908
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1909
    );
cleanup
yuki-kimoto authored on 2010-08-05
1910

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1911
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1912
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1913
    
1914
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1915
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1916
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1917
    
1918
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1919
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1920

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1925
    # Select, more complex
1926
    my $result = $dbi->select(
1927
        table  => 'book',
1928
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1929
            {book => [qw/title author/]},
1930
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1931
        ],
1932
        where  => {'book.author' => 'Ken'},
1933
        join => ['left outer join company on book.company_id = company.id'],
1934
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1935
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1936
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1937
    # Fetch
1938
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1939
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1940
    }
1941
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1942
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1943
    while (my $row = $result->fetch_hash) {
1944
        
1945
    }
1946
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1947
    # Execute SQL with parameter.
1948
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1949
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1950
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1951
    );
1952
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1953
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1954

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1970
Named place holder support
1971

            
1972
=item *
1973

            
cleanup
Yuki Kimoto authored on 2011-07-29
1974
Model support
1975

            
1976
=item *
1977

            
1978
Connection manager support
1979

            
1980
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1981

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

            
1986
=item *
1987

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

            
1990
=item *
1991

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

            
1994
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1995

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2003
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2004
L<DBIx::Custom::Result>,
2005
L<DBIx::Custom::Query>,
2006
L<DBIx::Custom::Where>,
2007
L<DBIx::Custom::Model>,
2008
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2009

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

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

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

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

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

            
2023
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2024
        "dbi:mysql:database=$database",
2025
        $user,
2026
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2027
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2028
    );
2029
    
updated pod
Yuki Kimoto authored on 2011-06-21
2030
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2031

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

            
2035
    my $dbi = DBIx::Custom->connect(
2036
      dsn => $dsn, user => $user, password => $password, connector => 1);
2037
    
2038
    my $connector = $dbi->connector; # DBIx::Connector
2039

            
2040
Note that L<DBIx::Connector> must be installed.
2041

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2057
    {
2058
        RaiseError => 1,
2059
        PrintError => 0,
2060
        AutoCommit => 1,
2061
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2062

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

            
2065
    my $exclude_table = $dbi->exclude_table;
2066
    $dbi = $dbi->exclude_table(qr/pg_/);
2067

            
2068
Excluded table regex.
2069
C<each_column>, C<each_table>, C<type_rule>,
2070
and C<setup_model> methods ignore matching tables.
2071

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

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

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

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

            
2081
    my $last_sql = $dbi->last_sql;
2082
    $dbi = $dbi->last_sql($last_sql);
2083

            
2084
Get last successed SQL executed by C<execute> method.
2085

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

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

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

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

            
2095
    my $option = $dbi->option;
2096
    $dbi = $dbi->option($option);
2097

            
2098
L<DBI> option, used when C<connect> method is executed.
2099
Each value in option override the value of C<default_option>.
2100

            
cleanup
yuki-kimoto authored on 2010-10-17
2101
=head2 C<password>
2102

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2123
You can set quote pair.
2124

            
2125
    $dbi->quote('[]');
2126

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2136
    my $safety_character = $dbi->safety_character;
2137
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2138

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

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

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

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

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

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

            
2155
    my $tag_parse = $dbi->tag_parse(0);
2156
    $dbi = $dbi->tag_parse;
2157

            
2158
Enable DEPRECATED tag parsing functionality, default to 1.
2159
If you want to disable tag parsing functionality, set to 0.
2160

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

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

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

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

            
2170
    my $user_column_info = $dbi->user_column_info;
2171
    $dbi = $dbi->user_column_info($user_column_info);
2172

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

            
2175
    [
2176
        {table => 'book', column => 'title', info => {...}},
2177
        {table => 'author', column => 'name', info => {...}}
2178
    ]
2179

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

            
2182
    my $user_column_info
2183
      = $dbi->get_column_info(exclude_table => qr/^system/);
2184
    $dbi->user_column_info($user_column_info);
2185

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

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

            
2191
    my $user_table_info = $dbi->user_table_info;
2192
    $dbi = $dbi->user_table_info($user_table_info);
2193

            
2194
You can set the following data.
2195

            
2196
    [
2197
        {table => 'book', info => {...}},
2198
        {table => 'author', info => {...}}
2199
    ]
2200

            
2201
Usually, you can set return value of C<get_table_info>.
2202

            
2203
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2204
    $dbi->user_table_info($user_table_info);
2205

            
2206
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2207
to find table info.
2208

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2245
Create column clause. The follwoing column clause is created.
2246

            
2247
    book.author as "book.author",
2248
    book.title as "book.title"
2249

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2252
    # Separator is hyphen
2253
    $dbi->separator('-');
2254
    
2255
    book.author as "book-author",
2256
    book.title as "book-title"
2257
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2258
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2259

            
update pod
Yuki Kimoto authored on 2011-03-13
2260
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2261
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2262
        user => 'ken',
2263
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2264
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2265
    );
2266

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

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

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

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

            
2277
Get rows count.
2278

            
2279
Options is same as C<select> method's ones.
2280

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2283
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2284
        table => 'book',
2285
        primary_key => 'id',
2286
        join => [
2287
            'inner join company on book.comparny_id = company.id'
2288
        ],
2289
    );
2290

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

            
2294
   $dbi->model('book')->select(...);
2295

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

            
2298
    my $dbh = $dbi->dbh;
2299

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

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

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

            
2307
Execute delete statement.
2308

            
2309
The following opitons are available.
2310

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

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

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

            
2318
=item C<id>
2319

            
2320
    id => 4
2321
    id => [4, 5]
2322

            
2323
ID corresponding to C<primary_key>.
2324
You can delete rows by C<id> and C<primary_key>.
2325

            
2326
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2327
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2328
        id => [4, 5],
2329
        table => 'book',
2330
    );
2331

            
2332
The above is same as the followin one.
2333

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

            
2336
=item C<prefix>
2337

            
2338
    prefix => 'some'
2339

            
2340
prefix before table name section.
2341

            
2342
    delete some from book
2343

            
2344
=item C<table>
2345

            
2346
    table => 'book'
2347

            
2348
Table name.
2349

            
2350
=item C<where>
2351

            
2352
Same as C<select> method's C<where> option.
2353

            
2354
=back
2355

            
2356
=head2 C<delete_all>
2357

            
2358
    $dbi->delete_all(table => $table);
2359

            
2360
Execute delete statement for all rows.
2361
Options is same as C<delete>.
2362

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

            
2365
    $dbi->each_column(
2366
        sub {
2367
            my ($dbi, $table, $column, $column_info) = @_;
2368
            
2369
            my $type = $column_info->{TYPE_NAME};
2370
            
2371
            if ($type eq 'DATE') {
2372
                # ...
2373
            }
2374
        }
2375
    );
2376

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

            
2382
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2383
infromation, you can improve the performance of C<each_column> in
2384
the following way.
2385

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

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

            
2392
    $dbi->each_table(
2393
        sub {
2394
            my ($dbi, $table, $table_info) = @_;
2395
            
2396
            my $table_name = $table_info->{TABLE_NAME};
2397
        }
2398
    );
2399

            
improved pod
Yuki Kimoto authored on 2011-10-14
2400
Iterate all table informationsfrom in database.
2401
Argument is callback which is executed when one table is found.
2402
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2403
C<table information>.
2404

            
2405
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2406
infromation, you can improve the performance of C<each_table> in
2407
the following way.
2408

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

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

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

            
2420
    my $result = $dbi->execute(
2421
      "select * from book where title = :book.title and author like :book.author",
2422
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2423
    );
2424

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2431
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2432
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2433
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2434
    select * from book where title = :title and author like :author
2435
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2436
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2437
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2438

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2442
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2443
    select * from book where :title{=} and :author{like}
2444
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2445
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2446
    select * from where title = ? and author like ?;
2447

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

            
2452
    select * from where title = "aa\\:bb";
2453

            
cleanup
Yuki Kimoto authored on 2011-10-20
2454
B<OPTIONS>
2455

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

            
2458
=over 4
2459

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

            
2462
You can filter sql after the sql is build.
2463

            
2464
    after_build_sql => $code_ref
2465

            
2466
The following one is one example.
2467

            
2468
    $dbi->select(
2469
        table => 'book',
2470
        column => 'distinct(name)',
2471
        after_build_sql => sub {
2472
            "select count(*) from ($_[0]) as t1"
2473
        }
2474
    );
2475

            
2476
The following SQL is executed.
2477

            
2478
    select count(*) from (select distinct(name) from book) as t1;
2479

            
cleanup
Yuki Kimoto authored on 2011-10-20
2480
=item C<append>
2481

            
2482
    append => 'order by name'
2483

            
2484
Append some statement after SQL.
2485

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

            
2488
Specify database bind data type.
2489

            
2490
    bind_type => [image => DBI::SQL_BLOB]
2491
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2492

            
2493
This is used to bind parameter by C<bind_param> of statment handle.
2494

            
2495
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2496

            
update pod
Yuki Kimoto authored on 2011-03-13
2497
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2498
    
2499
    filter => {
2500
        title  => sub { uc $_[0] }
2501
        author => sub { uc $_[0] }
2502
    }
update pod
Yuki Kimoto authored on 2011-03-13
2503

            
updated pod
Yuki Kimoto authored on 2011-06-09
2504
    # Filter name
2505
    filter => {
2506
        title  => 'upper_case',
2507
        author => 'upper_case'
2508
    }
2509
        
2510
    # At once
2511
    filter => [
2512
        [qw/title author/]  => sub { uc $_[0] }
2513
    ]
2514

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2520
=item C<id>
2521

            
2522
    id => 4
2523
    id => [4, 5]
2524

            
2525
ID corresponding to C<primary_key>.
2526
You can delete rows by C<id> and C<primary_key>.
2527

            
2528
    $dbi->execute(
2529
        "select * from book where id1 = :id1 and id2 = :id2",
2530
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2531
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2532
        id => [4, 5],
2533
    );
2534

            
2535
The above is same as the followin one.
2536

            
2537
    $dbi->execute(
2538
        "select * from book where id1 = :id1 and id2 = :id2",
2539
        {id1 => 4, id2 => 5}
2540
    );
2541

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

            
2544
    query => 1
2545

            
2546
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
cleanup
Yuki Kimoto authored on 2011-07-30
2547
You can check SQL or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2548

            
2549
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2550
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2551
    my $columns = $query->columns;
2552
    
2553
If you want to execute SQL fast, you can do the following way.
2554

            
2555
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2556
    for my $row (@$rows) {
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2557
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2558
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2559
    }
2560

            
2561
Statement handle is reused and SQL parsing is finished,
2562
so you can get more performance than normal way.
cleanup
Yuki Kimoto authored on 2011-07-30
2563

            
2564
If you want to execute SQL as possible as fast and don't need filtering.
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2565
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2566
    
2567
    my $query;
2568
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2569
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2570
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2571
      $sth ||= $query->sth;
2572
      $sth->execute(map { $row->{$_} } sort keys %$row);
2573
    }
2574

            
2575
Note that $row must be simple hash reference, such as
2576
{title => 'Perl', author => 'Ken'}.
2577
and don't forget to sort $row values by $row key asc order.
updated document
Yuki Kimoto authored on 2011-06-09
2578

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2581
    primary_key => 'id'
2582
    primary_key => ['id1', 'id2']
2583

            
2584
Priamry key. This is used when C<id> option find primary key.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2585

            
updated pod
Yuki Kimoto authored on 2011-06-09
2586
=item C<table>
2587
    
2588
    table => 'author'
2589

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2597
    # Same
2598
    $dbi->execute(
2599
      "select * from book where title = :book.title and author = :book.author",
2600
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2601

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

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

            
2606
Table alias. Key is real table name, value is alias table name.
2607
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2608
on alias table name.
2609

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2610
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2611
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2612
    reuse_query => $has_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2613

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2614
Reuse query object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2615
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2616
    my $queries = {};
2617
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2618

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2619
This will improved performance when you want to execute same query repeatedly
2620
because generally creating query object is slow.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2621

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

            
2624
    type_rule_off => 1
2625

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

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

            
2630
    type_rule1_off => 1
2631

            
2632
Turn C<into1> type rule off.
2633

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

            
2636
    type_rule2_off => 1
2637

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

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

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

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

            
2646
get column infomation except for one which match C<exclude_table> pattern.
2647

            
2648
    [
2649
        {table => 'book', column => 'title', info => {...}},
2650
        {table => 'author', column => 'name' info => {...}}
2651
    ]
2652

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

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

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

            
2659
    [
2660
        {table => 'book', info => {...}},
2661
        {table => 'author', info => {...}}
2662
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2663

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

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

            
2668
    $dbi->helper(
2669
        update_or_insert => sub {
2670
            my $self = shift;
2671
            
2672
            # Process
2673
        },
2674
        find_or_create   => sub {
2675
            my $self = shift;
2676
            
2677
            # Process
2678
        }
2679
    );
2680

            
2681
Register helper. These helper is called directly from L<DBIx::Custom> object.
2682

            
2683
    $dbi->update_or_insert;
2684
    $dbi->find_or_create;
2685

            
cleanup
yuki-kimoto authored on 2010-10-17
2686
=head2 C<insert>
2687

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

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

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

            
2696
    {date => \"NOW()"}
2697

            
cleanup
Yuki Kimoto authored on 2011-10-20
2698
B<options>
2699

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2707
    id => 4
2708
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2709

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2713
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2714
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2715
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2716
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2717
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2718
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2719

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

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

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

            
2729
    prefix => 'or replace'
2730

            
2731
prefix before table name section
2732

            
2733
    insert or replace into book
2734

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

            
2737
    table => 'book'
2738

            
2739
Table name.
2740

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2741
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
2742

            
2743
    timestamp => 1
2744

            
2745
If this value is set to 1,
2746
automatically created timestamp column is set based on
2747
C<timestamp> attribute's C<insert> value.
2748

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

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

            
2753
placeholder wrapped string.
2754

            
2755
If the following statement
2756

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

            
2760
is executed, the following SQL is executed.
2761

            
2762
    insert into book price values ( ? + 5 );
2763

            
update pod
Yuki Kimoto authored on 2011-03-13
2764
=back
2765

            
2766
=over 4
2767

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2775
    lib / MyModel.pm
2776
        / MyModel / book.pm
2777
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2778

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

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

            
2783
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2784
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2785
    
2786
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2787

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2792
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2793
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2794
    
2795
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2796

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2799
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2800
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2801
    
2802
    1;
2803
    
updated pod
Yuki Kimoto authored on 2011-06-21
2804
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2805

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2813
=head2 C<insert_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2814

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2815
    $dbi->insert_timestamp(
2816
      [qw/created_at updated_at/]
2817
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2818
    );
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2819

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2820
Timestamp value when C<insert> method is executed
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2821
with C<timestamp> option.
2822

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2823
If C<insert_timestamp> is set and C<insert> method is executed
2824
with C<timestamp> option, column C<created_at> and C<update_at>
2825
is automatically set to the value like "2010-10-11 10:12:54".
2826

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2827
    $dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2828

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

            
2831
    my $like_value = $dbi->like_value
2832

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

            
2835
    sub { "%$_[0]%" }
2836

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

            
2839
    my $mapper = $dbi->mapper(param => $param);
2840

            
2841
Create a new L<DBIx::Custom::Mapper> object.
2842

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

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

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

            
2849
    {key1 => [1, 1], key2 => 2}
2850

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

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

            
2855
    my $model = $dbi->model('book');
2856

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

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

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

            
2864
Create column clause for myself. The follwoing column clause is created.
2865

            
2866
    book.author as author,
2867
    book.title as title
2868

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

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

            
2878
Create a new L<DBIx::Custom> object.
2879

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

            
2882
    my $not_exists = $dbi->not_exists;
2883

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

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

            
2889
    my $order = $dbi->order;
2890

            
2891
Create a new L<DBIx::Custom::Order> object.
2892

            
cleanup
yuki-kimoto authored on 2010-10-17
2893
=head2 C<register_filter>
2894

            
update pod
Yuki Kimoto authored on 2011-03-13
2895
    $dbi->register_filter(
2896
        # Time::Piece object to database DATE format
2897
        tp_to_date => sub {
2898
            my $tp = shift;
2899
            return $tp->strftime('%Y-%m-%d');
2900
        },
2901
        # database DATE format to Time::Piece object
2902
        date_to_tp => sub {
2903
           my $date = shift;
2904
           return Time::Piece->strptime($date, '%Y-%m-%d');
2905
        }
2906
    );
cleanup
yuki-kimoto authored on 2010-10-17
2907
    
update pod
Yuki Kimoto authored on 2011-03-13
2908
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2909

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2912
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2913
        table  => 'book',
2914
        column => ['author', 'title'],
2915
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2916
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2917
    
updated document
Yuki Kimoto authored on 2011-06-09
2918
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2919

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2927
=item C<column>
2928
    
updated document
Yuki Kimoto authored on 2011-06-09
2929
    column => 'author'
2930
    column => ['author', 'title']
2931

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2940
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2941
        {book => [qw/author title/]},
2942
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2943
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2944

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

            
2947
    book.author as "book.author",
2948
    book.title as "book.title",
2949
    person.name as "person.name",
2950
    person.age as "person.age"
2951

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2963
=item C<filter>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2964

            
updated document
Yuki Kimoto authored on 2011-06-09
2965
Same as C<execute> method's C<filter> option.
2966

            
2967
=item C<id>
2968

            
2969
    id => 4
2970
    id => [4, 5]
2971

            
2972
ID corresponding to C<primary_key>.
2973
You can select rows by C<id> and C<primary_key>.
2974

            
2975
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2976
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2977
        id => [4, 5],
2978
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2979
    );
2980

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2983
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2984
        where => {id1 => 4, id2 => 5},
2985
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2986
    );
2987
    
cleanup
Yuki Kimoto authored on 2011-10-20
2988
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2989

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

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

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

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

            
3002
    prefix => 'SQL_CALC_FOUND_ROWS'
3003

            
3004
Prefix of column cluase
3005

            
3006
    select SQL_CALC_FOUND_ROWS title, author from book;
3007

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

            
3010
    join => [
3011
        'left outer join company on book.company_id = company_id',
3012
        'left outer join location on company.location_id = location.id'
3013
    ]
3014
        
3015
Join clause. If column cluase or where clause contain table name like "company.name",
3016
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3017

            
3018
    $dbi->select(
3019
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3020
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3021
        where => {'company.name' => 'Orange'},
3022
        join => [
3023
            'left outer join company on book.company_id = company.id',
3024
            'left outer join location on company.location_id = location.id'
3025
        ]
3026
    );
3027

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3031
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3032
    from book
3033
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3034
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3035

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3036
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
3037
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3038

            
3039
    $dbi->select(
3040
        table => 'book',
3041
        column => ['company.location_id as location_id'],
3042
        where => {'company.name' => 'Orange'},
3043
        join => [
3044
            {
3045
                clause => 'left outer join location on company.location_id = location.id',
3046
                table => ['company', 'location']
3047
            }
3048
        ]
3049
    );
3050

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3055
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3056

            
updated document
Yuki Kimoto authored on 2011-06-09
3057
=item C<where>
3058
    
3059
    # Hash refrence
3060
    where => {author => 'Ken', 'title' => 'Perl'}
3061
    
3062
    # DBIx::Custom::Where object
3063
    where => $dbi->where(
3064
        clause => ['and', 'author = :author', 'title like :title'],
3065
        param  => {author => 'Ken', title => '%Perl%'}
3066
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3067
    
3068
    # Array reference 1 (array reference, hash referenc). same as above
3069
    where => [
3070
        ['and', 'author = :author', 'title like :title'],
3071
        {author => 'Ken', title => '%Perl%'}
3072
    ];    
3073
    
3074
    # Array reference 2 (String, hash reference)
3075
    where => [
3076
        'title like :title',
3077
        {title => '%Perl%'}
3078
    ]
3079
    
3080
    # String
3081
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3082

            
cleanup
Yuki Kimoto authored on 2011-10-20
3083
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3084
    
update pod
Yuki Kimoto authored on 2011-03-12
3085
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3086

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

            
3089
    $dbi->setup_model;
3090

            
3091
Setup all model objects.
3092
C<columns> of model object is automatically set, parsing database information.
3093

            
3094
=head2 C<type_rule>
3095

            
3096
    $dbi->type_rule(
3097
        into1 => {
3098
            date => sub { ... },
3099
            datetime => sub { ... }
3100
        },
3101
        into2 => {
3102
            date => sub { ... },
3103
            datetime => sub { ... }
3104
        },
3105
        from1 => {
3106
            # DATE
3107
            9 => sub { ... },
3108
            # DATETIME or TIMESTAMP
3109
            11 => sub { ... },
3110
        }
3111
        from2 => {
3112
            # DATE
3113
            9 => sub { ... },
3114
            # DATETIME or TIMESTAMP
3115
            11 => sub { ... },
3116
        }
3117
    );
3118

            
3119
Filtering rule when data is send into and get from database.
3120
This has a little complex problem.
3121

            
3122
In C<into1> and C<into2> you can specify
3123
type name as same as type name defined
3124
by create table, such as C<DATETIME> or C<DATE>.
3125

            
3126
Note that type name and data type don't contain upper case.
3127
If these contain upper case charactor, you convert it to lower case.
3128

            
3129
C<into2> is executed after C<into1>.
3130

            
3131
Type rule of C<into1> and C<into2> is enabled on the following
3132
column name.
3133

            
3134
=over 4
3135

            
3136
=item 1. column name
3137

            
3138
    issue_date
3139
    issue_datetime
3140

            
3141
This need C<table> option in each method.
3142

            
3143
=item 2. table name and column name, separator is dot
3144

            
3145
    book.issue_date
3146
    book.issue_datetime
3147

            
3148
=back
3149

            
3150
You get all type name used in database by C<available_typename>.
3151

            
3152
    print $dbi->available_typename;
3153

            
3154
In C<from1> and C<from2> you specify data type, not type name.
3155
C<from2> is executed after C<from1>.
3156
You get all data type by C<available_datatype>.
3157

            
3158
    print $dbi->available_datatype;
3159

            
3160
You can also specify multiple types at once.
3161

            
3162
    $dbi->type_rule(
3163
        into1 => [
3164
            [qw/DATE DATETIME/] => sub { ... },
3165
        ],
3166
    );
3167

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

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

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

            
3174
If you want to set constant value to row data, use scalar reference
3175
as parameter value.
3176

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3188
    id => 4
3189
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3190

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3194
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3195
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3196
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3197
        id => [4, 5],
3198
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3199
    );
update pod
Yuki Kimoto authored on 2011-03-13
3200

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3203
    $dbi->update(
3204
        {title => 'Perl', author => 'Ken'}
3205
        where => {id1 => 4, id2 => 5},
3206
        table => 'book'
3207
    );
update pod
Yuki Kimoto authored on 2011-03-13
3208

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

            
3211
    prefix => 'or replace'
3212

            
3213
prefix before table name section
3214

            
3215
    update or replace book
3216

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3223
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
3224

            
3225
    timestamp => 1
3226

            
3227
If this value is set to 1,
3228
automatically updated timestamp column is set based on
3229
C<timestamp> attribute's C<update> value.
3230

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

            
3233
Same as C<select> method's C<where> option.
3234

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

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

            
3239
placeholder wrapped string.
3240

            
3241
If the following statement
3242

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

            
3246
is executed, the following SQL is executed.
3247

            
3248
    update book set price =  ? + 5;
3249

            
updated pod
Yuki Kimoto authored on 2011-06-08
3250
=back
update pod
Yuki Kimoto authored on 2011-03-13
3251

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3259
=head2 C<update_or_insert EXPERIMENTAL>
3260
    
3261
    # Where
3262
    $dbi->update_or_insert(
3263
        {id => 1, title => 'Perl'},
3264
        table => 'book',
3265
        where => {id => 1},
3266
        select_option => {append => 'for update'}
3267
    );
3268
    
3269
    # ID
3270
    $dbi->update_or_insert(
3271
        {title => 'Perl'},
3272
        table => 'book',
3273
        id => 1,
3274
        primary_key => 'id',
3275
        select_option => {append => 'for update'}
3276
    );
3277
    
3278
Update or insert.
3279

            
3280
In both examples, the following SQL is executed.
3281

            
3282
    # In case insert
3283
    insert into book (id, title) values (?, ?)
3284
    
3285
    # In case update
3286
    update book set (id = ?, title = ?) where book.id = ?
3287

            
3288
The following opitons are available adding to C<update> option.
3289

            
3290
=over 4
3291

            
3292
=item C<select_option>
3293

            
3294
    select_option => {append => 'for update'}
3295

            
3296
select method option,
3297
select method is used to check the row is already exists.
3298

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3299
=head2 C<update_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3300

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3301
    $dbi->update_timestamp(
3302
      updated_at
3303
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
cleanup
Yuki Kimoto authored on 2011-03-09
3304
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3305

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3306
Timestamp value when C<update> method is executed
3307
with C<timestamp> option.
cleanup
Yuki Kimoto authored on 2011-01-12
3308

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3309
If C<insert_timestamp> is set and C<insert> method is executed
3310
with C<timestamp> option, column C<update_at>
3311
is automatically set to the value like "2010-10-11 10:12:54".
cleanup
Yuki Kimoto authored on 2011-01-12
3312

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3313
>|perl|
3314
$dbi->update($param, table => 'book', timestamp => 1);
3315
||<
cleanup
Yuki Kimoto authored on 2011-01-12
3316

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

            
3319
    $dbi->show_datatype($table);
3320

            
3321
Show data type of the columns of specified table.
3322

            
3323
    book
3324
    title: 5
3325
    issue_date: 91
3326

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

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

            
3331
    $dbi->show_tables;
3332

            
3333
Show tables.
3334

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

            
3337
    $dbi->show_typename($table);
3338

            
3339
Show type name of the columns of specified table.
3340

            
3341
    book
3342
    title: varchar
3343
    issue_date: date
3344

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

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

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

            
3351
Create values clause.
3352

            
3353
    (title, author) values (title = :title, age = :age);
3354

            
3355
You can use this in insert statement.
3356

            
3357
    my $insert_sql = "insert into book $values_clause";
3358

            
3359
=head2 C<where>
3360

            
3361
    my $where = $dbi->where(
3362
        clause => ['and', 'title = :title', 'author = :author'],
3363
        param => {title => 'Perl', author => 'Ken'}
3364
    );
3365

            
3366
Create a new L<DBIx::Custom::Where> object.
3367

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

            
3370
=head2 C<DBIX_CUSTOM_DEBUG>
3371

            
3372
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3373
executed SQL and bind values are printed to STDERR.
3374

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

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

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

            
3381
L<DBIx::Custom>
3382

            
3383
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3384
    default_dbi_option # will be removed 2017/1/1
3385
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3386
    data_source # will be removed at 2017/1/1
3387
    dbi_options # will be removed at 2017/1/1
3388
    filter_check # will be removed at 2017/1/1
3389
    reserved_word_quote # will be removed at 2017/1/1
3390
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3391
    
3392
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3393
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3394
    assign_param # will be removed at 2017/1/1
3395
    update_param # will be removed at 2017/1/1
3396
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3397
    create_query # will be removed at 2017/1/1
3398
    apply_filter # will be removed at 2017/1/1
3399
    select_at # will be removed at 2017/1/1
3400
    delete_at # will be removed at 2017/1/1
3401
    update_at # will be removed at 2017/1/1
3402
    insert_at # will be removed at 2017/1/1
3403
    register_tag # will be removed at 2017/1/1
3404
    default_bind_filter # will be removed at 2017/1/1
3405
    default_fetch_filter # will be removed at 2017/1/1
3406
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3407
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3408
    register_tag_processor # will be removed at 2017/1/1
3409
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3410
    
3411
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3412
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3413
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3414
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3415
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3416
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3417
    select method relation option # will be removed at 2017/1/1
3418
    select method column option [COLUMN, as => ALIAS] format
3419
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3420
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3421
    
3422
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3423
    execute("select * from {= title}"); # execute method's
3424
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3425
                                        # will be removed at 2017/1/1
3426
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3427

            
3428
L<DBIx::Custom::Model>
3429

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3430
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3431
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3432
    filter # will be removed at 2017/1/1
3433
    name # will be removed at 2017/1/1
3434
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3435

            
3436
L<DBIx::Custom::Query>
3437
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3438
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3439
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3440
    table # will be removed at 2017/1/1
3441
    filters # will be removed at 2017/1/1
3442
    
3443
    # Methods
3444
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3445

            
3446
L<DBIx::Custom::QueryBuilder>
3447
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3448
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3449
    tags # will be removed at 2017/1/1
3450
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3451
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3452
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3453
    register_tag # will be removed at 2017/1/1
3454
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3455
    
3456
    # Others
3457
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3458
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3459

            
3460
L<DBIx::Custom::Result>
3461
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3462
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3463
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3464
    
3465
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3466
    end_filter # will be removed at 2017/1/1
3467
    remove_end_filter # will be removed at 2017/1/1
3468
    remove_filter # will be removed at 2017/1/1
3469
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3470

            
3471
L<DBIx::Custom::Tag>
3472

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

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

            
3477
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3478
except for attribute method.
3479
You can check all DEPRECATED functionalities by document.
3480
DEPRECATED functionality is removed after five years,
3481
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
3482
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3483

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

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

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

            
3490
C<< <kimoto.yuki at gmail.com> >>
3491

            
3492
L<http://github.com/yuki-kimoto/DBIx-Custom>
3493

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3494
=head1 AUTHOR
3495

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

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

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

            
3502
This program is free software; you can redistribute it and/or modify it
3503
under the same terms as Perl itself.
3504

            
3505
=cut