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

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
4
our $VERSION = '0.1717';
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/;
improved debug message
Yuki Kimoto authored on 2011-05-23
17
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
18
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
19

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
20
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
21
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
23
has [qw/connector dsn password quote user exclude_table user_table_info
24
        user_column_info/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
25
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
26
    cache_method => sub {
27
        sub {
28
            my $self = shift;
29
            
30
            $self->{_cached} ||= {};
31
            
32
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
33
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
34
            }
35
            else {
update pod
Yuki Kimoto authored on 2011-03-13
36
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
37
            }
38
        }
update pod
Yuki Kimoto authored on 2011-03-13
39
    },
40
    dbi_option => sub { {} },
41
    default_dbi_option => sub {
42
        {
43
            RaiseError => 1,
44
            PrintError => 0,
45
            AutoCommit => 1
46
        }
47
    },
fix tests
Yuki Kimoto authored on 2011-01-13
48
    filters => sub {
49
        {
50
            encode_utf8 => sub { encode_utf8($_[0]) },
51
            decode_utf8 => sub { decode_utf8($_[0]) }
52
        }
update pod
Yuki Kimoto authored on 2011-03-13
53
    },
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
54
    last_sql => '',
update pod
Yuki Kimoto authored on 2011-03-13
55
    models => sub { {} },
cleanup
Yuki Kimoto authored on 2011-08-13
56
    query_builder => sub {
57
        my $self = shift;
58
        my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
59
        weaken $builder->{dbi};
60
        return $builder;
61
    },
update pod
Yuki Kimoto authored on 2011-03-13
62
    result_class  => 'DBIx::Custom::Result',
63
    safety_character => '\w',
cleanup test
Yuki Kimoto authored on 2011-08-10
64
    separator => '.',
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
65
    stash => sub { {} },
66
    tag_parse => 1;
cleanup
yuki-kimoto authored on 2010-10-17
67

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
68
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
69
    my $self = shift;
70
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
71
    my $data_types = '';
72
    foreach my $i (-1000 .. 1000) {
73
         my $type_info = $self->dbh->type_info($i);
74
         my $data_type = $type_info->{DATA_TYPE};
75
         my $type_name = $type_info->{TYPE_NAME};
76
         $data_types .= "$data_type ($type_name)\n"
77
           if defined $data_type;
78
    }
79
    return "Data Type maybe equal to Type Name" unless $data_types;
80
    $data_types = "Data Type (Type name)\n" . $data_types;
81
    return $data_types;
82
}
83

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
120
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
121
    my ($self, $param) = @_;
122
    
123
    # Create set tag
124
    my @params;
125
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
126
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
127
        croak qq{"$column" is not safety column name } . _subname
128
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
129
        my $column_quote = $self->_q($column);
130
        $column_quote =~ s/\./$self->_q(".")/e;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
131
        push @params, ref $param->{$column} eq 'SCALAR'
132
          ? "$column_quote = " . ${$param->{$column}}
133
          : "$column_quote = :$column";
134

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
135
    }
136
    my $tag = join(', ', @params);
137
    
138
    return $tag;
139
}
140

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
166
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
167
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
168
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
169
    # Connect
170
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
171
    
packaging one directory
yuki-kimoto authored on 2009-11-16
172
    return $self;
173
}
174

            
update pod
Yuki Kimoto authored on 2011-03-13
175
sub dbh {
176
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
177
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
178
    # Set
179
    if (@_) {
180
        $self->{dbh} = $_[0];
181
        
182
        return $self;
183
    }
184
    
185
    # Get
186
    else {
187
        # From Connction manager
188
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
189
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
190
              unless ref $connector && $connector->can('dbh');
191
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
192
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
193
        }
194
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
195
        # Connect
196
        $self->{dbh} ||= $self->_connect;
197
        
198
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
199
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
200
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
201
            my $quote =  $driver eq 'odbc' ? '[]'
202
                       : $driver eq 'ado' ? '[]'
203
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
204
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
205
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
206
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
207
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
208
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
209
    }
210
}
211

            
cleanup
yuki-kimoto authored on 2010-10-17
212
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
213
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
214

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
215
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
216
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
217
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
218
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
219
    my $where            = delete $args{where} || {};
220
    my $append           = delete $args{append};
221
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
222
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
223
    my $id = delete $args{id};
224
    my $primary_key = delete $args{primary_key};
225
    croak "update method primary_key option " .
226
          "must be specified when id is specified " . _subname
227
      if defined $id && !defined $primary_key;
228
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
229
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
230
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
231
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
232
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
233
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
234
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
235
        $where_clause = "where " . $where->[0];
236
        $where_param = $where->[1];
237
    }
238
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
239
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
240
        $where_param = keys %$where_param
241
                     ? $self->merge_param($where_param, $where->param)
242
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
243
        
244
        # String where
245
        $where_clause = $where->to_string;
246
    }
247
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
248
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
249
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250

            
cleanup
Yuki Kimoto authored on 2011-04-02
251
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
252
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
253
    push @sql, "delete";
254
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
255
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
256
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
257
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
258
    
259
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
260
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
261
}
262

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

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

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

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

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

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

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

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
355
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
356
  allow_update_all bind_type column filter id join param prefix primary_key
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
357
  query relation sqlfilter table table_alias type type_rule_off type_rule1_off
simplified arguments check
Yuki Kimoto authored on 2011-07-11
358
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
359

            
360
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
361
    my $self = shift;
362
    my $query = shift;
363
    my $param;
364
    $param = shift if @_ % 2;
365
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
366
    
cleanup
Yuki Kimoto authored on 2011-04-02
367
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
368
    my $p = delete $args{param} || {};
369
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
370
    my $tables = delete $args{table} || [];
371
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
372
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
373
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
374
    my $bind_type = delete $args{bind_type} || delete $args{type};
375
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
376
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
377
    my $type_rule_off_parts = {
378
        1 => delete $args{type_rule1_off},
379
        2 => delete $args{type_rule2_off}
380
    };
cleanup
Yuki Kimoto authored on 2011-06-09
381
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
382
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
383
    my $sqlfilter = $args{sqlfilter};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
384
    
cleanup
Yuki Kimoto authored on 2011-03-09
385
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
386
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
387
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
388
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
389
    }
390
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
391
    $query = $self->_create_query($query, $sqlfilter) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
392
    
393
    # Save query
394
    $self->last_sql($query->sql);
395

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
565
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
566
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
567
    
cleanup
yuki-kimoto authored on 2010-10-17
568
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
569
    my $param;
570
    $param = shift if @_ % 2;
571
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
572
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
573
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
574
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
575
    my $p = delete $args{param} || {};
576
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
577
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
578
    my $id = delete $args{id};
579
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
580
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
581
          "must be specified when id is specified " . _subname
582
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
583
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
584
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
585

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
586
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
587
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
588
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
589
        $param = $self->merge_param($id_param, $param);
590
    }
591

            
cleanup
Yuki Kimoto authored on 2011-04-02
592
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
593
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
594
    push @sql, "insert";
595
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
596
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
597
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
598
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
599
    
600
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
601
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
602
}
603

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
604
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
605
    my ($self, $param) = @_;
606
    
cleanup
Yuki Kimoto authored on 2011-04-02
607
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
608
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
609
    my @columns;
610
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
611
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
612
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
613
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
614
        my $column_quote = $self->_q($column);
615
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
616
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
617
        push @placeholders, ref $param->{$column} eq 'SCALAR'
618
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
619
    }
620
    
cleanup
Yuki Kimoto authored on 2011-04-02
621
    return '(' . join(', ', @columns) . ') ' . 'values ' .
