DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3486 lines | 90.069kb
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-22
4
our $VERSION = '0.1734';
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} || {};
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
    
127
    # Create set tag
128
    my @params;
129
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-10-21
130
    for my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
131
        croak qq{"$column" is not safety column name } . _subname
132
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
133
        my $column_quote = $self->_q($column);
134
        $column_quote =~ s/\./$self->_q(".")/e;
updated pod
Yuki Kimoto authored on 2011-09-02
135
        my $func = $wrap->{$column} || sub { $_[0] };
136
        push @params,
137
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
138
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
139
    }
140
    my $tag = join(', ', @params);
141
    
142
    return $tag;
143
}
144

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
451
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
452
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
453
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
454
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-22
455
        $sth->bind_param($_ + 1, $bind->[$_]->{value},
456
            $bind->[$_]->{bind_type} ? $bind->[$_]->{bind_type} : ())
457
          for (0 .. @$bind - 1);
cleanup
Yuki Kimoto authored on 2011-03-21
458
        $affected = $sth->execute;
459
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
460
    
micro optimization
Yuki Kimoto authored on 2011-07-30
461
    $self->_croak($@, qq{. Following SQL is executed.\n}
462
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
463
    
improved debug message
Yuki Kimoto authored on 2011-05-23
464
    # DEBUG message
465
    if (DEBUG) {
466
        print STDERR "SQL:\n" . $query->sql . "\n";
467
        my @output;
cleanup
Yuki Kimoto authored on 2011-10-21
468
        for my $b (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
469
            my $value = $b->{value};
470
            $value = 'undef' unless defined $value;
471
            $value = encode(DEBUG_ENCODING(), $value)
472
              if utf8::is_utf8($value);
473
            push @output, $value;
474
        }
475
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
476
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
477
    
cleanup
Yuki Kimoto authored on 2011-04-02
478
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
479
    if ($sth->{NUM_OF_FIELDS}) {
480
        
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
481
        # Filter(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-04-02
482
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
483
        if ($self->{filter}{on}) {
484
            $filter->{in}  = {};
485
            $filter->{end} = {};
486
            push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-10-21
487
            for my $table (@$tables) {
488
                for my $way (qw/in end/) {
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
489
                    $filter->{$way} = {%{$filter->{$way}},
490
                      %{$self->{filter}{$way}{$table} || {}}};
micro optimization
Yuki Kimoto authored on 2011-07-30
491
                }
cleanup
Yuki Kimoto authored on 2011-04-02
492
            }
cleanup
Yuki Kimoto authored on 2011-01-12
493
        }
494
        
495
        # Result
496
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
497
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
498
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
499
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
500
            filter => $filter->{in} || {},
501
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
502
            type_rule => {
503
                from1 => $self->type_rule->{from1},
504
                from2 => $self->type_rule->{from2}
505
            },
cleanup
yuki-kimoto authored on 2010-10-17
506
        );
507
        return $result;
508
    }
cleanup
Yuki Kimoto authored on 2011-04-02
509
    # Not select statement
510
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
511
}
512

            
added test
Yuki Kimoto authored on 2011-08-16
513
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
514
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
515
    
cleanup
Yuki Kimoto authored on 2011-10-21
516
    my $exclude = delete $opt{exclude};
517
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
518
    
added test
Yuki Kimoto authored on 2011-08-16
519
    my $table_info = [];
520
    $self->each_table(
521
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
522
        exclude => $exclude
523
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
524
    
cleanup test
Yuki Kimoto authored on 2011-08-16
525
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
526
}
527

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
528
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
529
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
530
    
cleanup
Yuki Kimoto authored on 2011-10-21
531
    my $exclude_table = delete $opt{exclude_table};
532
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
533
    
534
    my $column_info = [];
535
    $self->each_column(
536
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
537
        exclude_table => $exclude_table
538
    );
539
    
540
    return [
541
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
542
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
543
}
544

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
545
sub helper {
546
    my $self = shift;
547
    
548
    # Register method
549
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
550
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
551
    
552
    return $self;
553
}
554

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
588
sub insert_timestamp {
589
    my $self = shift;
590
    
591
    if (@_) {
592
        $self->{insert_timestamp} = [@_];
593
        
594
        return $self;
595
    }
596
    return $self->{insert_timestamp};
597
}
598

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
599
sub include_model {
600
    my ($self, $name_space, $model_infos) = @_;
601
    
cleanup
Yuki Kimoto authored on 2011-04-02
602
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
603
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
604
    
605
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
606
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
607

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
666
sub mapper {
667
    my $self = shift;
668
    return DBIx::Custom::Mapper->new(@_);
669
}
670

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
695
sub model {
696
    my ($self, $name, $model) = @_;
697
    
cleanup
Yuki Kimoto authored on 2011-04-02
698
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
    if ($model) {
700
        $self->models->{$name} = $model;
701
        return $self;
702
    }
703
    
704
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
705
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
706
      unless $self->models->{$name};
707
    
cleanup
Yuki Kimoto authored on 2011-04-02
708
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
709
    return $self->models->{$name};
710
}
711

            
cleanup
Yuki Kimoto authored on 2011-03-21
712
sub mycolumn {
713
    my ($self, $table, $columns) = @_;
714
    
cleanup
Yuki Kimoto authored on 2011-04-02
715
    # Create column clause
716
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
717
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
718
    push @column, $self->_q($table) . "." . $self->_q($_) .
719
      " as " . $self->_q($_)
720
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
721
    
722
    return join (', ', @column);
723
}
724

            
added dbi_options attribute
kimoto authored on 2010-12-20
725
sub new {
726
    my $self = shift->SUPER::new(@_);
727
    
cleanup
Yuki Kimoto authored on 2011-04-02
728
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
729
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
730
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
731
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
732
          unless $self->can($attr);
733
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
734

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
735
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
736
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
737
        '?'     => \&DBIx::Custom::Tag::placeholder,
738
        '='     => \&DBIx::Custom::Tag::equal,
739
        '<>'    => \&DBIx::Custom::Tag::not_equal,
740
        '>'     => \&DBIx::Custom::Tag::greater_than,
741
        '<'     => \&DBIx::Custom::Tag::lower_than,
742
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
743
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
744
        'like'  => \&DBIx::Custom::Tag::like,
745
        'in'    => \&DBIx::Custom::Tag::in,
746
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
747
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
748
    };
749
    
750
    return $self;
751
}
752

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

            
755
sub order {
756
    my $self = shift;
757
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
758
}
759

            
cleanup
yuki-kimoto authored on 2010-10-17
760
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
761
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
762
    
