DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3362 lines | 87.151kb
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 execute m...
Yuki Kimoto authored on 2011-08-14
4
our $VERSION = '0.1715';
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
263
sub DESTROY { }
added helper method
yuki-kimoto authored on 2010-10-17
264

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

            
299
sub each_column {
300
    my ($self, $cb) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
301

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
302
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
303
    
added SQL Server test
Yuki Kimoto authored on 2011-08-14
304
    my %tables;
305
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
306
    # Iterate all tables
307
    my $sth_tables = $self->dbh->table_info;
308
    while (my $table_info = $sth_tables->fetchrow_hashref) {
309
        # Table
310
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
311
        next if defined $re && $table =~ /$re/;
added SQL Server test
Yuki Kimoto authored on 2011-08-14
312
        $tables{$table}++;
313
    }
314

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
329
sub each_table {
330
    my ($self, $cb) = @_;
331
    
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
332
    my $re = $self->exclude_table;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
333
    
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
334
    # Iterate all tables
335
    my $sth_tables = $self->dbh->table_info;
336
    while (my $table_info = $sth_tables->fetchrow_hashref) {
337
        
338
        # Table
339
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
340
        next if defined $re && $table =~ /$re/;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
341
        $self->$cb($table, $table_info);
342
    }
343
}
344

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

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

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

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

            
516
        return $result;
517
    }
cleanup
Yuki Kimoto authored on 2011-04-02
518
    
519
    # Not select statement
520
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
521
}
522

            
523
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
524
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
525
    
cleanup
yuki-kimoto authored on 2010-10-17
526
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
527
    my $param;
528
    $param = shift if @_ % 2;
529
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
530
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
531
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
532
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
533
    my $p = delete $args{param} || {};
534
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
535
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
536
    my $id = delete $args{id};
537
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
538
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
539
          "must be specified when id is specified " . _subname
540
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
541
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
542
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
543

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
544
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
545
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
546
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
547
        $param = $self->merge_param($id_param, $param);
548
    }
549

            
cleanup
Yuki Kimoto authored on 2011-04-02
550
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
551
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
552
    push @sql, "insert";
553
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
554
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
555
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
556
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
557
    
558
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
559
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
560
}
561

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
562
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
563
    my ($self, $param) = @_;
564
    
cleanup
Yuki Kimoto authored on 2011-04-02
565
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
566
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
567
    my @columns;
568
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
569
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
570
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
571
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
572
        my $column_quote = $self->_q($column);
573
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
574
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
575
        push @placeholders, ref $param->{$column} eq 'SCALAR'
576
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
577
    }
578
    
cleanup
Yuki Kimoto authored on 2011-04-02
579
    return '(' . join(', ', @columns) . ') ' . 'values ' .
580
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
581
}
582

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
583
sub include_model {
584
    my ($self, $name_space, $model_infos) = @_;
585
    
cleanup
Yuki Kimoto authored on 2011-04-02
586
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
587
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
588
    
589
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
590
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
591

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
592
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
593
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
594
          if $name_space =~ /[^\w:]/;
595
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
596
        croak qq{Name space module "$name_space.pm" is needed. $@ }
597
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
598
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
599
        
600
        # Search model modules
601
        my $path = $INC{"$name_space.pm"};
602
        $path =~ s/\.pm$//;
603
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
604
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
605
        $model_infos = [];
606
        while (my $module = readdir $dh) {
607
            push @$model_infos, $module
608
              if $module =~ s/\.pm$//;
609
        }
610
        close $dh;
611
    }
612
    
cleanup
Yuki Kimoto authored on 2011-04-02
613
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
614
    foreach my $model_info (@$model_infos) {
615
        
cleanup
Yuki Kimoto authored on 2011-04-02
616
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
617
        my $model_class;
618
        my $model_name;
619
        my $model_table;
620
        if (ref $model_info eq 'HASH') {
621
            $model_class = $model_info->{class};
622
            $model_name  = $model_info->{name};
623
            $model_table = $model_info->{table};
624
            
625
            $model_name  ||= $model_class;
626
            $model_table ||= $model_name;
627
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
628
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
629
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
630
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
631
          if $mclass =~ /[^\w:]/;
632
        unless ($mclass->can('isa')) {
633
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
634
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
635
        }
636
        
cleanup
Yuki Kimoto authored on 2011-04-02
637
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
638
        my $args = {};
639
        $args->{model_class} = $mclass if $mclass;
640
        $args->{name}        = $model_name if $model_name;
641
        $args->{table}       = $model_table if $model_table;
642
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
643
    }
644
    
645
    return $self;
646
}
647

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
648
sub map_param {
649
    my $self = shift;
650
    my $param = shift;
651
    my %map = @_;
652
    
653
    # Mapping
654
    my $map_param = {};
655
    foreach my $key (keys %map) {
656
        my $value_cb;
657
        my $condition;
658
        my $map_key;
659
        
660
        # Get mapping information
661
        if (ref $map{$key} eq 'ARRAY') {
662
            foreach my $some (@{$map{$key}}) {
663
                $map_key = $some unless ref $some;
664
                $condition = $some->{if} if ref $some eq 'HASH';
665
                $value_cb = $some if ref $some eq 'CODE';
666
            }
667
        }
668
        else {
669
            $map_key = $map{$key};
670
        }
671
        $value_cb ||= sub { $_[0] };
672
        $condition ||= sub { defined $_[0] && length $_[0] };
673

            
674
        # Map parameter
675
        my $value;
676
        if (ref $condition eq 'CODE') {
677
            $map_param->{$map_key} = $value_cb->($param->{$key})
678
              if $condition->($param->{$key});
679
        }
680
        elsif ($condition eq 'exists') {
681
            $map_param->{$map_key} = $value_cb->($param->{$key})
682
              if exists $param->{$key};
683
        }
684
        else { croak qq/Condition must be code reference or "exists" / . _subname }
685
    }
686
    
687
    return $map_param;
688
}
689

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
714
sub method {
715
    my $self = shift;
716
    
cleanup
Yuki Kimoto authored on 2011-04-02
717
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
718
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
719
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
720
    
721
    return $self;
722
}
723

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
724
sub model {
725
    my ($self, $name, $model) = @_;
726
    
cleanup
Yuki Kimoto authored on 2011-04-02
727
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
728
    if ($model) {
729
        $self->models->{$name} = $model;
730
        return $self;
731
    }
732
    
733
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
734
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
735
      unless $self->models->{$name};
736
    
cleanup
Yuki Kimoto authored on 2011-04-02
737
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
738
    return $self->models->{$name};
739
}
740

            
cleanup
Yuki Kimoto authored on 2011-03-21
741
sub mycolumn {
742
    my ($self, $table, $columns) = @_;
743
    
cleanup
Yuki Kimoto authored on 2011-04-02
744
    # Create column clause
745
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
746
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
747
    push @column, $self->_q($table) . "." . $self->_q($_) .
748
      " as " . $self->_q($_)
749
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
750
    
751
    return join (', ', @column);
752
}
753

            
added dbi_options attribute
kimoto authored on 2010-12-20
754
sub new {
755
    my $self = shift->SUPER::new(@_);
756
    
cleanup
Yuki Kimoto authored on 2011-04-02
757
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
758
    my @attrs = keys %$self;
759
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
760
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
761
          unless $self->can($attr);
762
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
763

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
764
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
765
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
766
        '?'     => \&DBIx::Custom::Tag::placeholder,
767
        '='     => \&DBIx::Custom::Tag::equal,
768
        '<>'    => \&DBIx::Custom::Tag::not_equal,
769
        '>'     => \&DBIx::Custom::Tag::greater_than,
770
        '<'     => \&DBIx::Custom::Tag::lower_than,
771
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
772
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
773
        'like'  => \&DBIx::Custom::Tag::like,
774
        'in'    => \&DBIx::Custom::Tag::in,
775
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
776
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
777
    };