622
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
623
}
624

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
625
sub include_model {
626
    my ($self, $name_space, $model_infos) = @_;
627
    
cleanup
Yuki Kimoto authored on 2011-04-02
628
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
629
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
630
    
631
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
632
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
633

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
690
sub map_param {
691
    my $self = shift;
692
    my $param = shift;
693
    my %map = @_;
694
    
695
    # Mapping
696
    my $map_param = {};
697
    foreach my $key (keys %map) {
698
        my $value_cb;
699
        my $condition;
700
        my $map_key;
701
        
702
        # Get mapping information
703
        if (ref $map{$key} eq 'ARRAY') {
704
            foreach my $some (@{$map{$key}}) {
705
                $map_key = $some unless ref $some;
706
                $condition = $some->{if} if ref $some eq 'HASH';
707
                $value_cb = $some if ref $some eq 'CODE';
708
            }
709
        }
710
        else {
711
            $map_key = $map{$key};
712
        }
713
        $value_cb ||= sub { $_[0] };
714
        $condition ||= sub { defined $_[0] && length $_[0] };
715

            
716
        # Map parameter
717
        my $value;
718
        if (ref $condition eq 'CODE') {
719
            $map_param->{$map_key} = $value_cb->($param->{$key})
720
              if $condition->($param->{$key});
721
        }
722
        elsif ($condition eq 'exists') {
723
            $map_param->{$map_key} = $value_cb->($param->{$key})
724
              if exists $param->{$key};
725
        }
726
        else { croak qq/Condition must be code reference or "exists" / . _subname }
727
    }
728
    
729
    return $map_param;
730
}
731

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
732
sub merge_param {
733
    my ($self, @params) = @_;
734
    
cleanup
Yuki Kimoto authored on 2011-04-02
735
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
736
    my $merge = {};
737
    foreach my $param (@params) {
738
        foreach my $column (keys %$param) {
739
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
740
            
741
            if (exists $merge->{$column}) {
742
                $merge->{$column} = [$merge->{$column}]
743
                  unless ref $merge->{$column} eq 'ARRAY';
744
                push @{$merge->{$column}},
745
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
746
            }
747
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
748
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
749
            }
750
        }
751
    }
752
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
753
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
754
}
755

            
cleanup
Yuki Kimoto authored on 2011-03-21
756
sub method {
757
    my $self = shift;
758
    
cleanup
Yuki Kimoto authored on 2011-04-02
759
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
760
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
761
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
762
    
763
    return $self;
764
}
765

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
766
sub model {
767
    my ($self, $name, $model) = @_;
768
    
cleanup
Yuki Kimoto authored on 2011-04-02
769
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
770
    if ($model) {
771
        $self->models->{$name} = $model;
772
        return $self;
773
    }
774
    
775
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
776
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
777
      unless $self->models->{$name};
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
    return $self->models->{$name};
781
}
782

            
cleanup
Yuki Kimoto authored on 2011-03-21
783
sub mycolumn {
784
    my ($self, $table, $columns) = @_;
785
    
cleanup
Yuki Kimoto authored on 2011-04-02
786
    # Create column clause
787
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
788
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
789
    push @column, $self->_q($table) . "." . $self->_q($_) .
790
      " as " . $self->_q($_)
791
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
792
    
793
    return join (', ', @column);
794
}
795

            
added dbi_options attribute
kimoto authored on 2010-12-20
796
sub new {
797
    my $self = shift->SUPER::new(@_);
798
    
cleanup
Yuki Kimoto authored on 2011-04-02
799
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
800
    my @attrs = keys %$self;
801
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
802
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
803
          unless $self->can($attr);
804
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
805

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
806
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
807
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
808
        '?'     => \&DBIx::Custom::Tag::placeholder,
809
        '='     => \&DBIx::Custom::Tag::equal,
810
        '<>'    => \&DBIx::Custom::Tag::not_equal,
811
        '>'     => \&DBIx::Custom::Tag::greater_than,
812
        '<'     => \&DBIx::Custom::Tag::lower_than,
813
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
814
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
815
        'like'  => \&DBIx::Custom::Tag::like,
816
        'in'    => \&DBIx::Custom::Tag::in,
817
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
818
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
819
    };
820
    
821
    return $self;
822
}
823

            
824
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
825
sub not_exists { $not_exists }
826

            
827
sub order {
828
    my $self = shift;
829
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
830
}
831

            
cleanup
yuki-kimoto authored on 2010-10-17
832
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
833
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
834
    
835
    # Register filter
836
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
837
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
838
    
cleanup
Yuki Kimoto authored on 2011-04-02
839
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
840
}
packaging one directory
yuki-kimoto authored on 2009-11-16
841

            
842
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
843
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
844

            
refactoring select
yuki-kimoto authored on 2010-04-28
845
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
846
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
847
    my $tables = ref $table eq 'ARRAY' ? $table
848
               : defined $table ? [$table]
849
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
850
    my $columns   = delete $args{column};
851
    my $where     = delete $args{where} || {};
852
    my $append    = delete $args{append};
853
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
854
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
855
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
856
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
857
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
858
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
859
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
860
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
861
      if keys %$param;
862
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
863
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
864
    my $id = delete $args{id};
865
    my $primary_key = delete $args{primary_key};
866
    croak "update method primary_key option " .
867
          "must be specified when id is specified " . _subname
868
      if defined $id && !defined $primary_key;
869
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
870
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
871
    
cleanup
Yuki Kimoto authored on 2011-03-09
872
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
873
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
874
    
cleanup
Yuki Kimoto authored on 2011-04-02
875
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
876
    my @sql;
877
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
878
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
879
    # Prefix
880
    push @sql, $prefix if defined $prefix;
881
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
882
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
883
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
884
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
885
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
886
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
887
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
888
            }
889
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
890
                if (@$column == 3 && $column->[1] eq 'as') {
891
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
892
                    splice @$column, 1, 1;
893
                }
894
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
895
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
896
            }
cleanup
Yuki Kimoto authored on 2011-04-02
897
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
898
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
899
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
900
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
901
    }
902
    else { push @sql, '*' }
903
    
904
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
905
    push @sql, 'from';
906
    if ($relation) {
907
        my $found = {};
908
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
909
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
910
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
911
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
912
    }
cleanup
Yuki Kimoto authored on 2011-03-30
913
    else {
914
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
915
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
916
    }
917
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
918
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
919
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
920

            
cleanup
Yuki Kimoto authored on 2011-04-02
921
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
922
    unshift @$tables,
923
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
924
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
925
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
926
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
927
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
928
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
929
        $where_clause = "where " . $where->[0];
930
        $where_param = $where->[1];
931
    }
932
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
933
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
934
        $where_param = keys %$where_param
935
                     ? $self->merge_param($where_param, $where->param)
936
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
937
        
938
        # String where
939
        $where_clause = $where->to_string;
940
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
941
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
942
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
943
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
944
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
945
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
946
    # Push join
947
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
948
    
cleanup
Yuki Kimoto authored on 2011-03-09
949
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
950
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
951
    
cleanup
Yuki Kimoto authored on 2011-03-08
952
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
953
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
954
    
cleanup
Yuki Kimoto authored on 2011-04-02
955
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
956
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
957
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
958
    # Wrap
959
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
960
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
961
          unless ref $wrap eq 'ARRAY';
962
        unshift @sql, $wrap->[0];
963
        push @sql, $wrap->[1];
964
    }
965
    
cleanup
Yuki Kimoto authored on 2011-01-27
966
    # SQL
967
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
968
    
969
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
970
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
971
    
972
    return $result;
