DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3532 lines | 91.654kb
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-04-02
263
    # Arguments
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-04-02
355
    # Arguments
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 2010-10-17
575
    # Arguments
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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
906
sub setup_model {
907
    my $self = shift;
908
    
cleanup
Yuki Kimoto authored on 2011-04-02
909
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
910
    $self->each_column(
911
        sub {
912
            my ($self, $table, $column, $column_info) = @_;
913
            if (my $model = $self->models->{$table}) {
914
                push @{$model->columns}, $column;
915
            }
916
        }
917
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
918
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
919
}
920

            
update pod
Yuki Kimoto authored on 2011-08-10
921
sub show_datatype {
922
    my ($self, $table) = @_;
923
    croak "Table name must be specified" unless defined $table;
924
    print "$table\n";
925
    
926
    my $result = $self->select(table => $table, where => "'0' <> '0'");
927
    my $sth = $result->sth;
928

            
929
    my $columns = $sth->{NAME};
930
    my $data_types = $sth->{TYPE};
931
    
932
    for (my $i = 0; $i < @$columns; $i++) {
933
        my $column = $columns->[$i];
934
        my $data_type = $data_types->[$i];
935
        print "$column: $data_type\n";
936
    }
937
}
938

            
939
sub show_typename {
940
    my ($self, $t) = @_;
941
    croak "Table name must be specified" unless defined $t;
942
    print "$t\n";
943
    
944
    $self->each_column(sub {
945
        my ($self, $table, $column, $infos) = @_;
946
        return unless $table eq $t;
947
        my $typename = $infos->{TYPE_NAME};
948
        print "$column: $typename\n";
949
    });
950
    
951
    return $self;
952
}
953

            
test cleanup
Yuki Kimoto authored on 2011-08-15
954
sub show_tables {
955
    my $self = shift;
956
    
957
    my %tables;
958
    $self->each_table(sub { $tables{$_[1]}++ });
959
    print join("\n", sort keys %tables) . "\n";
960
    return $self;
961
}
962

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
998
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
999
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1000
                }
1001
            });
1002
        }
1003

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1029
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1030
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1031
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1032
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1033
    warn "update method where_param option is DEPRECATED!"
1034
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1035
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
1036
    my $where = $opt{where} || {};
1037
    my $where_param = $opt{where_param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1038
    
cleanup
Yuki Kimoto authored on 2011-10-21
1039
    # Don't allow update all rows
1040
    croak qq{update method where option must be specified } . _subname
1041
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1042
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1043
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1044
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1045
        my $columns = $update_timestamp->[0];
1046
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1047
        my $value = $update_timestamp->[1];
1048
        $value = $value->() if ref $value eq 'CODE';
1049
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1050
    }
1051

            
cleanup
Yuki Kimoto authored on 2011-10-21
1052
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1053
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1054

            
1055
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1056
    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
1057
      if defined $opt{id};
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1058
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1059
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1060
        $where_clause = "where " . $where->[0];
1061
        $where_param = $where->[1];
1062
    }
1063
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1064
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1065
        $where_param = keys %$where_param
1066
                     ? $self->merge_param($where_param, $where->param)
1067
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1068
        
1069
        # String where
1070
        $where_clause = $where->to_string;
1071
    }
1072
    elsif ($where) { $where_clause = "where $where" }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1073
    
cleanup
Yuki Kimoto authored on 2011-10-21
1074
    # Merge where parameter to parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1075
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1076
    
cleanup
Yuki Kimoto authored on 2011-04-02
1077
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1078
    my $sql = "update ";
1079
    $sql .= "$opt{prefix} " if defined $opt{prefix};
1080
    $sql .= $self->_q($opt{table}) . " set $assign_clause $where_clause ";
cleanup
Yuki Kimoto authored on 2011-01-27
1081
    
cleanup
yuki-kimoto authored on 2010-10-17
1082
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1083
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1084
}
1085

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1088
sub update_or_insert {
1089
    my $self = shift;
1090

            
1091
    # Arguments
1092
    my $param  = shift;
1093
    my %opt = @_;
1094
    my $id = $opt{id};
1095
    my $primary_key = $opt{primary_key};
1096
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1097
    croak "update_or_insert method need primary_key option " .
1098
          "when id is specified" . _subname
1099
      if defined $id && !defined $primary_key;
1100
    my $table  = $opt{table};
1101
    croak qq{"table" option must be specified } . _subname
1102
      unless defined $table;
1103
    my $select_option = $opt{select_option};
1104
    
1105
    my $rows = $self->select(table => $table, id => $id,
1106
        primary_key => $primary_key, %$select_option)->all;
1107
    
1108
    croak "selected row count must be one or zero" . _subname
1109
      if @$rows > 1;
1110
    
1111
    my $row = $rows->[0];
1112
    my @opt = (table => $table);
1113
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1114
    push @opt, %opt;
1115
    
1116
    if ($row) {
1117
        return $self->update($param, @opt);
1118
    }
1119
    else {
1120
        return $self->insert($param, @opt);
1121
    }
1122
}
1123

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1124
sub update_timestamp {
1125
    my $self = shift;
1126
    
1127
    if (@_) {
1128
        $self->{update_timestamp} = [@_];
1129
        
1130
        return $self;
1131
    }
1132
    return $self->{update_timestamp};
1133
}
1134

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1135
sub values_clause {
1136
    my ($self, $param, $opts) = @_;
1137
    
1138
    my $wrap = $opts->{wrap} || {};
1139
    
1140
    # Create insert parameter tag
1141
    my $safety = $self->safety_character;
1142
    my @columns;
1143
    my @placeholders;
1144
    foreach my $column (sort keys %$param) {
1145
        croak qq{"$column" is not safety column name } . _subname
1146
          unless $column =~ /^[$safety\.]+$/;
1147
        my $column_quote = $self->_q($column);
1148
        $column_quote =~ s/\./$self->_q(".")/e;
1149
        push @columns, $column_quote;
1150
        
1151
        my $func = $wrap->{$column} || sub { $_[0] };
1152
        push @placeholders,
1153
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1154
        : $func->(":$column");
1155
    }
1156
    
1157
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1158
           '(' . join(', ', @placeholders) . ')'
1159
}
1160

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1163
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1164
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1165
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1166
    
updated pod
Yuki Kimoto authored on 2011-06-21
1167
    # Cache
1168
    my $cache = $self->cache;
1169
    
1170
    # Query
1171
    my $query;
1172
    
1173
    # Get cached query
1174
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1175
        
updated pod
Yuki Kimoto authored on 2011-06-21
1176
        # Get query
1177
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1178
        
updated pod
Yuki Kimoto authored on 2011-06-21
1179
        # Create query
1180
        if ($q) {
1181
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1182
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1183
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1184
    }