778
    
779
    return $self;
780
}
781

            
782
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
783
sub not_exists { $not_exists }
784

            
785
sub order {
786
    my $self = shift;
787
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
788
}
789

            
cleanup
yuki-kimoto authored on 2010-10-17
790
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
791
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
792
    
793
    # Register filter
794
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
795
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
796
    
cleanup
Yuki Kimoto authored on 2011-04-02
797
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
798
}
packaging one directory
yuki-kimoto authored on 2009-11-16
799

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
879
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
880
    unshift @$tables,
881
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
882
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
883
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
884
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
885
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
886
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
887
        $where_clause = "where " . $where->[0];
888
        $where_param = $where->[1];
889
    }
890
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
891
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
892
        $where_param = keys %$where_param
893
                     ? $self->merge_param($where_param, $where->param)
894
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
895
        
896
        # String where
897
        $where_clause = $where->to_string;
898
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
899
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
900
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
901
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
902
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
903
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
904
    # Push join
905
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
906
    
cleanup
Yuki Kimoto authored on 2011-03-09
907
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
908
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
909
    
cleanup
Yuki Kimoto authored on 2011-03-08
910
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
911
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
912
    
cleanup
Yuki Kimoto authored on 2011-04-02
913
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
914
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
915
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
916
    # Wrap
917
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
918
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
919
          unless ref $wrap eq 'ARRAY';
920
        unshift @sql, $wrap->[0];
921
        push @sql, $wrap->[1];
922
    }
923
    
cleanup
Yuki Kimoto authored on 2011-01-27
924
    # SQL
925
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
926
    
927
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
928
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
929
    
930
    return $result;
931
}
932

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
933
sub setup_model {
934
    my $self = shift;
935
    
cleanup
Yuki Kimoto authored on 2011-04-02
936
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
937
    $self->each_column(
938
        sub {
939
            my ($self, $table, $column, $column_info) = @_;
940
            if (my $model = $self->models->{$table}) {
941
                push @{$model->columns}, $column;
942
            }
943
        }
944
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
945
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
946
}
947

            
update pod
Yuki Kimoto authored on 2011-08-10
948
sub show_datatype {
949
    my ($self, $table) = @_;
950
    croak "Table name must be specified" unless defined $table;
951
    print "$table\n";
952
    
953
    my $result = $self->select(table => $table, where => "'0' <> '0'");
954
    my $sth = $result->sth;
955

            
956
    my $columns = $sth->{NAME};
957
    my $data_types = $sth->{TYPE};
958
    
959
    for (my $i = 0; $i < @$columns; $i++) {
960
        my $column = $columns->[$i];
961
        my $data_type = $data_types->[$i];
962
        print "$column: $data_type\n";
963
    }
964
}
965

            
966
sub show_typename {
967
    my ($self, $t) = @_;
968
    croak "Table name must be specified" unless defined $t;
969
    print "$t\n";
970
    
971
    $self->each_column(sub {
972
        my ($self, $table, $column, $infos) = @_;
973
        return unless $table eq $t;
974
        my $typename = $infos->{TYPE_NAME};
975
        print "$column: $typename\n";
976
    });
977
    
978
    return $self;
979
}
980

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
981
sub type_rule {
982
    my $self = shift;
983
    
984
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
985
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
986
        
987
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
988
        foreach my $i (1 .. 2) {
989
            my $into = "into$i";
990
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
991
            $self->{type_rule} = $type_rule;
992
            $self->{"_$into"} = {};
993
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
994
                croak qq{type name of $into section must be lower case}
995
                  if $type_name =~ /[A-Z]/;
996
            }
997
            $self->each_column(sub {
998
                my ($dbi, $table, $column, $column_info) = @_;
999
                
1000
                my $type_name = lc $column_info->{TYPE_NAME};
1001
                if ($type_rule->{$into} &&
1002
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1003
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1004
                    return unless exists $type_rule->{$into}->{$type_name};
1005
                    if  (defined $filter && ref $filter ne 'CODE') 
1006
                    {
1007
                        my $fname = $filter;
1008
                        croak qq{Filter "$fname" is not registered" } . _subname
1009
                          unless exists $self->filters->{$fname};
1010
                        
1011
                        $filter = $self->filters->{$fname};
1012
                    }
1013

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1014
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1015
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1016
                }
1017
            });
1018
        }
1019

            
1020
        # From
1021
        foreach my $i (1 .. 2) {
1022
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1023
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1024
                croak qq{data type of from$i section must be lower case or number}
1025
                  if $data_type =~ /[A-Z]/;
1026
                my $fname = $type_rule->{"from$i"}{$data_type};
1027
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1028
                    croak qq{Filter "$fname" is not registered" } . _subname
1029
                      unless exists $self->filters->{$fname};
1030
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1031
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1032
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1033
            }
1034
        }
1035
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1036
        return $self;
1037
    }
1038
    
1039
    return $self->{type_rule} || {};
1040
}
1041

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1045
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1046
    my $param;
1047
    $param = shift if @_ % 2;
1048
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1049
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1050
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1051
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1052
    my $p = delete $args{param} || {};
1053
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1054
    my $where = delete $args{where} || {};
1055
    my $where_param = delete $args{where_param} || {};
1056
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1057
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1058
    my $id = delete $args{id};
1059
    my $primary_key = delete $args{primary_key};
1060
    croak "update method primary_key option " .
1061
          "must be specified when id is specified " . _subname
1062
      if defined $id && !defined $primary_key;
1063
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1064
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1065

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

            
1069
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1070
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1071
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1072
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1073
        $where_clause = "where " . $where->[0];
1074
        $where_param = $where->[1];
1075
    }
1076
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1077
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1078
        $where_param = keys %$where_param
1079
                     ? $self->merge_param($where_param, $where->param)
1080
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1081
        
1082
        # String where
1083
        $where_clause = $where->to_string;
1084
    }
1085
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1086
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1087
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1088
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1089
    # Merge param
1090
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1091
    
cleanup
Yuki Kimoto authored on 2011-04-02
1092
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1093
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1094
    push @sql, "update";
1095
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1096
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1097
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1098
    
cleanup
Yuki Kimoto authored on 2011-01-27
1099
    # SQL
1100
    my $sql = join(' ', @sql);
1101
    
cleanup
yuki-kimoto authored on 2010-10-17
1102
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1103
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1104
}
1105

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1108
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1109
    my ($self, $param, $opt) = @_;
1110
    
cleanup
Yuki Kimoto authored on 2011-04-02
1111
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1112
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1113
    $tag = "set $tag" unless $opt->{no_set};
1114

            
cleanup
Yuki Kimoto authored on 2011-04-02
1115
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1116
}
1117

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1120
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1121
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1122
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1123
    
updated pod
Yuki Kimoto authored on 2011-06-21
1124
    # Cache
1125
    my $cache = $self->cache;
1126
    
1127
    # Query
1128
    my $query;
1129
    
1130
    # Get cached query
1131
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1132
        
updated pod
Yuki Kimoto authored on 2011-06-21
1133
        # Get query
1134
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1135
        
updated pod
Yuki Kimoto authored on 2011-06-21
1136
        # Create query
1137
        if ($q) {
1138
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1139
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1140
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1141
    }
