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

            
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
4
our $VERSION = '0.1733';
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 = '';
74
    foreach my $i (-1000 .. 1000) {
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;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
130
    foreach 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}
243
           ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
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;
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
351
    my $param;
352
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
353
    my %opt = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
354
    
cleanup
Yuki Kimoto authored on 2011-10-21
355
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
356
    my $p = $opt{param} || {};
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
357
    $param ||= $p;
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';
cleanup
Yuki Kimoto authored on 2011-10-21
360
    my $filter = $opt{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
361
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-10-21
362
    my $bind_type = $opt{bind_type} || $opt{type};
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
363
    $bind_type = _array_to_hash($bind_type);
cleanup
Yuki Kimoto authored on 2011-10-21
364
    my $type_rule_off = $opt{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
365
    my $type_rule_off_parts = {
cleanup
Yuki Kimoto authored on 2011-10-21
366
        1 => $opt{type_rule1_off},
367
        2 => $opt{type_rule2_off}
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
368
    };
cleanup
Yuki Kimoto authored on 2011-10-21
369
    my $query_return = $opt{query};
370
    my $table_alias = $opt{table_alias} || {};
371
    my $after_build_sql = $opt{after_build_sql} || $opt{sqlfilter};
372
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
373
    my $id = $opt{id};
374
    my $primary_key = $opt{primary_key};
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
375
    croak "execute method primary_key option " .
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
376
          "must be specified when id is specified " . _subname
377
      if defined $id && !defined $primary_key;
378
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
379
    my $append = $opt{append};
cleanup
Yuki Kimoto authored on 2011-10-20
380
    $sql .= $append if defined $append && !ref $sql;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
381
    
cleanup
Yuki Kimoto authored on 2011-10-20
382
    my $query
383
      = ref $sql ? $sql : $self->_create_query($sql, $after_build_sql);
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
384
    
385
    # Save query
386
    $self->last_sql($query->sql);
387

            
cleanup
Yuki Kimoto authored on 2011-06-09
388
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
389
    
390
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
391
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
392
    
cleanup
Yuki Kimoto authored on 2011-04-02
393
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
394
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
395
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
396

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

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

            
523
        return $result;
524
    }
cleanup
Yuki Kimoto authored on 2011-04-02
525
    
526
    # Not select statement
527
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
528
}
529

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

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
562
sub helper {
563
    my $self = shift;
564
    
565
    # Register method
566
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
567
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
568
    
569
    return $self;
570
}
571

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
605
sub insert_timestamp {
606
    my $self = shift;
607
    
608
    if (@_) {
609
        $self->{insert_timestamp} = [@_];
610
        
611
        return $self;
612
    }
613
    return $self->{insert_timestamp};
614
}
615

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
616
sub include_model {
617
    my ($self, $name_space, $model_infos) = @_;
618
    
cleanup
Yuki Kimoto authored on 2011-04-02
619
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
620
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
621
    
622
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
623
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
624

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
683
sub mapper {
684
    my $self = shift;
685
    return DBIx::Custom::Mapper->new(@_);
686
}
687

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
688
sub merge_param {
689
    my ($self, @params) = @_;
690
    
cleanup
Yuki Kimoto authored on 2011-04-02
691
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
692
    my $merge = {};
693
    foreach my $param (@params) {
694
        foreach my $column (keys %$param) {
695
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
696
            
697
            if (exists $merge->{$column}) {
698
                $merge->{$column} = [$merge->{$column}]
699
                  unless ref $merge->{$column} eq 'ARRAY';
700
                push @{$merge->{$column}},
701
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
702
            }
703
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
704
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
705
            }
706
        }
707
    }
708
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
709
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
710
}
711

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
712
sub model {
713
    my ($self, $name, $model) = @_;
714
    
cleanup
Yuki Kimoto authored on 2011-04-02
715
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
716
    if ($model) {
717
        $self->models->{$name} = $model;
718
        return $self;
719
    }
720
    
721
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
722
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
723
      unless $self->models->{$name};
724
    
cleanup
Yuki Kimoto authored on 2011-04-02
725
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
726
    return $self->models->{$name};
727
}
728

            
cleanup
Yuki Kimoto authored on 2011-03-21
729
sub mycolumn {
730
    my ($self, $table, $columns) = @_;
731
    
cleanup
Yuki Kimoto authored on 2011-04-02
732
    # Create column clause
733
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
734
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
735
    push @column, $self->_q($table) . "." . $self->_q($_) .
736
      " as " . $self->_q($_)
737
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
738
    
739
    return join (', ', @column);
740
}
741

            
added dbi_options attribute
kimoto authored on 2010-12-20
742
sub new {
743
    my $self = shift->SUPER::new(@_);
744
    
cleanup
Yuki Kimoto authored on 2011-04-02
745
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
746
    my @attrs = keys %$self;
747
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
748
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
749
          unless $self->can($attr);
750
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
751

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
752
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
753
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
754
        '?'     => \&DBIx::Custom::Tag::placeholder,
755
        '='     => \&DBIx::Custom::Tag::equal,
756
        '<>'    => \&DBIx::Custom::Tag::not_equal,
757
        '>'     => \&DBIx::Custom::Tag::greater_than,
758
        '<'     => \&DBIx::Custom::Tag::lower_than,
759
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
760
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
761
        'like'  => \&DBIx::Custom::Tag::like,
762
        'in'    => \&DBIx::Custom::Tag::in,
763
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
764
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
765
    };
766
    
767
    return $self;
768
}
769

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

            
772
sub order {
773
    my $self = shift;
774
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
775
}
776

            
cleanup
yuki-kimoto authored on 2010-10-17
777
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
778
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
779
    
780
    # Register filter
781
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
782
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
783
    
cleanup
Yuki Kimoto authored on 2011-04-02
784
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
785
}
packaging one directory
yuki-kimoto authored on 2009-11-16
786

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
790
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
791
    my $table = $opt{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
792
    my $tables = ref $table eq 'ARRAY' ? $table
793
               : defined $table ? [$table]
794
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
795
    $opt{table} = $tables;
796
    my $where     = $opt{where} || {};
797
    my $param = $opt{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
798
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
799
      if keys %$param;
cleanup
Yuki Kimoto authored on 2011-10-21
800
    my $where_param = $opt{where_param} || $param || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
801
    
cleanup
Yuki Kimoto authored on 2011-03-09
802
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
803
    if ($opt{relation}) {
804
        warn "select() relation option is DEPRECATED!";
805
        $self->_add_relation_table($tables, $opt{relation});
806
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
807
    
cleanup
Yuki Kimoto authored on 2011-04-02
808
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
809
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
810
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
811
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
812
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
813
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
814
    # Column clause
cleanup
Yuki Kimoto authored on 2011-10-21
815
    if (defined $opt{column}) {
816
        my $columns
817
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
818
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
819
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
820
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
821
            }
822
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
823
                if (@$column == 3 && $column->[1] eq 'as') {
824
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
825
                    splice @$column, 1, 1;
826
                }
827
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
828
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
829
            }
cleanup
Yuki Kimoto authored on 2011-04-02
830
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
831
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
832
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
833
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
834
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
835
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
836
    
837
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
838
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
839
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
840
        my $found = {};
841
        foreach my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
842
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
843
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
844
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
845
    }
cleanup
Yuki Kimoto authored on 2011-03-30
846
    else {
847
        my $main_table = $tables->[-1] || '';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
848
        $sql .= $self->_q($main_table) . ' ';
cleanup
Yuki Kimoto authored on 2011-03-30
849
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
850
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-04-25
851
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
852
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
853

            
cleanup
Yuki Kimoto authored on 2011-04-02
854
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
855
    unshift @$tables,
856
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
857
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
858
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
859
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-21
860
    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $tables->[-1])
861
      if defined $opt{id};
updated pod
Yuki Kimoto authored on 2011-06-21
862
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
863
        $where_clause = "where " . $where->[0];
864
        $where_param = $where->[1];
865
    }
