DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3503 lines | 90.6kb
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
micro optimization
Yuki Kimoto authored on 2011-10-23
1091
    my $safety = $self->{safety_character} || $self->safety_character;
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
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
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1098
    my $safety_re = qr/^[$safety\.]+$/;
cleanup
Yuki Kimoto authored on 2011-10-21
1099
    for my $column (sort keys %$param) {
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1100
        croak qq{"$column" is not safety column name } . _subname
micro optimization
Yuki Kimoto authored on 2011-10-23
1101
          unless $column =~ /$safety_re/;
1102
        push @columns, "$q$column$p";
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1103
        push @placeholders,
micro optimization
Yuki Kimoto authored on 2011-10-23
1104
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}} :
1105
          $wrap->{$column} ? $wrap->{$column}->(":$column") :
1106
          ":$column"
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1107
    }
1108
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1109
    '(' . join(', ', @columns) . ') ' . 'values ' .
1110
      '(' . join(', ', @placeholders) . ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1111
}
1112

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1462
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1463
}
1464

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

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

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

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

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

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

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

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

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

            
1661
    return $tag;
1662
}
1663

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1968
Named place holder support
1969

            
1970
=item *
1971

            
cleanup
Yuki Kimoto authored on 2011-07-29
1972
Model support
1973

            
1974
=item *
1975

            
1976
Connection manager support
1977

            
1978
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1979

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

            
1984
=item *
1985

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

            
1988
=item *
1989

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

            
1992
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1993

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

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

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

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

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

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

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

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

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

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

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

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

            
2038
Note that L<DBIx::Connector> must be installed.
2039

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

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

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

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

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

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

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

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

            
2063
    my $exclude_table = $dbi->exclude_table;
2064
    $dbi = $dbi->exclude_table(qr/pg_/);
2065

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

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

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

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

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

            
2079
    my $last_sql = $dbi->last_sql;
2080
    $dbi = $dbi->last_sql($last_sql);
2081

            
2082
Get last successed SQL executed by C<execute> method.
2083

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

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

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

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

            
2093
    my $option = $dbi->option;
2094
    $dbi = $dbi->option($option);
2095

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2099
=head2 C<password>
2100

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2121
You can set quote pair.
2122

            
2123
    $dbi->quote('[]');
2124

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

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

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

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

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

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

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

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

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

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

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

            
2153
    my $tag_parse = $dbi->tag_parse(0);
2154
    $dbi = $dbi->tag_parse;
2155

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

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

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

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

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

            
2168
    my $user_column_info = $dbi->user_column_info;
2169
    $dbi = $dbi->user_column_info($user_column_info);
2170

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

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

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

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

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

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

            
2189
    my $user_table_info = $dbi->user_table_info;
2190
    $dbi = $dbi->user_table_info($user_table_info);
2191

            
2192
You can set the following data.
2193

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

            
2199
Usually, you can set return value of C<get_table_info>.
2200

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2243
Create column clause. The follwoing column clause is created.
2244

            
2245
    book.author as "book.author",
2246
    book.title as "book.title"
2247

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

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

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

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

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

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

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

            
2275
Get rows count.
2276

            
2277
Options is same as C<select> method's ones.
2278

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

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

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

            
2292
   $dbi->model('book')->select(...);
2293

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

            
2296
    my $dbh = $dbi->dbh;
2297

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

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

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

            
2305
Execute delete statement.
2306

            
2307
The following opitons are available.
2308

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

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

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

            
2316
=item C<id>
2317

            
2318
    id => 4
2319
    id => [4, 5]
2320

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

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

            
2330
The above is same as the followin one.
2331

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

            
2334
=item C<prefix>
2335

            
2336
    prefix => 'some'
2337

            
2338
prefix before table name section.
2339

            
2340
    delete some from book
2341

            
2342
=item C<table>
2343

            
2344
    table => 'book'
2345

            
2346
Table name.
2347

            
2348
=item C<where>
2349

            
2350
Same as C<select> method's C<where> option.
2351

            
2352
=back
2353

            
2354
=head2 C<delete_all>
2355

            
2356
    $dbi->delete_all(table => $table);