1142
    
1143
    # Create query
1144
    unless ($query) {
1145

            
1146
        # Create query
1147
        my $builder = $self->query_builder;
1148
        $query = $builder->build_query($source);
1149

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

            
1156
        # Save query to cache
1157
        $self->cache_method->(
1158
            $self, $source,
1159
            {
1160
                sql     => $query->sql, 
1161
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1162
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1163
            }
1164
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1165
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1166

            
1167
    # Filter SQL
1168
    if ($sqlfilter) {
1169
        my $sql = $query->sql;
1170
        $sql =~ s/\s*;$//;
1171
        $sql = $sqlfilter->($sql);
1172
        $sql .= ';';
1173
        $query->sql($sql);
1174
    }
1175
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1176
    # Save sql
1177
    $self->last_sql($query->sql);
1178
    
updated pod
Yuki Kimoto authored on 2011-06-21
1179
    # Prepare statement handle
1180
    my $sth;
1181
    eval { $sth = $self->dbh->prepare($query->{sql})};
1182
    
1183
    if ($@) {
1184
        $self->_croak($@, qq{. Following SQL is executed.\n}
1185
                        . qq{$query->{sql}\n} . _subname);
1186
    }
1187
    
1188
    # Set statement handle
1189
    $query->sth($sth);
1190
    
1191
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1192
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1193
    
1194
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1195
}
1196

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1247
sub _create_param_from_id {
1248
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1249
    
cleanup
Yuki Kimoto authored on 2011-06-08
1250
    # Create parameter
1251
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1252
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1253
        $id = [$id] unless ref $id;
1254
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1255
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1256
          unless !ref $id || ref $id eq 'ARRAY';
1257
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1258
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1259
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1260
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1261
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1262
        }
1263
    }
1264
    
cleanup
Yuki Kimoto authored on 2011-06-08
1265
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1266
}
1267

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1268
sub _connect {
1269
    my $self = shift;
1270
    
1271
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1272
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1273
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1274
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1275
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1276
    croak qq{"dsn" must be specified } . _subname
1277
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1278
    my $user        = $self->user;
1279
    my $password    = $self->password;
1280
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1281
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1282
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1283
    
1284
    # Connect
1285
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1286
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1287
        $user,
1288
        $password,
1289
        {
1290
            %{$self->default_dbi_option},
1291
            %$dbi_option
1292
        }
1293
    )};
1294
    
1295
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1296
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1297
    
1298
    return $dbh;
1299
}
1300

            
cleanup
yuki-kimoto authored on 2010-10-17
1301
sub _croak {
1302
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1303
    
1304
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1305
    $append ||= "";
1306
    
1307
    # Verbose
1308
    if ($Carp::Verbose) { croak $error }
1309
    
1310
    # Not verbose
1311
    else {
1312
        
1313
        # Remove line and module infromation
1314
        my $at_pos = rindex($error, ' at ');
1315
        $error = substr($error, 0, $at_pos);
1316
        $error =~ s/\s+$//;
1317
        croak "$error$append";
1318
    }
1319
}
1320

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1321
sub _need_tables {
1322
    my ($self, $tree, $need_tables, $tables) = @_;
1323
    
cleanup
Yuki Kimoto authored on 2011-04-02
1324
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1325
    foreach my $table (@$tables) {
1326
        if ($tree->{$table}) {
1327
            $need_tables->{$table} = 1;
1328
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1329
        }
1330
    }
1331
}
1332

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1333
sub _push_join {
1334
    my ($self, $sql, $join, $join_tables) = @_;
1335
    
cleanup
Yuki Kimoto authored on 2011-04-02
1336
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1337
    return unless @$join;
1338
    
cleanup
Yuki Kimoto authored on 2011-04-02
1339
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1340
    my $tree = {};
1341
    for (my $i = 0; $i < @$join; $i++) {
1342
        
cleanup
Yuki Kimoto authored on 2011-07-28
1343
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1344
        my $join_clause;;
1345
        my $option;
1346
        if (ref $join->[$i] eq 'HASH') {
1347
            $join_clause = $join->[$i]->{clause};
1348
            $option = {table => $join->[$i]->{table}};
1349
        }
1350
        else {
1351
            $join_clause = $join->[$i];
1352
            $option = {};
1353
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1354

            
1355
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1356
        my $table1;
1357
        my $table2;
1358
        if (my $table = $option->{table}) {
1359
            $table1 = $table->[0];
1360
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1361
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1362
        else {
1363
            my $q = $self->_quote;
1364
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1365
            $j_clause =~ s/'.+?'//g;
1366
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1367
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1368
            my $c = $self->safety_character;
1369
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1370
            if ($j_clause =~ $join_re) {
1371
                $table1 = $1;
1372
                $table2 = $2;
1373
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1374
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1375
        croak qq{join clause must have two table name after "on" keyword. } .
1376
              qq{"$join_clause" is passed }  . _subname
1377
          unless defined $table1 && defined $table2;
1378
        croak qq{right side table of "$join_clause" must be unique }
1379
            . _subname
1380
          if exists $tree->{$table2};
1381
        croak qq{Same table "$table1" is specified} . _subname
1382
          if $table1 eq $table2;
1383
        $tree->{$table2}
1384
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1385
    }
1386
    
cleanup
Yuki Kimoto authored on 2011-04-02
1387
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1388
    my $need_tables = {};
1389
    $self->_need_tables($tree, $need_tables, $join_tables);
1390
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1391
    
1392
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1393
    foreach my $need_table (@need_tables) {
1394
        push @$sql, $tree->{$need_table}{join};
1395
    }
1396
}
cleanup
Yuki Kimoto authored on 2011-03-08
1397

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1398
sub _quote {
1399
    my $self = shift;
1400
    
1401
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1402
         : defined $self->quote ? $self->quote
1403
         : '';
1404
}
1405

            
cleanup
Yuki Kimoto authored on 2011-07-29
1406
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1407
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1408
    
1409
    my $quote = $self->_quote;
1410
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1411
    my $p;
1412
    if (defined $quote && length $quote > 1) {
1413
        $p = substr($quote, 1, 1);
1414
    }
1415
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1416
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1417
    if ($quotemeta) {
1418
        $q = quotemeta($q);
1419
        $p = quotemeta($p);
1420
    }
1421
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1422
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1423
}
1424

            
cleanup
Yuki Kimoto authored on 2011-04-02
1425
sub _remove_duplicate_table {
1426
    my ($self, $tables, $main_table) = @_;
1427
    
1428
    # Remove duplicate table
1429
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1430
    delete $tables{$main_table} if $main_table;
1431
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1432
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1433
    if (my $q = $self->_quote) {
1434
        $q = quotemeta($q);
1435
        $_ =~ s/[$q]//g for @$new_tables;
1436
    }
1437

            
1438
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1439
}
1440

            
cleanup
Yuki Kimoto authored on 2011-04-02
1441
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1442
    my ($self, $source) = @_;
1443
    
cleanup
Yuki Kimoto authored on 2011-04-02
1444
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1445
    my $tables = [];
1446
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1447
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1448
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1449
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1450
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1451
    while ($source =~ /$table_re/g) {
1452
        push @$tables, $1;
1453
    }
1454
    
1455
    return $tables;
1456
}
1457

            
cleanup
Yuki Kimoto authored on 2011-04-02
1458
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1459
    my ($self, $where) = @_;
1460
    
cleanup
Yuki Kimoto authored on 2011-04-02
1461
    my $obj;
1462
    
1463
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1464
    if (ref $where eq 'HASH') {
1465
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1466
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1467
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1468
            my $table;
1469
            my $c;
1470
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1471
                $table = $1;
1472
                $c = $2;
1473
            }
1474
            
1475
            my $table_quote;
1476
            $table_quote = $self->_q($table) if defined $table;
1477
            my $column_quote = $self->_q($c);
1478
            $column_quote = $table_quote . '.' . $column_quote
1479
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1480
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1481
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1482
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1483
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1484
    
1485
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1486
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1487
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1488
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1489
    
updated pod
Yuki Kimoto authored on 2011-06-21
1490
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1491
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1492
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1493
            clause => $where->[0],
1494
            param  => $where->[1]
1495
        );
1496
    }