866
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
867
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
868
        $where_param = keys %$where_param
869
                     ? $self->merge_param($where_param, $where->param)
870
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
871
        
872
        # String where
873
        $where_clause = $where->to_string;
874
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
875
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
876
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
877
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
878
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
879
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
880
    # Push join
cleanup
Yuki Kimoto authored on 2011-10-21
881
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
882
    
cleanup
Yuki Kimoto authored on 2011-03-09
883
    # Add where clause
micro optimization
Yuki Kimoto authored on 2011-09-30
884
    $sql .= "$where_clause ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
885
    
cleanup
Yuki Kimoto authored on 2011-03-08
886
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
887
    $self->_push_relation(\$sql, $tables, $opt{relation}, $where_clause eq '' ? 1 : 0)
888
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
889
    
packaging one directory
yuki-kimoto authored on 2009-11-16
890
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
891
    my $result = $self->execute($sql, $where_param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
892
    
893
    return $result;
894
}
895

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
896
sub setup_model {
897
    my $self = shift;
898
    
cleanup
Yuki Kimoto authored on 2011-04-02
899
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
900
    $self->each_column(
901
        sub {
902
            my ($self, $table, $column, $column_info) = @_;
903
            if (my $model = $self->models->{$table}) {
904
                push @{$model->columns}, $column;
905
            }
906
        }
907
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
908
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
909
}
910

            
update pod
Yuki Kimoto authored on 2011-08-10
911
sub show_datatype {
912
    my ($self, $table) = @_;
913
    croak "Table name must be specified" unless defined $table;
914
    print "$table\n";
915
    
916
    my $result = $self->select(table => $table, where => "'0' <> '0'");
917
    my $sth = $result->sth;
918

            
919
    my $columns = $sth->{NAME};
920
    my $data_types = $sth->{TYPE};
921
    
922
    for (my $i = 0; $i < @$columns; $i++) {
923
        my $column = $columns->[$i];
924
        my $data_type = $data_types->[$i];
925
        print "$column: $data_type\n";
926
    }
927
}
928

            
929
sub show_typename {
930
    my ($self, $t) = @_;
931
    croak "Table name must be specified" unless defined $t;
932
    print "$t\n";
933
    
934
    $self->each_column(sub {
935
        my ($self, $table, $column, $infos) = @_;
936
        return unless $table eq $t;
937
        my $typename = $infos->{TYPE_NAME};
938
        print "$column: $typename\n";
939
    });
940
    
941
    return $self;
942
}
943

            
test cleanup
Yuki Kimoto authored on 2011-08-15
944
sub show_tables {
945
    my $self = shift;
946
    
947
    my %tables;
948
    $self->each_table(sub { $tables{$_[1]}++ });
949
    print join("\n", sort keys %tables) . "\n";
950
    return $self;
951
}
952

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
953
sub type_rule {
954
    my $self = shift;
955
    
956
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
957
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
958
        
959
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
960
        foreach my $i (1 .. 2) {
961
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
962
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
963
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
964
            $self->{type_rule} = $type_rule;
965
            $self->{"_$into"} = {};
966
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
967
                croak qq{type name of $into section must be lower case}
968
                  if $type_name =~ /[A-Z]/;
969
            }
cleanup
Yuki Kimoto authored on 2011-08-16
970
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
971
            $self->each_column(sub {
972
                my ($dbi, $table, $column, $column_info) = @_;
973
                
974
                my $type_name = lc $column_info->{TYPE_NAME};
975
                if ($type_rule->{$into} &&
976
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
977
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
978
                    return unless exists $type_rule->{$into}->{$type_name};
979
                    if  (defined $filter && ref $filter ne 'CODE') 
980
                    {
981
                        my $fname = $filter;
982
                        croak qq{Filter "$fname" is not registered" } . _subname
983
                          unless exists $self->filters->{$fname};
984
                        
985
                        $filter = $self->filters->{$fname};
986
                    }
987

            
micro optimization
Yuki Kimoto authored on 2011-07-30
988
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
989
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
990
                }
991
            });
992
        }
993

            
994
        # From
995
        foreach my $i (1 .. 2) {
996
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
997
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
998
                croak qq{data type of from$i section must be lower case or number}
999
                  if $data_type =~ /[A-Z]/;
1000
                my $fname = $type_rule->{"from$i"}{$data_type};
1001
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1002
                    croak qq{Filter "$fname" is not registered" } . _subname
1003
                      unless exists $self->filters->{$fname};
1004
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1005
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1006
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1007
            }
1008
        }
1009
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1010
        return $self;
1011
    }
1012
    
1013
    return $self->{type_rule} || {};
1014
}
1015

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1019
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1020
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1021
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1022
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1023
    warn "update method where_param option is DEPRECATED!"
1024
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1025
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1026
    
cleanup
Yuki Kimoto authored on 2011-10-21
1027
    # Don't allow update all rows
1028
    croak qq{update method where option must be specified } . _subname
1029
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1030
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1031
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1032
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1033
        my $columns = $update_timestamp->[0];
1034
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1035
        my $value = $update_timestamp->[1];
1036
        $value = $value->() if ref $value eq 'CODE';
1037
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1038
    }
1039

            
cleanup
Yuki Kimoto authored on 2011-10-21
1040
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1041
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1042
    
1043
    # Convert id to where parameter
1044
    my $where = defined $opt{id}
1045
      ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
1046
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1047

            
1048
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1049
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1050
    
cleanup
Yuki Kimoto authored on 2011-10-21
1051
    # Merge where parameter to parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1052
    $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1053
    
cleanup
Yuki Kimoto authored on 2011-04-02
1054
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1055
    my $sql = "update ";
1056
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1057
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1058
    