1185
    
1186
    # Create query
1187
    unless ($query) {
1188

            
1189
        # Create query
1190
        my $builder = $self->query_builder;
1191
        $query = $builder->build_query($source);
1192

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

            
1199
        # Save query to cache
1200
        $self->cache_method->(
1201
            $self, $source,
1202
            {
1203
                sql     => $query->sql, 
1204
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1205
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1206
            }
1207
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1208
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1209

            
1210
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1211
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1212
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1213
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1214
        $query->sql($sql);
1215
    }
1216
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1217
    # Save sql
1218
    $self->last_sql($query->sql);
1219
    
updated pod
Yuki Kimoto authored on 2011-06-21
1220
    # Prepare statement handle
1221
    my $sth;
1222
    eval { $sth = $self->dbh->prepare($query->{sql})};
1223
    
1224
    if ($@) {
1225
        $self->_croak($@, qq{. Following SQL is executed.\n}
1226
                        . qq{$query->{sql}\n} . _subname);
1227
    }
1228
    
1229
    # Set statement handle
1230
    $query->sth($sth);
1231
    
1232
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1233
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1234
    
1235
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1236
}
1237

            
cleanup
Yuki Kimoto authored on 2011-04-02
1238
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1239
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1240
    
cleanup
Yuki Kimoto authored on 2011-04-02
1241
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1242
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1243
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1244
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1245
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1246
        
1247
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1248
        my $value;
1249
        if(ref $params->{$column} eq 'ARRAY') {
1250
            my $i = $count->{$column} || 0;
1251
            $i += $not_exists->{$column} || 0;
1252
            my $found;
1253
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1254
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1255
                    $not_exists->{$column}++;
1256
                }
1257
                else  {
1258
                    $value = $params->{$column}->[$k];
1259
                    $found = 1;
1260
                    last
1261
                }
1262
            }
1263
            next unless $found;
1264
        }
1265
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1266
        
cleanup
Yuki Kimoto authored on 2011-01-12
1267
        # Filter
1268
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1269
        $value = $f->($value) if $f;
1270
        
1271
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1272
        foreach my $i (1 .. 2) {
1273
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1274
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1275
            $value = $tf->($value) if $tf;
1276
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1277
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1278
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1279
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1280
        
1281
        # Count up 
1282
        $count->{$column}++;
1283
    }
1284
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1285
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1286
}
1287

            
cleanup
Yuki Kimoto authored on 2011-10-21
1288
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1289
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1290
    
1291
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1292
    croak "primary_key option " .
1293
          "must be specified with id option " . _subname
1294
      unless defined $primary_keys;
1295
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1296
    
cleanup
Yuki Kimoto authored on 2011-06-08
1297
    # Create parameter
1298
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1299
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1300
        $id = [$id] unless ref $id;
1301
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1302
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1303
          unless !ref $id || ref $id eq 'ARRAY';
1304
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1305
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1306
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1307
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1308
           my $key = $primary_keys->[$i];
1309
           $key = "$table." . $key if $table;
1310
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1311
        }
1312
    }
1313
    