1497
    
cleanup
Yuki Kimoto authored on 2011-04-02
1498
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1499
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1500
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1501
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1502
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1503
    
cleanup
Yuki Kimoto authored on 2011-04-02
1504
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1505
}
1506

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

            
1510
    # Initialize filters
1511
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1512
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1513
    $self->{filter}{out} ||= {};
1514
    $self->{filter}{in} ||= {};
1515
    $self->{filter}{end} ||= {};
1516
    
1517
    # Usage
1518
    my $usage = "Usage: \$dbi->apply_filter(" .
1519
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1520
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1521
    
1522
    # Apply filter
1523
    for (my $i = 0; $i < @cinfos; $i += 2) {
1524
        
1525
        # Column
1526
        my $column = $cinfos[$i];
1527
        if (ref $column eq 'ARRAY') {
1528
            foreach my $c (@$column) {
1529
                push @cinfos, $c, $cinfos[$i + 1];
1530
            }
1531
            next;
1532
        }
1533
        
1534
        # Filter infomation
1535
        my $finfo = $cinfos[$i + 1] || {};
1536
        croak "$usage (table: $table) " . _subname
1537
          unless  ref $finfo eq 'HASH';
1538
        foreach my $ftype (keys %$finfo) {
1539
            croak "$usage (table: $table) " . _subname
1540
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1541
        }
1542
        
1543
        # Set filters
1544
        foreach my $way (qw/in out end/) {
1545
        
1546
            # Filter
1547
            my $filter = $finfo->{$way};
1548
            
1549
            # Filter state
1550
            my $state = !exists $finfo->{$way} ? 'not_exists'
1551
                      : !defined $filter        ? 'not_defined'
1552
                      : ref $filter eq 'CODE'   ? 'code'
1553
                      : 'name';
1554
            
1555
            # Filter is not exists
1556
            next if $state eq 'not_exists';
1557
            
1558
            # Check filter name
1559
            croak qq{Filter "$filter" is not registered } . _subname
1560
              if  $state eq 'name'
1561
               && ! exists $self->filters->{$filter};
1562
            
1563
            # Set filter
1564
            my $f = $state eq 'not_defined' ? undef
1565
                  : $state eq 'code'        ? $filter
1566
                  : $self->filters->{$filter};
1567
            $self->{filter}{$way}{$table}{$column} = $f;
1568
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1569
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1570
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1571
        }
1572
    }
1573
    
1574
    return $self;
1575
}
1576

            
1577
# DEPRECATED!
1578
sub create_query {
1579
    warn "create_query is DEPRECATED! use query option of each method";
1580
    shift->_create_query(@_);
1581
}
1582

            
cleanup
Yuki Kimoto authored on 2011-06-13
1583
# DEPRECATED!
1584
sub apply_filter {
1585
    my $self = shift;
1586
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1587
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1588
    return $self->_apply_filter(@_);
1589
}
1590

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1598
    # Arguments
1599
    my $primary_keys = delete $args{primary_key};
1600
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1601
    my $where = delete $args{where};
1602
    my $param = delete $args{param};
1603
    
1604
    # Check arguments
1605
    foreach my $name (keys %args) {
1606
        croak qq{"$name" is wrong option } . _subname
1607
          unless $SELECT_AT_ARGS{$name};
1608
    }
1609
    
1610
    # Table
1611
    croak qq{"table" option must be specified } . _subname
1612
      unless $args{table};
1613
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1614
    
1615
    # Create where parameter
1616
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1617
    
1618
    return $self->select(where => $where_param, %args);
1619
}
1620

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

            
1626
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1627
    
1628
    # Arguments
1629
    my $primary_keys = delete $args{primary_key};
1630
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1631
    my $where = delete $args{where};
1632
    
1633
    # Check arguments
1634
    foreach my $name (keys %args) {
1635
        croak qq{"$name" is wrong option } . _subname
1636
          unless $DELETE_AT_ARGS{$name};
1637
    }
1638
    
1639
    # Create where parameter
1640
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1641
    
1642
    return $self->delete(where => $where_param, %args);
1643
}
1644

            
cleanup
Yuki Kimoto authored on 2011-06-08
1645
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1646
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1647
sub update_at {
1648
    my $self = shift;
1649

            
1650
    warn "update_at is DEPRECATED! use update and id option instead";
1651
    
1652
    # Arguments
1653
    my $param;
1654
    $param = shift if @_ % 2;
1655
    my %args = @_;
1656
    my $primary_keys = delete $args{primary_key};
1657
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1658
    my $where = delete $args{where};
1659
    my $p = delete $args{param} || {};
1660
    $param  ||= $p;
1661
    
1662
    # Check arguments
1663
    foreach my $name (keys %args) {
1664
        croak qq{"$name" is wrong option } . _subname
1665
          unless $UPDATE_AT_ARGS{$name};
1666
    }
1667
    
1668
    # Create where parameter
1669
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1670
    
1671
    return $self->update(where => $where_param, param => $param, %args);
1672
}
1673

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1674
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1675
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1676
sub insert_at {
1677
    my $self = shift;
1678
    
1679
    warn "insert_at is DEPRECATED! use insert and id option instead";
1680
    
1681
    # Arguments
1682
    my $param;
1683
    $param = shift if @_ % 2;
1684
    my %args = @_;
1685
    my $primary_key = delete $args{primary_key};
1686
    $primary_key = [$primary_key] unless ref $primary_key;
1687
    my $where = delete $args{where};
1688
    my $p = delete $args{param} || {};
1689
    $param  ||= $p;
1690
    
1691
    # Check arguments
1692
    foreach my $name (keys %args) {
1693
        croak qq{"$name" is wrong option } . _subname
1694
          unless $INSERT_AT_ARGS{$name};
1695
    }
1696
    
1697
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1698
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1699
    $param = $self->merge_param($where_param, $param);
1700
    
1701
    return $self->insert(param => $param, %args);
1702
}
1703

            
added warnings
Yuki Kimoto authored on 2011-06-07
1704
# DEPRECATED!
1705
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1706
    my $self = shift;
1707
    
added warnings
Yuki Kimoto authored on 2011-06-07
1708
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1709
    
1710
    # Merge tag
1711
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1712
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1713
    
1714
    return $self;
1715
}
1716

            
1717
# DEPRECATED!
1718
sub register_tag_processor {
1719
    my $self = shift;
1720
    warn "register_tag_processor is DEPRECATED!";
1721
    # Merge tag
1722
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1723
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1724
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1725
}
1726

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1727
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1728
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1729
has dbi_options => sub { {} };
1730
has filter_check  => 1;
1731
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1732

            
cleanup
Yuki Kimoto authored on 2011-01-25
1733
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1734
sub default_bind_filter {
1735
    my $self = shift;
1736
    
cleanup
Yuki Kimoto authored on 2011-06-13
1737
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1738
    
cleanup
Yuki Kimoto authored on 2011-01-12
1739
    if (@_) {
1740
        my $fname = $_[0];
1741
        
1742
        if (@_ && !$fname) {
1743
            $self->{default_out_filter} = undef;
1744
        }
1745
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1746
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1747
              unless exists $self->filters->{$fname};
1748
        
1749
            $self->{default_out_filter} = $self->filters->{$fname};
1750
        }
1751
        return $self;
1752
    }