973
}
974

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
975
sub setup_model {
976
    my $self = shift;
977
    
cleanup
Yuki Kimoto authored on 2011-04-02
978
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
979
    $self->each_column(
980
        sub {
981
            my ($self, $table, $column, $column_info) = @_;
982
            if (my $model = $self->models->{$table}) {
983
                push @{$model->columns}, $column;
984
            }
985
        }
986
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
987
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
988
}
989

            
update pod
Yuki Kimoto authored on 2011-08-10
990
sub show_datatype {
991
    my ($self, $table) = @_;
992
    croak "Table name must be specified" unless defined $table;
993
    print "$table\n";
994
    
995
    my $result = $self->select(table => $table, where => "'0' <> '0'");
996
    my $sth = $result->sth;
997

            
998
    my $columns = $sth->{NAME};
999
    my $data_types = $sth->{TYPE};
1000
    
1001
    for (my $i = 0; $i < @$columns; $i++) {
1002
        my $column = $columns->[$i];
1003
        my $data_type = $data_types->[$i];
1004
        print "$column: $data_type\n";
1005
    }
1006
}
1007

            
1008
sub show_typename {
1009
    my ($self, $t) = @_;
1010
    croak "Table name must be specified" unless defined $t;
1011
    print "$t\n";
1012
    
1013
    $self->each_column(sub {
1014
        my ($self, $table, $column, $infos) = @_;
1015
        return unless $table eq $t;
1016
        my $typename = $infos->{TYPE_NAME};
1017
        print "$column: $typename\n";
1018
    });
1019
    
1020
    return $self;
1021
}
1022

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1023
sub show_tables {
1024
    my $self = shift;
1025
    
1026
    my %tables;
1027
    $self->each_table(sub { $tables{$_[1]}++ });
1028
    print join("\n", sort keys %tables) . "\n";
1029
    return $self;
1030
}
1031

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1032
sub type_rule {
1033
    my $self = shift;
1034
    
1035
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1036
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1037
        
1038
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1039
        foreach my $i (1 .. 2) {
1040
            my $into = "into$i";
1041
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1042
            $self->{type_rule} = $type_rule;
1043
            $self->{"_$into"} = {};
1044
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1045
                croak qq{type name of $into section must be lower case}
1046
                  if $type_name =~ /[A-Z]/;
1047
            }
1048
            $self->each_column(sub {
1049
                my ($dbi, $table, $column, $column_info) = @_;
1050
                
1051
                my $type_name = lc $column_info->{TYPE_NAME};
1052
                if ($type_rule->{$into} &&
1053
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1054
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1055
                    return unless exists $type_rule->{$into}->{$type_name};
1056
                    if  (defined $filter && ref $filter ne 'CODE') 
1057
                    {
1058
                        my $fname = $filter;
1059
                        croak qq{Filter "$fname" is not registered" } . _subname
1060
                          unless exists $self->filters->{$fname};
1061
                        
1062
                        $filter = $self->filters->{$fname};
1063
                    }
1064

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1065
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1066
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1067
                }
1068
            });
1069
        }
1070

            
1071
        # From
1072
        foreach my $i (1 .. 2) {
1073
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1074
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1075
                croak qq{data type of from$i section must be lower case or number}
1076
                  if $data_type =~ /[A-Z]/;
1077
                my $fname = $type_rule->{"from$i"}{$data_type};
1078
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1079
                    croak qq{Filter "$fname" is not registered" } . _subname
1080
                      unless exists $self->filters->{$fname};
1081
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1082
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1083
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1084
            }
1085
        }
1086
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1087
        return $self;
1088
    }
1089
    
1090
    return $self->{type_rule} || {};
1091
}
1092

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1096
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1097
    my $param;
1098
    $param = shift if @_ % 2;
1099
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1100
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1101
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1102
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1103
    my $p = delete $args{param} || {};
1104
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1105
    my $where = delete $args{where} || {};
1106
    my $where_param = delete $args{where_param} || {};
1107
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1108
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1109
    my $id = delete $args{id};
1110
    my $primary_key = delete $args{primary_key};
1111
    croak "update method primary_key option " .
1112
          "must be specified when id is specified " . _subname
1113
      if defined $id && !defined $primary_key;
1114
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1115
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1116

            
cleanup
yuki-kimoto authored on 2010-10-17
1117
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1118
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1119

            
1120
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1121
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1122
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1123
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1124
        $where_clause = "where " . $where->[0];
1125
        $where_param = $where->[1];
1126
    }
1127
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1128
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1129
        $where_param = keys %$where_param
1130
                     ? $self->merge_param($where_param, $where->param)
1131
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1132
        
1133
        # String where
1134
        $where_clause = $where->to_string;
1135
    }
1136
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1137
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1138
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1139
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1140
    # Merge param
1141
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1142
    
cleanup
Yuki Kimoto authored on 2011-04-02
1143
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1144
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1145
    push @sql, "update";
1146
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1147
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1148
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1149
    
cleanup
Yuki Kimoto authored on 2011-01-27
1150
    # SQL
1151
    my $sql = join(' ', @sql);
1152
    
cleanup
yuki-kimoto authored on 2010-10-17
1153
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1154
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1155
}
1156

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1159
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1160
    my ($self, $param, $opt) = @_;
1161
    
cleanup
Yuki Kimoto authored on 2011-04-02
1162
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1163
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1164
    $tag = "set $tag" unless $opt->{no_set};
1165

            
cleanup
Yuki Kimoto authored on 2011-04-02
1166
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1167
}
1168

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1171
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1172
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1173
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1174
    
updated pod
Yuki Kimoto authored on 2011-06-21
1175
    # Cache
1176
    my $cache = $self->cache;
1177
    
1178
    # Query
1179
    my $query;
1180
    
1181
    # Get cached query
1182
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1183
        
updated pod
Yuki Kimoto authored on 2011-06-21
1184
        # Get query
1185
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1186
        
updated pod
Yuki Kimoto authored on 2011-06-21
1187
        # Create query
1188
        if ($q) {
1189
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1190
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1191
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1192
    }
1193
    
1194
    # Create query