cleanup
Yuki Kimoto authored on 2011-06-08
1314
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1315
}
1316

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1317
sub _connect {
1318
    my $self = shift;
1319
    
1320
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1321
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1322
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1323
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1324
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1325
    croak qq{"dsn" must be specified } . _subname
1326
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1327
    my $user        = $self->user;
1328
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1329
    my $option = $self->_option;
1330
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1331
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1332
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1333
    my $dbh;
1334
    eval {
1335
        $dbh = DBI->connect(
1336
            $dsn,
1337
            $user,
1338
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1339
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1340
        );
1341
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1342
    
1343
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1344
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1345
    
1346
    return $dbh;
1347
}
1348

            
cleanup
yuki-kimoto authored on 2010-10-17
1349
sub _croak {
1350
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1351
    
1352
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1353
    $append ||= "";
1354
    
1355
    # Verbose
1356
    if ($Carp::Verbose) { croak $error }
1357
    
1358
    # Not verbose
1359
    else {
1360
        
1361
        # Remove line and module infromation
1362
        my $at_pos = rindex($error, ' at ');
1363
        $error = substr($error, 0, $at_pos);
1364
        $error =~ s/\s+$//;
1365
        croak "$error$append";
1366
    }
1367
}
1368

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1371
sub _need_tables {
1372
    my ($self, $tree, $need_tables, $tables) = @_;
1373
    
cleanup
Yuki Kimoto authored on 2011-04-02
1374
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1375
    foreach my $table (@$tables) {
1376
        if ($tree->{$table}) {
1377
            $need_tables->{$table} = 1;
1378
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1379
        }
1380
    }
1381
}
1382

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1383
sub _option {
1384
    my $self = shift;
1385
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1386
    warn "dbi_options is DEPRECATED! use option instead\n"
1387
      if keys %{$self->dbi_options};
1388
    warn "dbi_option is DEPRECATED! use option instead\n"
1389
      if keys %{$self->dbi_option};
1390
    return $option;
1391
}
1392

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1393
sub _push_join {
1394
    my ($self, $sql, $join, $join_tables) = @_;
1395
    
cleanup
Yuki Kimoto authored on 2011-04-02
1396
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1397
    return unless @$join;
1398
    
cleanup
Yuki Kimoto authored on 2011-04-02
1399
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1400
    my $tree = {};
1401
    for (my $i = 0; $i < @$join; $i++) {
1402
        
cleanup
Yuki Kimoto authored on 2011-07-28
1403
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1404
        my $join_clause;;
1405
        my $option;
1406
        if (ref $join->[$i] eq 'HASH') {
1407
            $join_clause = $join->[$i]->{clause};
1408
            $option = {table => $join->[$i]->{table}};
1409
        }
1410
        else {
1411
            $join_clause = $join->[$i];
1412
            $option = {};
1413
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1414

            
1415
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1416
        my $table1;
1417
        my $table2;
1418
        if (my $table = $option->{table}) {
1419
            $table1 = $table->[0];
1420
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1421
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1422
        else {
1423
            my $q = $self->_quote;
1424
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1425
            $j_clause =~ s/'.+?'//g;
1426
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1427
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1428
            
1429
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1430
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1431
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1432
            for my $clause (@j_clauses) {
1433
                if ($clause =~ $join_re) {
1434
                    $table1 = $1;
1435
                    $table2 = $2;
1436
                    last;
1437
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1438
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1439
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1440
        croak qq{join clause must have two table name after "on" keyword. } .
1441
              qq{"$join_clause" is passed }  . _subname
1442
          unless defined $table1 && defined $table2;
1443
        croak qq{right side table of "$join_clause" must be unique }
1444
            . _subname
1445
          if exists $tree->{$table2};
1446
        croak qq{Same table "$table1" is specified} . _subname
1447
          if $table1 eq $table2;
1448
        $tree->{$table2}
1449
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1450
    }
1451
    
cleanup
Yuki Kimoto authored on 2011-04-02
1452
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1453
    my $need_tables = {};
1454
    $self->_need_tables($tree, $need_tables, $join_tables);
1455
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1456
    
1457
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1458
    foreach my $need_table (@need_tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1459
        $$sql .= $tree->{$need_table}{join} . ' ';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1460
    }
1461
}
cleanup
Yuki Kimoto authored on 2011-03-08
1462

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1463
sub _quote {
1464
    my $self = shift;
1465
    
1466
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1467
         : defined $self->quote ? $self->quote
1468
         : '';
1469
}
1470

            
cleanup
Yuki Kimoto authored on 2011-07-29
1471
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1472
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1473
    
1474
    my $quote = $self->_quote;
1475
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1476
    my $p;
1477
    if (defined $quote && length $quote > 1) {
1478
        $p = substr($quote, 1, 1);
1479
    }
1480
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1481
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1482
    if ($quotemeta) {
1483
        $q = quotemeta($q);
1484
        $p = quotemeta($p);
1485
    }
1486
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1487
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1488
}
1489

            
cleanup
Yuki Kimoto authored on 2011-04-02
1490
sub _remove_duplicate_table {
1491
    my ($self, $tables, $main_table) = @_;
1492
    
1493
    # Remove duplicate table
1494
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1495
    delete $tables{$main_table} if $main_table;
1496
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1497
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1498
    if (my $q = $self->_quote) {
1499
        $q = quotemeta($q);
1500
        $_ =~ s/[$q]//g for @$new_tables;
1501
    }
1502

            
1503
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1504
}
1505

            
cleanup
Yuki Kimoto authored on 2011-04-02
1506
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1507
    my ($self, $source) = @_;
1508
    
cleanup
Yuki Kimoto authored on 2011-04-02
1509
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1510
    my $tables = [];
1511
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1512
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1513
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1514
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1515
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1516
    while ($source =~ /$table_re/g) {
1517
        push @$tables, $1;
1518
    }
1519
    
1520
    return $tables;
1521
}
1522

            
cleanup
Yuki Kimoto authored on 2011-04-02
1523
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1524
    my ($self, $where) = @_;
1525
    
cleanup
Yuki Kimoto authored on 2011-04-02
1526
    my $obj;
1527
    
1528
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1529
    if (ref $where eq 'HASH') {
1530
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1531
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1532
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1533
            my $table;
1534
            my $c;
1535
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1536
                $table = $1;
1537
                $c = $2;
1538
            }
1539
            
1540
            my $table_quote;
1541
            $table_quote = $self->_q($table) if defined $table;
1542
            my $column_quote = $self->_q($c);
1543
            $column_quote = $table_quote . '.' . $column_quote
1544
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1545
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1546
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1547
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1548
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1549
    
1550
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1551
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1552
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1553
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1554
    
updated pod
Yuki Kimoto authored on 2011-06-21
1555
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1556
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1557
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1558
            clause => $where->[0],
1559
            param  => $where->[1]
1560
        );
1561
    }
1562
    
cleanup
Yuki Kimoto authored on 2011-04-02
1563
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1564
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1565
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1566
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1567
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1568
    
cleanup
Yuki Kimoto authored on 2011-04-02
1569
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1570
}
1571

            
cleanup
Yuki Kimoto authored on 2011-10-21
1572
sub _where_clause_and_param {
1573
    my ($self, $where, $param) = @_;
1574
 
1575
    $where ||= {};
1576
    $param ||= {};
1577
    my $w = {};
1578
    my $where_clause = '';
1579
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1580
        $w->{clause} = "where " . $where->[0];
1581
        $w->{param} = $where->[1];
1582
    }
1583
    elsif (ref $where) {
1584
        $where = $self->_where_to_obj($where);
1585
        $w->{param} = keys %$param
1586
                    ? $self->merge_param($param, $where->param)
1587
                    : $where->param;
1588
        $w->{clause} = $where->to_string;
1589
    }
1590
    elsif ($where) {
1591
        $w->{clause} = "where $where";
1592
        $w->{param} = $param;
1593
    }
1594
    
1595
    return $w;
1596
}
1597

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

            
1601
    # Initialize filters
1602
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1603
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1604
    $self->{filter}{out} ||= {};
1605
    $self->{filter}{in} ||= {};
1606
    $self->{filter}{end} ||= {};
1607
    
1608
    # Usage
1609
    my $usage = "Usage: \$dbi->apply_filter(" .
1610
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1611
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1612
    
1613
    # Apply filter
1614
    for (my $i = 0; $i < @cinfos; $i += 2) {
1615
        
1616
        # Column
1617
        my $column = $cinfos[$i];
1618
        if (ref $column eq 'ARRAY') {
1619
            foreach my $c (@$column) {
1620
                push @cinfos, $c, $cinfos[$i + 1];
1621
            }
1622
            next;
1623
        }
1624
        
1625
        # Filter infomation
1626
        my $finfo = $cinfos[$i + 1] || {};
1627
        croak "$usage (table: $table) " . _subname
1628
          unless  ref $finfo eq 'HASH';
1629
        foreach my $ftype (keys %$finfo) {
1630
            croak "$usage (table: $table) " . _subname
1631
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1632
        }
1633
        
1634
        # Set filters
1635
        foreach my $way (qw/in out end/) {
1636
        
1637
            # Filter
1638
            my $filter = $finfo->{$way};
1639
            
1640
            # Filter state
1641
            my $state = !exists $finfo->{$way} ? 'not_exists'
1642
                      : !defined $filter        ? 'not_defined'
1643
                      : ref $filter eq 'CODE'   ? 'code'
1644
                      : 'name';
1645
            
1646
            # Filter is not exists
1647
            next if $state eq 'not_exists';
1648
            
1649
            # Check filter name
1650
            croak qq{Filter "$filter" is not registered } . _subname
1651
              if  $state eq 'name'
1652
               && ! exists $self->filters->{$filter};
1653
            
1654
            # Set filter
1655
            my $f = $state eq 'not_defined' ? undef
1656
                  : $state eq 'code'        ? $filter
1657
                  : $self->filters->{$filter};
1658
            $self->{filter}{$way}{$table}{$column} = $f;
1659
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1660
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1661
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1662
        }
1663
    }
1664
    
1665
    return $self;