1753
    
1754
    return $self->{default_out_filter};
1755
}
1756

            
cleanup
Yuki Kimoto authored on 2011-01-25
1757
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1758
sub default_fetch_filter {
1759
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1760

            
cleanup
Yuki Kimoto authored on 2011-06-13
1761
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1762
    
1763
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1764
        my $fname = $_[0];
1765

            
cleanup
Yuki Kimoto authored on 2011-01-12
1766
        if (@_ && !$fname) {
1767
            $self->{default_in_filter} = undef;
1768
        }
1769
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1770
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1771
              unless exists $self->filters->{$fname};
1772
        
1773
            $self->{default_in_filter} = $self->filters->{$fname};
1774
        }
1775
        
1776
        return $self;
1777
    }
1778
    
many changed
Yuki Kimoto authored on 2011-01-23
1779
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1780
}
1781

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1782
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1783
sub insert_param_tag {
1784
    warn "insert_param_tag is DEPRECATED! " .
1785
         "use insert_param instead!";
1786
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1787
}
1788

            
1789
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1790
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1791
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1792
         "use update_param instead";
1793
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1794
}
cleanup
Yuki Kimoto authored on 2011-03-08
1795
# DEPRECATED!
1796
sub _push_relation {
1797
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1798
    
1799
    if (keys %{$relation || {}}) {
1800
        push @$sql, $need_where ? 'where' : 'and';
1801
        foreach my $rcolumn (keys %$relation) {
1802
            my $table1 = (split (/\./, $rcolumn))[0];
1803
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1804
            push @$tables, ($table1, $table2);
1805
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1806
        }
1807
    }
1808
    pop @$sql if $sql->[-1] eq 'and';    
1809
}
1810

            
1811
# DEPRECATED!
1812
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1813
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1814
    
1815
    if (keys %{$relation || {}}) {
1816
        foreach my $rcolumn (keys %$relation) {
1817
            my $table1 = (split (/\./, $rcolumn))[0];
1818
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1819
            my $table1_exists;
1820
            my $table2_exists;
1821
            foreach my $table (@$tables) {
1822
                $table1_exists = 1 if $table eq $table1;
1823
                $table2_exists = 1 if $table eq $table2;
1824
            }
1825
            unshift @$tables, $table1 unless $table1_exists;
1826
            unshift @$tables, $table2 unless $table2_exists;
1827
        }
1828
    }
1829
}
1830

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1833
=head1 NAME
1834

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

            
1837
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1838

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1839
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1840
    
1841
    # Connect
1842
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1843
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1844
        user => 'ken',
1845
        password => '!LFKD%$&',
1846
        dbi_option => {mysql_enable_utf8 => 1}
1847
    );
cleanup
yuki-kimoto authored on 2010-08-05
1848

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1849
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1850
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1851
    
1852
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1853
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1854
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1855
    
1856
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1857
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1858

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1863
    # Select, more complex
1864
    my $result = $dbi->select(
1865
        table  => 'book',
1866
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1867
            {book => [qw/title author/]},
1868
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1869
        ],
1870
        where  => {'book.author' => 'Ken'},
1871
        join => ['left outer join company on book.company_id = company.id'],
1872
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1873
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1874
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1875
    # Fetch
1876
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1877
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1878
    }
1879
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1880
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1881
    while (my $row = $result->fetch_hash) {
1882
        
1883
    }
1884
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1885
    # Execute SQL with parameter.
1886
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1887
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1888
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1889
    );
1890
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1891
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1892

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1908
Named place holder support
1909

            
1910
=item *
1911

            
cleanup
Yuki Kimoto authored on 2011-07-29
1912
Model support
1913

            
1914
=item *
1915

            
1916
Connection manager support
1917

            
1918
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1919

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

            
1924
=item *
1925

            
1926
Filtering by data type or column name(EXPERIMENTAL)
1927

            
1928
=item *
1929

            
1930
Create C<order by> clause flexibly(EXPERIMENTAL)
1931

            
1932
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1933

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1941
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1942
L<DBIx::Custom::Result>,
1943
L<DBIx::Custom::Query>,
1944
L<DBIx::Custom::Where>,
1945
L<DBIx::Custom::Model>,
1946
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1947

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

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

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

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

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

            
1961
    my $connector = DBIx::Connector->new(
1962
        "dbi:mysql:database=$DATABASE",
1963
        $USER,
1964
        $PASSWORD,
1965
        DBIx::Custom->new->default_dbi_option
1966
    );
1967
    
updated pod
Yuki Kimoto authored on 2011-06-21
1968
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1969

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

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

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

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

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

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

            
1985
=head2 C<default_dbi_option>
1986

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1993
    {
1994
        RaiseError => 1,
1995
        PrintError => 0,
1996
        AutoCommit => 1,
1997
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1998

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

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

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

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

            
2008
    my $last_sql = $dbi->last_sql;
2009
    $dbi = $dbi->last_sql($last_sql);
2010

            
2011
Get last successed SQL executed by C<execute> method.
2012

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2020
=head2 C<password>
2021

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2042
You can set quote pair.
2043

            
2044
    $dbi->quote('[]');
2045

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

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

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

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

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

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

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

            
2063
    my $separator = $self->separator;
2064
    $dbi = $self->separator($separator);
2065

            
2066
Separator whichi join table and column.
2067
This is used by C<column> and C<mycolumn> method.
2068

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

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

            
2074
Regex matching system table.
2075
this regex match is used by C<each_table> method and C<each_column> method
2076
System table is ignored.
2077
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2078
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2079
The performance is up.
2080

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

            
2083
    my $tag_parse = $dbi->tag_parse(0);
2084
    $dbi = $dbi->tag_parse;
2085

            
2086
Enable DEPRECATED tag parsing functionality, default to 1.
2087
If you want to disable tag parsing functionality, set to 0.
2088

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2130
Create column clause. The follwoing column clause is created.
2131

            
2132
    book.author as "book.author",
2133
    book.title as "book.title"
2134

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2137
    # Separator is double underbar
2138
    $dbi->separator('__');
2139
    
2140
    book.author as "book__author",
2141
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2142

            
cleanup
Yuki Kimoto authored on 2011-06-13
2143
    # Separator is hyphen
2144
    $dbi->separator('-');
2145
    
2146
    book.author as "book-author",
2147
    book.title as "book-title"
2148
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2149
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2150

            
update pod
Yuki Kimoto authored on 2011-03-13
2151
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2152
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2153
        user => 'ken',
2154
        password => '!LFKD%$&',
2155
        dbi_option => {mysql_enable_utf8 => 1}
2156
    );
2157

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2166
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2167
        table => 'book',
2168
        primary_key => 'id',
2169
        join => [
2170
            'inner join company on book.comparny_id = company.id'
2171
        ],
2172
    );
2173

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

            
2177
   $dbi->model('book')->select(...);
2178

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

            
2181
    my $dbh = $dbi->dbh;
2182

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

            
2186
=head2 C<each_column>
2187

            
2188
    $dbi->each_column(
2189
        sub {
2190
            my ($dbi, $table, $column, $column_info) = @_;
2191
            
2192
            my $type = $column_info->{TYPE_NAME};
2193
            
2194
            if ($type eq 'DATE') {
2195
                # ...
2196
            }
2197
        }
2198
    );