763
    # Register filter
764
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
765
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
766
    
cleanup
Yuki Kimoto authored on 2011-04-02
767
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
768
}
packaging one directory
yuki-kimoto authored on 2009-11-16
769

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
858
sub setup_model {
859
    my $self = shift;
860
    
cleanup
Yuki Kimoto authored on 2011-04-02
861
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
862
    $self->each_column(
863
        sub {
864
            my ($self, $table, $column, $column_info) = @_;
865
            if (my $model = $self->models->{$table}) {
866
                push @{$model->columns}, $column;
867
            }
868
        }
869
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
870
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
871
}
872

            
update pod
Yuki Kimoto authored on 2011-08-10
873
sub show_datatype {
874
    my ($self, $table) = @_;
875
    croak "Table name must be specified" unless defined $table;
876
    print "$table\n";
877
    
878
    my $result = $self->select(table => $table, where => "'0' <> '0'");
879
    my $sth = $result->sth;
880

            
881
    my $columns = $sth->{NAME};
882
    my $data_types = $sth->{TYPE};
883
    
884
    for (my $i = 0; $i < @$columns; $i++) {
885
        my $column = $columns->[$i];
886
        my $data_type = $data_types->[$i];
887
        print "$column: $data_type\n";
888
    }
889
}
890

            
891
sub show_typename {
892
    my ($self, $t) = @_;
893
    croak "Table name must be specified" unless defined $t;
894
    print "$t\n";
895
    
896
    $self->each_column(sub {
897
        my ($self, $table, $column, $infos) = @_;
898
        return unless $table eq $t;
899
        my $typename = $infos->{TYPE_NAME};
900
        print "$column: $typename\n";
901
    });
902
    
903
    return $self;
904
}
905

            
test cleanup
Yuki Kimoto authored on 2011-08-15
906
sub show_tables {
907
    my $self = shift;
908
    
909
    my %tables;
910
    $self->each_table(sub { $tables{$_[1]}++ });
911
    print join("\n", sort keys %tables) . "\n";
912
    return $self;
913
}
914

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
950
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
951
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
952
                }
953
            });
954
        }
955

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1002
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1003
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1004
    
1005
    # Convert id to where parameter
1006
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1007
      ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
1008
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1009

            
1010
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1011
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1012
    
cleanup
Yuki Kimoto authored on 2011-10-21
1013
    # Merge where parameter to parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1014
    $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1015
    
cleanup
Yuki Kimoto authored on 2011-04-02
1016
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1017
    my $sql = "update ";
1018
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1019
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1020
    