1666
}
1667

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1668
# DEPRECATED!
1669
has 'data_source';
1670
has dbi_options => sub { {} };
1671
has filter_check  => 1;
1672
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1673
has dbi_option => sub { {} };
1674
has default_dbi_option => sub {
1675
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1676
    return shift->default_option;
1677
};
1678

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1679
# DEPRECATED!
1680
sub method {
1681
    warn "method is DEPRECATED! use helper instead";
1682
    return shift->helper(@_);
1683
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1684

            
1685
# DEPRECATED!
1686
sub assign_param {
1687
    my $self = shift;
1688
    warn "assing_param is DEPRECATED! use assign_clause instead";
1689
    return $self->assign_clause(@_);
1690
}
1691

            
1692
# DEPRECATED
1693
sub update_param {
1694
    my ($self, $param, $opts) = @_;
1695
    
1696
    warn "update_param is DEPRECATED! use assing_clause instead.";
1697
    
1698
    # Create update parameter tag
1699
    my $tag = $self->assign_clause($param, $opts);
1700
    $tag = "set $tag" unless $opts->{no_set};
1701

            
1702
    return $tag;
1703
}
1704

            
updated pod
Yuki Kimoto authored on 2011-06-21
1705
# DEPRECATED!
1706
sub create_query {
1707
    warn "create_query is DEPRECATED! use query option of each method";
1708
    shift->_create_query(@_);
1709
}
1710

            
cleanup
Yuki Kimoto authored on 2011-06-13
1711
# DEPRECATED!
1712
sub apply_filter {
1713
    my $self = shift;
1714
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1715
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1716
    return $self->_apply_filter(@_);
1717
}
1718

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1725
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1726
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1727
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1728
    my $where = delete $opt{where};
1729
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1730
    
1731
    # Table
1732
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1733
      unless $opt{table};
1734
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1735
    
1736
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1737
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1738
    
cleanup
Yuki Kimoto authored on 2011-10-21
1739
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1740
}
1741

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

            
1746
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1747
    
1748
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1749
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1750
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1751
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1752
    
1753
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1754
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1755
    
cleanup
Yuki Kimoto authored on 2011-10-21
1756
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1757
}
1758

            
cleanup
Yuki Kimoto authored on 2011-06-08
1759
# DEPRECATED!
1760
sub update_at {
1761
    my $self = shift;
1762

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1781
# DEPRECATED!
1782
sub insert_at {
1783
    my $self = shift;
1784
    
1785
    warn "insert_at is DEPRECATED! use insert and id option instead";
1786
    
1787
    # Arguments
1788
    my $param;
1789
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1790
    my %opt = @_;
1791
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1792
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1793
    my $where = delete $opt{where};
1794
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1795
    $param  ||= $p;
1796
    
1797
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1798
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1799
    $param = $self->merge_param($where_param, $param);
1800
    
cleanup
Yuki Kimoto authored on 2011-10-21
1801
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1802
}
1803

            
added warnings
Yuki Kimoto authored on 2011-06-07
1804
# DEPRECATED!
1805
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1806
    my $self = shift;
1807
    
added warnings
Yuki Kimoto authored on 2011-06-07
1808
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1809
    
1810
    # Merge tag
1811
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1812
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1813
    
1814
    return $self;
1815
}
1816

            
1817
# DEPRECATED!
1818
sub register_tag_processor {
1819
    my $self = shift;
1820
    warn "register_tag_processor is DEPRECATED!";
1821
    # Merge tag
1822
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1823
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1824
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1825
}
1826

            
cleanup
Yuki Kimoto authored on 2011-01-25
1827
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1828
sub default_bind_filter {
1829
    my $self = shift;
1830
    
cleanup
Yuki Kimoto authored on 2011-06-13
1831
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1832
    
cleanup
Yuki Kimoto authored on 2011-01-12
1833
    if (@_) {
1834
        my $fname = $_[0];
1835
        
1836
        if (@_ && !$fname) {
1837
            $self->{default_out_filter} = undef;
1838
        }
1839
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1840
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1841
              unless exists $self->filters->{$fname};
1842
        
1843
            $self->{default_out_filter} = $self->filters->{$fname};
1844
        }
1845
        return $self;
1846
    }
1847
    
1848
    return $self->{default_out_filter};
1849
}
1850

            
cleanup
Yuki Kimoto authored on 2011-01-25
1851
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1852
sub default_fetch_filter {
1853
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1854

            
cleanup
Yuki Kimoto authored on 2011-06-13
1855
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1856
    
1857
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1858
        my $fname = $_[0];
1859

            
cleanup
Yuki Kimoto authored on 2011-01-12
1860
        if (@_ && !$fname) {
1861
            $self->{default_in_filter} = undef;
1862
        }
1863
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1864
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1865
              unless exists $self->filters->{$fname};
1866
        
1867
            $self->{default_in_filter} = $self->filters->{$fname};
1868
        }
1869
        
1870
        return $self;
1871
    }
1872
    
many changed
Yuki Kimoto authored on 2011-01-23
1873
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1874
}
1875

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1876
# DEPRECATED!
1877
sub insert_param {
1878
    my $self = shift;
1879
    warn "insert_param is DEPRECATED! use values_clause instead";
1880
    return $self->values_clause(@_);
1881
}
1882

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1883
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1884
sub insert_param_tag {
1885
    warn "insert_param_tag is DEPRECATED! " .
1886
         "use insert_param instead!";
1887
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1888
}
1889

            
1890
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1891
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1892
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1893
         "use update_param instead";
1894
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1895
}
cleanup
Yuki Kimoto authored on 2011-03-08
1896
# DEPRECATED!
1897
sub _push_relation {
1898
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1899
    
1900
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1901
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1902
        foreach my $rcolumn (keys %$relation) {
1903
            my $table1 = (split (/\./, $rcolumn))[0];
1904
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1905
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1906
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1907
        }
1908
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1909
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1910
}
1911

            
1912
# DEPRECATED!
1913
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1914
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1915
    
1916
    if (keys %{$relation || {}}) {
1917
        foreach my $rcolumn (keys %$relation) {
1918
            my $table1 = (split (/\./, $rcolumn))[0];
1919
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1920
            my $table1_exists;
1921
            my $table2_exists;
1922
            foreach my $table (@$tables) {
1923
                $table1_exists = 1 if $table eq $table1;
1924
                $table2_exists = 1 if $table eq $table2;
1925
            }
1926
            unshift @$tables, $table1 unless $table1_exists;
1927
            unshift @$tables, $table2 unless $table2_exists;
1928
        }
1929
    }
1930
}
1931

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1934
=head1 NAME
1935

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1940
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1941
    
1942
    # Connect
1943
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1944
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1945
        user => 'ken',
1946
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1947
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1948
    );
cleanup
yuki-kimoto authored on 2010-08-05
1949

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1950
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1951
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1952
    
1953
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1954
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1955
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1956
    
1957
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1958
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1959

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1964
    # Select, more complex
1965
    my $result = $dbi->select(
1966
        table  => 'book',
1967
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1968
            {book => [qw/title author/]},
1969
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1970
        ],