cleanup
yuki-kimoto authored on 2010-10-17
1059
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1060
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1061
}
1062

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1065
sub update_or_insert {
1066
    my $self = shift;
1067

            
cleanup
Yuki Kimoto authored on 2011-10-21
1068
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1069
    my $param  = shift;
1070
    my %opt = @_;
1071
    my $id = $opt{id};
1072
    my $primary_key = $opt{primary_key};
1073
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1074
    croak "update_or_insert method need primary_key option " .
1075
          "when id is specified" . _subname
1076
      if defined $id && !defined $primary_key;
1077
    my $table  = $opt{table};
1078
    croak qq{"table" option must be specified } . _subname
1079
      unless defined $table;
1080
    my $select_option = $opt{select_option};
1081
    
1082
    my $rows = $self->select(table => $table, id => $id,
1083
        primary_key => $primary_key, %$select_option)->all;
1084
    
1085
    croak "selected row count must be one or zero" . _subname
1086
      if @$rows > 1;
1087
    
1088
    my $row = $rows->[0];
1089
    my @opt = (table => $table);
1090
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1091
    push @opt, %opt;
1092
    
1093
    if ($row) {
1094
        return $self->update($param, @opt);
1095
    }
1096
    else {
1097
        return $self->insert($param, @opt);
1098
    }
1099
}
1100

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1101
sub update_timestamp {
1102
    my $self = shift;
1103
    
1104
    if (@_) {
1105
        $self->{update_timestamp} = [@_];
1106
        
1107
        return $self;
1108
    }
1109
    return $self->{update_timestamp};
1110
}
1111

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1112
sub values_clause {
1113
    my ($self, $param, $opts) = @_;
1114
    
1115
    my $wrap = $opts->{wrap} || {};
1116
    
1117
    # Create insert parameter tag
1118
    my $safety = $self->safety_character;
1119
    my @columns;
1120
    my @placeholders;
1121
    foreach my $column (sort keys %$param) {
1122
        croak qq{"$column" is not safety column name } . _subname
1123
          unless $column =~ /^[$safety\.]+$/;
1124
        my $column_quote = $self->_q($column);
1125
        $column_quote =~ s/\./$self->_q(".")/e;
1126
        push @columns, $column_quote;
1127
        
1128
        my $func = $wrap->{$column} || sub { $_[0] };
1129
        push @placeholders,
1130
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1131
        : $func->(":$column");
1132
    }
1133
    
1134
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1135
           '(' . join(', ', @placeholders) . ')'
1136
}
1137

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1140
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1141
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1142
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1143
    
updated pod
Yuki Kimoto authored on 2011-06-21
1144
    # Cache
1145
    my $cache = $self->cache;
1146
    
1147
    # Query
1148
    my $query;
1149
    
1150
    # Get cached query
1151
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1152
        
updated pod
Yuki Kimoto authored on 2011-06-21
1153
        # Get query
1154
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1155
        
updated pod
Yuki Kimoto authored on 2011-06-21
1156
        # Create query
1157
        if ($q) {
1158
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1159
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1160
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1161
    }
1162
    
1163
    # Create query
1164
    unless ($query) {
1165

            
1166
        # Create query
1167
        my $builder = $self->query_builder;
1168
        $query = $builder->build_query($source);
1169

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

            
1176
        # Save query to cache
1177
        $self->cache_method->(
1178
            $self, $source,
1179
            {
1180
                sql     => $query->sql, 
1181
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1182
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1183
            }
1184
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1185
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1186

            
1187
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1188
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1189
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1190
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1191
        $query->sql($sql);
1192
    }
1193
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1194
    # Save sql
1195
    $self->last_sql($query->sql);
1196
    
updated pod
Yuki Kimoto authored on 2011-06-21
1197
    # Prepare statement handle
1198
    my $sth;
1199
    eval { $sth = $self->dbh->prepare($query->{sql})};
1200
    
1201
    if ($@) {
1202
        $self->_croak($@, qq{. Following SQL is executed.\n}
1203
                        . qq{$query->{sql}\n} . _subname);
1204
    }
1205
    
1206
    # Set statement handle
1207
    $query->sth($sth);
1208
    
1209
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1210
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1211
    
1212
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1213
}
1214

            
cleanup
Yuki Kimoto authored on 2011-04-02
1215
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1216
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1217
    
cleanup
Yuki Kimoto authored on 2011-04-02
1218
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1219
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1220
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1221
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1222
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1223
        
1224
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1225
        my $value;
1226
        if(ref $params->{$column} eq 'ARRAY') {
1227
            my $i = $count->{$column} || 0;
1228
            $i += $not_exists->{$column} || 0;
1229
            my $found;
1230
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1231
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1232
                    $not_exists->{$column}++;
1233
                }
1234
                else  {
1235
                    $value = $params->{$column}->[$k];
1236
                    $found = 1;
1237
                    last
1238
                }
1239
            }
1240
            next unless $found;
1241
        }
1242
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1243
        
cleanup
Yuki Kimoto authored on 2011-01-12
1244
        # Filter
1245
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1246
        $value = $f->($value) if $f;
1247
        
1248
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1249
        foreach my $i (1 .. 2) {
1250
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1251
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1252
            $value = $tf->($value) if $tf;
1253
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1254
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1255
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1256
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1257
        
1258
        # Count up 
1259
        $count->{$column}++;
1260
    }
1261
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1262
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1263
}
1264

            
cleanup
Yuki Kimoto authored on 2011-10-21
1265
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1266
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1267
    
1268
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1269
    croak "primary_key option " .
1270
          "must be specified with id option " . _subname
1271
      unless defined $primary_keys;
1272
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1273
    
cleanup
Yuki Kimoto authored on 2011-06-08
1274
    # Create parameter
1275
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1276
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1277
        $id = [$id] unless ref $id;
1278
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1279
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1280
          unless !ref $id || ref $id eq 'ARRAY';
1281
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1282
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1283
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1284
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1285
           my $key = $primary_keys->[$i];
1286
           $key = "$table." . $key if $table;
1287
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1288
        }
1289
    }
1290
    