cleanup
yuki-kimoto authored on 2010-10-17
1021
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1022
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1023
}
1024

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1027
sub update_or_insert {
1028
    my $self = shift;
1029

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1063
sub update_timestamp {
1064
    my $self = shift;
1065
    
1066
    if (@_) {
1067
        $self->{update_timestamp} = [@_];
1068
        
1069
        return $self;
1070
    }
1071
    return $self->{update_timestamp};
1072
}
1073

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1106
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1107
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1108
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1109
    
updated pod
Yuki Kimoto authored on 2011-06-21
1110
    # Cache
1111
    my $cache = $self->cache;
1112
    
1113
    # Query
1114
    my $query;
1115
    
1116
    # Get cached query
1117
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1118
        
updated pod
Yuki Kimoto authored on 2011-06-21
1119
        # Get query
1120
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1121
        
updated pod
Yuki Kimoto authored on 2011-06-21
1122
        # Create query
1123
        if ($q) {
1124
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1125
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1126
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1127
    }
1128
    
1129
    # Create query
1130
    unless ($query) {
1131

            
1132
        # Create query
1133
        my $builder = $self->query_builder;
1134
        $query = $builder->build_query($source);
1135

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

            
1142
        # Save query to cache
1143
        $self->cache_method->(
1144
            $self, $source,
1145
            {
1146
                sql     => $query->sql, 
1147
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1148
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1149
            }
1150
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1151
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1152

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1293
sub _croak {
1294
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1295
    
1296
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1297
    $append ||= "";
1298
    
1299
    # Verbose
1300
    if ($Carp::Verbose) { croak $error }
1301
    
1302
    # Not verbose
1303
    else {
1304
        
1305
        # Remove line and module infromation
1306
        my $at_pos = rindex($error, ' at ');
1307
        $error = substr($error, 0, $at_pos);
1308
        $error =~ s/\s+$//;
1309
        croak "$error$append";
1310
    }
1311
}
1312

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1315
sub _need_tables {
1316
    my ($self, $tree, $need_tables, $tables) = @_;
1317
    
cleanup
Yuki Kimoto authored on 2011-04-02
1318
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1319
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1320
        if ($tree->{$table}) {
1321
            $need_tables->{$table} = 1;
1322
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1323
        }
1324
    }
1325
}
1326

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1327
sub _option {
1328
    my $self = shift;
1329
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1330
    warn "dbi_options is DEPRECATED! use option instead\n"
1331
      if keys %{$self->dbi_options};
1332
    warn "dbi_option is DEPRECATED! use option instead\n"
1333
      if keys %{$self->dbi_option};
1334
    return $option;
1335
}
1336

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1337
sub _push_join {
1338
    my ($self, $sql, $join, $join_tables) = @_;
1339
    
cleanup
Yuki Kimoto authored on 2011-10-21
1340
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1341
    
cleanup
Yuki Kimoto authored on 2011-04-02
1342
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1343
    return unless @$join;
1344
    
cleanup
Yuki Kimoto authored on 2011-04-02
1345
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1346
    my $tree = {};
1347
    for (my $i = 0; $i < @$join; $i++) {
1348
        
cleanup
Yuki Kimoto authored on 2011-07-28
1349
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1350
        my $join_clause;;
1351
        my $option;
1352
        if (ref $join->[$i] eq 'HASH') {
1353
            $join_clause = $join->[$i]->{clause};
1354
            $option = {table => $join->[$i]->{table}};
1355
        }
1356
        else {
1357
            $join_clause = $join->[$i];
1358
            $option = {};
1359
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1360

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1408
sub _quote {
1409
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1410
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1411
}
1412

            
cleanup
Yuki Kimoto authored on 2011-07-29
1413
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1414
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1415
    
1416
    my $quote = $self->_quote;
1417
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1418
    my $p;
1419
    if (defined $quote && length $quote > 1) {
1420
        $p = substr($quote, 1, 1);
1421
    }
1422
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1423
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1424
    if ($quotemeta) {
1425
        $q = quotemeta($q);
1426
        $p = quotemeta($p);
1427
    }
1428
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1429
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1430
}
1431

            
cleanup
Yuki Kimoto authored on 2011-04-02
1432
sub _remove_duplicate_table {
1433
    my ($self, $tables, $main_table) = @_;
1434
    
1435
    # Remove duplicate table
1436
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1437
    delete $tables{$main_table} if $main_table;
1438
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1439
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1440
    if (my $q = $self->_quote) {
1441
        $q = quotemeta($q);
1442
        $_ =~ s/[$q]//g for @$new_tables;
1443
    }
1444

            
1445
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1446
}
1447

            
cleanup
Yuki Kimoto authored on 2011-04-02
1448
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1449
    my ($self, $source) = @_;
1450
    
cleanup
Yuki Kimoto authored on 2011-04-02
1451
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1452
    my $tables = [];
1453
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1454
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1455
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1456
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1457
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1458
    while ($source =~ /$table_re/g) {
1459
        push @$tables, $1;
1460
    }
1461
    
1462
    return $tables;
1463
}
1464

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1514
sub _where_clause_and_param {
1515
    my ($self, $where, $param) = @_;
1516
 
1517
    $where ||= {};
1518
    $param ||= {};
1519
    my $w = {};
1520
    my $where_clause = '';
1521
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1522
        $w->{clause} = "where " . $where->[0];
1523
        $w->{param} = $where->[1];
1524
    }
1525
    elsif (ref $where) {
1526
        $where = $self->_where_to_obj($where);
1527
        $w->{param} = keys %$param
1528
                    ? $self->merge_param($param, $where->param)
1529
                    : $where->param;
1530
        $w->{clause} = $where->to_string;
1531
    }
1532
    elsif ($where) {
1533
        $w->{clause} = "where $where";
1534
        $w->{param} = $param;
1535
    }
1536
    
1537
    return $w;
1538
}
1539

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1610
# DEPRECATED!
1611
has 'data_source';
1612
has dbi_options => sub { {} };
1613
has filter_check  => 1;
1614
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1615
has dbi_option => sub { {} };
1616
has default_dbi_option => sub {
1617
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1618
    return shift->default_option;
1619
};
1620

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1621
# DEPRECATED!
1622
sub method {
1623
    warn "method is DEPRECATED! use helper instead";
1624
    return shift->helper(@_);
1625
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1626

            
1627
# DEPRECATED!
1628
sub assign_param {
1629
    my $self = shift;
1630
    warn "assing_param is DEPRECATED! use assign_clause instead";
1631
    return $self->assign_clause(@_);
1632
}
1633

            
1634
# DEPRECATED
1635
sub update_param {
1636
    my ($self, $param, $opts) = @_;
1637
    
1638
    warn "update_param is DEPRECATED! use assing_clause instead.";
1639
    
1640
    # Create update parameter tag
1641
    my $tag = $self->assign_clause($param, $opts);
1642
    $tag = "set $tag" unless $opts->{no_set};
1643

            
1644
    return $tag;
1645
}
1646

            
updated pod
Yuki Kimoto authored on 2011-06-21
1647
# DEPRECATED!
1648
sub create_query {
1649
    warn "create_query is DEPRECATED! use query option of each method";
1650
    shift->_create_query(@_);
1651
}
1652

            
cleanup
Yuki Kimoto authored on 2011-06-13
1653
# DEPRECATED!
1654
sub apply_filter {
1655
    my $self = shift;
1656
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1657
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1658
    return $self->_apply_filter(@_);
1659
}
1660

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1667
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1668
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1669
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1670
    my $where = delete $opt{where};
1671
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1672
    
1673
    # Table
1674
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1675
      unless $opt{table};
1676
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1677
    
1678
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1679
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1680
    
cleanup
Yuki Kimoto authored on 2011-10-21
1681
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1682
}
1683

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1688
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1689
    
cleanup
Yuki Kimoto authored on 2011-10-21
1690
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1691
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1692
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1693
    my $where = delete $opt{where};
delete_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);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1697
    
cleanup
Yuki Kimoto authored on 2011-10-21
1698
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1699
}
1700

            
cleanup
Yuki Kimoto authored on 2011-06-08
1701
# DEPRECATED!
1702
sub update_at {
1703
    my $self = shift;
1704

            
cleanup
Yuki Kimoto authored on 2011-10-21
1705
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1706
    
cleanup
Yuki Kimoto authored on 2011-10-21
1707
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1708
    my $param;
1709
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1710
    my %opt = @_;
1711
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1712
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1713
    my $where = delete $opt{where};
1714
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1715
    $param  ||= $p;
1716
    
1717
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1718
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1719
    
cleanup
Yuki Kimoto authored on 2011-10-21
1720
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1721
}
1722

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1746
# DEPRECATED!
1747
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1748
    my $self = shift;
1749
    
added warnings
Yuki Kimoto authored on 2011-06-07
1750
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1751
    
1752
    # Merge tag
1753
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1754
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1755
    
1756
    return $self;
1757
}
1758

            
1759
# DEPRECATED!
1760
sub register_tag_processor {
1761
    my $self = shift;
1762
    warn "register_tag_processor is DEPRECATED!";
1763
    # Merge tag
1764
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1765
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1766
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1767
}
1768

            
cleanup
Yuki Kimoto authored on 2011-01-25
1769
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1770
sub default_bind_filter {
1771
    my $self = shift;
1772
    
cleanup
Yuki Kimoto authored on 2011-06-13
1773
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1774
    
cleanup
Yuki Kimoto authored on 2011-01-12
1775
    if (@_) {
1776
        my $fname = $_[0];
1777
        
1778
        if (@_ && !$fname) {
1779
            $self->{default_out_filter} = undef;
1780
        }
1781
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1782
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1783
              unless exists $self->filters->{$fname};
1784
        
1785
            $self->{default_out_filter} = $self->filters->{$fname};
1786
        }
1787
        return $self;
1788
    }