1971
        where  => {'book.author' => 'Ken'},
1972
        join => ['left outer join company on book.company_id = company.id'],
1973
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1974
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1975
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1976
    # Fetch
1977
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1978
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1979
    }
1980
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1981
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1982
    while (my $row = $result->fetch_hash) {
1983
        
1984
    }
1985
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1986
    # Execute SQL with parameter.
1987
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1988
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1989
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1990
    );
1991
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1992
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1993

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2009
Named place holder support
2010

            
2011
=item *
2012

            
cleanup
Yuki Kimoto authored on 2011-07-29
2013
Model support
2014

            
2015
=item *
2016

            
2017
Connection manager support
2018

            
2019
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2020

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

            
2025
=item *
2026

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

            
2029
=item *
2030

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

            
2033
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2034

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2042
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2043
L<DBIx::Custom::Result>,
2044
L<DBIx::Custom::Query>,
2045
L<DBIx::Custom::Where>,
2046
L<DBIx::Custom::Model>,
2047
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2048

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

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

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

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

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

            
2062
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2063
        "dbi:mysql:database=$database",
2064
        $user,
2065
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2066
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2067
    );
2068
    
updated pod
Yuki Kimoto authored on 2011-06-21
2069
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2070

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

            
2074
    my $dbi = DBIx::Custom->connect(
2075
      dsn => $dsn, user => $user, password => $password, connector => 1);
2076
    
2077
    my $connector = $dbi->connector; # DBIx::Connector
2078

            
2079
Note that L<DBIx::Connector> must be installed.
2080

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2096
    {
2097
        RaiseError => 1,
2098
        PrintError => 0,
2099
        AutoCommit => 1,
2100
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2101

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

            
2104
    my $exclude_table = $dbi->exclude_table;
2105
    $dbi = $dbi->exclude_table(qr/pg_/);
2106

            
2107
Excluded table regex.
2108
C<each_column>, C<each_table>, C<type_rule>,
2109
and C<setup_model> methods ignore matching tables.
2110

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

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

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

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

            
2120
    my $last_sql = $dbi->last_sql;
2121
    $dbi = $dbi->last_sql($last_sql);
2122

            
2123
Get last successed SQL executed by C<execute> method.
2124

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

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

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

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

            
2134
    my $option = $dbi->option;
2135
    $dbi = $dbi->option($option);
2136

            
2137
L<DBI> option, used when C<connect> method is executed.
2138
Each value in option override the value of C<default_option>.
2139

            
cleanup
yuki-kimoto authored on 2010-10-17
2140
=head2 C<password>
2141

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2162
You can set quote pair.
2163

            
2164
    $dbi->quote('[]');
2165

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2175
    my $safety_character = $dbi->safety_character;
2176
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2177

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

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

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

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

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

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

            
2194
    my $tag_parse = $dbi->tag_parse(0);
2195
    $dbi = $dbi->tag_parse;
2196

            
2197
Enable DEPRECATED tag parsing functionality, default to 1.
2198
If you want to disable tag parsing functionality, set to 0.
2199

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

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

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

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

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

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

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

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

            
2221
    my $user_column_info
2222
      = $dbi->get_column_info(exclude_table => qr/^system/);
2223
    $dbi->user_column_info($user_column_info);
2224

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

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

            
2230
    my $user_table_info = $dbi->user_table_info;
2231
    $dbi = $dbi->user_table_info($user_table_info);
2232

            
2233
You can set the following data.
2234

            
2235
    [
2236
        {table => 'book', info => {...}},
2237
        {table => 'author', info => {...}}
2238
    ]
2239

            
2240
Usually, you can set return value of C<get_table_info>.
2241

            
2242
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2243
    $dbi->user_table_info($user_table_info);
2244

            
2245
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2246
to find table info.
2247

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2284
Create column clause. The follwoing column clause is created.
2285

            
2286
    book.author as "book.author",
2287
    book.title as "book.title"
2288

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2291
    # Separator is hyphen
2292
    $dbi->separator('-');
2293
    
2294
    book.author as "book-author",
2295
    book.title as "book-title"
2296
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2297
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2298

            
update pod
Yuki Kimoto authored on 2011-03-13
2299
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2300
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2301
        user => 'ken',
2302
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2303
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2304
    );
2305

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

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

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

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

            
2316
Get rows count.
2317

            
2318
Options is same as C<select> method's ones.
2319

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2322
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2323
        table => 'book',
2324
        primary_key => 'id',
2325
        join => [
2326
            'inner join company on book.comparny_id = company.id'
2327
        ],
2328
    );
2329

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

            
2333
   $dbi->model('book')->select(...);
2334

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

            
2337
    my $dbh = $dbi->dbh;
2338

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

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

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

            
2346
Execute delete statement.
2347

            
2348
The following opitons are available.
2349

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

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

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

            
2357
=item C<id>
2358

            
2359
    id => 4
2360
    id => [4, 5]
2361

            
2362
ID corresponding to C<primary_key>.
2363
You can delete rows by C<id> and C<primary_key>.
2364

            
2365
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2366
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2367
        id => [4, 5],
2368
        table => 'book',
2369
    );
2370

            
2371
The above is same as the followin one.
2372

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

            
2375
=item C<prefix>
2376

            
2377
    prefix => 'some'
2378

            
2379
prefix before table name section.
2380

            
2381
    delete some from book
2382

            
2383
=item C<table>
2384

            
2385
    table => 'book'
2386

            
2387
Table name.
2388

            
2389
=item C<where>
2390

            
2391
Same as C<select> method's C<where> option.
2392

            
2393
=back
2394

            
2395
=head2 C<delete_all>
2396

            
2397
    $dbi->delete_all(table => $table);
2398

            
2399
Execute delete statement for all rows.
2400
Options is same as C<delete>.
2401

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

            
2404
    $dbi->each_column(
2405
        sub {
2406
            my ($dbi, $table, $column, $column_info) = @_;
2407
            
2408
            my $type = $column_info->{TYPE_NAME};
2409
            
2410
            if ($type eq 'DATE') {
2411
                # ...
2412
            }
2413
        }
2414
    );
2415

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

            
2421
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2422
infromation, you can improve the performance of C<each_column> in
2423
the following way.
2424

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

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

            
2431
    $dbi->each_table(
2432
        sub {
2433
            my ($dbi, $table, $table_info) = @_;
2434
            
2435
            my $table_name = $table_info->{TABLE_NAME};
2436
        }
2437
    );
2438

            
improved pod
Yuki Kimoto authored on 2011-10-14
2439
Iterate all table informationsfrom in database.
2440
Argument is callback which is executed when one table is found.
2441
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2442
C<table information>.
2443

            
2444
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2445
infromation, you can improve the performance of C<each_table> in
2446
the following way.
2447

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

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

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

            
2459
    my $result = $dbi->execute(
2460
      "select * from book where title = :book.title and author like :book.author",
2461
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2462
    );