cleanup
Yuki Kimoto authored on 2011-06-08
1291
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1292
}
1293

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1294
sub _connect {
1295
    my $self = shift;
1296
    
1297
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1298
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1299
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1300
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1301
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1302
    croak qq{"dsn" must be specified } . _subname
1303
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1304
    my $user        = $self->user;
1305
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1306
    my $option = $self->_option;
1307
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1308
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1309
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1310
    my $dbh;
1311
    eval {
1312
        $dbh = DBI->connect(
1313
            $dsn,
1314
            $user,
1315
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1316
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1317
        );
1318
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1319
    
1320
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1321
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1322
    
1323
    return $dbh;
1324
}
1325

            
cleanup
yuki-kimoto authored on 2010-10-17
1326
sub _croak {
1327
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1328
    
1329
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1330
    $append ||= "";
1331
    
1332
    # Verbose
1333
    if ($Carp::Verbose) { croak $error }
1334
    
1335
    # Not verbose
1336
    else {
1337
        
1338
        # Remove line and module infromation
1339
        my $at_pos = rindex($error, ' at ');
1340
        $error = substr($error, 0, $at_pos);
1341
        $error =~ s/\s+$//;
1342
        croak "$error$append";
1343
    }
1344
}
1345

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1348
sub _need_tables {
1349
    my ($self, $tree, $need_tables, $tables) = @_;
1350
    
cleanup
Yuki Kimoto authored on 2011-04-02
1351
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1352
    foreach my $table (@$tables) {
1353
        if ($tree->{$table}) {
1354
            $need_tables->{$table} = 1;
1355
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1356
        }
1357
    }
1358
}
1359

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1360
sub _option {
1361
    my $self = shift;
1362
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1363
    warn "dbi_options is DEPRECATED! use option instead\n"
1364
      if keys %{$self->dbi_options};
1365
    warn "dbi_option is DEPRECATED! use option instead\n"
1366
      if keys %{$self->dbi_option};
1367
    return $option;
1368
}
1369

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1370
sub _push_join {
1371
    my ($self, $sql, $join, $join_tables) = @_;
1372
    
cleanup
Yuki Kimoto authored on 2011-10-21
1373
    $join ||= [];
1374
    
cleanup
Yuki Kimoto authored on 2011-04-02
1375
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1376
    return unless @$join;
1377
    
cleanup
Yuki Kimoto authored on 2011-04-02
1378
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1379
    my $tree = {};
1380
    for (my $i = 0; $i < @$join; $i++) {
1381
        
cleanup
Yuki Kimoto authored on 2011-07-28
1382
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1383
        my $join_clause;;
1384
        my $option;
1385
        if (ref $join->[$i] eq 'HASH') {
1386
            $join_clause = $join->[$i]->{clause};
1387
            $option = {table => $join->[$i]->{table}};
1388
        }
1389
        else {
1390
            $join_clause = $join->[$i];
1391
            $option = {};
1392
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1393

            
1394
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1395
        my $table1;
1396
        my $table2;
1397
        if (my $table = $option->{table}) {
1398
            $table1 = $table->[0];
1399
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1400
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1401
        else {
1402
            my $q = $self->_quote;
1403
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1404
            $j_clause =~ s/'.+?'//g;
1405
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1406
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1407
            
1408
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1409
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1410
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1411
            for my $clause (@j_clauses) {
1412
                if ($clause =~ $join_re) {
1413
                    $table1 = $1;
1414
                    $table2 = $2;
1415
                    last;
1416
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1417
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1418
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1419
        croak qq{join clause must have two table name after "on" keyword. } .
1420
              qq{"$join_clause" is passed }  . _subname
1421
          unless defined $table1 && defined $table2;
1422
        croak qq{right side table of "$join_clause" must be unique }
1423
            . _subname
1424
          if exists $tree->{$table2};
1425
        croak qq{Same table "$table1" is specified} . _subname
1426
          if $table1 eq $table2;
1427
        $tree->{$table2}
1428
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1429
    }
1430
    
cleanup
Yuki Kimoto authored on 2011-04-02
1431
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1432
    my $need_tables = {};
1433
    $self->_need_tables($tree, $need_tables, $join_tables);
1434
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1435
    
1436
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1437
    foreach my $need_table (@need_tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1438
        $$sql .= $tree->{$need_table}{join} . ' ';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1439
    }
1440
}
cleanup
Yuki Kimoto authored on 2011-03-08
1441

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1442
sub _quote {
1443
    my $self = shift;
1444
    
1445
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1446
         : defined $self->quote ? $self->quote
1447
         : '';
1448
}
1449

            
cleanup
Yuki Kimoto authored on 2011-07-29
1450
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1451
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1452
    
1453
    my $quote = $self->_quote;
1454
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1455
    my $p;
1456
    if (defined $quote && length $quote > 1) {
1457
        $p = substr($quote, 1, 1);
1458
    }
1459
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1460
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1461
    if ($quotemeta) {
1462
        $q = quotemeta($q);
1463
        $p = quotemeta($p);
1464
    }
1465
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1466
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1467
}
1468

            
cleanup
Yuki Kimoto authored on 2011-04-02
1469
sub _remove_duplicate_table {
1470
    my ($self, $tables, $main_table) = @_;
1471
    
1472
    # Remove duplicate table
1473
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1474
    delete $tables{$main_table} if $main_table;
1475
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1476
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1477
    if (my $q = $self->_quote) {
1478
        $q = quotemeta($q);
1479
        $_ =~ s/[$q]//g for @$new_tables;
1480
    }
1481

            
1482
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1483
}
1484

            
cleanup
Yuki Kimoto authored on 2011-04-02
1485
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1486
    my ($self, $source) = @_;
1487
    
cleanup
Yuki Kimoto authored on 2011-04-02
1488
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1489
    my $tables = [];
1490
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1491
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1492
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1493
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1494
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1495
    while ($source =~ /$table_re/g) {
1496
        push @$tables, $1;
1497
    }
1498
    
1499
    return $tables;
1500
}
1501

            
cleanup
Yuki Kimoto authored on 2011-04-02
1502
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1503
    my ($self, $where) = @_;
1504
    
cleanup
Yuki Kimoto authored on 2011-04-02
1505
    my $obj;
1506
    
1507
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1508
    if (ref $where eq 'HASH') {
1509
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1510
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1511
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1512
            my $table;
1513
            my $c;
1514
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1515
                $table = $1;
1516
                $c = $2;
1517
            }
1518
            
1519
            my $table_quote;
1520
            $table_quote = $self->_q($table) if defined $table;
1521
            my $column_quote = $self->_q($c);
1522
            $column_quote = $table_quote . '.' . $column_quote
1523
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1524
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1525
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1526
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1527
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1528
    
1529
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1530
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1531
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1532
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1533
    
updated pod
Yuki Kimoto authored on 2011-06-21
1534
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1535
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1536
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1537
            clause => $where->[0],
1538
            param  => $where->[1]
1539
        );
1540
    }
1541
    
cleanup
Yuki Kimoto authored on 2011-04-02
1542
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1543
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1544
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1545
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1546
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1547
    
cleanup
Yuki Kimoto authored on 2011-04-02
1548
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1549
}
1550

            
cleanup
Yuki Kimoto authored on 2011-10-21
1551
sub _where_clause_and_param {
1552
    my ($self, $where, $param) = @_;
1553
 
1554
    $where ||= {};
1555
    $param ||= {};
1556
    my $w = {};
1557
    my $where_clause = '';
1558
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1559
        $w->{clause} = "where " . $where->[0];
1560
        $w->{param} = $where->[1];
1561
    }
1562
    elsif (ref $where) {
1563
        $where = $self->_where_to_obj($where);
1564
        $w->{param} = keys %$param
1565
                    ? $self->merge_param($param, $where->param)
1566
                    : $where->param;
1567
        $w->{clause} = $where->to_string;
1568
    }
1569
    elsif ($where) {
1570
        $w->{clause} = "where $where";
1571
        $w->{param} = $param;
1572
    }
1573
    
1574
    return $w;
1575
}
1576

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1647
# DEPRECATED!
1648
has 'data_source';
1649
has dbi_options => sub { {} };
1650
has filter_check  => 1;
1651
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1652
has dbi_option => sub { {} };
1653
has default_dbi_option => sub {
1654
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1655
    return shift->default_option;
1656
};
1657

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1658
# DEPRECATED!
1659
sub method {
1660
    warn "method is DEPRECATED! use helper instead";
1661
    return shift->helper(@_);
1662
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1663

            
1664
# DEPRECATED!
1665
sub assign_param {
1666
    my $self = shift;
1667
    warn "assing_param is DEPRECATED! use assign_clause instead";
1668
    return $self->assign_clause(@_);
1669
}
1670

            
1671
# DEPRECATED
1672
sub update_param {
1673
    my ($self, $param, $opts) = @_;
1674
    
1675
    warn "update_param is DEPRECATED! use assing_clause instead.";
1676
    
1677
    # Create update parameter tag
1678
    my $tag = $self->assign_clause($param, $opts);
1679
    $tag = "set $tag" unless $opts->{no_set};
1680

            
1681
    return $tag;
1682
}
1683

            
updated pod
Yuki Kimoto authored on 2011-06-21
1684
# DEPRECATED!
1685
sub create_query {
1686
    warn "create_query is DEPRECATED! use query option of each method";
1687
    shift->_create_query(@_);
1688
}
1689

            
cleanup
Yuki Kimoto authored on 2011-06-13
1690
# DEPRECATED!
1691
sub apply_filter {
1692
    my $self = shift;
1693
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1694
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1695
    return $self->_apply_filter(@_);
1696
}
1697

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
1702
    warn "select_at is DEPRECATED! use update and id option instead";
1703

            
cleanup
Yuki Kimoto authored on 2011-10-21
1704
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1705
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1706
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1707
    my $where = delete $opt{where};
1708
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1709
    
1710
    # Table
1711
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1712
      unless $opt{table};
1713
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1714
    
1715
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1716
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1717
    
cleanup
Yuki Kimoto authored on 2011-10-21
1718
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1719
}
1720

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

            
1725
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1726
    