2199

            
2200
Iterate all column informations of all table from database.
2201
Argument is callback when one column is found.
2202
Callback receive four arguments, dbi object, table name,
2203
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2204

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

            
2207
    $dbi->each_table(
2208
        sub {
2209
            my ($dbi, $table, $table_info) = @_;
2210
            
2211
            my $table_name = $table_info->{TABLE_NAME};
2212
        }
2213
    );
2214

            
2215
Iterate all table informationsfrom database.
2216
Argument is callback when one table is found.
2217
Callback receive three arguments, dbi object, table name,
2218
table information.
2219

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

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

            
2227
    my $result = $dbi->execute(
2228
      "select * from book where title = :book.title and author like :book.author",
2229
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2230
    );
2231

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2238
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2239
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2240
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2241
    select * from book where title = :title and author like :author
2242
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2243
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2244
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2245

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2249
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2250
    select * from book where :title{=} and :author{like}
2251
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2252
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2253
    select * from where title = ? and author like ?;
2254

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

            
2259
    select * from where title = "aa\\:bb";
2260

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

            
2263
=over 4
2264

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

            
2267
Specify database bind data type.
2268

            
2269
    bind_type => [image => DBI::SQL_BLOB]
2270
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2271

            
2272
This is used to bind parameter by C<bind_param> of statment handle.
2273

            
2274
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2275

            
update pod
Yuki Kimoto authored on 2011-03-13
2276
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2277
    
2278
    filter => {
2279
        title  => sub { uc $_[0] }
2280
        author => sub { uc $_[0] }
2281
    }
update pod
Yuki Kimoto authored on 2011-03-13
2282

            
updated pod
Yuki Kimoto authored on 2011-06-09
2283
    # Filter name
2284
    filter => {
2285
        title  => 'upper_case',
2286
        author => 'upper_case'
2287
    }
2288
        
2289
    # At once
2290
    filter => [
2291
        [qw/title author/]  => sub { uc $_[0] }
2292
    ]
2293

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

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

            
2301
    query => 1
2302

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

            
2306
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2307
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2308
    my $columns = $query->columns;
2309
    
2310
If you want to execute SQL fast, you can do the following way.
2311

            
2312
    my $query;
2313
    foreach my $row (@$rows) {
2314
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2315
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2316
    }
2317

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

            
2321
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
2322
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2323
    
2324
    my $query;
2325
    my $sth;
2326
    foreach my $row (@$rows) {
2327
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2328
      $sth ||= $query->sth;
2329
      $sth->execute(map { $row->{$_} } sort keys %$row);
2330
    }
2331

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

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

            
2338
SQL filter function.
2339

            
2340
    sqlfilter => $code_ref
2341

            
2342
This option is generally for Oracle and SQL Server paging process.
2343
    
2344
    my $limit = sub {
2345
        my ($sql, $count, $offset) = @_;
2346
        
2347
        my $min = $offset + 1;
2348
        my $max = $offset + $count;
2349
        
2350
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2351
        
2352
        return $sql;
2353
    }
2354
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2355
        my $sql = shift;
2356
        return $limit->($sql, 100, 50);
2357
    })
2358

            
updated pod
Yuki Kimoto authored on 2011-06-09
2359
=item C<table>
2360
    
2361
    table => 'author'
2362

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2370
    # Same