2357

            
2358
Execute delete statement for all rows.
2359
Options is same as C<delete>.
2360

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2450
    select * from where title = "aa\\:bb";
2451

            
cleanup
Yuki Kimoto authored on 2011-10-20
2452
B<OPTIONS>
2453

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

            
2456
=over 4
2457

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

            
2460
You can filter sql after the sql is build.
2461

            
2462
    after_build_sql => $code_ref
2463

            
2464
The following one is one example.
2465

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

            
2474
The following SQL is executed.
2475

            
2476
    select count(*) from (select distinct(name) from book) as t1;
2477

            
cleanup
Yuki Kimoto authored on 2011-10-20
2478
=item C<append>
2479

            
2480
    append => 'order by name'
2481

            
2482
Append some statement after SQL.
2483

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

            
2486
Specify database bind data type.
2487

            
2488
    bind_type => [image => DBI::SQL_BLOB]
2489
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2490

            
2491
This is used to bind parameter by C<bind_param> of statment handle.
2492

            
2493
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2494

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

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

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

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

            
2520
    id => 4
2521
    id => [4, 5]
2522

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

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

            
2533
The above is same as the followin one.
2534

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

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

            
2542
    query => 1
2543

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

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

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

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

            
2562
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
2563
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2564
    
2565
    my $query;
2566
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2567
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2568
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2569
      $sth ||= $query->sth;
2570
      $sth->execute(map { $row->{$_} } sort keys %$row);
2571
    }
2572

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2608
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2609
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2610
    reuse_query => $has_ref
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 object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2613
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2614
    my $queries = {};
2615
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2616

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

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

            
2622
    type_rule_off => 1
2623

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

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

            
2628
    type_rule1_off => 1
2629

            
2630
Turn C<into1> type rule off.
2631

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

            
2634
    type_rule2_off => 1
2635

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

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

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

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

            
2644
get column infomation except for one which match C<exclude_table> pattern.
2645

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

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

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

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

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

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

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

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

            
2679
Register helper. These helper is called directly from L<DBIx::Custom> object.
2680

            
2681
    $dbi->update_or_insert;
2682
    $dbi->find_or_create;
2683

            
cleanup
yuki-kimoto authored on 2010-10-17
2684
=head2 C<insert>
2685

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

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

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

            
2694
    {date => \"NOW()"}
2695

            
cleanup
Yuki Kimoto authored on 2011-10-20
2696
B<options>
2697

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

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

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

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

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

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

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

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

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

            
2727
    prefix => 'or replace'
2728

            
2729
prefix before table name section
2730

            
2731
    insert or replace into book
2732

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

            
2735
    table => 'book'
2736

            
2737
Table name.
2738

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

            
2741
    timestamp => 1
2742

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

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

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

            
2751
placeholder wrapped string.
2752

            
2753
If the following statement
2754

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

            
2758
is executed, the following SQL is executed.
2759

            
2760
    insert into book price values ( ? + 5 );
2761

            
update pod
Yuki Kimoto authored on 2011-03-13
2762
=back
2763

            
2764
=over 4
2765

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2829
    my $like_value = $dbi->like_value
2830

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

            
2833
    sub { "%$_[0]%" }
2834

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

            
2837
    my $mapper = $dbi->mapper(param => $param);
2838

            
2839
Create a new L<DBIx::Custom::Mapper> object.
2840

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

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

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

            
2847
    {key1 => [1, 1], key2 => 2}
2848

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

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

            
2853
    my $model = $dbi->model('book');
2854

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

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

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

            
2862
Create column clause for myself. The follwoing column clause is created.
2863

            
2864
    book.author as author,
2865
    book.title as title
2866

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

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

            
2876
Create a new L<DBIx::Custom> object.
2877

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

            
2880
    my $not_exists = $dbi->not_exists;
2881

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

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

            
2887
    my $order = $dbi->order;