1789
    
1790
    return $self->{default_out_filter};
1791
}
1792

            
cleanup
Yuki Kimoto authored on 2011-01-25
1793
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1794
sub default_fetch_filter {
1795
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1796

            
cleanup
Yuki Kimoto authored on 2011-06-13
1797
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1798
    
1799
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1800
        my $fname = $_[0];
1801

            
cleanup
Yuki Kimoto authored on 2011-01-12
1802
        if (@_ && !$fname) {
1803
            $self->{default_in_filter} = undef;
1804
        }
1805
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1806
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1807
              unless exists $self->filters->{$fname};
1808
        
1809
            $self->{default_in_filter} = $self->filters->{$fname};
1810
        }
1811
        
1812
        return $self;
1813
    }
1814
    
many changed
Yuki Kimoto authored on 2011-01-23
1815
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1816
}
1817

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1818
# DEPRECATED!
1819
sub insert_param {
1820
    my $self = shift;
1821
    warn "insert_param is DEPRECATED! use values_clause instead";
1822
    return $self->values_clause(@_);
1823
}
1824

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1825
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1826
sub insert_param_tag {
1827
    warn "insert_param_tag is DEPRECATED! " .
1828
         "use insert_param instead!";
1829
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1830
}
1831

            
1832
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1833
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1834
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1835
         "use update_param instead";
1836
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1837
}
cleanup
Yuki Kimoto authored on 2011-03-08
1838
# DEPRECATED!
1839
sub _push_relation {
1840
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1841
    
1842
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1843
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1844
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1845
            my $table1 = (split (/\./, $rcolumn))[0];
1846
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1847
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1848
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1849
        }
1850
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1851
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1852
}
1853

            
1854
# DEPRECATED!
1855
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1856
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1857
    
1858
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1859
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1860
            my $table1 = (split (/\./, $rcolumn))[0];
1861
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1862
            my $table1_exists;
1863
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1864
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1865
                $table1_exists = 1 if $table eq $table1;
1866
                $table2_exists = 1 if $table eq $table2;
1867
            }
1868
            unshift @$tables, $table1 unless $table1_exists;
1869
            unshift @$tables, $table2 unless $table2_exists;
1870
        }
1871
    }
1872
}
1873

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

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

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1882
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1883
    
1884
    # Connect
1885
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1886
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1887
        user => 'ken',
1888
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1889
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1890
    );
cleanup
yuki-kimoto authored on 2010-08-05
1891

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1892
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1893
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1894
    
1895
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1896
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1897
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1898
    
1899
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1900
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1901

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1906
    # Select, more complex
1907
    my $result = $dbi->select(
1908
        table  => 'book',
1909
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1910
            {book => [qw/title author/]},
1911
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1912
        ],
1913
        where  => {'book.author' => 'Ken'},
1914
        join => ['left outer join company on book.company_id = company.id'],
1915
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1916
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1917
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1918
    # Fetch
1919
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1920
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1921
    }
1922
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1923
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1924
    while (my $row = $result->fetch_hash) {
1925
        
1926
    }
1927
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1928
    # Execute SQL with parameter.
1929
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1930
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1931
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1932
    );
1933
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1934
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1935

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1951
Named place holder support
1952

            
1953
=item *
1954

            
cleanup
Yuki Kimoto authored on 2011-07-29
1955
Model support
1956

            
1957
=item *
1958

            
1959
Connection manager support
1960

            
1961
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1962

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

            
1967
=item *
1968

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

            
1971
=item *
1972

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

            
1975
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1976

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1984
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1985
L<DBIx::Custom::Result>,
1986
L<DBIx::Custom::Query>,
1987
L<DBIx::Custom::Where>,
1988
L<DBIx::Custom::Model>,
1989
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1990

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

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

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

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

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

            
2004
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2005
        "dbi:mysql:database=$database",
2006
        $user,
2007
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2008
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2009
    );
2010
    
updated pod
Yuki Kimoto authored on 2011-06-21
2011
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2012

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

            
2016
    my $dbi = DBIx::Custom->connect(
2017
      dsn => $dsn, user => $user, password => $password, connector => 1);
2018
    
2019
    my $connector = $dbi->connector; # DBIx::Connector
2020

            
2021
Note that L<DBIx::Connector> must be installed.
2022

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2038
    {
2039
        RaiseError => 1,
2040
        PrintError => 0,
2041
        AutoCommit => 1,
2042
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2043

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

            
2046
    my $exclude_table = $dbi->exclude_table;
2047
    $dbi = $dbi->exclude_table(qr/pg_/);
2048

            
2049
Excluded table regex.
2050
C<each_column>, C<each_table>, C<type_rule>,
2051
and C<setup_model> methods ignore matching tables.
2052

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

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

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

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

            
2062
    my $last_sql = $dbi->last_sql;
2063
    $dbi = $dbi->last_sql($last_sql);
2064

            
2065
Get last successed SQL executed by C<execute> method.
2066

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

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

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

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

            
2076
    my $option = $dbi->option;
2077
    $dbi = $dbi->option($option);
2078

            
2079
L<DBI> option, used when C<connect> method is executed.
2080
Each value in option override the value of C<default_option>.
2081

            
cleanup
yuki-kimoto authored on 2010-10-17
2082
=head2 C<password>
2083

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2104
You can set quote pair.
2105

            
2106
    $dbi->quote('[]');
2107

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2117
    my $safety_character = $dbi->safety_character;
2118
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2119

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

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

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

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

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

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

            
2136
    my $tag_parse = $dbi->tag_parse(0);
2137
    $dbi = $dbi->tag_parse;
2138

            
2139
Enable DEPRECATED tag parsing functionality, default to 1.
2140
If you want to disable tag parsing functionality, set to 0.
2141

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

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

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

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

            
2151
    my $user_column_info = $dbi->user_column_info;
2152
    $dbi = $dbi->user_column_info($user_column_info);
2153

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

            
2156
    [
2157
        {table => 'book', column => 'title', info => {...}},
2158
        {table => 'author', column => 'name', info => {...}}
2159
    ]
2160

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

            
2163
    my $user_column_info
2164
      = $dbi->get_column_info(exclude_table => qr/^system/);
2165
    $dbi->user_column_info($user_column_info);
2166

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

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

            
2172
    my $user_table_info = $dbi->user_table_info;
2173
    $dbi = $dbi->user_table_info($user_table_info);
2174

            
2175
You can set the following data.
2176

            
2177
    [
2178
        {table => 'book', info => {...}},
2179
        {table => 'author', info => {...}}
2180
    ]
2181

            
2182
Usually, you can set return value of C<get_table_info>.
2183

            
2184
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2185
    $dbi->user_table_info($user_table_info);
2186

            
2187
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2188
to find table info.
2189

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2226
Create column clause. The follwoing column clause is created.
2227

            
2228
    book.author as "book.author",
2229
    book.title as "book.title"
2230

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2233
    # Separator is hyphen
2234
    $dbi->separator('-');
2235
    
2236
    book.author as "book-author",
2237
    book.title as "book-title"
2238
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2239
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2240

            
update pod
Yuki Kimoto authored on 2011-03-13
2241
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2242
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2243
        user => 'ken',
2244
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2245
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2246
    );