2371
    $dbi->execute(
2372
      "select * from book where title = :book.title and author = :book.author",
2373
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2374

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

            
2377
    table_alias => {user => 'hiker'}
2378

            
2379
Table alias. Key is real table name, value is alias table name.
2380
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2381
on alias table name.
2382

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

            
2385
    type_rule_off => 1
2386

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

            
2389
=item C<type_rule1_off> EXPERIMENTAL
2390

            
2391
    type_rule1_off => 1
2392

            
2393
Turn C<into1> type rule off.
2394

            
2395
=item C<type_rule2_off> EXPERIMENTAL
2396

            
2397
    type_rule2_off => 1
2398

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

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

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2403
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
2404

            
update pod
Yuki Kimoto authored on 2011-03-13
2405
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2406

            
updated document
Yuki Kimoto authored on 2011-06-09
2407
Execute delete statement.
update pod
Yuki Kimoto authored on 2011-03-13
2408

            
updated document
Yuki Kimoto authored on 2011-06-09
2409
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2410

            
update pod
Yuki Kimoto authored on 2011-03-13
2411
=over 4
2412

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2415
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2416

            
2417
=item C<filter>
2418

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2419
Same as C<execute> method's C<filter> option.
update pod
Yuki Kimoto authored on 2011-03-13
2420

            
updated document
Yuki Kimoto authored on 2011-06-09
2421
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2422

            
updated document
Yuki Kimoto authored on 2011-06-09
2423
    id => 4
2424
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2425

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2429
    $dbi->delete(
2430
        parimary_key => ['id1', 'id2'],
2431
        id => [4, 5],
2432
        table => 'book',
2433
    );
update pod
Yuki Kimoto authored on 2011-03-13
2434

            
updated document
Yuki Kimoto authored on 2011-06-09
2435
The above is same as the followin one.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2436

            
updated document
Yuki Kimoto authored on 2011-06-09
2437
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2438

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

            
2441
    prefix => 'some'
2442

            
2443
prefix before table name section.
2444

            
2445
    delete some from book
2446

            
updated document
Yuki Kimoto authored on 2011-06-09
2447
=item C<query>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2448

            
updated document
Yuki Kimoto authored on 2011-06-09
2449
Same as C<execute> method's C<query> option.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2450

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

            
2453
Same as C<execute> method's C<sqlfilter> option.
2454

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2459
Table name.
2460

            
updated document
Yuki Kimoto authored on 2011-06-09
2461
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2462

            
updated document
Yuki Kimoto authored on 2011-06-09
2463
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2464

            
updated pod
Yuki Kimoto authored on 2011-06-08
2465
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2466

            
updated pod
Yuki Kimoto authored on 2011-06-08
2467
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2468

            
updated pod
Yuki Kimoto authored on 2011-06-21
2469
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2470

            
updated pod
Yuki Kimoto authored on 2011-06-21
2471
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2472

            
2473
=item C<type_rule_off> EXPERIMENTAL
2474

            
2475
Same as C<execute> method's C<type_rule_off> option.
2476

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

            
2479
    type_rule1_off => 1
2480

            
2481
Same as C<execute> method's C<type_rule1_off> option.
2482

            
2483
=item C<type_rule2_off> EXPERIMENTAL
2484

            
2485
    type_rule2_off => 1
2486

            
2487
Same as C<execute> method's C<type_rule2_off> option.
2488

            
updated pod
Yuki Kimoto authored on 2011-06-08
2489
=back
update pod
Yuki Kimoto authored on 2011-03-13
2490

            
updated pod
Yuki Kimoto authored on 2011-06-08
2491
=head2 C<delete_all>
update pod
Yuki Kimoto authored on 2011-03-13
2492

            
updated pod
Yuki Kimoto authored on 2011-06-08
2493
    $dbi->delete_all(table => $table);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2494

            
updated document
Yuki Kimoto authored on 2011-06-09
2495
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
2496
Options is same as C<delete>.
update pod
Yuki Kimoto authored on 2011-03-13
2497

            
cleanup
yuki-kimoto authored on 2010-10-17
2498
=head2 C<insert>
2499

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

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

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

            
2508
    {date => \"NOW()"}
2509

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

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

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

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

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

            
2520
Same as C<execute> method's C<bind_type> option.
2521

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

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

            
2526
=item C<id>
2527

            
updated document
Yuki Kimoto authored on 2011-06-09
2528
    id => 4
2529
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2530

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2534
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2535
        {title => 'Perl', author => 'Ken'}
2536
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2537
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2538
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2539
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2540

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

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

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

            
2550
    prefix => 'or replace'
2551

            
2552
prefix before table name section
2553

            
2554
    insert or replace into book
2555

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

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

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

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

            
2565
Same as C<execute> method's C<query> option.
2566

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

            
2569
Same as C<execute> method's C<sqlfilter> option.
2570

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

            
2573
    table => 'book'
2574

            
2575
Table name.
2576

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

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

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

            
2583
    type_rule1_off => 1
2584

            
2585
Same as C<execute> method's C<type_rule1_off> option.
2586

            
2587
=item C<type_rule2_off> EXPERIMENTAL
2588

            
2589
    type_rule2_off => 1
2590

            
2591
Same as C<execute> method's C<type_rule2_off> option.
2592

            
update pod
Yuki Kimoto authored on 2011-03-13
2593
=back
2594

            
2595
=over 4
2596

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2612
    lib / MyModel.pm
2613
        / MyModel / book.pm
2614
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2615

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

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

            
2620
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2621
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2622
    
2623
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2624

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2629
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2630
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2631
    
2632
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2633

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2636
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2637
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2638
    
2639
    1;
2640
    
updated pod
Yuki Kimoto authored on 2011-06-21
2641
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2642

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

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

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

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

            
2652
    my $map_param = $dbi->map_param(
2653
        {id => 1, authro => 'Ken', price => 1900},
2654
        'id' => 'book.id',
2655
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2656
        'price' => [
2657
            'book.price', {if => sub { length $_[0] }}
2658
        ]
2659
    );
2660

            
2661
Map paramters to other key and value. First argument is original
2662
parameter. this is hash reference. Rest argument is mapping.
2663
By default, Mapping is done if the value length is not zero.
2664

            
2665
=over 4
2666

            
2667
=item Key mapping
2668

            
2669
    'id' => 'book.id'
2670

            
2671
This is only key mapping. Value is same as original one.
2672

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

            
2675
=item Key and value mapping
2676

            
2677
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2678

            
2679
This is key and value mapping. Frist element of array reference
2680
is mapped key name, second element is code reference to map the value.
2681

            
2682
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2683
      if value length is not zero.
2684

            
2685
=item Condition
2686

            
2687
    'price' => ['book.price', {if => 'exists'}]
2688
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2689
    'price' => ['book.price', {if => sub { defined shift }}]
2690

            
2691
If you need condition, you can sepecify it. this is code reference
2692
or 'exists'. By default, condition is the following one.
2693

            
2694
    sub { defined $_[0] && length $_[0] }
2695

            
2696
=back
2697

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

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

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

            
2704
    {key1 => [1, 1], key2 => 2}
2705

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

            
2708
    $dbi->method(
2709
        update_or_insert => sub {
2710
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2711
            
2712
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2713
        },
2714
        find_or_create   => sub {
2715
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2716
            
2717
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2718
        }
2719
    );
2720

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

            
2723
    $dbi->update_or_insert;
2724
    $dbi->find_or_create;
2725

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

            
2728
    my $model = $dbi->model('book');
2729

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

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

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

            
2736
Create column clause for myself. The follwoing column clause is created.
2737

            
2738
    book.author as author,
2739
    book.title as title
2740

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2743
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2744
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2745
        user => 'ken',
2746
        password => '!LFKD%$&',
2747
        dbi_option => {mysql_enable_utf8 => 1}
2748
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2749

            
2750
Create a new L<DBIx::Custom> object.
2751

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

            
2754
    my $not_exists = $dbi->not_exists;
2755

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

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

            
2761
    my $order = $dbi->order;
2762

            
2763
Create a new L<DBIx::Custom::Order> object.
2764

            
cleanup
yuki-kimoto authored on 2010-10-17
2765
=head2 C<register_filter>
2766

            
update pod
Yuki Kimoto authored on 2011-03-13
2767
    $dbi->register_filter(
2768
        # Time::Piece object to database DATE format
2769
        tp_to_date => sub {
2770
            my $tp = shift;
2771
            return $tp->strftime('%Y-%m-%d');
2772
        },
2773
        # database DATE format to Time::Piece object
2774
        date_to_tp => sub {
2775
           my $date = shift;
2776
           return Time::Piece->strptime($date, '%Y-%m-%d');
2777
        }
2778
    );
cleanup
yuki-kimoto authored on 2010-10-17
2779
    
update pod
Yuki Kimoto authored on 2011-03-13
2780
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2781

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

            
2784
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2785
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2786
            date => sub { ... },
2787
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2788
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2789
        into2 => {
2790
            date => sub { ... },
2791
            datetime => sub { ... }
2792
        },
2793
        from1 => {
2794
            # DATE
2795
            9 => sub { ... },
2796
            # DATETIME or TIMESTAMP
2797
            11 => sub { ... },
2798
        }
2799
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2800
            # DATE
2801
            9 => sub { ... },
2802
            # DATETIME or TIMESTAMP
2803
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2804
        }
2805
    );
2806

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2822
=over 4
2823

            
2824
=item 1. column name
2825

            
2826
    issue_date
2827
    issue_datetime
2828

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

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

            
2833
    book.issue_date
2834
    book.issue_datetime
2835

            
2836
=back
2837

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

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

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

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

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

            
2850
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2851
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2852
            [qw/DATE DATETIME/] => sub { ... },
2853
        ],
2854
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2855

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2858
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2859
        table  => 'book',
2860
        column => ['author', 'title'],
2861
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2862
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2863
    
updated document
Yuki Kimoto authored on 2011-06-09
2864
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2865

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

            
2868
=over 4
2869

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

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

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

            
2876
=item C<bind_type>
2877

            
2878
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2879
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2880
=item C<column>
2881
    
updated document
Yuki Kimoto authored on 2011-06-09
2882
    column => 'author'
2883
    column => ['author', 'title']
2884

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2893
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2894
        {book => [qw/author title/]},
2895
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2896
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2897

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

            
2900
    book.author as "book.author",
2901
    book.title as "book.title",
2902
    person.name as "person.name",
2903
    person.age as "person.age"
2904

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

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

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

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

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

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

            
2920
=item C<id>
2921

            
2922
    id => 4
2923
    id => [4, 5]
2924

            
2925
ID corresponding to C<primary_key>.
2926
You can select rows by C<id> and C<primary_key>.
2927

            
2928
    $dbi->select(
2929
        parimary_key => ['id1', 'id2'],
2930
        id => [4, 5],
2931
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2932
    );
2933

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2936
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2937
        where => {id1 => 4, id2 => 5},
2938
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2939
    );
2940
    
updated document
Yuki Kimoto authored on 2011-06-09
2941
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2942

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

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

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

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

            
2955
    prefix => 'SQL_CALC_FOUND_ROWS'
2956

            
2957
Prefix of column cluase
2958

            
2959
    select SQL_CALC_FOUND_ROWS title, author from book;
2960

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

            
2963
    join => [
2964
        'left outer join company on book.company_id = company_id',
2965
        'left outer join location on company.location_id = location.id'
2966
    ]
2967
        
2968
Join clause. If column cluase or where clause contain table name like "company.name",
2969
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2970

            
2971
    $dbi->select(
2972
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2973
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2974
        where => {'company.name' => 'Orange'},
2975
        join => [
2976
            'left outer join company on book.company_id = company.id',
2977
            'left outer join location on company.location_id = location.id'
2978
        ]
2979
    );