2888

            
2889
Create a new L<DBIx::Custom::Order> object.
2890

            
cleanup
yuki-kimoto authored on 2010-10-17
2891
=head2 C<register_filter>
2892

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

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

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

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

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

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

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

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

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

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

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

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

            
2945
    book.author as "book.author",
2946
    book.title as "book.title",
2947
    person.name as "person.name",
2948
    person.age as "person.age"
2949

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

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

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

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

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

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

            
2965
=item C<id>
2966

            
2967
    id => 4
2968
    id => [4, 5]
2969

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

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

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

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

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

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

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

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

            
3000
    prefix => 'SQL_CALC_FOUND_ROWS'
3001

            
3002
Prefix of column cluase
3003

            
3004
    select SQL_CALC_FOUND_ROWS title, author from book;
3005

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3053
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3054

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

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

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

            
3087
    $dbi->setup_model;
3088

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

            
3092
=head2 C<type_rule>
3093

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

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

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

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

            
3127
C<into2> is executed after C<into1>.
3128

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

            
3132
=over 4
3133

            
3134
=item 1. column name
3135

            
3136
    issue_date
3137
    issue_datetime
3138

            
3139
This need C<table> option in each method.
3140

            
3141
=item 2. table name and column name, separator is dot
3142

            
3143
    book.issue_date
3144
    book.issue_datetime
3145

            
3146
=back
3147

            
3148
You get all type name used in database by C<available_typename>.
3149

            
3150
    print $dbi->available_typename;
3151

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

            
3156
    print $dbi->available_datatype;
3157

            
3158
You can also specify multiple types at once.
3159

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3209
    prefix => 'or replace'
3210

            
3211
prefix before table name section
3212

            
3213
    update or replace book
3214

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

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

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

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

            
3223
    timestamp => 1
3224

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

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

            
3231
Same as C<select> method's C<where> option.
3232

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

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

            
3237
placeholder wrapped string.
3238

            
3239
If the following statement
3240

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

            
3244
is executed, the following SQL is executed.
3245

            
3246
    update book set price =  ? + 5;
3247

            
updated pod
Yuki Kimoto authored on 2011-06-08
3248
=back
update pod
Yuki Kimoto authored on 2011-03-13
3249

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

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

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

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

            
3278
In both examples, the following SQL is executed.
3279

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

            
3286
The following opitons are available adding to C<update> option.
3287

            
3288
=over 4
3289

            
3290
=item C<select_option>
3291

            
3292
    select_option => {append => 'for update'}
3293

            
3294
select method option,
3295
select method is used to check the row is already exists.
3296

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

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

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

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

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

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

            
3317
    $dbi->show_datatype($table);
3318

            
3319
Show data type of the columns of specified table.
3320

            
3321
    book
3322
    title: 5
3323
    issue_date: 91
3324

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

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

            
3329
    $dbi->show_tables;
3330

            
3331
Show tables.
3332

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

            
3335
    $dbi->show_typename($table);
3336

            
3337
Show type name of the columns of specified table.
3338

            
3339
    book
3340
    title: varchar
3341
    issue_date: date
3342

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

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

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

            
3349
Create values clause.
3350

            
3351
    (title, author) values (title = :title, age = :age);
3352

            
3353
You can use this in insert statement.
3354

            
3355
    my $insert_sql = "insert into book $values_clause";
3356

            
3357
=head2 C<where>
3358

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

            
3364
Create a new L<DBIx::Custom::Where> object.
3365

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

            
3368
=head2 C<DBIX_CUSTOM_DEBUG>
3369

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

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

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

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

            
3379
L<DBIx::Custom>
3380

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

            
3426
L<DBIx::Custom::Model>
3427

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

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

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

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

            
3469
L<DBIx::Custom::Tag>
3470

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

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

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

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

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

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

            
3488
C<< <kimoto.yuki at gmail.com> >>
3489

            
3490
L<http://github.com/yuki-kimoto/DBIx-Custom>
3491

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3492
=head1 AUTHOR
3493

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

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

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

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

            
3503
=cut