DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3522 lines | 91.616kb
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-08-16
167
    my $self = ref $_[0] ? shift : shift->new(@_);
168
    
169
    my $connector = $self->connector;
170
    
171
    if (!ref $connector && $connector) {
172
        require DBIx::Connector;
173
        
174
        my $dsn = $self->dsn;
175
        my $user = $self->user;
176
        my $password = $self->password;
177
        my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
178
        my $connector = DBIx::Connector->new($dsn, $user, $password,
179
          {%{$self->default_dbi_option} , %$dbi_option});
180
        $self->connector($connector);
181
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
182
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
183
    # Connect
184
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
185
    
packaging one directory
yuki-kimoto authored on 2009-11-16
186
    return $self;
187
}
188

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

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

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

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
231
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
232
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
233
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
234
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
235
    my $where            = delete $args{where} || {};
236
    my $append           = delete $args{append};
237
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
238
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
239
    my $id = delete $args{id};
240
    my $primary_key = delete $args{primary_key};
241
    croak "update method primary_key option " .
242
          "must be specified when id is specified " . _subname
243
      if defined $id && !defined $primary_key;
244
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
245
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
246
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
247
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
248
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
249
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
250
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
251
        $where_clause = "where " . $where->[0];
252
        $where_param = $where->[1];
253
    }
254
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
255
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
256
        $where_param = keys %$where_param
257
                     ? $self->merge_param($where_param, $where->param)
258
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
259
        
260
        # String where
261
        $where_clause = $where->to_string;
262
    }
263
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
264
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
265
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
266

            
cleanup
Yuki Kimoto authored on 2011-04-02
267
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
268
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
269
    push @sql, "delete";
270
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
271
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
272
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
273
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
274
    
275
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
276
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
277
}
278

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
283
sub create_model {
284
    my $self = shift;
285
    
cleanup
Yuki Kimoto authored on 2011-04-02
286
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
287
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
288
    $args->{dbi} = $self;
289
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
290
    my $model_name  = delete $args->{name};
291
    my $model_table = delete $args->{table};
292
    $model_name ||= $model_table;
293
    
cleanup
Yuki Kimoto authored on 2011-04-02
294
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
295
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
296
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
297
    $model->name($model_name) unless $model->name;
298
    $model->table($model_table) unless $model->table;
299
    
micro optimization
Yuki Kimoto authored on 2011-07-30
300
    # Apply filter(DEPRECATED logic)
301
    if ($model->{filter}) {
302
        my $filter = ref $model->filter eq 'HASH'
303
                   ? [%{$model->filter}]
304
                   : $model->filter;
305
        $filter ||= [];
306
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
307
          if @$filter;
308
        $self->_apply_filter($model->table, @$filter);
309
    }
310
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
311
    # Set model
312
    $self->model($model->name, $model);
313
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
314
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
315
}
316

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
320
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
321
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
322
    if ($user_column_info) {
323
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
324
    }
325
    else {
326
    
327
        my $re = $self->exclude_table || $options{exclude_table};
328
        # Tables
329
        my %tables;
330
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
331

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
332
        # Iterate all tables
333
        my @tables = sort keys %tables;
334
        for (my $i = 0; $i < @tables; $i++) {
335
            my $table = $tables[$i];
336
            
337
            # Iterate all columns
338
            my $sth_columns;
339
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
340
            next if $@;
341
            while (my $column_info = $sth_columns->fetchrow_hashref) {
342
                my $column = $column_info->{COLUMN_NAME};
343
                $self->$cb($table, $column, $column_info);
344
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
345
        }
346
    }
347
}
348

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
349
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
350
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
351
    
cleanup test
Yuki Kimoto authored on 2011-08-16
352
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
353
    
added test
Yuki Kimoto authored on 2011-08-16
354
    # Iterate tables
355
    if ($user_table_infos) {
356
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
357
    }
358
    else {
359
        my $re = $self->exclude_table || $option{exclude};
360
        my $sth_tables = $self->dbh->table_info;
361
        while (my $table_info = $sth_tables->fetchrow_hashref) {
362
            
363
            # Table
364
            my $table = $table_info->{TABLE_NAME};
365
            next if defined $re && $table =~ /$re/;
366
            $self->$cb($table, $table_info);
367
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
368
    }
369
}
370

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

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

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

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

            
542
        return $result;
543
    }
cleanup
Yuki Kimoto authored on 2011-04-02
544
    
545
    # Not select statement
546
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
547
}
548

            
added test
Yuki Kimoto authored on 2011-08-16
549
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
550
    my ($self, %args) = @_;
551
    
552
    my $exclude = delete $args{exclude};
553
    croak qq/"$_" is wrong option/ for keys %args;
554
    
added test
Yuki Kimoto authored on 2011-08-16
555
    my $table_info = [];
556
    $self->each_table(
557
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
558
        exclude => $exclude
559
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
560
    
cleanup test
Yuki Kimoto authored on 2011-08-16
561
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
562
}
563

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
564
sub get_column_info {
565
    my ($self, %args) = @_;
566
    
567
    my $exclude_table = delete $args{exclude_table};
568
    croak qq/"$_" is wrong option/ for keys %args;
569
    
570
    my $column_info = [];
571
    $self->each_column(
572
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
573
        exclude_table => $exclude_table
574
    );
575
    
576
    return [
577
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
578
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
579
}
580

            
cleanup
yuki-kimoto authored on 2010-10-17
581
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
582
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
583
    
cleanup
yuki-kimoto authored on 2010-10-17
584
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
585
    my $param;
586
    $param = shift if @_ % 2;
587
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
588
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
589
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
590
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
591
    my $p = delete $args{param} || {};
592
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
593
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
594
    my $id = delete $args{id};
595
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
596
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
597
          "must be specified when id is specified " . _subname
598
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
599
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
600
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
601

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
602
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
603
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
604
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
605
        $param = $self->merge_param($id_param, $param);
606
    }
607

            
cleanup
Yuki Kimoto authored on 2011-04-02
608
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
609
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
610
    push @sql, "insert";
611
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
612
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
613
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
614
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
615
    
616
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
617
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
618
}
619

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
620
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
621
    my ($self, $param) = @_;
622
    
cleanup
Yuki Kimoto authored on 2011-04-02
623
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
624
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
625
    my @columns;
626
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
627
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
628
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
629
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
630
        my $column_quote = $self->_q($column);
631
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
632
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
633
        push @placeholders, ref $param->{$column} eq 'SCALAR'