1195
    unless ($query) {
1196

            
1197
        # Create query
1198
        my $builder = $self->query_builder;
1199
        $query = $builder->build_query($source);
1200

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

            
1207
        # Save query to cache
1208
        $self->cache_method->(
1209
            $self, $source,
1210
            {
1211
                sql     => $query->sql, 
1212
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1213
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1214
            }
1215
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1216
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1217

            
1218
    # Filter SQL
1219
    if ($sqlfilter) {
1220
        my $sql = $query->sql;
1221
        $sql = $sqlfilter->($sql);
1222
        $query->sql($sql);
1223
    }
1224
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1225
    # Save sql
1226
    $self->last_sql($query->sql);
1227
    
updated pod
Yuki Kimoto authored on 2011-06-21
1228
    # Prepare statement handle
1229
    my $sth;
1230
    eval { $sth = $self->dbh->prepare($query->{sql})};
1231
    
1232
    if ($@) {
1233
        $self->_croak($@, qq{. Following SQL is executed.\n}
1234
                        . qq{$query->{sql}\n} . _subname);
1235
    }
1236
    
1237
    # Set statement handle
1238
    $query->sth($sth);
1239
    
1240
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1241
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1242
    
1243
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1244
}
1245

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

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1449
sub _quote {
1450
    my $self = shift;
1451
    
1452
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1453
         : defined $self->quote ? $self->quote
1454
         : '';
1455
}
1456

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

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

            
1489
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1490
}
1491

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

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

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

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

            
1628
# DEPRECATED!
1629
sub create_query {
1630
    warn "create_query is DEPRECATED! use query option of each method";
1631
    shift->_create_query(@_);
1632
}
1633

            
cleanup
Yuki Kimoto authored on 2011-06-13
1634
# DEPRECATED!
1635
sub apply_filter {
1636
    my $self = shift;
1637
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1638
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1639
    return $self->_apply_filter(@_);
1640
}
1641

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1642
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1643
our %SELECT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1644
sub select_at {
1645
    my ($self, %args) = @_;
1646

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1649
    # Arguments
1650
    my $primary_keys = delete $args{primary_key};
1651
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1652
    my $where = delete $args{where};
1653
    my $param = delete $args{param};
1654
    
1655
    # Check arguments
1656
    foreach my $name (keys %args) {
1657
        croak qq{"$name" is wrong option } . _subname
1658
          unless $SELECT_AT_ARGS{$name};
1659
    }
1660
    
1661
    # Table
1662
    croak qq{"table" option must be specified } . _subname
1663
      unless $args{table};
1664
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1665
    
1666
    # Create where parameter
1667
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1668
    
1669
    return $self->select(where => $where_param, %args);
1670
}
1671

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1672
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1673
our %DELETE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1674
sub delete_at {
1675
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1676

            
1677
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1678
    
1679
    # Arguments
1680
    my $primary_keys = delete $args{primary_key};
1681
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1682
    my $where = delete $args{where};
1683
    
1684
    # Check arguments
1685
    foreach my $name (keys %args) {
1686
        croak qq{"$name" is wrong option } . _subname
1687
          unless $DELETE_AT_ARGS{$name};
1688
    }
1689
    
1690
    # Create where parameter
1691
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1692
    
1693
    return $self->delete(where => $where_param, %args);
1694
}
1695

            
cleanup
Yuki Kimoto authored on 2011-06-08
1696
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1697
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1698
sub update_at {
1699
    my $self = shift;
1700

            
1701
    warn "update_at is DEPRECATED! use update and id option instead";
1702
    
1703
    # Arguments
1704
    my $param;
1705
    $param = shift if @_ % 2;
1706
    my %args = @_;
1707
    my $primary_keys = delete $args{primary_key};
1708
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1709
    my $where = delete $args{where};
1710
    my $p = delete $args{param} || {};
1711
    $param  ||= $p;
1712
    
1713
    # Check arguments
1714
    foreach my $name (keys %args) {
1715
        croak qq{"$name" is wrong option } . _subname
1716
          unless $UPDATE_AT_ARGS{$name};
1717
    }
1718
    
1719
    # Create where parameter
1720
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1721
    
1722
    return $self->update(where => $where_param, param => $param, %args);
1723
}
1724

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1725
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1726
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1727
sub insert_at {
1728
    my $self = shift;
1729
    
1730
    warn "insert_at is DEPRECATED! use insert and id option instead";
1731
    
1732
    # Arguments
1733
    my $param;
1734
    $param = shift if @_ % 2;
1735
    my %args = @_;
1736
    my $primary_key = delete $args{primary_key};
1737
    $primary_key = [$primary_key] unless ref $primary_key;
1738
    my $where = delete $args{where};
1739
    my $p = delete $args{param} || {};
1740
    $param  ||= $p;
1741
    
1742
    # Check arguments
1743
    foreach my $name (keys %args) {
1744
        croak qq{"$name" is wrong option } . _subname
1745
          unless $INSERT_AT_ARGS{$name};
1746
    }
1747
    
1748
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1749
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1750
    $param = $self->merge_param($where_param, $param);
1751
    
1752
    return $self->insert(param => $param, %args);
1753
}
1754

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

            
1768
# DEPRECATED!
1769
sub register_tag_processor {
1770
    my $self = shift;
1771
    warn "register_tag_processor is DEPRECATED!";
1772
    # Merge tag
1773
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1774
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1775
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1776
}
1777

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1778
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1779
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1780
has dbi_options => sub { {} };
1781
has filter_check  => 1;
1782
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1783

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

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

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

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1833
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1834
sub insert_param_tag {
1835
    warn "insert_param_tag is DEPRECATED! " .
1836
         "use insert_param instead!";
1837
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1838
}
1839

            
1840
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1841
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1842
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1843
         "use update_param instead";
1844
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1845
}
cleanup
Yuki Kimoto authored on 2011-03-08
1846
# DEPRECATED!
1847
sub _push_relation {
1848
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1849
    
1850
    if (keys %{$relation || {}}) {
1851
        push @$sql, $need_where ? 'where' : 'and';
1852
        foreach my $rcolumn (keys %$relation) {
1853
            my $table1 = (split (/\./, $rcolumn))[0];
1854
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1855
            push @$tables, ($table1, $table2);
1856
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1857
        }
1858
    }
1859
    pop @$sql if $sql->[-1] eq 'and';    
1860
}
1861

            
1862
# DEPRECATED!
1863
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1864
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1865
    
1866
    if (keys %{$relation || {}}) {
1867
        foreach my $rcolumn (keys %$relation) {
1868
            my $table1 = (split (/\./, $rcolumn))[0];
1869
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1870
            my $table1_exists;
1871
            my $table2_exists;
1872
            foreach my $table (@$tables) {
1873
                $table1_exists = 1 if $table eq $table1;
1874
                $table2_exists = 1 if $table eq $table2;
1875
            }
1876
            unshift @$tables, $table1 unless $table1_exists;
1877
            unshift @$tables, $table2 unless $table2_exists;
1878
        }
1879
    }
1880
}
1881

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1884
=head1 NAME
1885

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

            
1888
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1889

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1890
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1891
    
1892
    # Connect
1893
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1894
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1895
        user => 'ken',
1896
        password => '!LFKD%$&',
1897
        dbi_option => {mysql_enable_utf8 => 1}
1898
    );
cleanup
yuki-kimoto authored on 2010-08-05
1899

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1900
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1901
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1902
    
1903
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1904
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1905
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1906
    
1907
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1908
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1909

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1959
Named place holder support
1960

            
1961
=item *
1962

            
cleanup
Yuki Kimoto authored on 2011-07-29
1963
Model support
1964

            
1965
=item *
1966

            
1967
Connection manager support
1968

            
1969
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1970

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

            
1975
=item *
1976

            
1977
Filtering by data type or column name(EXPERIMENTAL)
1978

            
1979
=item *
1980

            
1981
Create C<order by> clause flexibly(EXPERIMENTAL)
1982

            
1983
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1984

            
cleanup
Yuki Kimoto authored on 2011-07-29
1985
=head1 DOCUMENTATIONS
pod fix
Yuki Kimoto authored on 2011-01-21
1986

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1992
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1993
L<DBIx::Custom::Result>,
1994
L<DBIx::Custom::Query>,
1995
L<DBIx::Custom::Where>,
1996
L<DBIx::Custom::Model>,
1997
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1998

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

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

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

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

            
2009
This is L<DBIx::Connector> example. Please pass
updated pod
Yuki Kimoto authored on 2011-06-21
2010
C<default_dbi_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2011

            
2012
    my $connector = DBIx::Connector->new(
2013
        "dbi:mysql:database=$DATABASE",
2014
        $USER,
2015
        $PASSWORD,
2016
        DBIx::Custom->new->default_dbi_option
2017
    );
2018
    
updated pod
Yuki Kimoto authored on 2011-06-21
2019
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2020

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

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

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
2028
=head2 C<dbi_option>
added dbi_options attribute
kimoto authored on 2010-12-20
2029

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
2030
    my $dbi_option = $dbi->dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2031
    $dbi = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2032

            
