DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3513 lines | 90.728kb
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 = '';
cleanup
Yuki Kimoto authored on 2011-10-21
74
    for my $i (-1000 .. 1000) {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
75
         my $type_info = $self->dbh->type_info($i);
76
         my $data_type = $type_info->{DATA_TYPE};
77
         my $type_name = $type_info->{TYPE_NAME};
78
         $data_types .= "$data_type ($type_name)\n"
79
           if defined $data_type;
80
    }
81
    return "Data Type maybe equal to Type Name" unless $data_types;
82
    $data_types = "Data Type (Type name)\n" . $data_types;
83
    return $data_types;
84
}
85

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
122
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
123
    my ($self, $param, $opts) = @_;
124
    
125
    my $wrap = $opts->{wrap} || {};
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
    
127
    # Create set tag
128
    my @params;
129
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-10-21
130
    for my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
131
        croak qq{"$column" is not safety column name } . _subname
132
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
133
        my $column_quote = $self->_q($column);
134
        $column_quote =~ s/\./$self->_q(".")/e;
updated pod
Yuki Kimoto authored on 2011-09-02
135
        my $func = $wrap->{$column} || sub { $_[0] };
136
        push @params,
137
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
138
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
139
    }
140
    my $tag = join(', ', @params);
141
    
142
    return $tag;
143
}
144

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
397
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-10-21
398
        my $id_param = $self->_id_to_param($id, $primary_key, $main_table);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
399
        $param = $self->merge_param($id_param, $param);
400
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
401
    
micro optimization
Yuki Kimoto authored on 2011-07-30
402
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
403
    $tables = $self->_remove_duplicate_table($tables, $main_table)