634
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
635
    }
636
    
cleanup
Yuki Kimoto authored on 2011-04-02
637
    return '(' . join(', ', @columns) . ') ' . 'values ' .
638
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
639
}
640

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
641
sub include_model {
642
    my ($self, $name_space, $model_infos) = @_;
643
    
cleanup
Yuki Kimoto authored on 2011-04-02
644
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
645
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
646
    
647
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
648
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
649

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
706
sub map_param {
707
    my $self = shift;
708
    my $param = shift;
709
    my %map = @_;
710
    
711
    # Mapping
712
    my $map_param = {};
713
    foreach my $key (keys %map) {
714
        my $value_cb;
715
        my $condition;
716
        my $map_key;
717
        
718
        # Get mapping information
719
        if (ref $map{$key} eq 'ARRAY') {
720
            foreach my $some (@{$map{$key}}) {
721
                $map_key = $some unless ref $some;
722
                $condition = $some->{if} if ref $some eq 'HASH';
723
                $value_cb = $some if ref $some eq 'CODE';
724
            }
725
        }
726
        else {
727
            $map_key = $map{$key};
728
        }
729
        $value_cb ||= sub { $_[0] };
730
        $condition ||= sub { defined $_[0] && length $_[0] };
731

            
732
        # Map parameter
733
        my $value;
734
        if (ref $condition eq 'CODE') {
735
            $map_param->{$map_key} = $value_cb->($param->{$key})
736
              if $condition->($param->{$key});
737
        }
738
        elsif ($condition eq 'exists') {
739
            $map_param->{$map_key} = $value_cb->($param->{$key})
740
              if exists $param->{$key};
741
        }
742
        else { croak qq/Condition must be code reference or "exists" / . _subname }
743
    }
744
    
745
    return $map_param;
746
}
747

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
748
sub merge_param {
749
    my ($self, @params) = @_;
750
    
cleanup
Yuki Kimoto authored on 2011-04-02
751
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
752
    my $merge = {};
753
    foreach my $param (@params) {
754
        foreach my $column (keys %$param) {
755
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
756
            
757
            if (exists $merge->{$column}) {
758
                $merge->{$column} = [$merge->{$column}]
759
                  unless ref $merge->{$column} eq 'ARRAY';
760
                push @{$merge->{$column}},
761
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
762
            }
763
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
764
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
765
            }
766
        }
767
    }
768
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
769
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
770
}
771

            
cleanup
Yuki Kimoto authored on 2011-03-21
772
sub method {
773
    my $self = shift;
774
    
cleanup
Yuki Kimoto authored on 2011-04-02
775
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
776
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
777
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
778
    
779
    return $self;
780
}
781

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
782
sub model {
783
    my ($self, $name, $model) = @_;
784
    
cleanup
Yuki Kimoto authored on 2011-04-02
785
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
786
    if ($model) {
787
        $self->models->{$name} = $model;
788
        return $self;
789
    }
790
    
791
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
792
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
793
      unless $self->models->{$name};
794
    
cleanup
Yuki Kimoto authored on 2011-04-02
795
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
796
    return $self->models->{$name};
797
}
798

            
cleanup
Yuki Kimoto authored on 2011-03-21
799
sub mycolumn {
800
    my ($self, $table, $columns) = @_;
801
    
cleanup
Yuki Kimoto authored on 2011-04-02
802
    # Create column clause
803
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
804
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
805
    push @column, $self->_q($table) . "." . $self->_q($_) .
806
      " as " . $self->_q($_)
807
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
808
    
809
    return join (', ', @column);
810
}
811

            
added dbi_options attribute
kimoto authored on 2010-12-20
812
sub new {
813
    my $self = shift->SUPER::new(@_);
814
    
cleanup
Yuki Kimoto authored on 2011-04-02
815
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
816
    my @attrs = keys %$self;
817
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
818
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
819
          unless $self->can($attr);
820
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
821

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
822
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
823
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
824
        '?'     => \&DBIx::Custom::Tag::placeholder,
825
        '='     => \&DBIx::Custom::Tag::equal,
826
        '<>'    => \&DBIx::Custom::Tag::not_equal,
827
        '>'     => \&DBIx::Custom::Tag::greater_than,
828
        '<'     => \&DBIx::Custom::Tag::lower_than,
829
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
830
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
831
        'like'  => \&DBIx::Custom::Tag::like,
832
        'in'    => \&DBIx::Custom::Tag::in,
833
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
834
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
835
    };
836
    
837
    return $self;
838
}
839

            
840
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
841
sub not_exists { $not_exists }
842

            
843
sub order {
844
    my $self = shift;
845
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
846
}
847

            
cleanup
yuki-kimoto authored on 2010-10-17
848
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
849
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
850
    
851
    # Register filter
852
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
853
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
854
    