updated pod
Yuki Kimoto authored on 2011-06-21
2033
L<DBI> option, used when C<connect> method is executed.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2034
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2035

            
2036
=head2 C<default_dbi_option>
2037

            
2038
    my $default_dbi_option = $dbi->default_dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2039
    $dbi = $dbi->default_dbi_option($default_dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2040

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2044
    {
2045
        RaiseError => 1,
2046
        PrintError => 0,
2047
        AutoCommit => 1,
2048
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2049

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

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

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

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

            
2059
    my $last_sql = $dbi->last_sql;
2060
    $dbi = $dbi->last_sql($last_sql);
2061

            
2062
Get last successed SQL executed by C<execute> method.
2063

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2071
=head2 C<password>
2072

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2093
You can set quote pair.
2094

            
2095
    $dbi->quote('[]');
2096

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2106
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2107
    $dbi = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2108

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

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

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

            
2117
Separator whichi join table and column.
2118
This is used by C<column> and C<mycolumn> method.
2119

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2120
=head2 C<exclude_table EXPERIMENTAL>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2121

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2122
    my $exclude_table = $self->exclude_table;
2123
    $dbi = $self->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2124

            
2125
Regex matching system table.
2126
this regex match is used by C<each_table> method and C<each_column> method
2127
System table is ignored.
2128
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2129
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2130
The performance is up.
2131

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

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

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

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

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2147
=head2 C<user_column_info EXPERIMENTAL>
2148

            
2149
    my $user_column_info = $dbi->user_column_info;
2150
    $dbi = $dbi->user_column_info($user_column_info);
2151

            
2152
You can set the following data.
2153

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

            
2159
Usually, you can set return value of C<get_column_info>.
2160

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

            
2165
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2166
to find column info.
2167

            
added test
Yuki Kimoto authored on 2011-08-16
2168
=head2 C<user_table_info EXPERIMENTAL>
2169

            
2170
    my $user_table_info = $dbi->user_table_info;
2171
    $dbi = $dbi->user_table_info($user_table_info);
2172

            
2173
You can set the following data.
2174

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

            
2180
Usually, you can set return value of C<get_table_info>.
2181

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

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2194
=head2 C<available_datatype> EXPERIMENTAL
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2195

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2201
=head2 C<available_typename> EXPERIMENTAL
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2202

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2208
=head2 C<assign_param> EXPERIMENTAL
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2209

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2210
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2211

            
updated pod
Yuki Kimoto authored on 2011-06-09
2212
Create assign parameter.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2213

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2216
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2217

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

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

            
2222
Create column clause. The follwoing column clause is created.
2223

            
2224
    book.author as "book.author",
2225
    book.title as "book.title"
2226

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2229
    # Separator is double underbar
2230
    $dbi->separator('__');
2231
    
2232
    book.author as "book__author",
2233
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2234

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2256
=head2 create_model
2257

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2258
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2259
        table => 'book',
2260
        primary_key => 'id',
2261
        join => [
2262
            'inner join company on book.comparny_id = company.id'
2263
        ],
2264
    );
2265

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

            
2269
   $dbi->model('book')->select(...);
2270

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

            
2273
    my $dbh = $dbi->dbh;
2274

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

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

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

            
2282
Execute delete statement.
2283

            
2284
The following opitons are available.
2285

            
2286
=over 4
2287

            
2288
=item C<append>
2289

            
2290
Same as C<select> method's C<append> option.
2291

            
2292
=item C<filter>
2293

            
2294
Same as C<execute> method's C<filter> option.
2295

            
2296
=item C<id>
2297

            
2298
    id => 4
2299
    id => [4, 5]
2300

            
2301
ID corresponding to C<primary_key>.
2302
You can delete rows by C<id> and C<primary_key>.
2303

            
2304
    $dbi->delete(
2305
        parimary_key => ['id1', 'id2'],
2306
        id => [4, 5],
2307
        table => 'book',
2308
    );
2309

            
2310
The above is same as the followin one.
2311

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

            
2314
=item C<prefix>
2315

            
2316
    prefix => 'some'
2317

            
2318
prefix before table name section.
2319

            
2320
    delete some from book
2321

            
2322
=item C<query>
2323

            
2324
Same as C<execute> method's C<query> option.
2325

            
2326
=item C<sqlfilter EXPERIMENTAL>
2327

            
2328
Same as C<execute> method's C<sqlfilter> option.
2329

            
2330
=item C<table>
2331

            
2332
    table => 'book'
2333

            
2334
Table name.
2335

            
2336
=item C<where>
2337

            
2338
Same as C<select> method's C<where> option.
2339

            
2340
=item C<primary_key>
2341

            
2342
See C<id> option.
2343

            
2344
=item C<bind_type>
2345

            
2346
Same as C<execute> method's C<bind_type> option.
2347

            
2348
=item C<type_rule_off> EXPERIMENTAL
2349

            
2350
Same as C<execute> method's C<type_rule_off> option.
2351

            
2352
=item C<type_rule1_off> EXPERIMENTAL
2353

            
2354
    type_rule1_off => 1
2355

            
2356
Same as C<execute> method's C<type_rule1_off> option.
2357

            
2358
=item C<type_rule2_off> EXPERIMENTAL
2359

            
2360
    type_rule2_off => 1
2361

            
2362
Same as C<execute> method's C<type_rule2_off> option.
2363

            
2364
=back
2365

            
2366
=head2 C<delete_all>
2367

            
2368
    $dbi->delete_all(table => $table);
2369

            
2370
Execute delete statement for all rows.
2371
Options is same as C<delete>.
2372

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

            
2375
    $dbi->each_column(
2376
        sub {
2377
            my ($dbi, $table, $column, $column_info) = @_;
2378
            
2379
            my $type = $column_info->{TYPE_NAME};
2380
            
2381
            if ($type eq 'DATE') {
2382
                # ...
2383
            }
2384
        }
2385
    );
2386

            
2387
Iterate all column informations of all table from database.
2388
Argument is callback when one column is found.
2389
Callback receive four arguments, dbi object, table name,
2390
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2391

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

            
2394
    $dbi->each_table(
2395
        sub {
2396
            my ($dbi, $table, $table_info) = @_;
2397
            
2398
            my $table_name = $table_info->{TABLE_NAME};
2399
        }
2400
    );
2401

            
2402
Iterate all table informationsfrom database.
2403
Argument is callback when one table is found.
2404
Callback receive three arguments, dbi object, table name,
2405
table information.
2406

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2433
You can specify operator with named placeholder
2434
 by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2435

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

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

            
2446
    select * from where title = "aa\\:bb";
2447

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

            
2450
=over 4
2451

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

            
2454
Specify database bind data type.
2455

            
2456
    bind_type => [image => DBI::SQL_BLOB]
2457
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2458

            
2459
This is used to bind parameter by C<bind_param> of statment handle.
2460

            
2461
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2462

            
update pod
Yuki Kimoto authored on 2011-03-13
2463
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2464
    
2465
    filter => {
2466
        title  => sub { uc $_[0] }
2467
        author => sub { uc $_[0] }
2468
    }
update pod
Yuki Kimoto authored on 2011-03-13
2469

            
updated pod
Yuki Kimoto authored on 2011-06-09
2470
    # Filter name
2471
    filter => {
2472
        title  => 'upper_case',
2473
        author => 'upper_case'
2474
    }
2475
        
2476
    # At once
2477
    filter => [
2478
        [qw/title author/]  => sub { uc $_[0] }
2479
    ]
2480

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

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

            
2488
    query => 1
2489

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

            
2493
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2494
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2495
    my $columns = $query->columns;
2496
    
2497
If you want to execute SQL fast, you can do the following way.
2498

            
2499
    my $query;
2500
    foreach my $row (@$rows) {
2501
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2502
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2503
    }
2504

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

            
2508
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
2509
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2510
    
2511
    my $query;
2512
    my $sth;
2513
    foreach my $row (@$rows) {
2514
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2515
      $sth ||= $query->sth;
2516
      $sth->execute(map { $row->{$_} } sort keys %$row);
2517
    }
2518

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2523
=item C<sqlfilter EXPERIMENTAL> 
2524

            
2525
SQL filter function.
2526

            
2527
    sqlfilter => $code_ref
2528

            
2529
This option is generally for Oracle and SQL Server paging process.
2530
    
2531
    my $limit = sub {
2532
        my ($sql, $count, $offset) = @_;
2533
        
2534
        my $min = $offset + 1;
2535
        my $max = $offset + $count;
2536
        
2537
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2538
        
2539
        return $sql;
2540
    }
2541
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2542
        my $sql = shift;
2543
        return $limit->($sql, 100, 50);
2544
    })