2247

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

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

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

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

            
2258
Get rows count.
2259

            
2260
Options is same as C<select> method's ones.
2261

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2264
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2265
        table => 'book',
2266
        primary_key => 'id',
2267
        join => [
2268
            'inner join company on book.comparny_id = company.id'
2269
        ],
2270
    );
2271

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

            
2275
   $dbi->model('book')->select(...);
2276

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

            
2279
    my $dbh = $dbi->dbh;
2280

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

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

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

            
2288
Execute delete statement.
2289

            
2290
The following opitons are available.
2291

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

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

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

            
2299
=item C<id>
2300

            
2301
    id => 4
2302
    id => [4, 5]
2303

            
2304
ID corresponding to C<primary_key>.
2305
You can delete rows by C<id> and C<primary_key>.
2306

            
2307
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2308
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2309
        id => [4, 5],
2310
        table => 'book',
2311
    );
2312

            
2313
The above is same as the followin one.
2314

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

            
2317
=item C<prefix>
2318

            
2319
    prefix => 'some'
2320

            
2321
prefix before table name section.
2322

            
2323
    delete some from book
2324

            
2325
=item C<table>
2326

            
2327
    table => 'book'
2328

            
2329
Table name.
2330

            
2331
=item C<where>
2332

            
2333
Same as C<select> method's C<where> option.
2334

            
2335
=back
2336

            
2337
=head2 C<delete_all>
2338

            
2339
    $dbi->delete_all(table => $table);
2340

            
2341
Execute delete statement for all rows.
2342
Options is same as C<delete>.
2343

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

            
2346
    $dbi->each_column(
2347
        sub {
2348
            my ($dbi, $table, $column, $column_info) = @_;
2349
            
2350
            my $type = $column_info->{TYPE_NAME};
2351
            
2352
            if ($type eq 'DATE') {
2353
                # ...
2354
            }
2355
        }
2356
    );
2357

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

            
2363
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2364
infromation, you can improve the performance of C<each_column> in
2365
the following way.
2366

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

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

            
2373
    $dbi->each_table(
2374
        sub {
2375
            my ($dbi, $table, $table_info) = @_;
2376
            
2377
            my $table_name = $table_info->{TABLE_NAME};
2378
        }
2379
    );
2380

            
improved pod
Yuki Kimoto authored on 2011-10-14
2381
Iterate all table informationsfrom in database.
2382
Argument is callback which is executed when one table is found.
2383
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2384
C<table information>.
2385

            
2386
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2387
infromation, you can improve the performance of C<each_table> in
2388
the following way.
2389

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

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

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

            
2401
    my $result = $dbi->execute(
2402
      "select * from book where title = :book.title and author like :book.author",
2403
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2404
    );
2405

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2412
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2413
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2414
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2415
    select * from book where title = :title and author like :author
2416
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2417
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2418
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2419

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2423
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2424
    select * from book where :title{=} and :author{like}
2425
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2426
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2427
    select * from where title = ? and author like ?;
2428

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

            
2433
    select * from where title = "aa\\:bb";
2434

            
cleanup
Yuki Kimoto authored on 2011-10-20
2435
B<OPTIONS>
2436

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

            
2439
=over 4
2440

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

            
2443
You can filter sql after the sql is build.
2444

            
2445
    after_build_sql => $code_ref
2446

            
2447
The following one is one example.
2448

            
2449
    $dbi->select(
2450
        table => 'book',
2451
        column => 'distinct(name)',
2452
        after_build_sql => sub {
2453
            "select count(*) from ($_[0]) as t1"
2454
        }
2455
    );
2456

            
2457
The following SQL is executed.
2458

            
2459
    select count(*) from (select distinct(name) from book) as t1;
2460

            
cleanup
Yuki Kimoto authored on 2011-10-20
2461
=item C<append>
2462

            
2463
    append => 'order by name'
2464

            
2465
Append some statement after SQL.
2466

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

            
2469
Specify database bind data type.
2470

            
2471
    bind_type => [image => DBI::SQL_BLOB]
2472
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2473

            
2474
This is used to bind parameter by C<bind_param> of statment handle.
2475

            
2476
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2477

            
update pod
Yuki Kimoto authored on 2011-03-13
2478
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2479
    
2480
    filter => {
2481
        title  => sub { uc $_[0] }
2482
        author => sub { uc $_[0] }
2483
    }
update pod
Yuki Kimoto authored on 2011-03-13
2484

            
updated pod
Yuki Kimoto authored on 2011-06-09
2485
    # Filter name
2486
    filter => {
2487
        title  => 'upper_case',
2488
        author => 'upper_case'
2489
    }
2490
        
2491
    # At once
2492
    filter => [
2493
        [qw/title author/]  => sub { uc $_[0] }
2494
    ]