cleanup
Yuki Kimoto authored on 2011-04-02
855
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
856
}
packaging one directory
yuki-kimoto authored on 2009-11-16
857

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
991
sub setup_model {
992
    my $self = shift;
993
    
cleanup
Yuki Kimoto authored on 2011-04-02
994
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
995
    $self->each_column(
996
        sub {
997
            my ($self, $table, $column, $column_info) = @_;
998
            if (my $model = $self->models->{$table}) {
999
                push @{$model->columns}, $column;
1000
            }
1001
        }
1002
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1003
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1004
}
1005

            
update pod
Yuki Kimoto authored on 2011-08-10
1006
sub show_datatype {
1007
    my ($self, $table) = @_;
1008
    croak "Table name must be specified" unless defined $table;
1009
    print "$table\n";
1010
    
1011
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1012
    my $sth = $result->sth;
1013

            
1014
    my $columns = $sth->{NAME};
1015
    my $data_types = $sth->{TYPE};
1016
    
1017
    for (my $i = 0; $i < @$columns; $i++) {
1018
        my $column = $columns->[$i];
1019
        my $data_type = $data_types->[$i];
1020
        print "$column: $data_type\n";
1021
    }
1022
}
1023

            
1024
sub show_typename {
1025
    my ($self, $t) = @_;
1026
    croak "Table name must be specified" unless defined $t;
1027
    print "$t\n";
1028
    
1029
    $self->each_column(sub {
1030
        my ($self, $table, $column, $infos) = @_;
1031
        return unless $table eq $t;
1032
        my $typename = $infos->{TYPE_NAME};
1033
        print "$column: $typename\n";
1034
    });
1035
    
1036
    return $self;
1037
}
1038

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1039
sub show_tables {
1040
    my $self = shift;
1041
    
1042
    my %tables;
1043
    $self->each_table(sub { $tables{$_[1]}++ });
1044
    print join("\n", sort keys %tables) . "\n";
1045
    return $self;
1046
}
1047

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1048
sub type_rule {
1049
    my $self = shift;
1050
    
1051
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1052
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1053
        
1054
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1055
        foreach my $i (1 .. 2) {
1056
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1057
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1058
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1059
            $self->{type_rule} = $type_rule;
1060
            $self->{"_$into"} = {};
1061
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1062
                croak qq{type name of $into section must be lower case}
1063
                  if $type_name =~ /[A-Z]/;
1064
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1065
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1066
            $self->each_column(sub {
1067
                my ($dbi, $table, $column, $column_info) = @_;
1068
                
1069
                my $type_name = lc $column_info->{TYPE_NAME};
1070
                if ($type_rule->{$into} &&
1071
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1072
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1073
                    return unless exists $type_rule->{$into}->{$type_name};
1074
                    if  (defined $filter && ref $filter ne 'CODE') 
1075
                    {
1076
                        my $fname = $filter;
1077
                        croak qq{Filter "$fname" is not registered" } . _subname
1078
                          unless exists $self->filters->{$fname};
1079
                        
1080
                        $filter = $self->filters->{$fname};
1081
                    }
1082

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1083
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1084
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1085
                }
1086
            });
1087
        }
1088

            
1089
        # From
1090
        foreach my $i (1 .. 2) {
1091
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1092
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1093
                croak qq{data type of from$i section must be lower case or number}
1094
                  if $data_type =~ /[A-Z]/;
1095
                my $fname = $type_rule->{"from$i"}{$data_type};
1096
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1097
                    croak qq{Filter "$fname" is not registered" } . _subname
1098
                      unless exists $self->filters->{$fname};
1099
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1100
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1101
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1102
            }
1103
        }
1104
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1105
        return $self;
1106
    }
1107
    
1108
    return $self->{type_rule} || {};
1109
}
1110

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1114
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1115
    my $param;
1116
    $param = shift if @_ % 2;
1117
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1118
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1119
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1120
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1121
    my $p = delete $args{param} || {};
1122
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1123
    my $where = delete $args{where} || {};
1124
    my $where_param = delete $args{where_param} || {};
1125
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1126
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1127
    my $id = delete $args{id};
1128
    my $primary_key = delete $args{primary_key};
1129
    croak "update method primary_key option " .
1130
          "must be specified when id is specified " . _subname
1131
      if defined $id && !defined $primary_key;
1132
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1133
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1134

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

            
1138
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1139
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1140
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1141
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1142
        $where_clause = "where " . $where->[0];
1143
        $where_param = $where->[1];
1144
    }
1145
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1146
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1147
        $where_param = keys %$where_param
1148
                     ? $self->merge_param($where_param, $where->param)
1149
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1150
        
1151
        # String where
1152
        $where_clause = $where->to_string;
1153
    }
1154
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1155
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1156
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1157
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1158
    # Merge param
1159
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1160
    
cleanup
Yuki Kimoto authored on 2011-04-02
1161
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1162
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1163
    push @sql, "update";
1164
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1165
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1166
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1167
    
cleanup
Yuki Kimoto authored on 2011-01-27
1168
    # SQL
1169
    my $sql = join(' ', @sql);
1170
    
cleanup
yuki-kimoto authored on 2010-10-17
1171
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1172
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1173
}
1174

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1177
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1178
    my ($self, $param, $opt) = @_;
1179
    
cleanup
Yuki Kimoto authored on 2011-04-02
1180
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1181
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1182
    $tag = "set $tag" unless $opt->{no_set};
1183

            
cleanup
Yuki Kimoto authored on 2011-04-02
1184
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1185
}
1186

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1189
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1190
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1191
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1192
    
updated pod
Yuki Kimoto authored on 2011-06-21
1193
    # Cache
1194
    my $cache = $self->cache;
1195
    
1196
    # Query
1197
    my $query;
1198
    
1199
    # Get cached query
1200
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1201
        
updated pod
Yuki Kimoto authored on 2011-06-21
1202
        # Get query
1203
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1204
        
updated pod
Yuki Kimoto authored on 2011-06-21
1205
        # Create query
1206
        if ($q) {
1207
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1208
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1209
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1210
    }
1211
    
1212
    # Create query
1213
    unless ($query) {
1214

            
1215
        # Create query
1216
        my $builder = $self->query_builder;
1217
        $query = $builder->build_query($source);
1218

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

            
1225
        # Save query to cache
1226
        $self->cache_method->(
1227
            $self, $source,
1228
            {
1229
                sql     => $query->sql, 
1230
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1231
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1232
            }
1233
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1234
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1235

            
1236
    # Filter SQL
1237
    if ($sqlfilter) {
1238
        my $sql = $query->sql;
1239
        $sql = $sqlfilter->($sql);
1240
        $query->sql($sql);
1241
    }
1242
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1243
    # Save sql
1244
    $self->last_sql($query->sql);
1245
    
updated pod
Yuki Kimoto authored on 2011-06-21
1246
    # Prepare statement handle
1247
    my $sth;
1248
    eval { $sth = $self->dbh->prepare($query->{sql})};
1249
    
1250
    if ($@) {
1251
        $self->_croak($@, qq{. Following SQL is executed.\n}
1252
                        . qq{$query->{sql}\n} . _subname);
1253
    }
1254
    
1255
    # Set statement handle
1256
    $query->sth($sth);
1257
    
1258
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1259
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1260
    
1261
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1262
}
1263

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1314
sub _create_param_from_id {
1315
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1316
    
cleanup
Yuki Kimoto authored on 2011-06-08
1317
    # Create parameter
1318
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1319
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1320
        $id = [$id] unless ref $id;
1321
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1322
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1323
          unless !ref $id || ref $id eq 'ARRAY';
1324
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1325
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1326
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1327
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1328
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1329
        }
1330
    }
1331
    