2545

            
updated pod
Yuki Kimoto authored on 2011-06-09
2546
=item C<table>
2547
    
2548
    table => 'author'
2549

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2557
    # Same
2558
    $dbi->execute(
2559
      "select * from book where title = :book.title and author = :book.author",
2560
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2561

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2562
=item C<table_alias> EXPERIMENTAL
2563

            
2564
    table_alias => {user => 'hiker'}
2565

            
2566
Table alias. Key is real table name, value is alias table name.
2567
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2568
on alias table name.
2569

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2570
=item C<type_rule_off> EXPERIMENTAL
2571

            
2572
    type_rule_off => 1
2573

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

            
2576
=item C<type_rule1_off> EXPERIMENTAL
2577

            
2578
    type_rule1_off => 1
2579

            
2580
Turn C<into1> type rule off.
2581

            
2582
=item C<type_rule2_off> EXPERIMENTAL
2583

            
2584
    type_rule2_off => 1
2585

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2590
=head2 C<get_column_info EXPERIMENTAL>
2591

            
2592
    my $tables = $self->get_column_info(exclude_table => qr/^system_/);
2593

            
2594
get column infomation except for one which match C<exclude_table> pattern.
2595

            
2596
    [
2597
        {table => 'book', column => 'title', info => {...}},
2598
        {table => 'author', column => 'name' info => {...}}
2599
    ]
2600

            
added test
Yuki Kimoto authored on 2011-08-16
2601
=head2 C<get_table_info EXPERIMENTAL>
2602

            
2603
    my $tables = $self->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2604

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

            
2607
    [
2608
        {table => 'book', info => {...}},
2609
        {table => 'author', info => {...}}
2610
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2611

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2614
=head2 C<insert>
2615

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

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

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

            
2624
    {date => \"NOW()"}
2625

            
cleanup
Yuki Kimoto authored on 2011-06-09
2626
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2627

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2630
=item C<append>
2631

            
cleanup
Yuki Kimoto authored on 2011-06-09
2632
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2633

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

            
2636
Same as C<execute> method's C<bind_type> option.
2637

            
update pod
Yuki Kimoto authored on 2011-03-13
2638
=item C<filter>
2639

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2640
Same as C<execute> method's C<filter> option.
2641

            
2642
=item C<id>
2643

            
updated document
Yuki Kimoto authored on 2011-06-09
2644
    id => 4
2645
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2646

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2650
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2651
        {title => 'Perl', author => 'Ken'}
2652
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2653
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2654
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2655
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2656

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

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

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

            
2666
    prefix => 'or replace'
2667

            
2668
prefix before table name section
2669

            
2670
    insert or replace into book
2671

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2672
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2673

            
updated document
Yuki Kimoto authored on 2011-06-09
2674
    primary_key => 'id'
2675
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2676

            
updated document
Yuki Kimoto authored on 2011-06-09
2677
Primary key. This is used by C<id> option.
cleanup
Yuki Kimoto authored on 2011-06-09
2678

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

            
2681
Same as C<execute> method's C<query> option.
2682

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2683
=item C<sqlfilter EXPERIMENTAL>
2684

            
2685
Same as C<execute> method's C<sqlfilter> option.
2686

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

            
2689
    table => 'book'
2690

            
2691
Table name.
2692

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2693
=item C<type_rule_off> EXPERIMENTAL
2694

            
updated document
Yuki Kimoto authored on 2011-06-09
2695
Same as C<execute> method's C<type_rule_off> option.
update pod
Yuki Kimoto authored on 2011-03-13
2696

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2697
=item C<type_rule1_off> EXPERIMENTAL
2698

            
2699
    type_rule1_off => 1
2700

            
2701
Same as C<execute> method's C<type_rule1_off> option.
2702

            
2703
=item C<type_rule2_off> EXPERIMENTAL
2704

            
2705
    type_rule2_off => 1
2706

            
2707
Same as C<execute> method's C<type_rule2_off> option.
2708

            
update pod
Yuki Kimoto authored on 2011-03-13
2709
=back
2710

            
2711
=over 4
2712

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2713
=head2 C<insert_param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2714

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2715
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2716

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2717
Create insert parameters.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2718

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2719
    (title, author) values (title = :title, age = :age);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2720

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2728
    lib / MyModel.pm
2729
        / MyModel / book.pm
2730
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2731

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

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

            
2736
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2737
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2738
    
2739
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2740

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2745
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2746
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2747
    
2748
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2749

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2752
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2753
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2754
    
2755
    1;
2756
    
updated pod
Yuki Kimoto authored on 2011-06-21
2757
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2758

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

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

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
2766
=head2 C<map_param> EXPERIMENTAL
2767

            
2768
    my $map_param = $dbi->map_param(
2769
        {id => 1, authro => 'Ken', price => 1900},
2770
        'id' => 'book.id',
2771
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2772
        'price' => [
2773
            'book.price', {if => sub { length $_[0] }}
2774
        ]
2775
    );
2776

            
2777
Map paramters to other key and value. First argument is original
2778
parameter. this is hash reference. Rest argument is mapping.
2779
By default, Mapping is done if the value length is not zero.
2780

            
2781
=over 4
2782

            
2783
=item Key mapping
2784

            
2785
    'id' => 'book.id'
2786

            
2787
This is only key mapping. Value is same as original one.
2788

            
2789
    (id => 1) is mapped to ('book.id' => 1) if value length is not zero.
2790

            
2791
=item Key and value mapping
2792

            
2793
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2794

            
2795
This is key and value mapping. Frist element of array reference
2796
is mapped key name, second element is code reference to map the value.
2797

            
2798
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2799
      if value length is not zero.
2800

            
2801
=item Condition
2802

            
2803
    'price' => ['book.price', {if => 'exists'}]
2804
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2805
    'price' => ['book.price', {if => sub { defined shift }}]
2806

            
2807
If you need condition, you can sepecify it. this is code reference
2808
or 'exists'. By default, condition is the following one.
2809

            
2810
    sub { defined $_[0] && length $_[0] }
2811

            
2812
=back
2813

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

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

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2818
Merge parameters.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2819

            
2820
    {key1 => [1, 1], key2 => 2}
2821

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2822
=head2 C<method>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2823

            
2824
    $dbi->method(
2825
        update_or_insert => sub {
2826
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2827
            
2828
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2829
        },
2830
        find_or_create   => sub {
2831
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2832
            
2833
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2834
        }
2835
    );
2836

            
update pod
Yuki Kimoto authored on 2011-03-13
2837
Register method. These method is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2838

            
2839
    $dbi->update_or_insert;
2840
    $dbi->find_or_create;
2841

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

            
2844
    my $model = $dbi->model('book');
2845

            
updated pod
Yuki Kimoto authored on 2011-06-21
2846
Get a L<DBIx::Custom::Model> object,
update pod
Yuki Kimoto authored on 2011-03-13
2847

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

            
2850
    my $column = $self->mycolumn(book => ['author', 'title']);
2851

            
2852
Create column clause for myself. The follwoing column clause is created.
2853

            
2854
    book.author as author,
2855
    book.title as title
2856

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2859
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2860
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2861
        user => 'ken',
2862
        password => '!LFKD%$&',
2863
        dbi_option => {mysql_enable_utf8 => 1}
2864
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2865

            
2866
Create a new L<DBIx::Custom> object.
2867

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2872
DBIx::Custom::NotExists object, indicating the column is not exists.
2873
This is used by C<clause> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2874

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2875
=head2 C<order> EXPERIMENTAL
2876

            
2877
    my $order = $dbi->order;
2878

            
2879
Create a new L<DBIx::Custom::Order> object.
2880

            
cleanup
yuki-kimoto authored on 2010-10-17
2881
=head2 C<register_filter>
2882

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

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2898
=head2 C<type_rule> EXPERIMENTAL
2899

            
2900
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2901
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2902
            date => sub { ... },
2903
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2904
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2905
        into2 => {
2906
            date => sub { ... },
2907
            datetime => sub { ... }
2908
        },
2909
        from1 => {
2910
            # DATE
2911
            9 => sub { ... },
2912
            # DATETIME or TIMESTAMP
2913
            11 => sub { ... },
2914
        }
2915
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2916
            # DATE
2917
            9 => sub { ... },
2918
            # DATETIME or TIMESTAMP
2919
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2920
        }
2921
    );