cleanup
Yuki Kimoto authored on 2011-10-21
1727
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1728
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1729
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1730
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1731
    
1732
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1733
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1734
    
cleanup
Yuki Kimoto authored on 2011-10-21
1735
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1736
}
1737

            
cleanup
Yuki Kimoto authored on 2011-06-08
1738
# DEPRECATED!
1739
sub update_at {
1740
    my $self = shift;
1741

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1760
# DEPRECATED!
1761
sub insert_at {
1762
    my $self = shift;
1763
    
1764
    warn "insert_at is DEPRECATED! use insert and id option instead";
1765
    
cleanup
Yuki Kimoto authored on 2011-10-21
1766
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1767
    my $param;
1768
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1769
    my %opt = @_;
1770
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1771
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1772
    my $where = delete $opt{where};
1773
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1774
    $param  ||= $p;
1775
    
1776
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1777
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1778
    $param = $self->merge_param($where_param, $param);
1779
    
cleanup
Yuki Kimoto authored on 2011-10-21
1780
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1781
}
1782

            
added warnings
Yuki Kimoto authored on 2011-06-07
1783
# DEPRECATED!
1784
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1785
    my $self = shift;
1786
    
added warnings
Yuki Kimoto authored on 2011-06-07
1787
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1788
    
1789
    # Merge tag
1790
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1791
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1792
    
1793
    return $self;
1794
}
1795

            
1796
# DEPRECATED!
1797
sub register_tag_processor {
1798
    my $self = shift;
1799
    warn "register_tag_processor is DEPRECATED!";
1800
    # Merge tag
1801
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1802
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1803
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1804
}
1805

            
cleanup
Yuki Kimoto authored on 2011-01-25
1806
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1807
sub default_bind_filter {
1808
    my $self = shift;
1809
    
cleanup
Yuki Kimoto authored on 2011-06-13
1810
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1811
    
cleanup
Yuki Kimoto authored on 2011-01-12
1812
    if (@_) {
1813
        my $fname = $_[0];
1814
        
1815
        if (@_ && !$fname) {
1816
            $self->{default_out_filter} = undef;
1817
        }
1818
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1819
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1820
              unless exists $self->filters->{$fname};
1821
        
1822
            $self->{default_out_filter} = $self->filters->{$fname};
1823
        }
1824
        return $self;
1825
    }
1826
    
1827
    return $self->{default_out_filter};
1828
}
1829

            
cleanup
Yuki Kimoto authored on 2011-01-25
1830
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1831
sub default_fetch_filter {
1832
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1833

            
cleanup
Yuki Kimoto authored on 2011-06-13
1834
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1835
    
1836
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1837
        my $fname = $_[0];
1838

            
cleanup
Yuki Kimoto authored on 2011-01-12
1839
        if (@_ && !$fname) {
1840
            $self->{default_in_filter} = undef;
1841
        }
1842
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1843
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1844
              unless exists $self->filters->{$fname};
1845
        
1846
            $self->{default_in_filter} = $self->filters->{$fname};
1847
        }
1848
        
1849
        return $self;
1850
    }
1851
    
many changed
Yuki Kimoto authored on 2011-01-23
1852
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1853
}
1854

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1855
# DEPRECATED!
1856
sub insert_param {
1857
    my $self = shift;
1858
    warn "insert_param is DEPRECATED! use values_clause instead";
1859
    return $self->values_clause(@_);
1860
}
1861

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1862
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1863
sub insert_param_tag {
1864
    warn "insert_param_tag is DEPRECATED! " .
1865
         "use insert_param instead!";
1866
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1867
}
1868

            
1869
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1870
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1871
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1872
         "use update_param instead";
1873
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1874
}
cleanup
Yuki Kimoto authored on 2011-03-08
1875
# DEPRECATED!
1876
sub _push_relation {
1877
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1878
    
1879
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1880
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1881
        foreach my $rcolumn (keys %$relation) {
1882
            my $table1 = (split (/\./, $rcolumn))[0];
1883
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1884
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1885
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1886
        }
1887
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1888
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1889
}
1890

            
1891
# DEPRECATED!
1892
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1893
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1894
    
1895
    if (keys %{$relation || {}}) {
1896
        foreach my $rcolumn (keys %$relation) {
1897
            my $table1 = (split (/\./, $rcolumn))[0];
1898
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1899
            my $table1_exists;
1900
            my $table2_exists;
1901
            foreach my $table (@$tables) {
1902
                $table1_exists = 1 if $table eq $table1;
1903
                $table2_exists = 1 if $table eq $table2;
1904
            }
1905
            unshift @$tables, $table1 unless $table1_exists;
1906
            unshift @$tables, $table2 unless $table2_exists;
1907
        }
1908
    }
1909
}
1910

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1913
=head1 NAME
1914

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1915
DBIx::Custom - Execute insert, update, delete, and select statement easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1916

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1919
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1920
    
1921
    # Connect
1922
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1923
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1924
        user => 'ken',
1925
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1926
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1927
    );
cleanup
yuki-kimoto authored on 2010-08-05
1928

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1929
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1930
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1931
    
1932
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1933
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1934
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1935
    
1936
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1937
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1938

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1943
    # Select, more complex