cleanup
Yuki Kimoto authored on 2011-06-08
1332
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1333
}
1334

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1335
sub _connect {
1336
    my $self = shift;
1337
    
1338
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1339
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1340
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1341
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1342
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1343
    croak qq{"dsn" must be specified } . _subname
1344
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1345
    my $user        = $self->user;
1346
    my $password    = $self->password;
1347
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1348
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1349
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1350
    
cleanup
Yuki Kimoto authored on 2011-08-16
1351
    $dbi_option = {%{$self->default_dbi_option}, %$dbi_option};
1352
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1353
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1354
    my $dbh;
1355
    eval {
1356
        $dbh = DBI->connect(
1357
            $dsn,
1358
            $user,
1359
            $password,
1360
            $dbi_option
1361
        );
1362
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1363
    
1364
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1365
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1366
    
1367
    return $dbh;
1368
}
1369

            
cleanup
yuki-kimoto authored on 2010-10-17
1370
sub _croak {
1371
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1372
    
1373
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1374
    $append ||= "";
1375
    
1376
    # Verbose
1377
    if ($Carp::Verbose) { croak $error }
1378
    
1379
    # Not verbose
1380
    else {
1381
        
1382
        # Remove line and module infromation
1383
        my $at_pos = rindex($error, ' at ');
1384
        $error = substr($error, 0, $at_pos);
1385
        $error =~ s/\s+$//;
1386
        croak "$error$append";
1387
    }
1388
}
1389

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1392
sub _need_tables {
1393
    my ($self, $tree, $need_tables, $tables) = @_;
1394
    
cleanup
Yuki Kimoto authored on 2011-04-02
1395
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1396
    foreach my $table (@$tables) {
1397
        if ($tree->{$table}) {
1398
            $need_tables->{$table} = 1;
1399
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1400
        }
1401
    }
1402
}
1403

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1404
sub _push_join {
1405
    my ($self, $sql, $join, $join_tables) = @_;
1406
    
cleanup
Yuki Kimoto authored on 2011-04-02
1407
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1408
    return unless @$join;
1409
    
cleanup
Yuki Kimoto authored on 2011-04-02
1410
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1411
    my $tree = {};
1412
    for (my $i = 0; $i < @$join; $i++) {
1413
        
cleanup
Yuki Kimoto authored on 2011-07-28
1414
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1415
        my $join_clause;;
1416
        my $option;
1417
        if (ref $join->[$i] eq 'HASH') {
1418
            $join_clause = $join->[$i]->{clause};
1419
            $option = {table => $join->[$i]->{table}};
1420
        }
1421
        else {
1422
            $join_clause = $join->[$i];
1423
            $option = {};
1424
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1425

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1469
sub _quote {
1470
    my $self = shift;
1471
    
1472
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1473
         : defined $self->quote ? $self->quote
1474
         : '';
1475
}
1476

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

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

            
1509
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1510
}
1511

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

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

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

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

            
1648
# DEPRECATED!
1649
sub create_query {
1650
    warn "create_query is DEPRECATED! use query option of each method";
1651
    shift->_create_query(@_);
1652
}
1653

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

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1669
    # Arguments
1670
    my $primary_keys = delete $args{primary_key};
1671
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1672
    my $where = delete $args{where};
1673
    my $param = delete $args{param};
1674
    
1675
    # Check arguments
1676
    foreach my $name (keys %args) {
1677
        croak qq{"$name" is wrong option } . _subname
1678
          unless $SELECT_AT_ARGS{$name};
1679
    }
1680
    
1681
    # Table
1682
    croak qq{"table" option must be specified } . _subname
1683
      unless $args{table};
1684
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1685
    
1686
    # Create where parameter
1687
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1688
    
1689
    return $self->select(where => $where_param, %args);
1690
}
1691

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

            
1697
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1698
    
1699
    # Arguments
1700
    my $primary_keys = delete $args{primary_key};
1701
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1702
    my $where = delete $args{where};
1703
    
1704
    # Check arguments
1705
    foreach my $name (keys %args) {
1706
        croak qq{"$name" is wrong option } . _subname
1707
          unless $DELETE_AT_ARGS{$name};
1708
    }
1709
    
1710
    # Create where parameter
1711
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1712
    
1713
    return $self->delete(where => $where_param, %args);
1714
}
1715

            
cleanup
Yuki Kimoto authored on 2011-06-08
1716
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1717
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1718
sub update_at {
1719
    my $self = shift;
1720

            
1721
    warn "update_at is DEPRECATED! use update and id option instead";
1722
    
1723
    # Arguments
1724
    my $param;
1725
    $param = shift if @_ % 2;
1726
    my %args = @_;
1727
    my $primary_keys = delete $args{primary_key};
1728
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1729
    my $where = delete $args{where};
1730
    my $p = delete $args{param} || {};
1731
    $param  ||= $p;
1732
    
1733
    # Check arguments
1734
    foreach my $name (keys %args) {
1735
        croak qq{"$name" is wrong option } . _subname
1736
          unless $UPDATE_AT_ARGS{$name};
1737
    }
1738
    
1739
    # Create where parameter
1740
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1741
    
1742
    return $self->update(where => $where_param, param => $param, %args);
1743
}
1744

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1745
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1746
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1747
sub insert_at {
1748
    my $self = shift;
1749
    
1750
    warn "insert_at is DEPRECATED! use insert and id option instead";
1751
    
1752
    # Arguments
1753
    my $param;
1754
    $param = shift if @_ % 2;
1755
    my %args = @_;
1756
    my $primary_key = delete $args{primary_key};
1757
    $primary_key = [$primary_key] unless ref $primary_key;
1758
    my $where = delete $args{where};
1759
    my $p = delete $args{param} || {};
1760
    $param  ||= $p;
1761
    
1762
    # Check arguments
1763
    foreach my $name (keys %args) {
1764
        croak qq{"$name" is wrong option } . _subname
1765
          unless $INSERT_AT_ARGS{$name};
1766
    }
1767
    
1768
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1769
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1770
    $param = $self->merge_param($where_param, $param);
1771
    
1772
    return $self->insert(param => $param, %args);
1773
}
1774

            
added warnings
Yuki Kimoto authored on 2011-06-07
1775
# DEPRECATED!
1776
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1777
    my $self = shift;
1778
    
added warnings
Yuki Kimoto authored on 2011-06-07
1779
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1780
    
1781
    # Merge tag
1782
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1783
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1784
    
1785
    return $self;
1786
}
1787

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

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1798
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1799
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1800
has dbi_options => sub { {} };
1801
has filter_check  => 1;
1802
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1803

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

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

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

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1853
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1854
sub insert_param_tag {
1855
    warn "insert_param_tag is DEPRECATED! " .
1856
         "use insert_param instead!";
1857
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1858
}
1859

            
1860
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1861
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1862
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1863
         "use update_param instead";