2495

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

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

            
2503
    id => 4
2504
    id => [4, 5]
2505

            
2506
ID corresponding to C<primary_key>.
2507
You can delete rows by C<id> and C<primary_key>.
2508

            
2509
    $dbi->execute(
2510
        "select * from book where id1 = :id1 and id2 = :id2",
2511
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2512
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2513
        id => [4, 5],
2514
    );
2515

            
2516
The above is same as the followin one.
2517

            
2518
    $dbi->execute(
2519
        "select * from book where id1 = :id1 and id2 = :id2",
2520
        {id1 => 4, id2 => 5}
2521
    );
2522

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

            
2525
    query => 1
2526

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

            
2530
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2531
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2532
    my $columns = $query->columns;
2533
    
2534
If you want to execute SQL fast, you can do the following way.
2535

            
2536
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2537
    for my $row (@$rows) {
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2538
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2539
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2540
    }
2541

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

            
2545
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
2546
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2547
    
2548
    my $query;
2549
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2550
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2551
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2552
      $sth ||= $query->sth;
2553
      $sth->execute(map { $row->{$_} } sort keys %$row);
2554
    }
2555

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2562
    primary_key => 'id'
2563
    primary_key => ['id1', 'id2']
2564

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2567
=item C<table>
2568
    
2569
    table => 'author'
2570

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2578
    # Same
2579
    $dbi->execute(
2580
      "select * from book where title = :book.title and author = :book.author",
2581
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2582

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

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

            
2587
Table alias. Key is real table name, value is alias table name.
2588
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2589
on alias table name.
2590

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2591
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2592
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2593
    reuse_query => $has_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2594

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2595
Reuse query object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2596
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2597
    my $queries = {};
2598
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2599

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

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

            
2605
    type_rule_off => 1
2606

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

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

            
2611
    type_rule1_off => 1
2612

            
2613
Turn C<into1> type rule off.
2614

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

            
2617
    type_rule2_off => 1
2618

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

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

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

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

            
2627
get column infomation except for one which match C<exclude_table> pattern.
2628

            
2629
    [
2630
        {table => 'book', column => 'title', info => {...}},
2631
        {table => 'author', column => 'name' info => {...}}
2632
    ]
2633

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

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

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

            
2640
    [
2641
        {table => 'book', info => {...}},
2642
        {table => 'author', info => {...}}
2643
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2644

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

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

            
2649
    $dbi->helper(
2650
        update_or_insert => sub {
2651
            my $self = shift;
2652
            
2653
            # Process
2654
        },
2655
        find_or_create   => sub {
2656
            my $self = shift;
2657
            
2658
            # Process
2659
        }
2660
    );
2661

            
2662
Register helper. These helper is called directly from L<DBIx::Custom> object.
2663

            
2664
    $dbi->update_or_insert;
2665
    $dbi->find_or_create;
2666

            
cleanup
yuki-kimoto authored on 2010-10-17
2667
=head2 C<insert>
2668

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

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

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

            
2677
    {date => \"NOW()"}
2678

            
cleanup
Yuki Kimoto authored on 2011-10-20
2679
B<options>
2680

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2688
    id => 4
2689
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2690

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2694
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2695
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2696
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2697
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2698
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2699
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2700

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

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

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

            
2710
    prefix => 'or replace'
2711

            
2712
prefix before table name section
2713

            
2714
    insert or replace into book
2715

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

            
2718
    table => 'book'
2719

            
2720
Table name.
2721

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

            
2724
    timestamp => 1
2725

            
2726
If this value is set to 1,
2727
automatically created timestamp column is set based on
2728
C<timestamp> attribute's C<insert> value.
2729

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

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

            
2734
placeholder wrapped string.
2735

            
2736
If the following statement
2737

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

            
2741
is executed, the following SQL is executed.
2742

            
2743
    insert into book price values ( ? + 5 );
2744

            
update pod
Yuki Kimoto authored on 2011-03-13
2745
=back
2746

            
2747
=over 4
2748

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2756
    lib / MyModel.pm
2757
        / MyModel / book.pm
2758
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2759

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

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

            
2764
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2765
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2766
    
2767
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2768

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2773
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2774
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2775
    
2776
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2777

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2780
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2781
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2782
    
2783
    1;
2784
    
updated pod
Yuki Kimoto authored on 2011-06-21
2785
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2786

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

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

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

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

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

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

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

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

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

            
2812
    my $like_value = $dbi->like_value
2813

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

            
2816
    sub { "%$_[0]%" }
2817

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

            
2820
    my $mapper = $dbi->mapper(param => $param);
2821

            
2822
Create a new L<DBIx::Custom::Mapper> object.
2823

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

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

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

            
2830
    {key1 => [1, 1], key2 => 2}
2831

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

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

            
2836
    my $model = $dbi->model('book');
2837

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

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

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

            
2845
Create column clause for myself. The follwoing column clause is created.
2846

            
2847
    book.author as author,
2848
    book.title as title
2849

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

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

            
2859
Create a new L<DBIx::Custom> object.
2860

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

            
2863
    my $not_exists = $dbi->not_exists;
2864

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

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

            
2870
    my $order = $dbi->order;
2871

            
2872
Create a new L<DBIx::Custom::Order> object.
2873

            
cleanup
yuki-kimoto authored on 2010-10-17
2874
=head2 C<register_filter>
2875

            
update pod
Yuki Kimoto authored on 2011-03-13
2876
    $dbi->register_filter(
2877
        # Time::Piece object to database DATE format
2878
        tp_to_date => sub {
2879
            my $tp = shift;
2880
            return $tp->strftime('%Y-%m-%d');
2881
        },
2882
        # database DATE format to Time::Piece object
2883
        date_to_tp => sub {
2884
           my $date = shift;
2885
           return Time::Piece->strptime($date, '%Y-%m-%d');
2886
        }
2887
    );
cleanup
yuki-kimoto authored on 2010-10-17
2888
    
update pod
Yuki Kimoto authored on 2011-03-13
2889
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2890

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2893
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2894
        table  => 'book',
2895
        column => ['author', 'title'],
2896
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2897
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2898
    
updated document
Yuki Kimoto authored on 2011-06-09
2899
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2900

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2908
=item C<column>
2909
    
updated document
Yuki Kimoto authored on 2011-06-09
2910
    column => 'author'
2911
    column => ['author', 'title']
2912

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2921
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2922
        {book => [qw/author title/]},
2923
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2924
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2925

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

            
2928
    book.author as "book.author",
2929
    book.title as "book.title",
2930
    person.name as "person.name",
2931
    person.age as "person.age"
2932

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

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

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

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

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

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

            
2948
=item C<id>
2949

            
2950
    id => 4
2951
    id => [4, 5]
2952

            
2953
ID corresponding to C<primary_key>.
2954
You can select rows by C<id> and C<primary_key>.
2955

            
2956
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2957
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2958
        id => [4, 5],
2959
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2960
    );
2961

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2964
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2965
        where => {id1 => 4, id2 => 5},
2966
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2967
    );