2980

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2984
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2985
    from book
2986
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2987
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2988

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

            
2992
    $dbi->select(
2993
        table => 'book',
2994
        column => ['company.location_id as location_id'],
2995
        where => {'company.name' => 'Orange'},
2996
        join => [
2997
            {
2998
                clause => 'left outer join location on company.location_id = location.id',
2999
                table => ['company', 'location']
3000
            }
3001
        ]
3002
    );
3003

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3023
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3024

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

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

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

            
3031
    type_rule1_off => 1
3032

            
3033
Same as C<execute> method's C<type_rule1_off> option.
3034

            
3035
=item C<type_rule2_off> EXPERIMENTAL
3036

            
3037
    type_rule2_off => 1
3038

            
3039
Same as C<execute> method's C<type_rule2_off> option.
3040

            
updated document
Yuki Kimoto authored on 2011-06-09
3041
=item C<where>
3042
    
3043
    # Hash refrence
3044
    where => {author => 'Ken', 'title' => 'Perl'}
3045
    
3046
    # DBIx::Custom::Where object
3047
    where => $dbi->where(
3048
        clause => ['and', 'author = :author', 'title like :title'],
3049
        param  => {author => 'Ken', title => '%Perl%'}
3050
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3051
    
3052
    # Array reference 1 (array reference, hash referenc). same as above
3053
    where => [
3054
        ['and', 'author = :author', 'title like :title'],
3055
        {author => 'Ken', title => '%Perl%'}
3056
    ];    
3057
    
3058
    # Array reference 2 (String, hash reference)
3059
    where => [
3060
        'title like :title',
3061
        {title => '%Perl%'}
3062
    ]
3063
    
3064
    # String
3065
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3066

            
updated document
Yuki Kimoto authored on 2011-06-09
3067
Where clause.
3068
    
improved pod
Yuki Kimoto authored on 2011-04-19
3069
=item C<wrap> EXPERIMENTAL
3070

            
3071
Wrap statement. This is array reference.
3072

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

            
3075
This option is for Oracle and SQL Server paging process.
3076

            
update pod
Yuki Kimoto authored on 2011-03-12
3077
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3078

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

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

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

            
3085
If you want to set constant value to row data, use scalar reference
3086
as parameter value.
3087

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3092
=over 4
3093

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

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

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

            
3100
Same as C<execute> method's C<bind_type> option.
3101

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3108
    id => 4
3109
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3110

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3114
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3115
        {title => 'Perl', author => 'Ken'}
3116
        parimary_key => ['id1', 'id2'],
3117
        id => [4, 5],
3118
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3119
    );
update pod
Yuki Kimoto authored on 2011-03-13
3120

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3123
    $dbi->update(
3124
        {title => 'Perl', author => 'Ken'}
3125
        where => {id1 => 4, id2 => 5},
3126
        table => 'book'
3127
    );
update pod
Yuki Kimoto authored on 2011-03-13
3128

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

            
3131
    prefix => 'or replace'
3132

            
3133
prefix before table name section
3134

            
3135
    update or replace book
3136

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

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

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

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

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

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

            
3150
Same as C<execute> method's C<sqlfilter> option.
3151

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

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

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

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

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

            
3162
=item C<type_rule1_off> EXPERIMENTAL
3163

            
3164
    type_rule1_off => 1
3165

            
3166
Same as C<execute> method's C<type_rule1_off> option.
3167

            
3168
=item C<type_rule2_off> EXPERIMENTAL
3169

            
3170
    type_rule2_off => 1
3171

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

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

            
3176
Same as C<select> method's C<where> option.
3177

            
updated pod
Yuki Kimoto authored on 2011-06-08
3178
=back
update pod
Yuki Kimoto authored on 2011-03-13
3179

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

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

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

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

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

            
3191
Create update parameter tag.
3192

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

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

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

            
3202
Create a new L<DBIx::Custom::Where> object.
3203

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

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

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

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

            
3213
=head2 C<DBIX_CUSTOM_DEBUG>
3214

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

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

            
3220
    $dbi->show_datatype($table);
3221

            
3222
Show data type of the columns of specified table.
3223

            
3224
    book
3225
    title: 5
3226
    issue_date: 91
3227

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

            
3230
=head2 C<show_typename EXPERIMENTAL>
3231

            
3232
    $dbi->show_typename($table);
3233

            
3234
Show type name of the columns of specified table.
3235

            
3236
    book
3237
    title: varchar
3238
    issue_date: date
3239

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

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

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

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

            
3248
L<DBIx::Custom>
3249

            
3250
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3251
    data_source # will be removed at 2017/1/1
3252
    dbi_options # will be removed at 2017/1/1
3253
    filter_check # will be removed at 2017/1/1
3254
    reserved_word_quote # will be removed at 2017/1/1
3255
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3256
    
3257
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3258
    create_query # will be removed at 2017/1/1
3259
    apply_filter # will be removed at 2017/1/1
3260
    select_at # will be removed at 2017/1/1
3261
    delete_at # will be removed at 2017/1/1
3262
    update_at # will be removed at 2017/1/1
3263
    insert_at # will be removed at 2017/1/1
3264
    register_tag # will be removed at 2017/1/1
3265
    default_bind_filter # will be removed at 2017/1/1
3266
    default_fetch_filter # will be removed at 2017/1/1
3267
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3268
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3269
    register_tag_processor # will be removed at 2017/1/1
3270
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3271
    
3272
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3273
    select method relation option # will be removed at 2017/1/1
3274
    select method param option # will be removed at 2017/1/1
3275
    select method column option [COLUMN, as => ALIAS] format
3276
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3277
    
3278
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3279
    execute("select * from {= title}"); # execute method's
3280
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3281
                                        # will be removed at 2017/1/1
3282
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3283

            
3284
L<DBIx::Custom::Model>
3285

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3286
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3287
    filter # will be removed at 2017/1/1
3288
    name # will be removed at 2017/1/1
3289
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3290

            
3291
L<DBIx::Custom::Query>
3292
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3293
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3294
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3295
    table # will be removed at 2017/1/1
3296
    filters # will be removed at 2017/1/1
3297
    
3298
    # Methods
3299
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3300

            
3301
L<DBIx::Custom::QueryBuilder>
3302
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3303
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3304
    tags # will be removed at 2017/1/1
3305
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3306
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3307
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3308
    register_tag # will be removed at 2017/1/1
3309
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3310
    
3311
    # Others
3312
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3313
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3314

            
3315
L<DBIx::Custom::Result>
3316
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3317
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3318
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3319
    
3320
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3321
    end_filter # will be removed at 2017/1/1
3322
    remove_end_filter # will be removed at 2017/1/1
3323
    remove_filter # will be removed at 2017/1/1
3324
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3325

            
3326
L<DBIx::Custom::Tag>
3327

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

            
3330
=head1 BACKWORD COMPATIBLE POLICY
3331

            
3332
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3333
except for attribute method.
3334
You can check all DEPRECATED functionalities by document.
3335
DEPRECATED functionality is removed after five years,
3336
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
3337
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3338

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

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

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

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

            
3347
C<< <kimoto.yuki at gmail.com> >>
3348

            
3349
L<http://github.com/yuki-kimoto/DBIx-Custom>
3350

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3351
=head1 AUTHOR
3352

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

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

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

            
3359
This program is free software; you can redistribute it and/or modify it
3360
under the same terms as Perl itself.
3361

            
3362
=cut