1944
    my $result = $dbi->select(
1945
        table  => 'book',
1946
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1947
            {book => [qw/title author/]},
1948
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1949
        ],
1950
        where  => {'book.author' => 'Ken'},
1951
        join => ['left outer join company on book.company_id = company.id'],
1952
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1953
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1954
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1955
    # Fetch
1956
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1957
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1958
    }
1959
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1960
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1961
    while (my $row = $result->fetch_hash) {
1962
        
1963
    }
1964
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1965
    # Execute SQL with parameter.
1966
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1967
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1968
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1969
    );
1970
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1971
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1972

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1988
Named place holder support
1989

            
1990
=item *
1991

            
cleanup
Yuki Kimoto authored on 2011-07-29
1992
Model support
1993

            
1994
=item *
1995

            
1996
Connection manager support
1997

            
1998
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1999

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

            
2004
=item *
2005

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

            
2008
=item *
2009

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

            
2012
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2013

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2021
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2022
L<DBIx::Custom::Result>,
2023
L<DBIx::Custom::Query>,
2024
L<DBIx::Custom::Where>,
2025
L<DBIx::Custom::Model>,
2026
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2027

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

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

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

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

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

            
2041
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2042
        "dbi:mysql:database=$database",
2043
        $user,
2044
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2045
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2046
    );
2047
    
updated pod
Yuki Kimoto authored on 2011-06-21
2048
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2049

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

            
2053
    my $dbi = DBIx::Custom->connect(
2054
      dsn => $dsn, user => $user, password => $password, connector => 1);
2055
    
2056
    my $connector = $dbi->connector; # DBIx::Connector
2057

            
2058
Note that L<DBIx::Connector> must be installed.
2059

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2075
    {
2076
        RaiseError => 1,
2077
        PrintError => 0,
2078
        AutoCommit => 1,
2079
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2080

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

            
2083
    my $exclude_table = $dbi->exclude_table;
2084
    $dbi = $dbi->exclude_table(qr/pg_/);
2085

            
2086
Excluded table regex.
2087
C<each_column>, C<each_table>, C<type_rule>,
2088
and C<setup_model> methods ignore matching tables.
2089

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

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

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

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

            
2099
    my $last_sql = $dbi->last_sql;
2100
    $dbi = $dbi->last_sql($last_sql);
2101

            
2102
Get last successed SQL executed by C<execute> method.
2103

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

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

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

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

            
2113
    my $option = $dbi->option;
2114
    $dbi = $dbi->option($option);
2115

            
2116
L<DBI> option, used when C<connect> method is executed.
2117
Each value in option override the value of C<default_option>.
2118

            
cleanup
yuki-kimoto authored on 2010-10-17
2119
=head2 C<password>
2120

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2141
You can set quote pair.
2142

            
2143
    $dbi->quote('[]');
2144

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2154
    my $safety_character = $dbi->safety_character;
2155
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2156

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

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

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

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

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

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

            
2173
    my $tag_parse = $dbi->tag_parse(0);
2174
    $dbi = $dbi->tag_parse;
2175

            
2176
Enable DEPRECATED tag parsing functionality, default to 1.
2177
If you want to disable tag parsing functionality, set to 0.
2178

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

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

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

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

            
2188
    my $user_column_info = $dbi->user_column_info;
2189
    $dbi = $dbi->user_column_info($user_column_info);
2190

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

            
2193
    [
2194
        {table => 'book', column => 'title', info => {...}},
2195
        {table => 'author', column => 'name', info => {...}}
2196
    ]
2197

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

            
2200
    my $user_column_info
2201
      = $dbi->get_column_info(exclude_table => qr/^system/);
2202
    $dbi->user_column_info($user_column_info);
2203

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

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

            
2209
    my $user_table_info = $dbi->user_table_info;
2210
    $dbi = $dbi->user_table_info($user_table_info);
2211

            
2212
You can set the following data.
2213

            
2214
    [
2215
        {table => 'book', info => {...}},
2216
        {table => 'author', info => {...}}
2217
    ]
2218

            
2219
Usually, you can set return value of C<get_table_info>.
2220

            
2221
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2222
    $dbi->user_table_info($user_table_info);
2223

            
2224
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2225
to find table info.
2226

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2263
Create column clause. The follwoing column clause is created.
2264

            
2265
    book.author as "book.author",
2266
    book.title as "book.title"
2267

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2270
    # Separator is hyphen
2271
    $dbi->separator('-');
2272
    
2273
    book.author as "book-author",
2274
    book.title as "book-title"
2275
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2276
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2277

            
update pod
Yuki Kimoto authored on 2011-03-13
2278
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2279
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2280
        user => 'ken',
2281
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2282
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2283
    );
2284

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

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

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

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

            
2295
Get rows count.
2296

            
2297
Options is same as C<select> method's ones.
2298

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2301
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2302
        table => 'book',
2303
        primary_key => 'id',
2304
        join => [
2305
            'inner join company on book.comparny_id = company.id'
2306
        ],
2307
    );
2308

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

            
2312
   $dbi->model('book')->select(...);
2313

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

            
2316
    my $dbh = $dbi->dbh;
2317

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

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

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

            
2325
Execute delete statement.
2326

            
2327
The following opitons are available.
2328

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

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

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

            
2336
=item C<id>
2337

            
2338
    id => 4
2339
    id => [4, 5]
2340

            
2341
ID corresponding to C<primary_key>.
2342
You can delete rows by C<id> and C<primary_key>.
2343

            
2344
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2345
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2346
        id => [4, 5],
2347
        table => 'book',
2348
    );
2349

            
2350
The above is same as the followin one.
2351

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

            
2354
=item C<prefix>
2355

            
2356
    prefix => 'some'
2357

            
2358
prefix before table name section.
2359

            
2360
    delete some from book
2361

            
2362
=item C<table>
2363

            
2364
    table => 'book'
2365

            
2366
Table name.
2367

            
2368
=item C<where>
2369

            
2370
Same as C<select> method's C<where> option.
2371

            
2372
=back
2373

            
2374
=head2 C<delete_all>
2375

            
2376
    $dbi->delete_all(table => $table);
2377

            
2378
Execute delete statement for all rows.
2379
Options is same as C<delete>.
2380

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

            
2383
    $dbi->each_column(
2384
        sub {
2385
            my ($dbi, $table, $column, $column_info) = @_;
2386
            
2387
            my $type = $column_info->{TYPE_NAME};
2388
            
2389
            if ($type eq 'DATE') {
2390
                # ...
2391
            }
2392
        }
2393
    );
2394

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

            
2400
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2401
infromation, you can improve the performance of C<each_column> in
2402
the following way.
2403

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

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

            
2410
    $dbi->each_table(
2411
        sub {
2412
            my ($dbi, $table, $table_info) = @_;
2413
            
2414
            my $table_name = $table_info->{TABLE_NAME};
2415
        }
2416
    );