2968
    
cleanup
Yuki Kimoto authored on 2011-10-20
2969
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2970

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

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

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

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

            
2983
    prefix => 'SQL_CALC_FOUND_ROWS'
2984

            
2985
Prefix of column cluase
2986

            
2987
    select SQL_CALC_FOUND_ROWS title, author from book;
2988

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

            
2991
    join => [
2992
        'left outer join company on book.company_id = company_id',
2993
        'left outer join location on company.location_id = location.id'
2994
    ]
2995
        
2996
Join clause. If column cluase or where clause contain table name like "company.name",
2997
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2998

            
2999
    $dbi->select(
3000
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3001
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3002
        where => {'company.name' => 'Orange'},
3003
        join => [
3004
            'left outer join company on book.company_id = company.id',
3005
            'left outer join location on company.location_id = location.id'
3006
        ]
3007
    );
3008

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3012
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3013
    from book
3014
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3015
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3016

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3017
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
3018
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3019

            
3020
    $dbi->select(
3021
        table => 'book',
3022
        column => ['company.location_id as location_id'],
3023
        where => {'company.name' => 'Orange'},
3024
        join => [
3025
            {
3026
                clause => 'left outer join location on company.location_id = location.id',
3027
                table => ['company', 'location']
3028
            }
3029
        ]
3030
    );
3031

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3036
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3037

            
updated document
Yuki Kimoto authored on 2011-06-09
3038
=item C<where>
3039
    
3040
    # Hash refrence
3041
    where => {author => 'Ken', 'title' => 'Perl'}
3042
    
3043
    # DBIx::Custom::Where object
3044
    where => $dbi->where(
3045
        clause => ['and', 'author = :author', 'title like :title'],
3046
        param  => {author => 'Ken', title => '%Perl%'}
3047
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3048
    
3049
    # Array reference 1 (array reference, hash referenc). same as above
3050
    where => [
3051
        ['and', 'author = :author', 'title like :title'],
3052
        {author => 'Ken', title => '%Perl%'}
3053
    ];    
3054
    
3055
    # Array reference 2 (String, hash reference)
3056
    where => [
3057
        'title like :title',
3058
        {title => '%Perl%'}
3059
    ]
3060
    
3061
    # String
3062
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3063

            
cleanup
Yuki Kimoto authored on 2011-10-20
3064
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3065
    
update pod
Yuki Kimoto authored on 2011-03-12
3066
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3067

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

            
3070
    $dbi->setup_model;
3071

            
3072
Setup all model objects.
3073
C<columns> of model object is automatically set, parsing database information.
3074

            
3075
=head2 C<type_rule>
3076

            
3077
    $dbi->type_rule(
3078
        into1 => {
3079
            date => sub { ... },
3080
            datetime => sub { ... }
3081
        },
3082
        into2 => {
3083
            date => sub { ... },
3084
            datetime => sub { ... }
3085
        },
3086
        from1 => {
3087
            # DATE
3088
            9 => sub { ... },
3089
            # DATETIME or TIMESTAMP
3090
            11 => sub { ... },
3091
        }
3092
        from2 => {
3093
            # DATE
3094
            9 => sub { ... },
3095
            # DATETIME or TIMESTAMP
3096
            11 => sub { ... },
3097
        }
3098
    );
3099

            
3100
Filtering rule when data is send into and get from database.
3101
This has a little complex problem.
3102

            
3103
In C<into1> and C<into2> you can specify
3104
type name as same as type name defined
3105
by create table, such as C<DATETIME> or C<DATE>.
3106

            
3107
Note that type name and data type don't contain upper case.
3108
If these contain upper case charactor, you convert it to lower case.
3109

            
3110
C<into2> is executed after C<into1>.
3111

            
3112
Type rule of C<into1> and C<into2> is enabled on the following
3113
column name.
3114

            
3115
=over 4
3116

            
3117
=item 1. column name
3118

            
3119
    issue_date
3120
    issue_datetime
3121

            
3122
This need C<table> option in each method.
3123

            
3124
=item 2. table name and column name, separator is dot
3125

            
3126
    book.issue_date
3127
    book.issue_datetime
3128

            
3129
=back
3130

            
3131
You get all type name used in database by C<available_typename>.
3132

            
3133
    print $dbi->available_typename;
3134

            
3135
In C<from1> and C<from2> you specify data type, not type name.
3136
C<from2> is executed after C<from1>.
3137
You get all data type by C<available_datatype>.
3138

            
3139
    print $dbi->available_datatype;
3140

            
3141
You can also specify multiple types at once.
3142

            
3143
    $dbi->type_rule(
3144
        into1 => [
3145
            [qw/DATE DATETIME/] => sub { ... },
3146
        ],
3147
    );
3148

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

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

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

            
3155
If you want to set constant value to row data, use scalar reference
3156
as parameter value.
3157

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3169
    id => 4
3170
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3171

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3175
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3176
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3177
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3178
        id => [4, 5],
3179
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3180
    );
update pod
Yuki Kimoto authored on 2011-03-13
3181

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3184
    $dbi->update(
3185
        {title => 'Perl', author => 'Ken'}
3186
        where => {id1 => 4, id2 => 5},
3187
        table => 'book'
3188
    );
update pod
Yuki Kimoto authored on 2011-03-13
3189

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

            
3192
    prefix => 'or replace'