404
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
405
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
406
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
407
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
408
    unless ($type_rule_off) {
cleanup
Yuki Kimoto authored on 2011-10-21
409
        for my $i (1, 2) {
micro optimization
Yuki Kimoto authored on 2011-07-30
410
            unless ($type_rule_off_parts->{$i}) {
411
                $type_filters->{$i} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
412
                for my $alias (keys %$table_alias) {
micro optimization
Yuki Kimoto authored on 2011-07-30
413
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
414
                    
cleanup
Yuki Kimoto authored on 2011-10-21
415
                    for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
micro optimization
Yuki Kimoto authored on 2011-07-30
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 = {};
cleanup
Yuki Kimoto authored on 2011-10-21
428
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
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
cleanup
Yuki Kimoto authored on 2011-10-21
438
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
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;
cleanup
Yuki Kimoto authored on 2011-10-21
481
        for my $b (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
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;
cleanup
Yuki Kimoto authored on 2011-10-21
500
            for my $table (@$tables) {
501
                for my $way (qw/in end/) {
micro optimization
Yuki Kimoto authored on 2011-07-30
502
                    $filter->{$way} = {
503
                        %{$filter->{$way}},
504
                        %{$self->{filter}{$way}{$table} || {}}
505
                    };
506
                }
cleanup
Yuki Kimoto authored on 2011-04-02
507
            }
cleanup
Yuki Kimoto authored on 2011-01-12
508
        }
509
        
510
        # Result
511
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
512
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
513
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
514
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
515
            filter => $filter->{in} || {},
516
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
517
            type_rule => {
518
                from1 => $self->type_rule->{from1},
519
                from2 => $self->type_rule->{from2}
520
            },
cleanup
yuki-kimoto authored on 2010-10-17
521
        );
522

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

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

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

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

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

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
625
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
626
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
627
          if $name_space =~ /[^\w:]/;
628
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
629
        croak qq{Name space module "$name_space.pm" is needed. $@ }
630
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
631
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
632
        
633
        # Search model modules
634
        my $path = $INC{"$name_space.pm"};
635
        $path =~ s/\.pm$//;
636
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
637
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
638
        $model_infos = [];
639
        while (my $module = readdir $dh) {
640
            push @$model_infos, $module
641
              if $module =~ s/\.pm$//;
642
        }
643
        close $dh;
644
    }
645
    
cleanup
Yuki Kimoto authored on 2011-04-02
646
    # Include models
cleanup
Yuki Kimoto authored on 2011-10-21
647
    for my $model_info (@$model_infos) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
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 = {};
cleanup
Yuki Kimoto authored on 2011-10-21
693
    for my $param (@params) {
694
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
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;
cleanup
Yuki Kimoto authored on 2011-10-21
747
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
748
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
749
          unless $self->can($attr);
750
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
751

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1682
    return $tag;
1683
}
1684

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1991
=item *
1992

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

            
1995
=item *
1996

            
1997
Connection manager support
1998

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

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

            
2005
=item *
2006

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

            
2009
=item *
2010

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2213
You can set the following data.
2214

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2296
Get rows count.
2297

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

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

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

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

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

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

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

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

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

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

            
2326
Execute delete statement.
2327

            
2328
The following opitons are available.
2329

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

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

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

            
2337
=item C<id>
2338

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

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

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

            
2351
The above is same as the followin one.
2352

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

            
2355
=item C<prefix>
2356

            
2357
    prefix => 'some'
2358

            
2359
prefix before table name section.
2360

            
2361
    delete some from book
2362

            
2363
=item C<table>
2364

            
2365
    table => 'book'
2366

            
2367
Table name.
2368

            
2369
=item C<where>
2370

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

            
2373
=back
2374

            
2375
=head2 C<delete_all>
2376

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2477
=over 4
2478

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

            
2481
    append => 'order by name'
2482

            
2483
Append some statement after SQL.
2484

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

            
2487
Specify database bind data type.
2488

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

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

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

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

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

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

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

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

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

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

            
2534
The above is same as the followin one.
2535

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

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

            
2543
    query => 1
2544

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2601
The following SQL is executed.
2602

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

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

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

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

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

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

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

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

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

            
2631
    type_rule_off => 1
2632

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

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

            
2637
    type_rule1_off => 1
2638

            
2639
Turn C<into1> type rule off.
2640

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

            
2643
    type_rule2_off => 1
2644

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2736
    prefix => 'or replace'
2737

            
2738
prefix before table name section
2739

            
2740
    insert or replace into book
2741

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

            
2744
    table => 'book'
2745

            
2746
Table name.
2747

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

            
2750
    timestamp => 1
2751

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

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

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

            
2760
placeholder wrapped string.
2761

            
2762
If the following statement
2763

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

            
2767
is executed, the following SQL is executed.
2768

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

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

            
2773
=over 4
2774

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2838
    my $like_value = $dbi->like_value
2839

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2974
=item C<id>
2975

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

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

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

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

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

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

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

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

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

            
3009
    prefix => 'SQL_CALC_FOUND_ROWS'
3010

            
3011
Prefix of column cluase
3012

            
3013
    select SQL_CALC_FOUND_ROWS title, author from book;
3014

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3096
    $dbi->setup_model;
3097

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

            
3101
=head2 C<type_rule>
3102

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

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

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

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

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

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

            
3141
=over 4
3142

            
3143
=item 1. column name
3144

            
3145
    issue_date
3146
    issue_datetime
3147

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

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

            
3152
    book.issue_date
3153
    book.issue_datetime
3154

            
3155
=back
3156

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

            
3159
    print $dbi->available_typename;
3160

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

            
3165
    print $dbi->available_datatype;
3166

            
3167
You can also specify multiple types at once.
3168

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3218
    prefix => 'or replace'
3219

            
3220
prefix before table name section
3221

            
3222
    update or replace book
3223

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

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

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

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

            
3232
    timestamp => 1
3233

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

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

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

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

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

            
3246
placeholder wrapped string.
3247

            
3248
If the following statement
3249

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

            
3253
is executed, the following SQL is executed.
3254

            
3255
    update book set price =  ? + 5;
3256

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

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

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

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

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

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

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

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

            
3297
=over 4
3298

            
3299
=item C<select_option>
3300

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

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

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

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

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

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

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

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

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

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

            
3330
    book
3331
    title: 5
3332
    issue_date: 91
3333

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

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

            
3338
    $dbi->show_tables;
3339

            
3340
Show tables.
3341

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

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

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

            
3348
    book
3349
    title: varchar
3350
    issue_date: date
3351

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

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

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

            
3358
Create values clause.
3359

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

            
3362
You can use this in insert statement.
3363

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

            
3366
=head2 C<where>
3367

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

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

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

            
3377
=head2 C<DBIX_CUSTOM_DEBUG>
3378

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

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

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

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

            
3388
L<DBIx::Custom>
3389

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3513
=cut