2417

            
improved pod
Yuki Kimoto authored on 2011-10-14
2418
Iterate all table informationsfrom in database.
2419
Argument is callback which is executed when one table is found.
2420
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2421
C<table information>.
2422

            
2423
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2424
infromation, you can improve the performance of C<each_table> in
2425
the following way.
2426

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

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

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

            
2438
    my $result = $dbi->execute(
2439
      "select * from book where title = :book.title and author like :book.author",
2440
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2441
    );
2442

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2449
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2450
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2451
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2452
    select * from book where title = :title and author like :author
2453
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2454
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2455
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2456

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2460
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2461
    select * from book where :title{=} and :author{like}
2462
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2463
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2464
    select * from where title = ? and author like ?;
2465

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

            
2470
    select * from where title = "aa\\:bb";
2471

            
cleanup
Yuki Kimoto authored on 2011-10-20
2472
B<OPTIONS>
2473

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

            
2476
=over 4
2477

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

            
2480
    append => 'order by name'
2481

            
2482
Append some statement after SQL.
2483

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

            
2486
Specify database bind data type.
2487

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

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

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

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

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

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

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

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

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

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

            
2533
The above is same as the followin one.
2534

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

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

            
2542
    query => 1
2543

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

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

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

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

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

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

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2584
=item C<after_build_sql> 
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2585

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2586
You can filter sql after the sql is build.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2587

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2588
    after_build_sql => $code_ref
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2589

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2590
The following one is one example.
2591

            
2592
    $dbi->select(
2593
        table => 'book',
2594
        column => 'distinct(name)',
2595
        after_build_sql => sub {
2596
            "select count(*) from ($_[0]) as t1"
2597
        }
2598
    );
2599

            
2600
The following SQL is executed.
2601

            
2602
    select count(*) from (select distinct(name) from book) as t1;
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2603

            
updated pod
Yuki Kimoto authored on 2011-06-09
2604
=item C<table>
2605
    
2606
    table => 'author'
2607

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2615
    # Same