3193

            
3194
prefix before table name section
3195

            
3196
    update or replace book
3197

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

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

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

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

            
3206
    timestamp => 1
3207

            
3208
If this value is set to 1,
3209
automatically updated timestamp column is set based on
3210
C<timestamp> attribute's C<update> value.
3211

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

            
3214
Same as C<select> method's C<where> option.
3215

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

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

            
3220
placeholder wrapped string.
3221

            
3222
If the following statement
3223

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

            
3227
is executed, the following SQL is executed.
3228

            
3229
    update book set price =  ? + 5;
3230

            
updated pod
Yuki Kimoto authored on 2011-06-08
3231
=back
update pod
Yuki Kimoto authored on 2011-03-13
3232

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3240
=head2 C<update_or_insert EXPERIMENTAL>
3241
    
3242
    # Where
3243
    $dbi->update_or_insert(
3244
        {id => 1, title => 'Perl'},
3245
        table => 'book',
3246
        where => {id => 1},
3247
        select_option => {append => 'for update'}
3248
    );
3249
    
3250
    # ID
3251
    $dbi->update_or_insert(
3252
        {title => 'Perl'},
3253
        table => 'book',
3254
        id => 1,
3255
        primary_key => 'id',
3256
        select_option => {append => 'for update'}
3257
    );
3258
    
3259
Update or insert.
3260

            
3261
In both examples, the following SQL is executed.
3262

            
3263
    # In case insert
3264
    insert into book (id, title) values (?, ?)
3265
    
3266
    # In case update
3267
    update book set (id = ?, title = ?) where book.id = ?
3268

            
3269
The following opitons are available adding to C<update> option.
3270

            
3271
=over 4
3272

            
3273
=item C<select_option>
3274

            
3275
    select_option => {append => 'for update'}
3276

            
3277
select method option,
3278
select method is used to check the row is already exists.
3279

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

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

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

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

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

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

            
3300
    $dbi->show_datatype($table);
3301

            
3302
Show data type of the columns of specified table.
3303

            
3304
    book
3305
    title: 5
3306
    issue_date: 91
3307

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

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

            
3312
    $dbi->show_tables;
3313

            
3314
Show tables.
3315

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

            
3318
    $dbi->show_typename($table);
3319

            
3320
Show type name of the columns of specified table.
3321

            
3322
    book
3323
    title: varchar
3324
    issue_date: date
3325

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

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

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

            
3332
Create values clause.
3333

            
3334
    (title, author) values (title = :title, age = :age);
3335

            
3336
You can use this in insert statement.
3337

            
3338
    my $insert_sql = "insert into book $values_clause";
3339

            
3340
=head2 C<where>
3341

            
3342
    my $where = $dbi->where(
3343
        clause => ['and', 'title = :title', 'author = :author'],
3344
        param => {title => 'Perl', author => 'Ken'}
3345
    );
3346

            
3347
Create a new L<DBIx::Custom::Where> object.
3348

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

            
3351
=head2 C<DBIX_CUSTOM_DEBUG>
3352

            
3353
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3354
executed SQL and bind values are printed to STDERR.
3355

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

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

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

            
3362
L<DBIx::Custom>
3363

            
3364
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3365
    default_dbi_option # will be removed 2017/1/1
3366
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3367
    data_source # will be removed at 2017/1/1
3368
    dbi_options # will be removed at 2017/1/1
3369
    filter_check # will be removed at 2017/1/1
3370
    reserved_word_quote # will be removed at 2017/1/1
3371
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3372
    
3373
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3374
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3375
    assign_param # will be removed at 2017/1/1
3376
    update_param # will be removed at 2017/1/1
3377
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3378
    create_query # will be removed at 2017/1/1
3379
    apply_filter # will be removed at 2017/1/1
3380
    select_at # will be removed at 2017/1/1
3381
    delete_at # will be removed at 2017/1/1
3382
    update_at # will be removed at 2017/1/1
3383
    insert_at # will be removed at 2017/1/1
3384
    register_tag # will be removed at 2017/1/1
3385
    default_bind_filter # will be removed at 2017/1/1
3386
    default_fetch_filter # will be removed at 2017/1/1
3387
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3388
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3389
    register_tag_processor # will be removed at 2017/1/1
3390
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3391
    
3392
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3393
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3394
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3395
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3396
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3397
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3398
    select method relation option # will be removed at 2017/1/1
3399
    select method column option [COLUMN, as => ALIAS] format
3400
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3401
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3402
    
3403
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3404
    execute("select * from {= title}"); # execute method's
3405
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3406
                                        # will be removed at 2017/1/1
3407
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3408

            
3409
L<DBIx::Custom::Model>
3410

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3411
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3412
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3413
    filter # will be removed at 2017/1/1
3414
    name # will be removed at 2017/1/1
3415
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3416

            
3417
L<DBIx::Custom::Query>
3418
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3419
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3420
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3421
    table # will be removed at 2017/1/1
3422
    filters # will be removed at 2017/1/1
3423
    
3424
    # Methods
3425
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3426

            
3427
L<DBIx::Custom::QueryBuilder>
3428
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3429
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3430
    tags # will be removed at 2017/1/1
3431
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3432
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3433
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3434
    register_tag # will be removed at 2017/1/1
3435
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3436
    
3437
    # Others
3438
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3439
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3440

            
3441
L<DBIx::Custom::Result>
3442
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3443
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3444
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3445
    
3446
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3447
    end_filter # will be removed at 2017/1/1
3448
    remove_end_filter # will be removed at 2017/1/1
3449
    remove_filter # will be removed at 2017/1/1
3450
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3451

            
3452
L<DBIx::Custom::Tag>
3453

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

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

            
3458
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3459
except for attribute method.
3460
You can check all DEPRECATED functionalities by document.
3461
DEPRECATED functionality is removed after five years,
3462
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
3463
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3464

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

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

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

            
3471
C<< <kimoto.yuki at gmail.com> >>
3472

            
3473
L<http://github.com/yuki-kimoto/DBIx-Custom>
3474

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3475
=head1 AUTHOR
3476

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

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

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

            
3483
This program is free software; you can redistribute it and/or modify it
3484
under the same terms as Perl itself.
3485

            
3486
=cut