2922

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2923
Filtering rule when data is send into and get from database.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2924
This has a little complex problem.
cleanup
Yuki Kimoto authored on 2011-06-13
2925

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2926
In C<into1> and C<into2> you can specify
2927
type name as same as type name defined
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2928
by create table, such as C<DATETIME> or C<DATE>.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2929

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2930
Note that type name and data type don't contain upper case.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2931
If these contain upper case charactor, you convert it to lower case.
2932

            
updated pod
Yuki Kimoto authored on 2011-06-21
2933
C<into2> is executed after C<into1>.
2934

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2935
Type rule of C<into1> and C<into2> is enabled on the following
2936
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2937

            
cleanup
Yuki Kimoto authored on 2011-06-13
2938
=over 4
2939

            
2940
=item 1. column name
2941

            
2942
    issue_date
2943
    issue_datetime
2944

            
updated pod
Yuki Kimoto authored on 2011-06-21
2945
This need C<table> option in each method.
2946

            
cleanup
Yuki Kimoto authored on 2011-06-13
2947
=item 2. table name and column name, separator is dot
2948

            
2949
    book.issue_date
2950
    book.issue_datetime
2951

            
2952
=back
2953

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2954
You get all type name used in database by C<available_typename>.
update pod
Yuki Kimoto authored on 2011-06-15
2955

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2956
    print $dbi->available_typename;
update pod
Yuki Kimoto authored on 2011-06-15
2957

            
updated pod
Yuki Kimoto authored on 2011-06-21
2958
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2959
C<from2> is executed after C<from1>.
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2960
You get all data type by C<available_datatype>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2961

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2964
You can also specify multiple types at once.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2965

            
2966
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2967
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2968
            [qw/DATE DATETIME/] => sub { ... },
2969
        ],
2970
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2971

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2974
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2975
        table  => 'book',
2976
        column => ['author', 'title'],
2977
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2978
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2979
    
updated document
Yuki Kimoto authored on 2011-06-09
2980
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2981

            
updated document
Yuki Kimoto authored on 2011-06-09
2982
The following opitons are available.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2983

            
2984
=over 4
2985

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2988
    append => 'order by title'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2989

            
updated document
Yuki Kimoto authored on 2011-06-09
2990
Append statement to last of SQL.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2991

            
2992
=item C<bind_type>
2993

            
2994
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2995
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2996
=item C<column>
2997
    
updated document
Yuki Kimoto authored on 2011-06-09
2998
    column => 'author'
2999
    column => ['author', 'title']
3000

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3009
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3010
        {book => [qw/author title/]},
3011
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3012
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3013

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

            
3016
    book.author as "book.author",
3017
    book.title as "book.title",
3018
    person.name as "person.name",
3019
    person.age as "person.age"
3020

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

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

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

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

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

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

            
3036
=item C<id>
3037

            
3038
    id => 4
3039
    id => [4, 5]
3040

            
3041
ID corresponding to C<primary_key>.
3042
You can select rows by C<id> and C<primary_key>.
3043

            
3044
    $dbi->select(
3045
        parimary_key => ['id1', 'id2'],
3046
        id => [4, 5],
3047
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3048
    );
3049

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3052
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3053
        where => {id1 => 4, id2 => 5},
3054
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3055
    );
3056
    
updated document
Yuki Kimoto authored on 2011-06-09
3057
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3058

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

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

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

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

            
3071
    prefix => 'SQL_CALC_FOUND_ROWS'
3072

            
3073
Prefix of column cluase
3074

            
3075
    select SQL_CALC_FOUND_ROWS title, author from book;
3076

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

            
3079
    join => [
3080
        'left outer join company on book.company_id = company_id',
3081
        'left outer join location on company.location_id = location.id'
3082
    ]
3083
        
3084
Join clause. If column cluase or where clause contain table name like "company.name",
3085
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3086

            
3087
    $dbi->select(
3088
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3089
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3090
        where => {'company.name' => 'Orange'},
3091
        join => [
3092
            'left outer join company on book.company_id = company.id',
3093
            'left outer join location on company.location_id = location.id'
3094
        ]
3095
    );
3096

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3100
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3101
    from book
3102
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3103
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3104

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3105
You can specify two table by yourself. This is useful when join parser can't parse
cleanup
Yuki Kimoto authored on 2011-07-28
3106
the join clause correctly. This is EXPERIMENTAL.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3107

            
3108
    $dbi->select(
3109
        table => 'book',
3110
        column => ['company.location_id as location_id'],
3111
        where => {'company.name' => 'Orange'},
3112
        join => [
3113
            {
3114
                clause => 'left outer join location on company.location_id = location.id',
3115
                table => ['company', 'location']
3116
            }
3117
        ]
3118
    );
3119

            
updated document
Yuki Kimoto authored on 2011-06-09
3120
=item C<primary_key>
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
3121

            
updated document
Yuki Kimoto authored on 2011-06-09
3122
    primary_key => 'id'
3123
    primary_key => ['id1', 'id2']
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
3124

            
updated document
Yuki Kimoto authored on 2011-06-09
3125
Primary key. This is used by C<id> option.
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
3126

            
updated document
Yuki Kimoto authored on 2011-06-09
3127
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-12
3128

            
updated document
Yuki Kimoto authored on 2011-06-09
3129
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-12
3130

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3131
=item C<sqlfilter EXPERIMENTAL>
updated pod
Yuki Kimoto authored on 2011-06-08
3132

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3133
Same as C<execute> method's C<sqlfilter> option
updated pod
Yuki Kimoto authored on 2011-06-08
3134

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3139
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3140

            
updated document
Yuki Kimoto authored on 2011-06-09
3141
=item C<type_rule_off> EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-08
3142

            
updated document
Yuki Kimoto authored on 2011-06-09
3143
Same as C<execute> method's C<type_rule_off> option.
updated pod
Yuki Kimoto authored on 2011-06-08
3144

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3145
=item C<type_rule1_off> EXPERIMENTAL
3146

            
3147
    type_rule1_off => 1
3148

            
3149
Same as C<execute> method's C<type_rule1_off> option.
3150

            
3151
=item C<type_rule2_off> EXPERIMENTAL
3152

            
3153
    type_rule2_off => 1
3154

            
3155
Same as C<execute> method's C<type_rule2_off> option.
3156

            
updated document
Yuki Kimoto authored on 2011-06-09
3157
=item C<where>
3158
    
3159
    # Hash refrence
3160
    where => {author => 'Ken', 'title' => 'Perl'}
3161
    
3162
    # DBIx::Custom::Where object