2616
    $dbi->execute(
2617
      "select * from book where title = :book.title and author = :book.author",
2618
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2619

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

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

            
2624
Table alias. Key is real table name, value is alias table name.
2625
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2626
on alias table name.
2627

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

            
2630
    type_rule_off => 1
2631

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

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

            
2636
    type_rule1_off => 1
2637

            
2638
Turn C<into1> type rule off.
2639

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

            
2642
    type_rule2_off => 1
2643

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

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

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

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

            
2652
get column infomation except for one which match C<exclude_table> pattern.
2653

            
2654
    [
2655
        {table => 'book', column => 'title', info => {...}},
2656
        {table => 'author', column => 'name' info => {...}}
2657
    ]
2658

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

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

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

            
2665
    [
2666
        {table => 'book', info => {...}},
2667
        {table => 'author', info => {...}}
2668
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2669

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

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

            
2674
    $dbi->helper(
2675
        update_or_insert => sub {
2676
            my $self = shift;
2677
            
2678
            # Process
2679
        },
2680
        find_or_create   => sub {
2681
            my $self = shift;
2682
            
2683
            # Process
2684
        }
2685
    );
2686

            
2687
Register helper. These helper is called directly from L<DBIx::Custom> object.
2688

            
2689
    $dbi->update_or_insert;
2690
    $dbi->find_or_create;
2691

            
cleanup
yuki-kimoto authored on 2010-10-17
2692
=head2 C<insert>
2693

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

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

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

            
2702
    {date => \"NOW()"}
2703

            
cleanup
Yuki Kimoto authored on 2011-10-20
2704
B<options>
2705

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2713
    id => 4
2714
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2715

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

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

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

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

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

            
2735
    prefix => 'or replace'
2736

            
2737
prefix before table name section
2738

            
2739
    insert or replace into book
2740

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

            
2743
    table => 'book'
2744

            
2745
Table name.
2746

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

            
2749
    timestamp => 1
2750

            
2751
If this value is set to 1,
2752
automatically created timestamp column is set based on
2753
C<timestamp> attribute's C<insert> value.
2754

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

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

            
2759
placeholder wrapped string.
2760

            
2761
If the following statement
2762

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

            
2766
is executed, the following SQL is executed.
2767

            
2768
    insert into book price values ( ? + 5 );
2769

            
update pod
Yuki Kimoto authored on 2011-03-13
2770
=back
2771

            
2772
=over 4
2773

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2781
    lib / MyModel.pm
2782
        / MyModel / book.pm
2783
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2784

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

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

            
2789
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2790
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2791
    
2792
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2793

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2798
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2799
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2800
    
2801
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2802

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2805
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2806
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2807
    
2808
    1;
2809
    
updated pod
Yuki Kimoto authored on 2011-06-21
2810
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2811

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2821
$dbi->insert_timestamp(
2822
  [qw/created_at updated_at/]
2823
    => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2824
);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2825

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

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

            
2833
$dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2834

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

            
2837
    my $like_value = $dbi->like_value
2838

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

            
2841
    sub { "%$_[0]%" }
2842

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

            
2845
    my $mapper = $dbi->mapper(param => $param);
2846

            
2847
Create a new L<DBIx::Custom::Mapper> object.
2848

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

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

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

            
2855
    {key1 => [1, 1], key2 => 2}
2856

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

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

            
2861
    my $model = $dbi->model('book');
2862

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

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

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

            
2870
Create column clause for myself. The follwoing column clause is created.
2871

            
2872
    book.author as author,
2873
    book.title as title
2874

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

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

            
2884
Create a new L<DBIx::Custom> object.
2885

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

            
2888
    my $not_exists = $dbi->not_exists;
2889

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

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

            
2895
    my $order = $dbi->order;
2896

            
2897
Create a new L<DBIx::Custom::Order> object.
2898

            
cleanup
yuki-kimoto authored on 2010-10-17
2899
=head2 C<register_filter>
2900

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2918
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2919
        table  => 'book',
2920
        column => ['author', 'title'],
2921
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2922
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2923
    
updated document
Yuki Kimoto authored on 2011-06-09
2924
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2925

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2933
=item C<column>
2934
    
updated document
Yuki Kimoto authored on 2011-06-09
2935
    column => 'author'
2936
    column => ['author', 'title']
2937

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2946
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2947
        {book => [qw/author title/]},
2948
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2949
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2950

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

            
2953
    book.author as "book.author",
2954
    book.title as "book.title",
2955
    person.name as "person.name",
2956
    person.age as "person.age"
2957

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

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

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

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

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

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

            
2973
=item C<id>
2974

            
2975
    id => 4
2976
    id => [4, 5]
2977

            
2978
ID corresponding to C<primary_key>.
2979
You can select rows by C<id> and C<primary_key>.
2980

            
2981
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2982
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2983
        id => [4, 5],
2984
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2985
    );
2986

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

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

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

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

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

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

            
3008
    prefix => 'SQL_CALC_FOUND_ROWS'
3009

            
3010
Prefix of column cluase
3011

            
3012
    select SQL_CALC_FOUND_ROWS title, author from book;
3013

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

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

            
3024
    $dbi->select(
3025
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3026
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3027
        where => {'company.name' => 'Orange'},
3028
        join => [
3029
            'left outer join company on book.company_id = company.id',
3030
            'left outer join location on company.location_id = location.id'
3031
        ]
3032
    );
3033

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3037
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3038
    from book
3039
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3040
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3041

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3042
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
3043
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3044

            
3045
    $dbi->select(
3046
        table => 'book',
3047
        column => ['company.location_id as location_id'],
3048
        where => {'company.name' => 'Orange'},
3049
        join => [
3050
            {
3051
                clause => 'left outer join location on company.location_id = location.id',
3052
                table => ['company', 'location']
3053
            }
3054
        ]
3055
    );
3056

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3061
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3062

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3089
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3090
    
update pod
Yuki Kimoto authored on 2011-03-12
3091
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3092

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

            
3095
    $dbi->setup_model;
3096

            
3097
Setup all model objects.
3098
C<columns> of model object is automatically set, parsing database information.
3099

            
3100
=head2 C<type_rule>
3101

            
3102
    $dbi->type_rule(
3103
        into1 => {
3104
            date => sub { ... },
3105
            datetime => sub { ... }
3106
        },
3107
        into2 => {
3108
            date => sub { ... },
3109
            datetime => sub { ... }
3110
        },
3111
        from1 => {
3112
            # DATE
3113
            9 => sub { ... },
3114
            # DATETIME or TIMESTAMP
3115
            11 => sub { ... },
3116
        }
3117
        from2 => {
3118
            # DATE
3119
            9 => sub { ... },
3120
            # DATETIME or TIMESTAMP
3121
            11 => sub { ... },
3122
        }
3123
    );
3124

            
3125
Filtering rule when data is send into and get from database.
3126
This has a little complex problem.
3127

            
3128
In C<into1> and C<into2> you can specify
3129
type name as same as type name defined
3130
by create table, such as C<DATETIME> or C<DATE>.
3131

            
3132
Note that type name and data type don't contain upper case.
3133
If these contain upper case charactor, you convert it to lower case.
3134

            
3135
C<into2> is executed after C<into1>.
3136

            
3137
Type rule of C<into1> and C<into2> is enabled on the following
3138
column name.
3139

            
3140
=over 4
3141

            
3142
=item 1. column name
3143

            
3144
    issue_date
3145
    issue_datetime
3146

            
3147
This need C<table> option in each method.
3148

            
3149
=item 2. table name and column name, separator is dot
3150

            
3151
    book.issue_date
3152
    book.issue_datetime
3153

            
3154
=back
3155

            
3156
You get all type name used in database by C<available_typename>.
3157

            
3158
    print $dbi->available_typename;
3159

            
3160
In C<from1> and C<from2> you specify data type, not type name.
3161
C<from2> is executed after C<from1>.
3162
You get all data type by C<available_datatype>.
3163

            
3164
    print $dbi->available_datatype;
3165

            
3166
You can also specify multiple types at once.
3167

            
3168
    $dbi->type_rule(
3169
        into1 => [
3170
            [qw/DATE DATETIME/] => sub { ... },
3171
        ],
3172
    );
3173

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

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

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

            
3180
If you want to set constant value to row data, use scalar reference
3181
as parameter value.
3182

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3194
    id => 4
3195
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3196

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3209
    $dbi->update(
3210
        {title => 'Perl', author => 'Ken'}
3211
        where => {id1 => 4, id2 => 5},
3212
        table => 'book'
3213
    );
update pod
Yuki Kimoto authored on 2011-03-13
3214

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

            
3217
    prefix => 'or replace'
3218

            
3219
prefix before table name section
3220

            
3221
    update or replace book
3222

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

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

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

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

            
3231
    timestamp => 1
3232

            
3233
If this value is set to 1,
3234
automatically updated timestamp column is set based on
3235
C<timestamp> attribute's C<update> value.
3236

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

            
3239
Same as C<select> method's C<where> option.
3240

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

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

            
3245
placeholder wrapped string.
3246

            
3247
If the following statement
3248

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

            
3252
is executed, the following SQL is executed.
3253

            
3254
    update book set price =  ? + 5;
3255

            
updated pod
Yuki Kimoto authored on 2011-06-08
3256
=back
update pod
Yuki Kimoto authored on 2011-03-13
3257

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

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

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

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

            
3286
In both examples, the following SQL is executed.
3287

            
3288
    # In case insert
3289
    insert into book (id, title) values (?, ?)
3290
    
3291
    # In case update
3292
    update book set (id = ?, title = ?) where book.id = ?
3293

            
3294
The following opitons are available adding to C<update> option.
3295

            
3296
=over 4
3297

            
3298
=item C<select_option>
3299

            
3300
    select_option => {append => 'for update'}
3301

            
3302
select method option,
3303
select method is used to check the row is already exists.
3304

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

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

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

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

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

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

            
3325
    $dbi->show_datatype($table);
3326

            
3327
Show data type of the columns of specified table.
3328

            
3329
    book
3330
    title: 5
3331
    issue_date: 91
3332

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

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

            
3337
    $dbi->show_tables;
3338

            
3339
Show tables.
3340

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

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

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

            
3347
    book
3348
    title: varchar
3349
    issue_date: date
3350

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

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

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

            
3357
Create values clause.
3358

            
3359
    (title, author) values (title = :title, age = :age);
3360

            
3361
You can use this in insert statement.
3362

            
3363
    my $insert_sql = "insert into book $values_clause";
3364

            
3365
=head2 C<where>
3366

            
3367
    my $where = $dbi->where(
3368
        clause => ['and', 'title = :title', 'author = :author'],
3369
        param => {title => 'Perl', author => 'Ken'}
3370
    );
3371

            
3372
Create a new L<DBIx::Custom::Where> object.
3373

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

            
3376
=head2 C<DBIX_CUSTOM_DEBUG>
3377

            
3378
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3379
executed SQL and bind values are printed to STDERR.
3380

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

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

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

            
3387
L<DBIx::Custom>
3388

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

            
3435
L<DBIx::Custom::Model>
3436

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3437
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3438
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3439
    filter # will be removed at 2017/1/1
3440
    name # will be removed at 2017/1/1
3441
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3442

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

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

            
3467
L<DBIx::Custom::Result>
3468
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3469
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3470
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3471
    
3472
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3473
    end_filter # will be removed at 2017/1/1
3474
    remove_end_filter # will be removed at 2017/1/1
3475
    remove_filter # will be removed at 2017/1/1
3476
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3477

            
3478
L<DBIx::Custom::Tag>
3479

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

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

            
3484
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3485
except for attribute method.
3486
You can check all DEPRECATED functionalities by document.
3487
DEPRECATED functionality is removed after five years,
3488
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
3489
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3490

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

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

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

            
3497
C<< <kimoto.yuki at gmail.com> >>
3498

            
3499
L<http://github.com/yuki-kimoto/DBIx-Custom>
3500

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3501
=head1 AUTHOR
3502

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

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

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

            
3509
This program is free software; you can redistribute it and/or modify it
3510
under the same terms as Perl itself.
3511

            
3512
=cut