2463

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2470
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2471
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2472
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2473
    select * from book where title = :title and author like :author
2474
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2475
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2476
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2477

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2481
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2482
    select * from book where :title{=} and :author{like}
2483
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2484
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2485
    select * from where title = ? and author like ?;
2486

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

            
2491
    select * from where title = "aa\\:bb";
2492

            
cleanup
Yuki Kimoto authored on 2011-10-20
2493
B<OPTIONS>
2494

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

            
2497
=over 4
2498

            
cleanup
Yuki Kimoto authored on 2011-10-20
2499
=item C<append>
2500

            
2501
    append => 'order by name'
2502

            
2503
Append some statement after SQL.
2504

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

            
2507
Specify database bind data type.
2508

            
2509
    bind_type => [image => DBI::SQL_BLOB]
2510
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2511

            
2512
This is used to bind parameter by C<bind_param> of statment handle.
2513

            
2514
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2515

            
update pod
Yuki Kimoto authored on 2011-03-13
2516
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2517
    
2518
    filter => {
2519
        title  => sub { uc $_[0] }
2520
        author => sub { uc $_[0] }
2521
    }
update pod
Yuki Kimoto authored on 2011-03-13
2522

            
updated pod
Yuki Kimoto authored on 2011-06-09
2523
    # Filter name
2524
    filter => {
2525
        title  => 'upper_case',
2526
        author => 'upper_case'
2527
    }
2528
        
2529
    # At once
2530
    filter => [
2531
        [qw/title author/]  => sub { uc $_[0] }
2532
    ]
2533

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

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

            
2541
    id => 4
2542
    id => [4, 5]
2543

            
2544
ID corresponding to C<primary_key>.
2545
You can delete rows by C<id> and C<primary_key>.
2546

            
2547
    $dbi->execute(
2548
        "select * from book where id1 = :id1 and id2 = :id2",
2549
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2550
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2551
        id => [4, 5],
2552
    );
2553

            
2554
The above is same as the followin one.
2555

            
2556
    $dbi->execute(
2557
        "select * from book where id1 = :id1 and id2 = :id2",
2558
        {id1 => 4, id2 => 5}
2559
    );
2560

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

            
2563
    query => 1
2564

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

            
2568
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2569
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2570
    my $columns = $query->columns;
2571
    
2572
If you want to execute SQL fast, you can do the following way.
2573

            
2574
    my $query;
2575
    foreach my $row (@$rows) {
2576
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2577
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2578
    }
2579

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

            
2583
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
2584
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2585
    
2586
    my $query;
2587
    my $sth;
2588
    foreach my $row (@$rows) {
2589
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2590
      $sth ||= $query->sth;
2591
      $sth->execute(map { $row->{$_} } sort keys %$row);
2592
    }
2593

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2600
    primary_key => 'id'
2601
    primary_key => ['id1', 'id2']
2602

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

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

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

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

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

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

            
2621
The following SQL is executed.
2622

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2625
=item C<table>
2626
    
2627
    table => 'author'
2628

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2636
    # Same
2637
    $dbi->execute(
2638
      "select * from book where title = :book.title and author = :book.author",
2639
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2640

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

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

            
2645
Table alias. Key is real table name, value is alias table name.
2646
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2647
on alias table name.
2648

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

            
2651
    type_rule_off => 1
2652

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

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

            
2657
    type_rule1_off => 1
2658

            
2659
Turn C<into1> type rule off.
2660

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

            
2663
    type_rule2_off => 1
2664

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

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

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

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

            
2673
get column infomation except for one which match C<exclude_table> pattern.
2674

            
2675
    [
2676
        {table => 'book', column => 'title', info => {...}},
2677
        {table => 'author', column => 'name' info => {...}}
2678
    ]
2679

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

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

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

            
2686
    [
2687
        {table => 'book', info => {...}},
2688
        {table => 'author', info => {...}}
2689
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2690

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

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

            
2695
    $dbi->helper(
2696
        update_or_insert => sub {
2697
            my $self = shift;
2698
            
2699
            # Process
2700
        },
2701
        find_or_create   => sub {
2702
            my $self = shift;
2703
            
2704
            # Process
2705
        }
2706
    );
2707

            
2708
Register helper. These helper is called directly from L<DBIx::Custom> object.
2709

            
2710
    $dbi->update_or_insert;
2711
    $dbi->find_or_create;
2712

            
cleanup
yuki-kimoto authored on 2010-10-17
2713
=head2 C<insert>
2714

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

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

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

            
2723
    {date => \"NOW()"}
2724

            
cleanup
Yuki Kimoto authored on 2011-10-20
2725
B<options>
2726

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2734
    id => 4
2735
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2736

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2740
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2741
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2742
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2743
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2744
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2745
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2746

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

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

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

            
2756
    prefix => 'or replace'
2757

            
2758
prefix before table name section
2759

            
2760
    insert or replace into book
2761

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

            
2764
    table => 'book'
2765

            
2766
Table name.
2767

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

            
2770
    timestamp => 1
2771

            
2772
If this value is set to 1,
2773
automatically created timestamp column is set based on
2774
C<timestamp> attribute's C<insert> value.
2775

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

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

            
2780
placeholder wrapped string.
2781

            
2782
If the following statement
2783

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

            
2787
is executed, the following SQL is executed.
2788

            
2789
    insert into book price values ( ? + 5 );
2790

            
update pod
Yuki Kimoto authored on 2011-03-13
2791
=back
2792

            
2793
=over 4
2794

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2802
    lib / MyModel.pm
2803
        / MyModel / book.pm
2804
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2805

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

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

            
2810
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2811
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2812
    
2813
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2814

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2819
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2820
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2821
    
2822
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2823

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2826
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2827
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2828
    
2829
    1;
2830
    
updated pod
Yuki Kimoto authored on 2011-06-21
2831
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2832

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

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

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

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

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

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

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

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

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

            
2858
    my $like_value = $dbi->like_value
2859

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

            
2862
    sub { "%$_[0]%" }
2863

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

            
2866
    my $mapper = $dbi->mapper(param => $param);
2867

            
2868
Create a new L<DBIx::Custom::Mapper> object.
2869

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

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

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

            
2876
    {key1 => [1, 1], key2 => 2}
2877

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

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

            
2882
    my $model = $dbi->model('book');
2883

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

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

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

            
2891
Create column clause for myself. The follwoing column clause is created.
2892

            
2893
    book.author as author,
2894
    book.title as title
2895

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

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

            
2905
Create a new L<DBIx::Custom> object.
2906

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

            
2909
    my $not_exists = $dbi->not_exists;
2910

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

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

            
2916
    my $order = $dbi->order;
2917

            
2918
Create a new L<DBIx::Custom::Order> object.
2919

            
cleanup
yuki-kimoto authored on 2010-10-17
2920
=head2 C<register_filter>
2921

            
update pod
Yuki Kimoto authored on 2011-03-13
2922
    $dbi->register_filter(
2923
        # Time::Piece object to database DATE format
2924
        tp_to_date => sub {
2925
            my $tp = shift;
2926
            return $tp->strftime('%Y-%m-%d');
2927
        },
2928
        # database DATE format to Time::Piece object
2929
        date_to_tp => sub {
2930
           my $date = shift;
2931
           return Time::Piece->strptime($date, '%Y-%m-%d');
2932
        }
2933
    );
cleanup
yuki-kimoto authored on 2010-10-17
2934
    
update pod
Yuki Kimoto authored on 2011-03-13
2935
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2936

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2939
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2940
        table  => 'book',
2941
        column => ['author', 'title'],
2942
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2943
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2944
    
updated document
Yuki Kimoto authored on 2011-06-09
2945
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2946

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2954
=item C<column>
2955
    
updated document
Yuki Kimoto authored on 2011-06-09
2956
    column => 'author'
2957
    column => ['author', 'title']
2958

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2967
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2968
        {book => [qw/author title/]},
2969
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2970
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2971

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

            
2974
    book.author as "book.author",
2975
    book.title as "book.title",
2976
    person.name as "person.name",
2977
    person.age as "person.age"
2978

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

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

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

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

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

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

            
2994
=item C<id>
2995

            
2996
    id => 4
2997
    id => [4, 5]
2998

            
2999
ID corresponding to C<primary_key>.
3000
You can select rows by C<id> and C<primary_key>.
3001

            
3002
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3003
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3004
        id => [4, 5],
3005
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3006
    );
3007

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3010
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3011
        where => {id1 => 4, id2 => 5},
3012
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3013
    );