3163
    where => $dbi->where(
3164
        clause => ['and', 'author = :author', 'title like :title'],
3165
        param  => {author => 'Ken', title => '%Perl%'}
3166
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3167
    
3168
    # Array reference 1 (array reference, hash referenc). same as above
3169
    where => [
3170
        ['and', 'author = :author', 'title like :title'],
3171
        {author => 'Ken', title => '%Perl%'}
3172
    ];    
3173
    
3174
    # Array reference 2 (String, hash reference)
3175
    where => [
3176
        'title like :title',
3177
        {title => '%Perl%'}
3178
    ]
3179
    
3180
    # String
3181
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3182

            
updated document
Yuki Kimoto authored on 2011-06-09
3183
Where clause.
3184
    
improved pod
Yuki Kimoto authored on 2011-04-19
3185
=item C<wrap> EXPERIMENTAL
3186

            
3187
Wrap statement. This is array reference.
3188

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3189
    wrap => ['select * from (', ') as t where ROWNUM < 10']
improved pod
Yuki Kimoto authored on 2011-04-19
3190

            
3191
This option is for Oracle and SQL Server paging process.
3192

            
update pod
Yuki Kimoto authored on 2011-03-12
3193
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3194

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3206
The following opitons are available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3207

            
update pod
Yuki Kimoto authored on 2011-03-13
3208
=over 4
3209

            
updated document
Yuki Kimoto authored on 2011-06-09
3210
=item C<append>
update pod
Yuki Kimoto authored on 2011-03-13
3211

            
updated document
Yuki Kimoto authored on 2011-06-09
3212
Same as C<select> method's C<append> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3213

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

            
3216
Same as C<execute> method's C<bind_type> option.
3217

            
updated document
Yuki Kimoto authored on 2011-06-09
3218
=item C<filter>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3219

            
updated document
Yuki Kimoto authored on 2011-06-09
3220
Same as C<execute> method's C<filter> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3221

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3224
    id => 4
3225
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3226

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3230
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3231
        {title => 'Perl', author => 'Ken'}
3232
        parimary_key => ['id1', 'id2'],
3233
        id => [4, 5],
3234
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3235
    );
update pod
Yuki Kimoto authored on 2011-03-13
3236

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3239
    $dbi->update(
3240
        {title => 'Perl', author => 'Ken'}
3241
        where => {id1 => 4, id2 => 5},
3242
        table => 'book'
3243
    );
update pod
Yuki Kimoto authored on 2011-03-13
3244

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

            
3247
    prefix => 'or replace'
3248

            
3249
prefix before table name section
3250

            
3251
    update or replace book
3252

            
updated document
Yuki Kimoto authored on 2011-06-09
3253
=item C<primary_key>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
3254

            
updated document
Yuki Kimoto authored on 2011-06-09
3255
    primary_key => 'id'
3256
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
3257

            
updated document
Yuki Kimoto authored on 2011-06-09
3258
Primary key. This is used by C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
3259

            
updated document
Yuki Kimoto authored on 2011-06-09
3260
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
3261

            
updated document
Yuki Kimoto authored on 2011-06-09
3262
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-13
3263

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3264
=item C<sqlfilter EXPERIMENTAL>
3265

            
3266
Same as C<execute> method's C<sqlfilter> option.
3267

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

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3274
=item C<type_rule_off> EXPERIMENTAL
3275

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3276
Same as C<execute> method's C<type_rule_off> option.
3277

            
3278
=item C<type_rule1_off> EXPERIMENTAL
3279

            
3280
    type_rule1_off => 1
3281

            
3282
Same as C<execute> method's C<type_rule1_off> option.
3283

            
3284
=item C<type_rule2_off> EXPERIMENTAL
3285

            
3286
    type_rule2_off => 1
3287

            
3288
Same as C<execute> method's C<type_rule2_off> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3289

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

            
3292
Same as C<select> method's C<where> option.
3293

            
updated pod
Yuki Kimoto authored on 2011-06-08
3294
=back
update pod
Yuki Kimoto authored on 2011-03-13
3295

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3303
=head2 C<update_param>
update pod
Yuki Kimoto authored on 2011-03-13
3304

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3305
    my $update_param = $dbi->update_param({title => 'a', age => 2});
update pod
Yuki Kimoto authored on 2011-03-13
3306

            
3307
Create update parameter tag.
3308

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3309
    set title = :title, author = :author
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
3310

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
3311
=head2 C<where>
fix tests
Yuki Kimoto authored on 2011-01-18
3312

            
cleanup
Yuki Kimoto authored on 2011-03-09
3313
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3314
        clause => ['and', 'title = :title', 'author = :author'],
cleanup
Yuki Kimoto authored on 2011-03-09
3315
        param => {title => 'Perl', author => 'Ken'}
3316
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3317

            
3318
Create a new L<DBIx::Custom::Where> object.
3319

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
3320
=head2 C<setup_model>
cleanup
Yuki Kimoto authored on 2011-01-12
3321

            
update pod
Yuki Kimoto authored on 2011-03-13
3322
    $dbi->setup_model;
cleanup
Yuki Kimoto authored on 2011-01-12
3323

            
update pod
Yuki Kimoto authored on 2011-03-13
3324
Setup all model objects.
update pod
Yuki Kimoto authored on 2011-03-13
3325
C<columns> of model object is automatically set, parsing database information.
cleanup
Yuki Kimoto authored on 2011-01-12
3326

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
3327
=head1 ENVIRONMENT VARIABLE
3328

            
3329
=head2 C<DBIX_CUSTOM_DEBUG>
3330

            
3331
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
improved debug message
Yuki Kimoto authored on 2011-05-23
3332
executed SQL and bind values are printed to STDERR.
3333

            
update pod
Yuki Kimoto authored on 2011-08-10
3334
=head2 C<show_datatype EXPERIMENTAL>
3335

            
3336
    $dbi->show_datatype($table);
3337

            
3338
Show data type of the columns of specified table.
3339

            
3340
    book
3341
    title: 5
3342
    issue_date: 91
3343

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
3346
=head2 C<show_tables EXPERIMETNAL>
3347

            
3348
    $dbi->show_tables;
3349

            
3350
Show tables.
3351

            
update pod
Yuki Kimoto authored on 2011-08-10
3352
=head2 C<show_typename EXPERIMENTAL>
3353

            
3354
    $dbi->show_typename($table);
3355

            
3356
Show type name of the columns of specified table.
3357

            
3358
    book
3359
    title: varchar
3360
    issue_date: date
3361

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

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

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3368
=head1 DEPRECATED FUNCTIONALITIES
3369

            
3370
L<DBIx::Custom>
3371

            
3372
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3373
    data_source # will be removed at 2017/1/1
3374
    dbi_options # will be removed at 2017/1/1
3375
    filter_check # will be removed at 2017/1/1
3376
    reserved_word_quote # will be removed at 2017/1/1
3377
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3378
    
3379
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3380
    create_query # will be removed at 2017/1/1
3381
    apply_filter # will be removed at 2017/1/1
3382
    select_at # will be removed at 2017/1/1
3383
    delete_at # will be removed at 2017/1/1
3384
    update_at # will be removed at 2017/1/1
3385
    insert_at # will be removed at 2017/1/1
3386
    register_tag # will be removed at 2017/1/1
3387
    default_bind_filter # will be removed at 2017/1/1
3388
    default_fetch_filter # will be removed at 2017/1/1
3389
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3390
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3391
    register_tag_processor # will be removed at 2017/1/1
3392
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3393
    
3394
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3395
    select method relation option # will be removed at 2017/1/1
3396
    select method param option # will be removed at 2017/1/1
3397
    select method column option [COLUMN, as => ALIAS] format
3398
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3399
    
3400
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3401
    execute("select * from {= title}"); # execute method's
3402
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3403
                                        # will be removed at 2017/1/1
3404
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3405

            
3406
L<DBIx::Custom::Model>
3407

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3408
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3409
    filter # will be removed at 2017/1/1
3410
    name # will be removed at 2017/1/1
3411
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3412

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

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

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

            
3448
L<DBIx::Custom::Tag>
3449

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

            
3452
=head1 BACKWORD COMPATIBLE POLICY
3453

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

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3463
This policy was changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3464

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

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

            
3469
C<< <kimoto.yuki at gmail.com> >>
3470

            
3471
L<http://github.com/yuki-kimoto/DBIx-Custom>
3472

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3473
=head1 AUTHOR
3474

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

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

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

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

            
3484
=cut