1864
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1865
}
cleanup
Yuki Kimoto authored on 2011-03-08
1866
# DEPRECATED!
1867
sub _push_relation {
1868
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1869
    
1870
    if (keys %{$relation || {}}) {
1871
        push @$sql, $need_where ? 'where' : 'and';
1872
        foreach my $rcolumn (keys %$relation) {
1873
            my $table1 = (split (/\./, $rcolumn))[0];
1874
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1875
            push @$tables, ($table1, $table2);
1876
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1877
        }
1878
    }
1879
    pop @$sql if $sql->[-1] eq 'and';    
1880
}
1881

            
1882
# DEPRECATED!
1883
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1884
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1885
    
1886
    if (keys %{$relation || {}}) {
1887
        foreach my $rcolumn (keys %$relation) {
1888
            my $table1 = (split (/\./, $rcolumn))[0];
1889
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1890
            my $table1_exists;
1891
            my $table2_exists;
1892
            foreach my $table (@$tables) {
1893
                $table1_exists = 1 if $table eq $table1;
1894
                $table2_exists = 1 if $table eq $table2;
1895
            }
1896
            unshift @$tables, $table1 unless $table1_exists;
1897
            unshift @$tables, $table2 unless $table2_exists;
1898
        }
1899
    }
1900
}
1901

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1904
=head1 NAME
1905

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1910
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1911
    
1912
    # Connect
1913
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1914
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1915
        user => 'ken',
1916
        password => '!LFKD%$&',
1917
        dbi_option => {mysql_enable_utf8 => 1}
1918
    );
cleanup
yuki-kimoto authored on 2010-08-05
1919

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1920
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1921
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1922
    
1923
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1924
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1925
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1926
    
1927
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1928
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1929

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1979
Named place holder support
1980

            
1981
=item *
1982

            
cleanup
Yuki Kimoto authored on 2011-07-29
1983
Model support
1984

            
1985
=item *
1986

            
1987
Connection manager support
1988

            
1989
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1990

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

            
1995
=item *
1996

            
1997
Filtering by data type or column name(EXPERIMENTAL)
1998

            
1999
=item *
2000

            
2001
Create C<order by> clause flexibly(EXPERIMENTAL)
2002

            
2003
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2004

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2012
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2013
L<DBIx::Custom::Result>,
2014
L<DBIx::Custom::Query>,
2015
L<DBIx::Custom::Where>,
2016
L<DBIx::Custom::Model>,
2017
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2018

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

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

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

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

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

            
2032
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2033
        "dbi:mysql:database=$database",
2034
        $user,
2035
        $password,
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2036
        DBIx::Custom->new->default_dbi_option
2037
    );
2038
    
updated pod
Yuki Kimoto authored on 2011-06-21
2039
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2040

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

            
2044
    my $dbi = DBIx::Custom->connect(
2045
      dsn => $dsn, user => $user, password => $password, connector => 1);
2046
    
2047
    my $connector = $dbi->connector; # DBIx::Connector
2048

            
2049
Note that L<DBIx::Connector> must be installed.
2050

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

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

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

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

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

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

            
2066
=head2 C<default_dbi_option>
2067

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

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

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

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

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

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

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

            
2089
    my $last_sql = $dbi->last_sql;
2090
    $dbi = $dbi->last_sql($last_sql);
2091

            
2092
Get last successed SQL executed by C<execute> method.
2093

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2101
=head2 C<password>
2102

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2123
You can set quote pair.
2124

            
2125
    $dbi->quote('[]');
2126

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

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

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

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

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

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

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

            
2144
    my $separator = $self->separator;
2145
    $dbi = $self->separator($separator);
2146

            
2147
Separator whichi join table and column.
2148
This is used by C<column> and C<mycolumn> method.
2149

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

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

            
2155
Regex matching system table.
2156
this regex match is used by C<each_table> method and C<each_column> method
2157
System table is ignored.
2158
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2159
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2160
The performance is up.
2161

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

            
2164
    my $tag_parse = $dbi->tag_parse(0);
2165
    $dbi = $dbi->tag_parse;
2166

            
2167
Enable DEPRECATED tag parsing functionality, default to 1.
2168
If you want to disable tag parsing functionality, set to 0.
2169

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

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

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

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

            
2179
    my $user_column_info = $dbi->user_column_info;
2180
    $dbi = $dbi->user_column_info($user_column_info);
2181

            
2182
You can set the following data.
2183

            
2184
    [
2185
        {table => 'book', column => 'title', info => {...}},
2186
        {table => 'author', column => 'name', info => {...}}
2187
    ]
2188

            
2189
Usually, you can set return value of C<get_column_info>.
2190

            
2191
    my $user_column_info
2192
      = $dbi->get_column_info(exclude_table => qr/^system/);
2193
    $dbi->user_column_info($user_column_info);
2194

            
2195
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2196
to find column info.
2197

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

            
2200
    my $user_table_info = $dbi->user_table_info;
2201
    $dbi = $dbi->user_table_info($user_table_info);
2202

            
2203
You can set the following data.
2204

            
2205
    [
2206
        {table => 'book', info => {...}},
2207
        {table => 'author', info => {...}}
2208
    ]
2209

            
2210
Usually, you can set return value of C<get_table_info>.
2211

            
2212
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2213
    $dbi->user_table_info($user_table_info);
2214

            
2215
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2216
to find table info.
2217

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2252
Create column clause. The follwoing column clause is created.
2253

            
2254
    book.author as "book.author",
2255
    book.title as "book.title"
2256

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2259
    # Separator is double underbar
2260
    $dbi->separator('__');
2261
    
2262
    book.author as "book__author",
2263
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2264

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2273
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2274
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2275
        user => 'ken',
2276
        password => '!LFKD%$&',
2277
        dbi_option => {mysql_enable_utf8 => 1}
2278
    );
2279

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2286
=head2 C<count> EXPERIMENTAL
2287

            
2288
    my $count = $model->count(table => 'book');
2289

            
2290
Get rows count.
2291

            
2292
Options is same as C<select> method's ones.
2293

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

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

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

            
2307
   $dbi->model('book')->select(...);
2308

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

            
2311
    my $dbh = $dbi->dbh;