3014
    
cleanup
Yuki Kimoto authored on 2011-10-20
3015
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3016

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

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

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

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

            
3029
    prefix => 'SQL_CALC_FOUND_ROWS'
3030

            
3031
Prefix of column cluase
3032

            
3033
    select SQL_CALC_FOUND_ROWS title, author from book;
3034

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

            
3037
    join => [
3038
        'left outer join company on book.company_id = company_id',
3039
        'left outer join location on company.location_id = location.id'
3040
    ]
3041
        
3042
Join clause. If column cluase or where clause contain table name like "company.name",
3043
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3044

            
3045
    $dbi->select(
3046
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3047
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3048
        where => {'company.name' => 'Orange'},
3049
        join => [
3050
            'left outer join company on book.company_id = company.id',
3051
            'left outer join location on company.location_id = location.id'
3052
        ]
3053
    );
3054

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3058
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3059
    from book
3060
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3061
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3062

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3063
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
3064
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3065

            
3066
    $dbi->select(
3067
        table => 'book',
3068
        column => ['company.location_id as location_id'],
3069
        where => {'company.name' => 'Orange'},
3070
        join => [
3071
            {
3072
                clause => 'left outer join location on company.location_id = location.id',
3073
                table => ['company', 'location']
3074
            }
3075
        ]
3076
    );
3077

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3082
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3083

            
updated document
Yuki Kimoto authored on 2011-06-09
3084
=item C<where>
3085
    
3086
    # Hash refrence
3087
    where => {author => 'Ken', 'title' => 'Perl'}
3088
    
3089
    # DBIx::Custom::Where object
3090
    where => $dbi->where(
3091
        clause => ['and', 'author = :author', 'title like :title'],
3092
        param  => {author => 'Ken', title => '%Perl%'}
3093
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3094
    
3095
    # Array reference 1 (array reference, hash referenc). same as above
3096
    where => [
3097
        ['and', 'author = :author', 'title like :title'],
3098
        {author => 'Ken', title => '%Perl%'}
3099
    ];    
3100
    
3101
    # Array reference 2 (String, hash reference)
3102
    where => [
3103
        'title like :title',
3104
        {title => '%Perl%'}
3105
    ]
3106
    
3107
    # String
3108
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3109

            
cleanup
Yuki Kimoto authored on 2011-10-20
3110
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3111
    
update pod
Yuki Kimoto authored on 2011-03-12
3112
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3113

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

            
3116
    $dbi->setup_model;
3117

            
3118
Setup all model objects.
3119
C<columns> of model object is automatically set, parsing database information.
3120

            
3121
=head2 C<type_rule>
3122

            
3123
    $dbi->type_rule(
3124
        into1 => {
3125
            date => sub { ... },
3126
            datetime => sub { ... }
3127
        },
3128
        into2 => {
3129
            date => sub { ... },
3130
            datetime => sub { ... }
3131
        },
3132
        from1 => {
3133
            # DATE
3134
            9 => sub { ... },
3135
            # DATETIME or TIMESTAMP
3136
            11 => sub { ... },
3137
        }
3138
        from2 => {
3139
            # DATE
3140
            9 => sub { ... },
3141
            # DATETIME or TIMESTAMP
3142
            11 => sub { ... },
3143
        }
3144
    );
3145

            
3146
Filtering rule when data is send into and get from database.
3147
This has a little complex problem.
3148

            
3149
In C<into1> and C<into2> you can specify
3150
type name as same as type name defined
3151
by create table, such as C<DATETIME> or C<DATE>.
3152

            
3153
Note that type name and data type don't contain upper case.
3154
If these contain upper case charactor, you convert it to lower case.
3155

            
3156
C<into2> is executed after C<into1>.
3157

            
3158
Type rule of C<into1> and C<into2> is enabled on the following
3159
column name.
3160

            
3161
=over 4
3162

            
3163
=item 1. column name
3164

            
3165
    issue_date
3166
    issue_datetime
3167

            
3168
This need C<table> option in each method.
3169

            
3170
=item 2. table name and column name, separator is dot
3171

            
3172
    book.issue_date
3173
    book.issue_datetime
3174

            
3175
=back
3176

            
3177
You get all type name used in database by C<available_typename>.
3178

            
3179
    print $dbi->available_typename;
3180

            
3181
In C<from1> and C<from2> you specify data type, not type name.
3182
C<from2> is executed after C<from1>.
3183
You get all data type by C<available_datatype>.
3184

            
3185
    print $dbi->available_datatype;
3186

            
3187
You can also specify multiple types at once.
3188

            
3189
    $dbi->type_rule(
3190
        into1 => [
3191
            [qw/DATE DATETIME/] => sub { ... },
3192
        ],
3193
    );
3194

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

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

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

            
3201
If you want to set constant value to row data, use scalar reference
3202
as parameter value.
3203

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3215
    id => 4
3216
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3217

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3221
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3222
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3223
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3224
        id => [4, 5],
3225
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3226
    );