2312

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

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

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

            
2320
Execute delete statement.
2321

            
2322
The following opitons are available.
2323

            
2324
=over 4
2325

            
2326
=item C<append>
2327

            
2328
Same as C<select> method's C<append> option.
2329

            
2330
=item C<filter>
2331

            
2332
Same as C<execute> method's C<filter> option.
2333

            
2334
=item C<id>
2335

            
2336
    id => 4
2337
    id => [4, 5]
2338

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

            
2342
    $dbi->delete(
2343
        parimary_key => ['id1', 'id2'],
2344
        id => [4, 5],
2345
        table => 'book',
2346
    );
2347

            
2348
The above is same as the followin one.
2349

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

            
2352
=item C<prefix>
2353

            
2354
    prefix => 'some'
2355

            
2356
prefix before table name section.
2357

            
2358
    delete some from book
2359

            
2360
=item C<query>
2361

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

            
2364
=item C<sqlfilter EXPERIMENTAL>
2365

            
2366
Same as C<execute> method's C<sqlfilter> option.
2367

            
2368
=item C<table>
2369

            
2370
    table => 'book'
2371

            
2372
Table name.
2373

            
2374
=item C<where>
2375

            
2376
Same as C<select> method's C<where> option.
2377

            
2378
=item C<primary_key>
2379

            
2380
See C<id> option.
2381

            
2382
=item C<bind_type>
2383

            
2384
Same as C<execute> method's C<bind_type> option.
2385

            
2386
=item C<type_rule_off> EXPERIMENTAL
2387

            
2388
Same as C<execute> method's C<type_rule_off> option.
2389

            
2390
=item C<type_rule1_off> EXPERIMENTAL
2391

            
2392
    type_rule1_off => 1
2393

            
2394
Same as C<execute> method's C<type_rule1_off> option.
2395

            
2396
=item C<type_rule2_off> EXPERIMENTAL
2397

            
2398
    type_rule2_off => 1
2399

            
2400
Same as C<execute> method's C<type_rule2_off> option.
2401

            
2402
=back
2403

            
2404
=head2 C<delete_all>
2405

            
2406
    $dbi->delete_all(table => $table);
2407

            
2408
Execute delete statement for all rows.
2409
Options is same as C<delete>.
2410

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

            
2413
    $dbi->each_column(
2414
        sub {
2415
            my ($dbi, $table, $column, $column_info) = @_;
2416
            
2417
            my $type = $column_info->{TYPE_NAME};
2418
            
2419
            if ($type eq 'DATE') {
2420
                # ...
2421
            }
2422
        }
2423
    );
2424

            
2425
Iterate all column informations of all table from database.
2426
Argument is callback when one column is found.
2427
Callback receive four arguments, dbi object, table name,
2428
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2429

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

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

            
2440
Iterate all table informationsfrom database.
2441
Argument is callback when one table is found.
2442
Callback receive three arguments, dbi object, table name,
2443
table information.
2444

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2463
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2464
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2465
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2466
    select * from book where title = :title and author like :author
2467
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2468
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2469
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2470

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2474
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2475
    select * from book where :title{=} and :author{like}
2476
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2477
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2478
    select * from where title = ? and author like ?;
2479

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

            
2484
    select * from where title = "aa\\:bb";
2485

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

            
2488
=over 4
2489

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

            
2492
Specify database bind data type.
2493

            
2494
    bind_type => [image => DBI::SQL_BLOB]
2495
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2496

            
2497
This is used to bind parameter by C<bind_param> of statment handle.
2498

            
2499
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2500

            
update pod
Yuki Kimoto authored on 2011-03-13
2501
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2502
    
2503
    filter => {
2504
        title  => sub { uc $_[0] }
2505
        author => sub { uc $_[0] }
2506
    }
update pod
Yuki Kimoto authored on 2011-03-13
2507

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

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

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

            
2526
    query => 1
2527

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

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

            
2537
    my $query;
2538
    foreach my $row (@$rows) {
2539
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2540
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2541
    }
2542

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

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

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

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

            
2563
SQL filter function.
2564

            
2565
    sqlfilter => $code_ref
2566

            
2567
This option is generally for Oracle and SQL Server paging process.
2568
    
2569
    my $limit = sub {
2570
        my ($sql, $count, $offset) = @_;
2571
        
2572
        my $min = $offset + 1;
2573
        my $max = $offset + $count;
2574
        
2575
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2576
        
2577
        return $sql;
2578
    }
2579
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2580
        my $sql = shift;
2581
        return $limit->($sql, 100, 50);
2582
    })
2583

            
updated pod
Yuki Kimoto authored on 2011-06-09
2584
=item C<table>
2585
    
2586
    table => 'author'
2587

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2595
    # Same