update pod
Yuki Kimoto authored on 2011-03-13
3227

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3230
    $dbi->update(
3231
        {title => 'Perl', author => 'Ken'}
3232
        where => {id1 => 4, id2 => 5},
3233
        table => 'book'
3234
    );
update pod
Yuki Kimoto authored on 2011-03-13
3235

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

            
3238
    prefix => 'or replace'
3239

            
3240
prefix before table name section
3241

            
3242
    update or replace book
3243

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

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

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

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

            
3252
    timestamp => 1
3253

            
3254
If this value is set to 1,
3255
automatically updated timestamp column is set based on
3256
C<timestamp> attribute's C<update> value.
3257

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

            
3260
Same as C<select> method's C<where> option.
3261

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

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

            
3266
placeholder wrapped string.
3267

            
3268
If the following statement
3269

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

            
3273
is executed, the following SQL is executed.
3274

            
3275
    update book set price =  ? + 5;
3276

            
updated pod
Yuki Kimoto authored on 2011-06-08
3277
=back
update pod
Yuki Kimoto authored on 2011-03-13
3278

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3286
=head2 C<update_or_insert EXPERIMENTAL>
3287
    
3288
    # Where
3289
    $dbi->update_or_insert(
3290
        {id => 1, title => 'Perl'},
3291
        table => 'book',
3292
        where => {id => 1},
3293
        select_option => {append => 'for update'}
3294
    );
3295
    
3296
    # ID
3297
    $dbi->update_or_insert(
3298
        {title => 'Perl'},
3299
        table => 'book',
3300
        id => 1,
3301
        primary_key => 'id',
3302
        select_option => {append => 'for update'}
3303
    );
3304
    
3305
Update or insert.
3306

            
3307
In both examples, the following SQL is executed.
3308

            
3309
    # In case insert
3310
    insert into book (id, title) values (?, ?)
3311
    
3312
    # In case update
3313
    update book set (id = ?, title = ?) where book.id = ?
3314

            
3315
The following opitons are available adding to C<update> option.
3316

            
3317
=over 4
3318

            
3319
=item C<select_option>
3320

            
3321
    select_option => {append => 'for update'}
3322

            
3323
select method option,
3324
select method is used to check the row is already exists.
3325

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

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

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

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

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

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

            
3346
    $dbi->show_datatype($table);
3347

            
3348
Show data type of the columns of specified table.
3349

            
3350
    book
3351
    title: 5
3352
    issue_date: 91
3353

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

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

            
3358
    $dbi->show_tables;
3359

            
3360
Show tables.
3361

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

            
3364
    $dbi->show_typename($table);
3365

            
3366
Show type name of the columns of specified table.
3367

            
3368
    book
3369
    title: varchar
3370
    issue_date: date
3371

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

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

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

            
3378
Create values clause.
3379

            
3380
    (title, author) values (title = :title, age = :age);
3381

            
3382
You can use this in insert statement.
3383

            
3384
    my $insert_sql = "insert into book $values_clause";
3385

            
3386
=head2 C<where>
3387

            
3388
    my $where = $dbi->where(
3389
        clause => ['and', 'title = :title', 'author = :author'],
3390
        param => {title => 'Perl', author => 'Ken'}
3391
    );
3392

            
3393
Create a new L<DBIx::Custom::Where> object.
3394

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

            
3397
=head2 C<DBIX_CUSTOM_DEBUG>
3398

            
3399
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3400
executed SQL and bind values are printed to STDERR.
3401

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

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

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

            
3408
L<DBIx::Custom>
3409

            
3410
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3411
    default_dbi_option # will be removed 2017/1/1
3412
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3413
    data_source # will be removed at 2017/1/1
3414
    dbi_options # will be removed at 2017/1/1
3415
    filter_check # will be removed at 2017/1/1
3416
    reserved_word_quote # will be removed at 2017/1/1
3417
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3418
    
3419
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3420
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3421
    assign_param # will be removed at 2017/1/1
3422
    update_param # will be removed at 2017/1/1
3423
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3424
    create_query # will be removed at 2017/1/1
3425
    apply_filter # will be removed at 2017/1/1
3426
    select_at # will be removed at 2017/1/1
3427
    delete_at # will be removed at 2017/1/1
3428
    update_at # will be removed at 2017/1/1
3429
    insert_at # will be removed at 2017/1/1
3430
    register_tag # will be removed at 2017/1/1
3431
    default_bind_filter # will be removed at 2017/1/1
3432
    default_fetch_filter # will be removed at 2017/1/1
3433
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3434
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3435
    register_tag_processor # will be removed at 2017/1/1
3436
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3437
    
3438
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3439
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3440
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3441
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3442
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3443
    select method relation option # will be removed at 2017/1/1
3444
    select method param option # will be removed at 2017/1/1
3445
    select method column option [COLUMN, as => ALIAS] format
3446
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3447
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3448
    
3449
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3450
    execute("select * from {= title}"); # execute method's
3451
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3452
                                        # will be removed at 2017/1/1
3453
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3454

            
3455
L<DBIx::Custom::Model>
3456

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3457
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3458
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3459
    filter # will be removed at 2017/1/1
3460
    name # will be removed at 2017/1/1
3461
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3462

            
3463
L<DBIx::Custom::Query>
3464
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3465
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3466
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3467
    table # will be removed at 2017/1/1
3468
    filters # will be removed at 2017/1/1
3469
    
3470
    # Methods
3471
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3472

            
3473
L<DBIx::Custom::QueryBuilder>
3474
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3475
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3476
    tags # will be removed at 2017/1/1
3477
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3478
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3479
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3480
    register_tag # will be removed at 2017/1/1
3481
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3482
    
3483
    # Others
3484
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3485
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3486

            
3487
L<DBIx::Custom::Result>
3488
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3489
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3490
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3491
    
3492
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3493
    end_filter # will be removed at 2017/1/1
3494
    remove_end_filter # will be removed at 2017/1/1
3495
    remove_filter # will be removed at 2017/1/1
3496
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3497

            
3498
L<DBIx::Custom::Tag>
3499

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

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

            
3504
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3505
except for attribute method.
3506
You can check all DEPRECATED functionalities by document.
3507
DEPRECATED functionality is removed after five years,
3508
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
3509
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3510

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

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

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

            
3517
C<< <kimoto.yuki at gmail.com> >>
3518

            
3519
L<http://github.com/yuki-kimoto/DBIx-Custom>
3520

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3521
=head1 AUTHOR
3522

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

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

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

            
3529
This program is free software; you can redistribute it and/or modify it
3530
under the same terms as Perl itself.
3531

            
3532
=cut