2596
    $dbi->execute(
2597
      "select * from book where title = :book.title and author = :book.author",
2598
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2599

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

            
2602
    table_alias => {user => 'hiker'}
2603

            
2604
Table alias. Key is real table name, value is alias table name.
2605
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2606
on alias table name.
2607

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

            
2610
    type_rule_off => 1
2611

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

            
2614
=item C<type_rule1_off> EXPERIMENTAL
2615

            
2616
    type_rule1_off => 1
2617

            
2618
Turn C<into1> type rule off.
2619

            
2620
=item C<type_rule2_off> EXPERIMENTAL
2621

            
2622
    type_rule2_off => 1
2623

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

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

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

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

            
2632
get column infomation except for one which match C<exclude_table> pattern.
2633

            
2634
    [
2635
        {table => 'book', column => 'title', info => {...}},
2636
        {table => 'author', column => 'name' info => {...}}
2637
    ]
2638

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

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

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

            
2645
    [
2646
        {table => 'book', info => {...}},
2647
        {table => 'author', info => {...}}
2648
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2649

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2652
=head2 C<insert>
2653

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

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

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

            
2662
    {date => \"NOW()"}
2663

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

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

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

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

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

            
2674
Same as C<execute> method's C<bind_type> option.
2675

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

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

            
2680
=item C<id>
2681

            
updated document
Yuki Kimoto authored on 2011-06-09
2682
    id => 4
2683
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2684

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2688
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2689
        {title => 'Perl', author => 'Ken'}
2690
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2691
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2692
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2693
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2694

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

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

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

            
2704
    prefix => 'or replace'
2705

            
2706
prefix before table name section
2707

            
2708
    insert or replace into book
2709

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

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

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

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

            
2719
Same as C<execute> method's C<query> option.
2720

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

            
2723
Same as C<execute> method's C<sqlfilter> option.
2724

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

            
2727
    table => 'book'
2728

            
2729
Table name.
2730

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

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

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

            
2737
    type_rule1_off => 1
2738

            
2739
Same as C<execute> method's C<type_rule1_off> option.
2740

            
2741
=item C<type_rule2_off> EXPERIMENTAL
2742

            
2743
    type_rule2_off => 1
2744

            
2745
Same as C<execute> method's C<type_rule2_off> option.
2746

            
update pod
Yuki Kimoto authored on 2011-03-13
2747
=back
2748

            
2749
=over 4
2750

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2766
    lib / MyModel.pm
2767
        / MyModel / book.pm
2768
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2769

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

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

            
2774
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2775
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2776
    
2777
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2778

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2783
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2784
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2785
    
2786
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2787

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2790
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2791
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2792
    
2793
    1;
2794
    
updated pod
Yuki Kimoto authored on 2011-06-21
2795
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2796

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

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

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

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

            
2806
    my $map_param = $dbi->map_param(
2807
        {id => 1, authro => 'Ken', price => 1900},
2808
        'id' => 'book.id',
2809
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2810
        'price' => [
2811
            'book.price', {if => sub { length $_[0] }}
2812
        ]
2813
    );
2814

            
2815
Map paramters to other key and value. First argument is original
2816
parameter. this is hash reference. Rest argument is mapping.
2817
By default, Mapping is done if the value length is not zero.
2818

            
2819
=over 4
2820

            
2821
=item Key mapping
2822

            
2823
    'id' => 'book.id'
2824

            
2825
This is only key mapping. Value is same as original one.
2826

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

            
2829
=item Key and value mapping
2830

            
2831
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2832

            
2833
This is key and value mapping. Frist element of array reference
2834
is mapped key name, second element is code reference to map the value.
2835

            
2836
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2837
      if value length is not zero.
2838

            
2839
=item Condition
2840

            
2841
    'price' => ['book.price', {if => 'exists'}]
2842
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2843
    'price' => ['book.price', {if => sub { defined shift }}]
2844

            
2845
If you need condition, you can sepecify it. this is code reference
2846
or 'exists'. By default, condition is the following one.
2847

            
2848
    sub { defined $_[0] && length $_[0] }
2849

            
2850
=back
2851

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

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

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

            
2858
    {key1 => [1, 1], key2 => 2}
2859

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

            
2862
    $dbi->method(
2863
        update_or_insert => sub {
2864
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2865
            
2866
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2867
        },
2868
        find_or_create   => sub {
2869
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2870
            
2871
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2872
        }
2873
    );
2874

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

            
2877
    $dbi->update_or_insert;
2878
    $dbi->find_or_create;
2879

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2938
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2939
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2940
            date => sub { ... },
2941
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2942
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2943
        into2 => {
2944
            date => sub { ... },
2945
            datetime => sub { ... }
2946
        },
2947
        from1 => {
2948
            # DATE
2949
            9 => sub { ... },
2950
            # DATETIME or TIMESTAMP
2951
            11 => sub { ... },
2952
        }
2953
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2954
            # DATE
2955
            9 => sub { ... },
2956
            # DATETIME or TIMESTAMP
2957
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2958
        }
2959
    );
2960

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2976
=over 4
2977

            
2978
=item 1. column name
2979

            
2980
    issue_date
2981
    issue_datetime
2982

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

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

            
2987
    book.issue_date
2988
    book.issue_datetime
2989

            
2990
=back
2991

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

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

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

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

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

            
3004
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3005
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3006
            [qw/DATE DATETIME/] => sub { ... },
3007
        ],
3008
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3009

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3012
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3013
        table  => 'book',
3014
        column => ['author', 'title'],
3015
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3016
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3017
    
updated document
Yuki Kimoto authored on 2011-06-09
3018
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3019

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

            
3022
=over 4
3023

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

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

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

            
3030
=item C<bind_type>
3031

            
3032
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3033
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3034
=item C<column>
3035
    
updated document
Yuki Kimoto authored on 2011-06-09
3036
    column => 'author'
3037
    column => ['author', 'title']
3038

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3047
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3048
        {book => [qw/author title/]},
3049
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3050
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3051

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

            
3054
    book.author as "book.author",
3055
    book.title as "book.title",
3056
    person.name as "person.name",
3057
    person.age as "person.age"
3058

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

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

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

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

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

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

            
3074
=item C<id>
3075

            
3076
    id => 4
3077
    id => [4, 5]
3078

            
3079
ID corresponding to C<primary_key>.
3080
You can select rows by C<id> and C<primary_key>.
3081

            
3082
    $dbi->select(
3083
        parimary_key => ['id1', 'id2'],
3084
        id => [4, 5],
3085
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3086
    );
3087

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3090
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3091
        where => {id1 => 4, id2 => 5},
3092
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3093
    );
3094
    
updated document
Yuki Kimoto authored on 2011-06-09
3095
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3096

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

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

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

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

            
3109
    prefix => 'SQL_CALC_FOUND_ROWS'
3110

            
3111
Prefix of column cluase
3112

            
3113
    select SQL_CALC_FOUND_ROWS title, author from book;
3114

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

            
3117
    join => [
3118
        'left outer join company on book.company_id = company_id',
3119
        'left outer join location on company.location_id = location.id'
3120
    ]
3121
        
3122
Join clause. If column cluase or where clause contain table name like "company.name",
3123
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3124

            
3125
    $dbi->select(
3126
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3127
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3128
        where => {'company.name' => 'Orange'},
3129
        join => [
3130
            'left outer join company on book.company_id = company.id',
3131
            'left outer join location on company.location_id = location.id'
3132
        ]
3133
    );
3134

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3138
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3139
    from book
3140
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3141
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3142

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

            
3146
    $dbi->select(
3147
        table => 'book',
3148
        column => ['company.location_id as location_id'],
3149
        where => {'company.name' => 'Orange'},
3150
        join => [
3151
            {
3152
                clause => 'left outer join location on company.location_id = location.id',
3153
                table => ['company', 'location']
3154
            }
3155
        ]
3156
    );
3157

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3177
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3178

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

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

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

            
3185
    type_rule1_off => 1
3186

            
3187
Same as C<execute> method's C<type_rule1_off> option.
3188

            
3189
=item C<type_rule2_off> EXPERIMENTAL
3190

            
3191
    type_rule2_off => 1
3192

            
3193
Same as C<execute> method's C<type_rule2_off> option.
3194

            
updated document
Yuki Kimoto authored on 2011-06-09
3195
=item C<where>
3196
    
3197
    # Hash refrence
3198
    where => {author => 'Ken', 'title' => 'Perl'}
3199
    
3200
    # DBIx::Custom::Where object
3201
    where => $dbi->where(
3202
        clause => ['and', 'author = :author', 'title like :title'],
3203
        param  => {author => 'Ken', title => '%Perl%'}
3204
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3205
    
3206
    # Array reference 1 (array reference, hash referenc). same as above
3207
    where => [
3208
        ['and', 'author = :author', 'title like :title'],
3209
        {author => 'Ken', title => '%Perl%'}
3210
    ];    
3211
    
3212
    # Array reference 2 (String, hash reference)
3213
    where => [
3214
        'title like :title',
3215
        {title => '%Perl%'}
3216
    ]
3217
    
3218
    # String
3219
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3220

            
updated document
Yuki Kimoto authored on 2011-06-09
3221
Where clause.
3222
    
improved pod
Yuki Kimoto authored on 2011-04-19
3223
=item C<wrap> EXPERIMENTAL
3224

            
3225
Wrap statement. This is array reference.
3226

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

            
3229
This option is for Oracle and SQL Server paging process.
3230

            
update pod
Yuki Kimoto authored on 2011-03-12
3231
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3232

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

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

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

            
3239
If you want to set constant value to row data, use scalar reference
3240
as parameter value.
3241

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3246
=over 4
3247

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

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

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

            
3254
Same as C<execute> method's C<bind_type> option.
3255

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3262
    id => 4
3263
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3264

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3268
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3269
        {title => 'Perl', author => 'Ken'}
3270
        parimary_key => ['id1', 'id2'],
3271
        id => [4, 5],
3272
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3273
    );
update pod
Yuki Kimoto authored on 2011-03-13
3274

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3277
    $dbi->update(
3278
        {title => 'Perl', author => 'Ken'}
3279
        where => {id1 => 4, id2 => 5},
3280
        table => 'book'
3281
    );
update pod
Yuki Kimoto authored on 2011-03-13
3282

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

            
3285
    prefix => 'or replace'
3286

            
3287
prefix before table name section
3288

            
3289
    update or replace book
3290

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

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

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

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

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

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

            
3304
Same as C<execute> method's C<sqlfilter> option.
3305

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

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

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

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

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

            
3316
=item C<type_rule1_off> EXPERIMENTAL
3317

            
3318
    type_rule1_off => 1
3319

            
3320
Same as C<execute> method's C<type_rule1_off> option.
3321

            
3322
=item C<type_rule2_off> EXPERIMENTAL
3323

            
3324
    type_rule2_off => 1
3325

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

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

            
3330
Same as C<select> method's C<where> option.
3331

            
updated pod
Yuki Kimoto authored on 2011-06-08
3332
=back
update pod
Yuki Kimoto authored on 2011-03-13
3333

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

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

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

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

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

            
3345
Create update parameter tag.
3346

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

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

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

            
3356
Create a new L<DBIx::Custom::Where> object.
3357

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

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

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3365
=head1 ENVIRONMENTAL VARIABLES
added environment variable D...
Yuki Kimoto authored on 2011-04-02
3366

            
3367
=head2 C<DBIX_CUSTOM_DEBUG>
3368

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

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

            
3374
    $dbi->show_datatype($table);
3375

            
3376
Show data type of the columns of specified table.
3377

            
3378
    book
3379
    title: 5
3380
    issue_date: 91
3381

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

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

            
3386
    $dbi->show_tables;
3387

            
3388
Show tables.
3389

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

            
3392
    $dbi->show_typename($table);
3393

            
3394
Show type name of the columns of specified table.
3395

            
3396
    book
3397
    title: varchar
3398
    issue_date: date
3399

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

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

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

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

            
3408
L<DBIx::Custom>
3409

            
3410
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3411
    data_source # will be removed at 2017/1/1
3412
    dbi_options # will be removed at 2017/1/1
3413
    filter_check # will be removed at 2017/1/1
3414
    reserved_word_quote # will be removed at 2017/1/1
3415
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3416
    
3417
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3418
    create_query # will be removed at 2017/1/1
3419
    apply_filter # will be removed at 2017/1/1
3420
    select_at # will be removed at 2017/1/1
3421
    delete_at # will be removed at 2017/1/1
3422
    update_at # will be removed at 2017/1/1
3423
    insert_at # will be removed at 2017/1/1
3424
    register_tag # will be removed at 2017/1/1
3425
    default_bind_filter # will be removed at 2017/1/1
3426
    default_fetch_filter # will be removed at 2017/1/1
3427
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3428
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3429
    register_tag_processor # will be removed at 2017/1/1
3430
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3431
    
3432
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3433
    select method relation option # will be removed at 2017/1/1
3434
    select method param option # will be removed at 2017/1/1
3435
    select method column option [COLUMN, as => ALIAS] format
3436
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3437
    
3438
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3439
    execute("select * from {= title}"); # execute method's
3440
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3441
                                        # will be removed at 2017/1/1
3442
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3443

            
3444
L<DBIx::Custom::Model>
3445

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3446
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3447
    filter # will be removed at 2017/1/1
3448
    name # will be removed at 2017/1/1
3449
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3450

            
3451
L<DBIx::Custom::Query>
3452
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3453
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3454
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3455
    table # will be removed at 2017/1/1
3456
    filters # will be removed at 2017/1/1
3457
    
3458
    # Methods
3459
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3460

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

            
3475
L<DBIx::Custom::Result>
3476
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3477
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3478
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479
    
3480
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3481
    end_filter # will be removed at 2017/1/1
3482
    remove_end_filter # will be removed at 2017/1/1
3483
    remove_filter # will be removed at 2017/1/1
3484
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3485

            
3486
L<DBIx::Custom::Tag>
3487

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

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

            
3492
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3493
except for attribute method.
3494
You can check all DEPRECATED functionalities by document.
3495
DEPRECATED functionality is removed after five years,
3496
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
3497
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3498

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

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

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

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

            
3507
C<< <kimoto.yuki at gmail.com> >>
3508

            
3509
L<http://github.com/yuki-kimoto/DBIx-Custom>
3510

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3511
=head1 AUTHOR
3512

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

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

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

            
3519
This program is free software; you can redistribute it and/or modify it
3520
under the same terms as Perl itself.
3521

            
3522
=cut